tmf: Use tabs in statistics view for each traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / internal / lttng / ui / views / latency / AbstractViewer.java
CommitLineData
fbd124dd
BH
1/*******************************************************************************\r
2 * Copyright (c) 2010, 2011 Ericsson\r
3 * \r
4 * All rights reserved. This program and the accompanying materials are\r
5 * made available under the terms of the Eclipse Public License v1.0 which\r
6 * accompanies this distribution, and is available at\r
7 * http://www.eclipse.org/legal/epl-v10.html\r
8 * \r
9 * Contributors:\r
10 * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation\r
11 * Mathieu Denis (mathieu.denis55@gmail.com) - Refactored code\r
12 * Bernd Hufmann - Adapted to new model-view-controller design\r
13 *******************************************************************************/\r
638eac44 14package org.eclipse.linuxtools.internal.lttng.ui.views.latency;\r
fbd124dd 15\r
638eac44
FC
16import org.eclipse.linuxtools.internal.lttng.ui.views.latency.listeners.AbstractMouseListener;\r
17import org.eclipse.linuxtools.internal.lttng.ui.views.latency.listeners.AbstractMouseTrackListener;\r
18import org.eclipse.linuxtools.internal.lttng.ui.views.latency.listeners.AbstractPaintListener;\r
19import org.eclipse.linuxtools.internal.lttng.ui.views.latency.listeners.ZoomListener;\r
e0752744 20import org.eclipse.linuxtools.tmf.ui.views.distribution.model.IBaseDistributionModel;\r
fbd124dd
BH
21import org.eclipse.swt.SWT;\r
22import org.eclipse.swt.SWTException;\r
23import org.eclipse.swt.widgets.Canvas;\r
24import org.eclipse.swt.widgets.Composite;\r
25import org.eclipse.swt.widgets.Display;\r
26\r
27/**\r
28 * <b><u>AbstractViewer</u></b>\r
29 * <p>\r
30 * Abstract viewer.\r
31 * \r
32 * @author Philippe Sawicki\r
33 */\r
34public abstract class AbstractViewer extends Canvas {\r
35\r
36 // ------------------------------------------------------------------------\r
37 // Attributes\r
38 // ------------------------------------------------------------------------\r
39\r
40 /**\r
41 * Parent composite node.\r
42 */\r
43 protected Composite fParent;\r
44\r
45 /**\r
46 * Paint listener.\r
47 */\r
48 protected AbstractPaintListener fPaintListener;\r
49\r
50 /**\r
51 * Zoom listener, to zoom in and out of a graph using the scroll wheel.\r
52 */\r
53 protected ZoomListener fZoomListener;\r
54\r
55 /**\r
56 * Tool tip listener.\r
57 */\r
58 protected AbstractMouseTrackListener fMouseTraceListener;\r
59\r
60 /**\r
61 * Mouse listener\r
62 */\r
63 protected AbstractMouseListener fMouseListener;\r
64\r
65 // ------------------------------------------------------------------------\r
66 // Constructor\r
67 // ------------------------------------------------------------------------\r
68 \r
69 /**\r
70 * Constructor.\r
71 * @param parent\r
72 * The parent composite node.\r
73 * @param style\r
74 * The SWT style to use to render the view.\r
75 */\r
76 public AbstractViewer(Composite parent, int style) {\r
77 super(parent, style);\r
78\r
79 fParent = parent;\r
80 }\r
81\r
82 // ------------------------------------------------------------------------\r
83 // Abstract interface\r
84 // ------------------------------------------------------------------------\r
85 \r
86 /**\r
87 * Clears the view.\r
88 */\r
89 abstract public void clear();\r
90\r
91 /**\r
92 * Clears the background of the view but keeps min and max values.\r
93 */\r
94 abstract public void clearBackground();\r
95\r
96 /**\r
97 * Method to increase bar width\r
98 */\r
99 abstract public void increaseBarWidth();\r
100 \r
101 /**\r
102 * Method to decrease bar width\r
103 */\r
104 abstract public void decreaseBarWidth();\r
105\r
106 /**\r
107 * Return data model\r
108 */\r
109 abstract public IBaseDistributionModel getModel();\r
110 \r
111 \r
112 // ------------------------------------------------------------------------\r
113 // Accessors\r
114 // ------------------------------------------------------------------------\r
115\r
116 /**\r
117 * Returns the zoom factor for the canvas.\r
118 * @return The zoom factor for the canvas.\r
119 */\r
120 public int getZoomFactor() {\r
121 if (fZoomListener != null) {\r
122 return fZoomListener.getZoomFactor();\r
123 } else {\r
124 return 1;\r
125 }\r
126 }\r
127\r
128 /**\r
129 * Returns the zoom increment for the canvas.\r
130 * @return The zoom increment for the canvas.\r
131 */\r
132 public int getZoomIncrement() {\r
133 if (fZoomListener != null) {\r
134 return fZoomListener.getZoomIncrement();\r
135 } else {\r
136 return 1;\r
137 }\r
138 }\r
139\r
140 \r
141 // ------------------------------------------------------------------------\r
142 // Operations\r
143 // ------------------------------------------------------------------------\r
144 \r
145 /**\r
146 * Draw horizontal label each "nbTicks" ticks.\r
147 * @param nbTicks\r
148 * The draw interval.\r
149 */\r
150 public void setDrawLabelEachNTicks(int nbTicks) {\r
151 fPaintListener.setDrawLabelEachNTicks(nbTicks);\r
152 }\r
153\r
154 /**\r
155 * Sets the title of the graph.\r
156 * @param graphTitle\r
157 * The title of the graph.\r
158 */\r
159 public void setGraphTitle(String graphTitle) {\r
160 fPaintListener.setGraphTitle(graphTitle);\r
161 }\r
162\r
163 /**\r
164 * Sets the horizontal axis label.\r
165 * @param xLabel\r
166 * The horizontal axis label.\r
167 * @param offset\r
168 * The horizontal axis draw offset (in pixels).\r
169 */\r
170 public void setXAxisLabel(String xLabel, int offset) {\r
171 fPaintListener.setXAxisLabel(xLabel, offset);\r
172 }\r
173\r
174 /**\r
175 * Sets the vertical axis label.\r
176 * @param yLabel\r
177 * The vertical axis label.\r
178 */\r
179 public void setYAxisLabel(String yLabel) {\r
180 fPaintListener.setYAxisLabel(yLabel);\r
181 }\r
182\r
183 /**\r
184 * Asks for the view to be redrawn, synchronously or asynchronously.\r
185 * @param asyncRedraw\r
186 * If "true", the view will be redrawn asynchronously, otherwise it will be redraw synchronously.\r
187 */\r
188 public void askForRedraw(boolean asyncRedraw) {\r
189 if (asyncRedraw == true) {\r
190 Display.getDefault().asyncExec(new Runnable() {\r
191 @Override\r
192 public void run() {\r
193 try {\r
194 redraw();\r
195 } catch (SWTException e) {\r
196 // ...\r
197 }\r
198 }\r
199 });\r
200 } else {\r
201 Display.getDefault().syncExec(new Runnable() {\r
202 @Override\r
203 public void run() {\r
204 try {\r
205 redraw();\r
206 } catch (SWTException e) {\r
207 // ...\r
208 }\r
209 }\r
210 });\r
211 }\r
212 }\r
213\r
214 /**\r
215 * Asks for the view to be redrawn (asynchronously).\r
216 */\r
217 public void askForRedraw() {\r
218 askForRedraw(true);\r
219 }\r
220\r
221 /**\r
222 * Redraws the title after a zoom to display the new zoom factor.\r
223 */\r
224 public void redrawTitle() {\r
225 fPaintListener.paintGraphTitle();\r
226 }\r
227\r
228 /**\r
229 * Removes the view's listeners before disposing of it.\r
230 */\r
231 @Override\r
232 public void dispose() {\r
233 try {\r
234 if (fPaintListener != null) {\r
235 removePaintListener(fPaintListener);\r
236 fPaintListener = null;\r
237 }\r
238 if (fZoomListener != null) {\r
239 removeListener(SWT.MouseWheel, fZoomListener);\r
240 fZoomListener = null;\r
241 }\r
242 if (fMouseTraceListener != null) {\r
243 removeListener(SWT.MouseMove, fMouseTraceListener);\r
244 fMouseTraceListener = null;\r
245 }\r
246 } catch (SWTException e) {\r
247 // This exception will be thrown if the user closes the view\r
248 // while it is receiving data from the Analyzer.\r
249\r
250 // ...\r
251 }\r
252\r
253 super.dispose();\r
254 }\r
255}
This page took 0.038597 seconds and 5 git commands to generate.