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