Bug #348267 - Documentation navigation arrows missing
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / histogram / ParentHistogramCanvasControlListener.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
3 *
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
8 *
9 * Contributors:
10 * 2010-06-20 Yuriy Vashchuk - Initial API and implementation
11 *
12 * Modifications:
13 * 2010-07-16 Yuriy Vashchuk - Base class simplification.
14 *******************************************************************************/
15
16 package org.eclipse.linuxtools.lttng.ui.views.histogram;
17
18 import org.eclipse.swt.events.ControlEvent;
19
20 /**
21 * <b><u>ParentHistogramCanvasControlListener</u></b>
22 * <p>
23 * Implementation of a ControlListener for the need of the ParentHistogramCanvas
24 * <p>
25 */
26 public class ParentHistogramCanvasControlListener extends HistogramCanvasControlListener {
27
28 private ParentHistogramCanvas ourCanvas = null;
29
30 /**
31 * ParentHistogramCanvasControlListenerl constructor
32 *
33 * @param newCanvas Related canvas
34 */
35 public ParentHistogramCanvasControlListener(ParentHistogramCanvas newCanvas) {
36 ourCanvas = newCanvas;
37 }
38
39
40 /**
41 * Method called when the canvas is resized.<p>
42 *
43 * We need to tell the content that the canvas size changed and to recenter the windows
44 *
45 * @param event The control event generated by the resize.
46 */
47 @Override
48 public void controlResized(ControlEvent event) {
49
50 if ( (ourCanvas != null) && (ourCanvas.getHistogramContent() != null) ) {
51 int newSize = ourCanvas.getSize().x;
52 int oldSize = ourCanvas.getHistogramContent().getCanvasWindowSize();
53
54 // Set the new canvas size
55 ourCanvas.getHistogramContent().setCanvasWindowSize(newSize);
56
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);
65 }
66 }
67 }
This page took 0.030881 seconds and 5 git commands to generate.