Commit | Line | Data |
---|---|---|
3e9fdb8b FC |
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 | |
f05aabed FC |
11 | * |
12 | * Modifications: | |
13 | * 2010-07-16 Yuriy Vashchuk - Base class simplification. | |
3e9fdb8b FC |
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 { | |
f05aabed FC |
27 | |
28 | private ParentHistogramCanvas ourCanvas = null; | |
3e9fdb8b FC |
29 | |
30 | /** | |
31 | * ParentHistogramCanvasControlListenerl constructor | |
32 | * | |
33 | * @param newCanvas Related canvas | |
34 | */ | |
f05aabed FC |
35 | public ParentHistogramCanvasControlListener(ParentHistogramCanvas newCanvas) { |
36 | ourCanvas = newCanvas; | |
3e9fdb8b FC |
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 | ||
f05aabed FC |
50 | if ( (ourCanvas != null) && (ourCanvas.getHistogramContent() != null) ) { |
51 | int newSize = ourCanvas.getSize().x; | |
52 | int oldSize = ourCanvas.getHistogramContent().getCanvasWindowSize(); | |
3e9fdb8b FC |
53 | |
54 | // Set the new canvas size | |
f05aabed | 55 | ourCanvas.getHistogramContent().setCanvasWindowSize(newSize); |
3e9fdb8b FC |
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. | |
f05aabed | 62 | int oldWindowCenter = ourCanvas.getCurrentWindow().getWindowXPositionCenter(); |
3e9fdb8b | 63 | int newWindowCenter = (int)Math.ceil((double)newSize * ((double)oldWindowCenter / (double)oldSize)); |
f05aabed | 64 | ourCanvas.setWindowCenterPosition(newWindowCenter); |
3e9fdb8b FC |
65 | } |
66 | } | |
67 | } |