Commit | Line | Data |
---|---|---|
b0d3496e | 1 | /*******************************************************************************\r |
a5823d5f | 2 | * Copyright (c) 2009, 2010 Ericsson\r |
b0d3496e ASL |
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 | * Alvaro Sanchez-Leon - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
2fa130b8 | 13 | package org.eclipse.linuxtools.internal.lttng.ui.viewers.timeAnalysis;\r |
b0d3496e | 14 | \r |
b0d3496e ASL |
15 | import java.util.Map;\r |
16 | \r | |
2fa130b8 PT |
17 | import org.eclipse.linuxtools.internal.lttng.ui.viewers.timeAnalysis.model.ITimeEvent;\r |
18 | import org.eclipse.linuxtools.internal.lttng.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry;\r | |
19 | import org.eclipse.linuxtools.internal.lttng.ui.viewers.timeAnalysis.widgets.TraceColorScheme;\r | |
b0d3496e ASL |
20 | import org.eclipse.swt.SWT;\r |
21 | import org.eclipse.swt.graphics.GC;\r | |
22 | import org.eclipse.swt.graphics.Image;\r | |
23 | import org.eclipse.swt.graphics.Rectangle;\r | |
24 | \r | |
25 | public abstract class TmfTimeAnalysisProvider {\r | |
26 | \r | |
27 | static public final int IMG_THREAD_RUNNING = 0;\r | |
28 | static public final int IMG_THREAD_SUSPENDED = 1;\r | |
29 | static public final int IMG_THREAD_STOPPED = 2;\r | |
30 | static public final int IMG_METHOD_RUNNING = 3;\r | |
31 | static public final int IMG_METHOD = 4;\r | |
32 | static public final int IMG_NUM = 5;\r | |
33 | \r | |
34 | public enum StateColor {\r | |
35 | GREEN, DARK_BLUE, RED, GOLD, ORANGE, GRAY, BLACK, DARK_GREEN, DARK_YELLOW, MAGENTA3, PURPLE1, PINK1, AQUAMARINE, LIGHT_BLUE, CADET_BLUE, OLIVE;\r | |
36 | \r | |
37 | private String stateName;\r | |
38 | \r | |
39 | StateColor() {\r | |
5a5c2fc7 | 40 | String undef = "Undefined"; //$NON-NLS-1$\r |
b0d3496e ASL |
41 | this.stateName = undef;\r |
42 | }\r | |
43 | \r | |
44 | public String getStateName() {\r | |
45 | return stateName;\r | |
46 | }\r | |
47 | \r | |
48 | public void setStateName(String stateName) {\r | |
49 | this.stateName = stateName;\r | |
50 | }\r | |
51 | }\r | |
52 | \r | |
a5823d5f ASL |
53 | // static private String _externalPath[] = {\r |
54 | // "icons/full/obj16/thread_obj.gif", // running thread\r | |
55 | // "icons/full/obj16/threads_obj.gif", // suspended\r | |
56 | // "icons/full/obj16/threadt_obj.gif", // stopped\r | |
57 | // "icons/full/obj16/stckframe_running_obj.gif", // running stack frame\r | |
58 | // "icons/full/obj16/stckframe_obj.gif", // stack frame\r | |
59 | // };\r | |
60 | //\r | |
61 | // static private String _externalPlugin[] = { "org.eclipse.debug.ui",\r | |
62 | // "org.eclipse.debug.ui", "org.eclipse.debug.ui",\r | |
63 | // "org.eclipse.debug.ui", "org.eclipse.debug.ui", };\r | |
64 | //\r | |
65 | // static private Image getImage(int idx) {\r | |
66 | // if (idx < 0 || idx >= IMG_NUM)\r | |
67 | // SWT.error(SWT.ERROR_INVALID_ARGUMENT);\r | |
68 | // String key = "trace.img." + idx;\r | |
69 | // Image img = TmfUiPlugin.getDefault().getImageRegistry().get(key);\r | |
70 | // if (null == img) {\r | |
71 | // ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(\r | |
72 | // _externalPlugin[idx], _externalPath[idx]);\r | |
73 | // TmfUiPlugin.getDefault().getImageRegistry().put(key, desc);\r | |
74 | // img = TmfUiPlugin.getDefault().getImageRegistry().get(key);\r | |
75 | // }\r | |
76 | // return img;\r | |
77 | // }\r | |
b0d3496e ASL |
78 | \r |
79 | public void drawState(TraceColorScheme colors, ITimeEvent event,\r | |
80 | Rectangle rect, GC gc, boolean selected, boolean rectBound,\r | |
81 | boolean timeSelected) {\r | |
82 | int colorIdx = getEventColorVal(event);\r | |
83 | drawState(colors, colorIdx, rect, gc, selected, rectBound, timeSelected);\r | |
84 | \r | |
85 | }\r | |
86 | \r | |
87 | public void drawState(TraceColorScheme colors, int colorIdx,\r | |
88 | Rectangle rect, GC gc, boolean selected, boolean rectBound,\r | |
89 | boolean timeSelected) {\r | |
90 | \r | |
91 | boolean visible = rect.width == 0 ? false : true;\r | |
92 | int colorIdx1 = colorIdx;\r | |
93 | \r | |
94 | timeSelected = timeSelected && selected;\r | |
95 | if (timeSelected) {\r | |
96 | colorIdx1 = colorIdx + TraceColorScheme.STATES_SEL0\r | |
97 | - TraceColorScheme.STATES0;\r | |
98 | }\r | |
99 | \r | |
100 | if (visible) {\r | |
101 | // fill all rect area\r | |
102 | if (rect.isEmpty())\r | |
103 | return;\r | |
104 | \r | |
105 | gc.setBackground(colors.getColor(colorIdx1));\r | |
106 | gc.fillRectangle(rect);\r | |
107 | colorIdx1 = colorIdx + TraceColorScheme.STATES_BORDER0\r | |
108 | - TraceColorScheme.STATES0;\r | |
109 | gc.setForeground(colors.getColor(colorIdx1));\r | |
110 | \r | |
111 | // draw bounds\r | |
112 | if (!timeSelected) {\r | |
113 | if (rectBound && rect.width >= 3) {\r | |
114 | gc.drawRectangle(rect.x, rect.y, rect.width - 1,\r | |
115 | rect.height - 1);\r | |
116 | } else {\r | |
117 | // Draw the top and bottom borders i.e. no side borders\r | |
118 | // top\r | |
119 | gc\r | |
120 | .drawLine(rect.x, rect.y, rect.x + rect.width - 1,\r | |
121 | rect.y);\r | |
122 | // bottom\r | |
123 | gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x\r | |
124 | + rect.width - 1, rect.y + rect.height - 1);\r | |
125 | }\r | |
126 | }\r | |
127 | // draw decoration middle line\r | |
128 | // int mindy = rect.y + rect.height / 2;\r | |
129 | // if (TraceColorScheme.GOLD_STATE == colorIdx\r | |
130 | // || TraceColorScheme.ORANGE_STATE == colorIdx) {\r | |
131 | // int s = gc.getLineStyle();\r | |
132 | // int w = gc.getLineWidth();\r | |
133 | // gc.setLineStyle(SWT.LINE_DOT);\r | |
134 | // gc.setLineWidth(2);\r | |
135 | // gc.drawLine(rect.x, mindy, rect.x + rect.width, mindy);\r | |
136 | // gc.setLineStyle(s);\r | |
137 | // gc.setLineWidth(w);\r | |
138 | // } else if (TraceColorScheme.RED_STATE == colorIdx\r | |
139 | // || TraceColorScheme.GRAY_STATE == colorIdx) {\r | |
140 | // int w = gc.getLineWidth();\r | |
141 | // gc.setLineWidth(2);\r | |
142 | // gc.drawLine(rect.x, mindy, rect.x + rect.width, mindy);\r | |
143 | // gc.setLineWidth(w);\r | |
144 | // }\r | |
145 | // // draw selection bounds\r | |
146 | // if (timeSelected) {\r | |
147 | // gc.setForeground(colors\r | |
148 | // .getColor(TraceColorScheme.SELECTED_TIME));\r | |
149 | // if (rect.width >= 3) {\r | |
150 | // gc.drawRectangle(rect.x, rect.y, rect.width - 1,\r | |
151 | // rect.height - 1);\r | |
152 | // // gc.drawRectangle(rect.x + 1, rect.y + 1, rect.width - 3,\r | |
153 | // // rect.height - 3);\r | |
154 | // } else {\r | |
155 | // gc\r | |
156 | // .drawLine(rect.x, rect.y, rect.x + rect.width - 1,\r | |
157 | // rect.y);\r | |
158 | // gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x\r | |
159 | // + rect.width - 1, rect.y + rect.height - 1);\r | |
160 | // }\r | |
161 | // gc.drawLine(rect.x, rect.y + 1, rect.x + rect.width - 1,\r | |
162 | // rect.y + 1);\r | |
163 | // gc.drawLine(rect.x, rect.y + rect.height - 2, rect.x\r | |
164 | // + rect.width - 1, rect.y + rect.height - 2);\r | |
165 | // }\r | |
166 | } else {\r | |
167 | // selected rectangle area is not visible but can be represented\r | |
168 | // with a broken vertical line of specified width.\r | |
169 | int width = 2;\r | |
170 | rect.width = width;\r | |
171 | // check if height is greater than zero.\r | |
172 | if (rect.isEmpty())\r | |
173 | return;\r | |
174 | // colorIdx1 = TraceColorScheme.BLACK;\r | |
175 | gc.setForeground(colors.getColor(colorIdx));\r | |
176 | int s = gc.getLineStyle();\r | |
177 | int w = gc.getLineWidth();\r | |
178 | gc.setLineStyle(SWT.LINE_DOT);\r | |
179 | gc.setLineWidth(width);\r | |
180 | // Trace.debug("Reactangle not visible, drawing vertical line with: "\r | |
181 | // + rect.x + "," + rect.y + "," + rect.x + "," + rect.y\r | |
182 | // + rect.height);\r | |
183 | gc.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height);\r | |
184 | gc.setLineStyle(s);\r | |
185 | gc.setLineWidth(w);\r | |
186 | }\r | |
187 | }\r | |
188 | \r | |
189 | /**\r | |
190 | * Uses the abstract method getEventcolor to obtain an enum value and\r | |
191 | * convert it to an internal color index\r | |
192 | * \r | |
193 | * @param event\r | |
0d9a6d76 | 194 | * @return the internal color index\r |
b0d3496e ASL |
195 | */\r |
196 | public int getEventColorVal(ITimeEvent event) {\r | |
197 | StateColor colors = getEventColor(event);\r | |
198 | if (colors == StateColor.GREEN) {\r | |
199 | return TraceColorScheme.GREEN_STATE;\r | |
200 | } else if (colors == StateColor.DARK_BLUE) {\r | |
201 | return TraceColorScheme.DARK_BLUE_STATE;\r | |
202 | } else if (colors == StateColor.RED) {\r | |
203 | return TraceColorScheme.RED_STATE;\r | |
204 | } else if (colors == StateColor.GOLD) {\r | |
205 | return TraceColorScheme.GOLD_STATE;\r | |
206 | } else if (colors == StateColor.ORANGE) {\r | |
207 | return TraceColorScheme.ORANGE_STATE;\r | |
208 | } else if (colors == StateColor.GRAY) {\r | |
209 | return TraceColorScheme.GRAY_STATE;\r | |
210 | } else if (colors == StateColor.DARK_GREEN) {\r | |
211 | return TraceColorScheme.DARK_GREEN_STATE;\r | |
212 | } else if (colors == StateColor.DARK_YELLOW) {\r | |
213 | return TraceColorScheme.DARK_YELLOW_STATE;\r | |
214 | } else if (colors == StateColor.MAGENTA3) {\r | |
215 | return TraceColorScheme.MAGENTA3_STATE;\r | |
216 | } else if (colors == StateColor.PURPLE1) {\r | |
217 | return TraceColorScheme.PURPLE1_STATE;\r | |
218 | } else if (colors == StateColor.PINK1) {\r | |
219 | return TraceColorScheme.PINK1_STATE;\r | |
220 | } else if (colors == StateColor.AQUAMARINE) {\r | |
221 | return TraceColorScheme.AQUAMARINE_STATE;\r | |
222 | } else if (colors == StateColor.LIGHT_BLUE) {\r | |
223 | return TraceColorScheme.LIGHT_BLUE_STATE;\r | |
224 | } else if (colors == StateColor.CADET_BLUE) {\r | |
225 | return TraceColorScheme.CADET_BLUE_STATE_SEL;\r | |
226 | } else if (colors == StateColor.OLIVE) {\r | |
227 | return TraceColorScheme.OLIVE_STATE;\r | |
228 | }\r | |
229 | \r | |
230 | return TraceColorScheme.BLACK_STATE;\r | |
231 | }\r | |
232 | \r | |
233 | /**\r | |
234 | * Select the color for the different internal variants of events.\r | |
235 | * \r | |
236 | * @param event\r | |
0d9a6d76 | 237 | * @return the corresponding event color\r |
b0d3496e ASL |
238 | */\r |
239 | public abstract StateColor getEventColor(ITimeEvent event);\r | |
240 | \r | |
241 | /**\r | |
242 | * This values is appended between braces to the right of Trace Name e.g.\r | |
243 | * Trace And Error Log [Board 17] or for a Thread trace e.g. State Server\r | |
244 | * [java.lang.Thread]\r | |
245 | * \r | |
246 | * @param trace\r | |
0d9a6d76 | 247 | * @return the trace class name\r |
b0d3496e ASL |
248 | */\r |
249 | public abstract String getTraceClassName(ITmfTimeAnalysisEntry trace);\r | |
250 | \r | |
251 | public String getEventName(ITimeEvent event) {\r | |
252 | return getEventName(event, true, false);\r | |
253 | }\r | |
254 | \r | |
255 | /**\r | |
256 | * Specify a Name for the event depending on its type or state e.g. blocked,\r | |
257 | * running, etc..\r | |
258 | * \r | |
259 | * @param event\r | |
260 | * @param upper\r | |
261 | * True return String value in Upper case\r | |
262 | * @param extInfo\r | |
263 | * Verbose, add additional information if applicable\r | |
0d9a6d76 | 264 | * @return the event name\r |
b0d3496e ASL |
265 | */\r |
266 | public abstract String getEventName(ITimeEvent event, boolean upper,\r | |
267 | boolean extInfo);\r | |
268 | \r | |
269 | public String composeTraceName(ITmfTimeAnalysisEntry trace, boolean inclState) {\r | |
270 | String name = trace.getName();\r | |
271 | String threadClass = getTraceClassName(trace);\r | |
272 | if (threadClass != null && threadClass.length() > 0) {\r | |
3b38ea61 | 273 | name += " [" + threadClass + "]"; //$NON-NLS-1$ //$NON-NLS-2$\r |
b0d3496e | 274 | }\r |
ce62370f FC |
275 | /*\r |
276 | * Check if this is still necessary!\r | |
b0d3496e ASL |
277 | if (inclState) {\r |
278 | List<TimeEvent> list = trace.getTraceEvents();\r | |
279 | if (null != list && list.size() > 0) {\r | |
280 | ITimeEvent event = (ITimeEvent) list.get(list.size() - 1);\r | |
3b38ea61 | 281 | name += " (" + getEventName(event, false, true) + ")"; //$NON-NLS-1$ //$NON-NLS-2$\r |
b0d3496e ASL |
282 | }\r |
283 | }\r | |
ce62370f | 284 | */\r |
b0d3496e ASL |
285 | return name;\r |
286 | }\r | |
287 | \r | |
288 | public String composeEventName(ITimeEvent event) {\r | |
289 | String name = event.getEntry().getName();\r | |
290 | String threadClass = getTraceClassName(event.getEntry());\r | |
291 | if (threadClass != null && threadClass.length() > 0) {\r | |
3b38ea61 | 292 | name += " [" + threadClass + "]"; //$NON-NLS-1$ //$NON-NLS-2$\r |
b0d3496e | 293 | }\r |
3b38ea61 | 294 | name += " (" + getEventName(event, false, true) + ")"; //$NON-NLS-1$ //$NON-NLS-2$\r |
b0d3496e ASL |
295 | return name;\r |
296 | }\r | |
297 | \r | |
298 | public abstract Map<String, String> getEventHoverToolTipInfo(\r | |
299 | ITimeEvent event);\r | |
300 | \r | |
301 | /**\r | |
302 | * Provides the image icon for a given Event or Trace e.g. customize to use\r | |
303 | * different icons according to specific event /state combination\r | |
304 | * \r | |
305 | * @param obj\r | |
0d9a6d76 | 306 | * @return the image icon\r |
b0d3496e ASL |
307 | */\r |
308 | public Image getItemImage(Object obj) {\r | |
a5823d5f | 309 | /*\r |
b0d3496e ASL |
310 | if (obj instanceof ITmfTimeAnalysisEntry) {\r |
311 | List<TimeEvent> list = ((ITmfTimeAnalysisEntry) obj).getTraceEvents();\r | |
312 | if (null != list && list.size() > 0)\r | |
313 | obj = list.get(list.size() - 1);\r | |
314 | else if (((ITmfTimeAnalysisEntry) obj).getStopTime() > 0)\r | |
315 | return getImage(IMG_THREAD_STOPPED);\r | |
316 | else\r | |
317 | return getImage(IMG_THREAD_RUNNING);\r | |
318 | }\r | |
319 | if (obj instanceof TimeEvent) {\r | |
320 | return getImage(IMG_THREAD_RUNNING);\r | |
321 | }\r | |
a5823d5f | 322 | */\r |
b0d3496e ASL |
323 | return null;\r |
324 | }\r | |
325 | \r | |
326 | public abstract String getStateName(StateColor color);\r | |
327 | \r | |
328 | } |