1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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
10 * Alvaro Sanchez-Leon - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
;
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
;
25 public abstract class TmfTimeAnalysisProvider
{
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;
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
;
37 private String stateName
;
40 String undef
= "Undefined"; //$NON-NLS-1$
41 this.stateName
= undef
;
44 public String
getStateName() {
48 public void setStateName(String stateName
) {
49 this.stateName
= stateName
;
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
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", };
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);
71 // ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(
72 // _externalPlugin[idx], _externalPath[idx]);
73 // TmfUiPlugin.getDefault().getImageRegistry().put(key, desc);
74 // img = TmfUiPlugin.getDefault().getImageRegistry().get(key);
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
);
87 public void drawState(TraceColorScheme colors
, int colorIdx
,
88 Rectangle rect
, GC gc
, boolean selected
, boolean rectBound
,
89 boolean timeSelected
) {
91 boolean visible
= rect
.width
== 0 ?
false : true;
92 int colorIdx1
= colorIdx
;
94 timeSelected
= timeSelected
&& selected
;
96 colorIdx1
= colorIdx
+ TraceColorScheme
.STATES_SEL0
97 - TraceColorScheme
.STATES0
;
101 // fill all rect area
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
));
113 if (rectBound
&& rect
.width
>= 3) {
114 gc
.drawRectangle(rect
.x
, rect
.y
, rect
.width
- 1,
117 // Draw the top and bottom borders i.e. no side borders
120 .drawLine(rect
.x
, rect
.y
, rect
.x
+ rect
.width
- 1,
123 gc
.drawLine(rect
.x
, rect
.y
+ rect
.height
- 1, rect
.x
124 + rect
.width
- 1, rect
.y
+ rect
.height
- 1);
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);
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,
152 // // gc.drawRectangle(rect.x + 1, rect.y + 1, rect.width - 3,
153 // // rect.height - 3);
156 // .drawLine(rect.x, rect.y, rect.x + rect.width - 1,
158 // gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x
159 // + rect.width - 1, rect.y + rect.height - 1);
161 // gc.drawLine(rect.x, rect.y + 1, rect.x + rect.width - 1,
163 // gc.drawLine(rect.x, rect.y + rect.height - 2, rect.x
164 // + rect.width - 1, rect.y + rect.height - 2);
167 // selected rectangle area is not visible but can be represented
168 // with a broken vertical line of specified width.
171 // check if height is greater than zero.
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
183 gc
.drawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+ rect
.height
);
190 * Uses the abstract method getEventcolor to obtain an enum value and
191 * convert it to an internal color index
194 * @return the internal color index
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
;
230 return TraceColorScheme
.BLACK_STATE
;
234 * Select the color for the different internal variants of events.
237 * @return the corresponding event color
239 public abstract StateColor
getEventColor(ITimeEvent event
);
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
247 * @return the trace class name
249 public abstract String
getTraceClassName(ITmfTimeAnalysisEntry trace
);
251 public String
getEventName(ITimeEvent event
) {
252 return getEventName(event
, true, false);
256 * Specify a Name for the event depending on its type or state e.g. blocked,
261 * True return String value in Upper case
263 * Verbose, add additional information if applicable
264 * @return the event name
266 public abstract String
getEventName(ITimeEvent event
, boolean upper
,
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$
276 * Check if this is still necessary!
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$
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$
294 name
+= " (" + getEventName(event
, false, true) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
298 public abstract Map
<String
, String
> getEventHoverToolTipInfo(
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
306 * @return the image icon
308 public Image
getItemImage(Object obj
) {
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);
317 return getImage(IMG_THREAD_RUNNING);
319 if (obj instanceof TimeEvent) {
320 return getImage(IMG_THREAD_RUNNING);
326 public abstract String
getStateName(StateColor color
);