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