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