1 /*******************************************************************************
2 * Copyright (c) 2010, 2011 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 * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11 * Mathieu Denis (mathieu.denis55@gmail.com) - Refactored code
12 * Bernd Hufmann - Adapted to new model-view-controller design
13 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.latency
;
16 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.latency
.listeners
.AbstractMouseListener
;
17 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.latency
.listeners
.AbstractMouseTrackListener
;
18 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.latency
.listeners
.AbstractPaintListener
;
19 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.latency
.listeners
.ZoomListener
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.distribution
.model
.IBaseDistributionModel
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.SWTException
;
23 import org
.eclipse
.swt
.widgets
.Canvas
;
24 import org
.eclipse
.swt
.widgets
.Composite
;
25 import org
.eclipse
.swt
.widgets
.Display
;
28 * <b><u>AbstractViewer</u></b>
32 * @author Philippe Sawicki
34 public abstract class AbstractViewer
extends Canvas
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
41 * Parent composite node.
43 protected Composite fParent
;
48 protected AbstractPaintListener fPaintListener
;
51 * Zoom listener, to zoom in and out of a graph using the scroll wheel.
53 protected ZoomListener fZoomListener
;
58 protected AbstractMouseTrackListener fMouseTraceListener
;
63 protected AbstractMouseListener fMouseListener
;
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
72 * The parent composite node.
74 * The SWT style to use to render the view.
76 public AbstractViewer(Composite parent
, int style
) {
82 // ------------------------------------------------------------------------
84 // ------------------------------------------------------------------------
89 abstract public void clear();
92 * Clears the background of the view but keeps min and max values.
94 abstract public void clearBackground();
97 * Method to increase bar width
99 abstract public void increaseBarWidth();
102 * Method to decrease bar width
104 abstract public void decreaseBarWidth();
109 abstract public IBaseDistributionModel
getModel();
112 // ------------------------------------------------------------------------
114 // ------------------------------------------------------------------------
117 * Returns the zoom factor for the canvas.
118 * @return The zoom factor for the canvas.
120 public int getZoomFactor() {
121 if (fZoomListener
!= null) {
122 return fZoomListener
.getZoomFactor();
129 * Returns the zoom increment for the canvas.
130 * @return The zoom increment for the canvas.
132 public int getZoomIncrement() {
133 if (fZoomListener
!= null) {
134 return fZoomListener
.getZoomIncrement();
141 // ------------------------------------------------------------------------
143 // ------------------------------------------------------------------------
146 * Draw horizontal label each "nbTicks" ticks.
150 public void setDrawLabelEachNTicks(int nbTicks
) {
151 fPaintListener
.setDrawLabelEachNTicks(nbTicks
);
155 * Sets the title of the graph.
157 * The title of the graph.
159 public void setGraphTitle(String graphTitle
) {
160 fPaintListener
.setGraphTitle(graphTitle
);
164 * Sets the horizontal axis label.
166 * The horizontal axis label.
168 * The horizontal axis draw offset (in pixels).
170 public void setXAxisLabel(String xLabel
, int offset
) {
171 fPaintListener
.setXAxisLabel(xLabel
, offset
);
175 * Sets the vertical axis label.
177 * The vertical axis label.
179 public void setYAxisLabel(String yLabel
) {
180 fPaintListener
.setYAxisLabel(yLabel
);
184 * Asks for the view to be redrawn, synchronously or asynchronously.
186 * If "true", the view will be redrawn asynchronously, otherwise it will be redraw synchronously.
188 public void askForRedraw(boolean asyncRedraw
) {
189 if (asyncRedraw
== true) {
190 Display
.getDefault().asyncExec(new Runnable() {
195 } catch (SWTException e
) {
201 Display
.getDefault().syncExec(new Runnable() {
206 } catch (SWTException e
) {
215 * Asks for the view to be redrawn (asynchronously).
217 public void askForRedraw() {
222 * Redraws the title after a zoom to display the new zoom factor.
224 public void redrawTitle() {
225 fPaintListener
.paintGraphTitle();
229 * Removes the view's listeners before disposing of it.
232 public void dispose() {
234 if (fPaintListener
!= null) {
235 removePaintListener(fPaintListener
);
236 fPaintListener
= null;
238 if (fZoomListener
!= null) {
239 removeListener(SWT
.MouseWheel
, fZoomListener
);
240 fZoomListener
= null;
242 if (fMouseTraceListener
!= null) {
243 removeListener(SWT
.MouseMove
, fMouseTraceListener
);
244 fMouseTraceListener
= null;
246 } catch (SWTException e
) {
247 // This exception will be thrown if the user closes the view
248 // while it is receiving data from the Analyzer.