1 /*******************************************************************************
2 * Copyright (c) 2009 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 * William Bourque - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.histogram
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
17 * <b><u>ParentHistogramCanvas</u></b>
19 * Extended implementation of the HistogramCanvas.
21 * This canvas goal is to display the "Full experiment" histogram.
23 public class ParentHistogramCanvas
extends HistogramCanvas
{
25 protected HistogramView parentHistogramWindow
= null;
28 * ParentHistogramCanvas constructor.<p>
29 * Same as HistogramCanvas, but receive a parent HistogramView that we can call from here.
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
34 public ParentHistogramCanvas(HistogramView newParentWindow
, Composite parent
, int style
) {
37 parentHistogramWindow
= newParentWindow
;
41 * Create a new HistogramContent for this HistogramCanvas<p>
42 * A new <I>empty</I> canvas will then be created.
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.
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.
54 public void createNewHistogramContent(int canvasSize
, int widthPerBar
, int barsHeight
, double maxBarsDifferenceToAverage
) {
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.
61 // The maximum size the canvas could ever had
62 int canvasMaxSize
= getParent().getDisplay().getBounds().width
;
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
);
69 histogramContent
= new HistogramContent( contentSize
, canvasSize
, widthPerBar
, barsHeight
, maxBarsDifferenceToAverage
);
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
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
);
83 * Create a histogram paint listener and bind it to this canvas.<p>
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.
89 protected void createAndAddPaintListener() {
90 paintListener
= new ParentHistogramCanvasPaintListener(this);;
91 this.addPaintListener( paintListener
);
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>
98 * Calculate the new position then re-center the window.<p>
99 * It will also notify the HistogramView that the window changed.
101 * @param newRelativeXPosition New position relative to the last known absolute position.
104 public void moveWindow(int newRelativeXPosition
) {
105 int absolutePosition
= currentWindow
.getWindowXPositionCenter() + newRelativeXPosition
;
107 setWindowCenterPosition(absolutePosition
);
108 notifyParentSelectionWindowChangedAsynchronously();
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>
115 * Recenter the window and notify the HistogramView that the window changed.
117 * @param newRelativeXPosition New absolute position.
120 public void setWindowCenterPosition(int newAbsoluteXPosition
) {
122 if ( newAbsoluteXPosition
< 0 ) {
123 newAbsoluteXPosition
= 0;
125 else if ( newAbsoluteXPosition
> getParent().getSize().x
) {
126 newAbsoluteXPosition
= getParent().getSize().x
;
129 if ( newAbsoluteXPosition
!= currentWindow
.getWindowXPositionCenter() ) {
130 currentWindow
.setWindowXPositionCenter(newAbsoluteXPosition
);
131 redrawAsynchronously();
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.
139 * Set the new window size and notify the HistogramView that the window changed.
141 * @param newTime New absoulte time (in nanoseconds) to apply to the window.
144 public void resizeWindowByAbsoluteTime(long newTime
) {
145 if ( newTime
!= getSelectedWindowSize() ) {
146 setSelectedWindowSize(newTime
);
148 notifyParentSelectionWindowChangedAsynchronously();
149 redrawAsynchronously();
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.
158 public void notifyParentUpdatedInformation() {
159 parentHistogramWindow
.updateFullExperimentInformation();
163 * Notify the parent HistogramView that the SelectionWindow changed.<p>
164 * This is intended to be called when the window move or is resized.
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();