1 /*******************************************************************************
2 * Copyright (c) 2009 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
;
15 import java
.util
.List
;
18 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.model
.ITimeEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.model
.ITmfTimeAnalysisEntry
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.model
.TimeEvent
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.widgets
.TraceColorScheme
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.graphics
.GC
;
26 import org
.eclipse
.swt
.graphics
.Image
;
27 import org
.eclipse
.swt
.graphics
.Rectangle
;
28 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
30 public abstract class TmfTimeAnalysisProvider
{
32 static public final int IMG_THREAD_RUNNING
= 0;
33 static public final int IMG_THREAD_SUSPENDED
= 1;
34 static public final int IMG_THREAD_STOPPED
= 2;
35 static public final int IMG_METHOD_RUNNING
= 3;
36 static public final int IMG_METHOD
= 4;
37 static public final int IMG_NUM
= 5;
39 public enum StateColor
{
40 GREEN
, DARK_BLUE
, RED
, GOLD
, ORANGE
, GRAY
, BLACK
, DARK_GREEN
, DARK_YELLOW
, MAGENTA3
, PURPLE1
, PINK1
, AQUAMARINE
, LIGHT_BLUE
, CADET_BLUE
, OLIVE
;
42 private String stateName
;
45 String undef
= new String("Undefined");
46 this.stateName
= undef
;
49 public String
getStateName() {
53 public void setStateName(String stateName
) {
54 this.stateName
= stateName
;
58 static private String _externalPath
[] = {
59 "icons/full/obj16/thread_obj.gif", // running thread
60 "icons/full/obj16/threads_obj.gif", // suspended
61 "icons/full/obj16/threadt_obj.gif", // stopped
62 "icons/full/obj16/stckframe_running_obj.gif", // running stack frame
63 "icons/full/obj16/stckframe_obj.gif", // stack frame
66 static private String _externalPlugin
[] = { "org.eclipse.debug.ui",
67 "org.eclipse.debug.ui", "org.eclipse.debug.ui",
68 "org.eclipse.debug.ui", "org.eclipse.debug.ui", };
70 static private Image
getImage(int idx
) {
71 if (idx
< 0 || idx
>= IMG_NUM
)
72 SWT
.error(SWT
.ERROR_INVALID_ARGUMENT
);
73 String key
= "trace.img." + idx
;
74 Image img
= TmfUiPlugin
.getDefault().getImageRegistry().get(key
);
76 ImageDescriptor desc
= AbstractUIPlugin
.imageDescriptorFromPlugin(
77 _externalPlugin
[idx
], _externalPath
[idx
]);
78 TmfUiPlugin
.getDefault().getImageRegistry().put(key
, desc
);
79 img
= TmfUiPlugin
.getDefault().getImageRegistry().get(key
);
84 public void drawState(TraceColorScheme colors
, ITimeEvent event
,
85 Rectangle rect
, GC gc
, boolean selected
, boolean rectBound
,
86 boolean timeSelected
) {
87 int colorIdx
= getEventColorVal(event
);
88 drawState(colors
, colorIdx
, rect
, gc
, selected
, rectBound
, timeSelected
);
92 public void drawState(TraceColorScheme colors
, int colorIdx
,
93 Rectangle rect
, GC gc
, boolean selected
, boolean rectBound
,
94 boolean timeSelected
) {
96 boolean visible
= rect
.width
== 0 ?
false : true;
97 int colorIdx1
= colorIdx
;
99 timeSelected
= timeSelected
&& selected
;
101 colorIdx1
= colorIdx
+ TraceColorScheme
.STATES_SEL0
102 - TraceColorScheme
.STATES0
;
106 // fill all rect area
110 gc
.setBackground(colors
.getColor(colorIdx1
));
111 gc
.fillRectangle(rect
);
112 colorIdx1
= colorIdx
+ TraceColorScheme
.STATES_BORDER0
113 - TraceColorScheme
.STATES0
;
114 gc
.setForeground(colors
.getColor(colorIdx1
));
118 if (rectBound
&& rect
.width
>= 3) {
119 gc
.drawRectangle(rect
.x
, rect
.y
, rect
.width
- 1,
122 // Draw the top and bottom borders i.e. no side borders
125 .drawLine(rect
.x
, rect
.y
, rect
.x
+ rect
.width
- 1,
128 gc
.drawLine(rect
.x
, rect
.y
+ rect
.height
- 1, rect
.x
129 + rect
.width
- 1, rect
.y
+ rect
.height
- 1);
132 // draw decoration middle line
133 // int mindy = rect.y + rect.height / 2;
134 // if (TraceColorScheme.GOLD_STATE == colorIdx
135 // || TraceColorScheme.ORANGE_STATE == colorIdx) {
136 // int s = gc.getLineStyle();
137 // int w = gc.getLineWidth();
138 // gc.setLineStyle(SWT.LINE_DOT);
139 // gc.setLineWidth(2);
140 // gc.drawLine(rect.x, mindy, rect.x + rect.width, mindy);
141 // gc.setLineStyle(s);
142 // gc.setLineWidth(w);
143 // } else if (TraceColorScheme.RED_STATE == colorIdx
144 // || TraceColorScheme.GRAY_STATE == colorIdx) {
145 // int w = gc.getLineWidth();
146 // gc.setLineWidth(2);
147 // gc.drawLine(rect.x, mindy, rect.x + rect.width, mindy);
148 // gc.setLineWidth(w);
150 // // draw selection bounds
151 // if (timeSelected) {
152 // gc.setForeground(colors
153 // .getColor(TraceColorScheme.SELECTED_TIME));
154 // if (rect.width >= 3) {
155 // gc.drawRectangle(rect.x, rect.y, rect.width - 1,
157 // // gc.drawRectangle(rect.x + 1, rect.y + 1, rect.width - 3,
158 // // rect.height - 3);
161 // .drawLine(rect.x, rect.y, rect.x + rect.width - 1,
163 // gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x
164 // + rect.width - 1, rect.y + rect.height - 1);
166 // gc.drawLine(rect.x, rect.y + 1, rect.x + rect.width - 1,
168 // gc.drawLine(rect.x, rect.y + rect.height - 2, rect.x
169 // + rect.width - 1, rect.y + rect.height - 2);
172 // selected rectangle area is not visible but can be represented
173 // with a broken vertical line of specified width.
176 // check if height is greater than zero.
179 // colorIdx1 = TraceColorScheme.BLACK;
180 gc
.setForeground(colors
.getColor(colorIdx
));
181 int s
= gc
.getLineStyle();
182 int w
= gc
.getLineWidth();
183 gc
.setLineStyle(SWT
.LINE_DOT
);
184 gc
.setLineWidth(width
);
185 // Trace.debug("Reactangle not visible, drawing vertical line with: "
186 // + rect.x + "," + rect.y + "," + rect.x + "," + rect.y
188 gc
.drawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+ rect
.height
);
195 * Uses the abstract method getEventcolor to obtain an enum value and
196 * convert it to an internal color index
201 public int getEventColorVal(ITimeEvent event
) {
202 StateColor colors
= getEventColor(event
);
203 if (colors
== StateColor
.GREEN
) {
204 return TraceColorScheme
.GREEN_STATE
;
205 } else if (colors
== StateColor
.DARK_BLUE
) {
206 return TraceColorScheme
.DARK_BLUE_STATE
;
207 } else if (colors
== StateColor
.RED
) {
208 return TraceColorScheme
.RED_STATE
;
209 } else if (colors
== StateColor
.GOLD
) {
210 return TraceColorScheme
.GOLD_STATE
;
211 } else if (colors
== StateColor
.ORANGE
) {
212 return TraceColorScheme
.ORANGE_STATE
;
213 } else if (colors
== StateColor
.GRAY
) {
214 return TraceColorScheme
.GRAY_STATE
;
215 } else if (colors
== StateColor
.DARK_GREEN
) {
216 return TraceColorScheme
.DARK_GREEN_STATE
;
217 } else if (colors
== StateColor
.DARK_YELLOW
) {
218 return TraceColorScheme
.DARK_YELLOW_STATE
;
219 } else if (colors
== StateColor
.MAGENTA3
) {
220 return TraceColorScheme
.MAGENTA3_STATE
;
221 } else if (colors
== StateColor
.PURPLE1
) {
222 return TraceColorScheme
.PURPLE1_STATE
;
223 } else if (colors
== StateColor
.PINK1
) {
224 return TraceColorScheme
.PINK1_STATE
;
225 } else if (colors
== StateColor
.AQUAMARINE
) {
226 return TraceColorScheme
.AQUAMARINE_STATE
;
227 } else if (colors
== StateColor
.LIGHT_BLUE
) {
228 return TraceColorScheme
.LIGHT_BLUE_STATE
;
229 } else if (colors
== StateColor
.CADET_BLUE
) {
230 return TraceColorScheme
.CADET_BLUE_STATE_SEL
;
231 } else if (colors
== StateColor
.OLIVE
) {
232 return TraceColorScheme
.OLIVE_STATE
;
235 return TraceColorScheme
.BLACK_STATE
;
239 * Select the color for the different internal variants of events.
244 public abstract StateColor
getEventColor(ITimeEvent event
);
247 * This values is appended between braces to the right of Trace Name e.g.
248 * Trace And Error Log [Board 17] or for a Thread trace e.g. State Server
254 public abstract String
getTraceClassName(ITmfTimeAnalysisEntry trace
);
256 public String
getEventName(ITimeEvent event
) {
257 return getEventName(event
, true, false);
261 * Specify a Name for the event depending on its type or state e.g. blocked,
266 * True return String value in Upper case
268 * Verbose, add additional information if applicable
271 public abstract String
getEventName(ITimeEvent event
, boolean upper
,
274 public String
composeTraceName(ITmfTimeAnalysisEntry trace
, boolean inclState
) {
275 String name
= trace
.getName();
276 String threadClass
= getTraceClassName(trace
);
277 if (threadClass
!= null && threadClass
.length() > 0) {
278 name
+= " [" + threadClass
+ "]";
281 List
<TimeEvent
> list
= trace
.getTraceEvents();
282 if (null != list
&& list
.size() > 0) {
283 ITimeEvent event
= (ITimeEvent
) list
.get(list
.size() - 1);
284 name
+= " (" + getEventName(event
, false, true) + ")";
290 public String
composeEventName(ITimeEvent event
) {
291 String name
= event
.getEntry().getName();
292 String threadClass
= getTraceClassName(event
.getEntry());
293 if (threadClass
!= null && threadClass
.length() > 0) {
294 name
+= " [" + threadClass
+ "]";
296 name
+= " (" + getEventName(event
, false, true) + ")";
300 public abstract Map
<String
, String
> getEventHoverToolTipInfo(
304 * Provides the image icon for a given Event or Trace e.g. customize to use
305 * different icons according to specific event /state combination
310 public Image
getItemImage(Object obj
) {
311 if (obj
instanceof ITmfTimeAnalysisEntry
) {
312 List
<TimeEvent
> list
= ((ITmfTimeAnalysisEntry
) obj
).getTraceEvents();
313 if (null != list
&& list
.size() > 0)
314 obj
= list
.get(list
.size() - 1);
315 else if (((ITmfTimeAnalysisEntry
) obj
).getStopTime() > 0)
316 return getImage(IMG_THREAD_STOPPED
);
318 return getImage(IMG_THREAD_RUNNING
);
320 if (obj
instanceof TimeEvent
) {
321 return getImage(IMG_THREAD_RUNNING
);
326 public abstract String
getStateName(StateColor color
);