blob: f361717efb8c8bb0fdd90cd83ffc41f35c88a137 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
package org.eclipse.linuxtools.lttng.ui.views.histogram;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
/**
* <b><u>HistogramCanvasControlListener</u></b>
* <p>
* Implementation of a ControlListener for the need of the HistogramCanvas
* <p>
*/
public class HistogramCanvasControlListener implements ControlListener {
protected HistogramCanvas parentCanvas = null;
/**
* HistogramCanvasControlListener constructor
*
* @param newCanvas Related canvas
*/
public HistogramCanvasControlListener(HistogramCanvas newCanvas) {
parentCanvas = newCanvas;
}
/**
* Method called when the canvas is moved.<p>
*
* Just redraw the canvas...
*
* @param event The controle event generated by the move.
*/
public void controlMoved(ControlEvent event) {
parentCanvas.redraw();
}
/**
* Method called when the canvas is resized.<p>
*
* We need to tell the content that the canvas size changed and to recenter the windows
*
* @param event The control event generated by the resize.
*/
public void controlResized(ControlEvent event) {
if ( (parentCanvas != null) && (parentCanvas.getHistogramContent() != null) ) {
int newSize = parentCanvas.getSize().x;
int oldSize = parentCanvas.getHistogramContent().getCanvasWindowSize();
// Set the new canvas size
parentCanvas.getHistogramContent().setCanvasWindowSize(newSize);
// Try to recenter to window at the same place it was
// Note : this is a best hope approach and is not intended to be precise;
// the idea is to avoid issuing a (maybe) long request fo the selection window;
// There WILL be slight discrepancy between the "window values" (timestamp, etc...) showed
// and what it really points to. The user should reclick by himself to refresh it.
int oldWindowCenter = parentCanvas.getCurrentWindow().getWindowXPositionCenter();
int newWindowCenter = (int)Math.ceil((double)newSize * ((double)oldWindowCenter / (double)oldSize));
parentCanvas.setWindowCenterPosition(newWindowCenter);
}
}
}
|