(no commit message)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / histogram / ParentHistogramCanvas.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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 * William Bourque - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.ui.views.histogram;
13
14 import org.eclipse.swt.widgets.Composite;
15
16 /**
17 * <b><u>ParentHistogramCanvas</u></b>
18 * <p>
19 * Extended implementation of the HistogramCanvas.
20 * <p>
21 * This canvas goal is to display the "Full experiment" histogram.
22 */
23 public class ParentHistogramCanvas extends HistogramCanvas {
24
25 protected HistogramView parentHistogramWindow = null;
26
27 /**
28 * ParentHistogramCanvas constructor.<p>
29 * Same as HistogramCanvas, but receive a parent HistogramView that we can call from here.
30 *
31 * @param parent Composite control which will be the parent of the new instance (cannot be null)
32 * @param Style the style of control to construct
33 */
34 public ParentHistogramCanvas(HistogramView newParentWindow, Composite parent, int style) {
35 super(parent, style);
36
37 parentHistogramWindow = newParentWindow;
38 }
39
40 /**
41 * Create a new HistogramContent for this HistogramCanvas<p>
42 * A new <I>empty</I> canvas will then be created.
43 *
44 * IMPORTANT NOTE : This implementaton use the next power of 2 to the full screen resolution as the content size.
45 * This allow us to resize the canvas at low cost (i.e. : no need to reissue a full request)
46 * We need a "particular" paint listener that know about this.
47 *
48 * @param canvasSize Size of the parent canvas.
49 * @param widthPerBar Width of the histogram "bars"
50 * @param barsHeight Height of the histogram "bars"
51 * @param maxBarsDifferenceToAverage Factor used to "chop" bars that are too tall. Set to something big (100.0?) if not needed.
52 */
53 @Override
54 public void createNewHistogramContent(int canvasSize, int widthPerBar, int barsHeight, double maxBarsDifferenceToAverage) {
55
56 // *** FIXME ***
57 // Note there MIGHT be some unhandled case, like if the resolution of the screen change
58 // or if a new screen is plugged.
59 // Let's ignore them for now.
60 //
61 // The maximum size the canvas could ever had
62 int canvasMaxSize = getParent().getDisplay().getBounds().width;
63
64 // Calculate the power of two superior to the max size
65 int exp = (int)Math.ceil( Math.log( (double)canvasMaxSize ) / Math.log(2.0) );
66 int contentSize = (int)Math.pow(2, exp);
67
68 // Create the content
69 histogramContent = new HistogramContent( contentSize, canvasSize, widthPerBar, barsHeight, maxBarsDifferenceToAverage);
70
71 // We need to ajust the "maxDifferenceToAverageFactor" as the bars we draw might be slitghly larger than the value asked
72 // Each "interval" are concatenated when draw so the worst case should be :
73 // contentSize / (closest power of 2 to canvasMaxSize)
74 // Ex : if canvasSize is 1500 -> (2048 / 1024) == 2 so maxDiff should be twice larger
75 //
76 // Note : this is not perfect, if the screen is resized after we calculate this, the resulting output can be quite ugly
77 // For this reason, this will be recalculated in the paintListener as well.
78 double maxBarsDiffFactor = ((double)contentSize / Math.pow(2, exp-1));
79 histogramContent.setMaxDifferenceToAverageFactor(maxBarsDiffFactor);
80 }
81
82 /*
83 * Create a histogram paint listener and bind it to this canvas.<p>
84 *
85 * Note : This one is a bit particular, as it is made to draw content that is of a power of 2.
86 * The default one draw content that is relative to the real pixels size.
87 */
88 @Override
89 protected void createAndAddPaintListener() {
90 paintListener = new ParentHistogramCanvasPaintListener(this);;
91 this.addPaintListener( paintListener );
92 }
93
94 /**
95 * Function that is called when the selection window is moved.<p>
96 * Note: Given position should be relative to the previous (centered) absolute position.<p>
97 *
98 * Calculate the new position then re-center the window.<p>
99 * It will also notify the HistogramView that the window changed.
100 *
101 * @param newRelativeXPosition New position relative to the last known absolute position.
102 */
103 @Override
104 public void moveWindow(int newRelativeXPosition) {
105 int absolutePosition = currentWindow.getWindowXPositionCenter() + newRelativeXPosition;
106
107 setWindowCenterPosition(absolutePosition);
108 notifyParentSelectionWindowChangedAsynchronously();
109 }
110
111 /**
112 * Function that is called when the selection window is re-centered.<p>
113 * Note: Given position should be absolute to the window and need to be the selection window center.<p>
114 *
115 * Recenter the window and notify the HistogramView that the window changed.
116 *
117 * @param newRelativeXPosition New absolute position.
118 */
119 @Override
120 public void setWindowCenterPosition(int newAbsoluteXPosition) {
121
122 if ( newAbsoluteXPosition < 0 ) {
123 newAbsoluteXPosition = 0;
124 }
125 else if ( newAbsoluteXPosition > getParent().getSize().x ) {
126 newAbsoluteXPosition = getParent().getSize().x;
127 }
128
129 if ( newAbsoluteXPosition != currentWindow.getWindowXPositionCenter() ) {
130 currentWindow.setWindowXPositionCenter(newAbsoluteXPosition);
131 redrawAsynchronously();
132 }
133 }
134
135 /**
136 * Function that is called when the selection window size (time width) changed by an absolute time.<p>
137 * Note: Given time should be in nanoseconds, positive.
138 *
139 * Set the new window size and notify the HistogramView that the window changed.
140 *
141 * @param newTime New absoulte time (in nanoseconds) to apply to the window.
142 */
143 @Override
144 public void resizeWindowByAbsoluteTime(long newTime) {
145 if ( newTime != getSelectedWindowSize() ) {
146 setSelectedWindowSize(newTime);
147
148 notifyParentSelectionWindowChangedAsynchronously();
149 redrawAsynchronously();
150 }
151 }
152
153 /**
154 * Notify the parent HistogramView that we have updated information.<p>
155 * This is intended to be called at the end of the request when we know we have up-to-date information.
156 */
157 @Override
158 public void notifyParentUpdatedInformation() {
159 parentHistogramWindow.updateFullExperimentInformation();
160 }
161
162 /**
163 * Notify the parent HistogramView that the SelectionWindow changed.<p>
164 * This is intended to be called when the window move or is resized.
165 */
166 @Override
167 public void notifyParentSelectionWindowChanged() {
168 // Notify the parent view that something changed
169 parentHistogramWindow.windowChangedNotification();
170 // Send a broadcast to the framework about the window change
171 parentHistogramWindow.sendTmfRangeSynchSignalBroadcast();
172 }
173 }
This page took 0.03409 seconds and 5 git commands to generate.