1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * 2010-06-20 Yuriy Vashchuk - Initial API and implementation
13 * 2010-07-16 Yuriy Vashchuk - Base class simplification.
14 *******************************************************************************/
16 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.histogram
;
18 import org
.eclipse
.swt
.events
.ControlEvent
;
21 * <b><u>ParentHistogramCanvasControlListener</u></b>
23 * Implementation of a ControlListener for the need of the ParentHistogramCanvas
26 public class ParentHistogramCanvasControlListener
extends HistogramCanvasControlListener
{
28 private ParentHistogramCanvas ourCanvas
= null;
31 * ParentHistogramCanvasControlListenerl constructor
33 * @param newCanvas Related canvas
35 public ParentHistogramCanvasControlListener(ParentHistogramCanvas newCanvas
) {
36 ourCanvas
= newCanvas
;
41 * Method called when the canvas is resized.<p>
43 * We need to tell the content that the canvas size changed and to recenter the windows
45 * @param event The control event generated by the resize.
48 public void controlResized(ControlEvent event
) {
50 if ( (ourCanvas
!= null) && (ourCanvas
.getHistogramContent() != null) ) {
51 int newSize
= ourCanvas
.getSize().x
;
52 int oldSize
= ourCanvas
.getHistogramContent().getCanvasWindowSize();
54 // Set the new canvas size
55 ourCanvas
.getHistogramContent().setCanvasWindowSize(newSize
);
57 // Try to recenter to window at the same place it was
58 // Note : this is a best hope approach and is not intended to be precise;
59 // the idea is to avoid issuing a (maybe) long request fo the selection window;
60 // There WILL be slight discrepancy between the "window values" (timestamp, etc...) showed
61 // and what it really points to. The user should reclick by himself to refresh it.
62 int oldWindowCenter
= ourCanvas
.getCurrentWindow().getWindowXPositionCenter();
63 int newWindowCenter
= (int)Math
.ceil((double)newSize
* ((double)oldWindowCenter
/ (double)oldSize
));
64 ourCanvas
.setWindowCenterPosition(newWindowCenter
);