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
;
15 import java
.util
.List
;
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
;
27 public abstract class TmfTimeAnalysisProvider
{
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;
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
;
39 private String stateName
;
42 String undef
= new String("Undefined");
43 this.stateName
= undef
;
46 public String
getStateName() {
50 public void setStateName(String stateName
) {
51 this.stateName
= stateName
;
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
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", };
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);
73 // ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(
74 // _externalPlugin[idx], _externalPath[idx]);
75 // TmfUiPlugin.getDefault().getImageRegistry().put(key, desc);
76 // img = TmfUiPlugin.getDefault().getImageRegistry().get(key);
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
);
89 public void drawState(TraceColorScheme colors
, int colorIdx
,
90 Rectangle rect
, GC gc
, boolean selected
, boolean rectBound
,
91 boolean timeSelected
) {
93 boolean visible
= rect
.width
== 0 ?
false : true;
94 int colorIdx1
= colorIdx
;
96 timeSelected
= timeSelected
&& selected
;
98 colorIdx1
= colorIdx
+ TraceColorScheme
.STATES_SEL0
99 - TraceColorScheme
.STATES0
;
103 // fill all rect area
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
));
115 if (rectBound
&& rect
.width
>= 3) {
116 gc
.drawRectangle(rect
.x
, rect
.y
, rect
.width
- 1,
119 // Draw the top and bottom borders i.e. no side borders
122 .drawLine(rect
.x
, rect
.y
, rect
.x
+ rect
.width
- 1,
125 gc
.drawLine(rect
.x
, rect
.y
+ rect
.height
- 1, rect
.x
126 + rect
.width
- 1, rect
.y
+ rect
.height
- 1);
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);
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,
154 // // gc.drawRectangle(rect.x + 1, rect.y + 1, rect.width - 3,
155 // // rect.height - 3);
158 // .drawLine(rect.x, rect.y, rect.x + rect.width - 1,
160 // gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x
161 // + rect.width - 1, rect.y + rect.height - 1);
163 // gc.drawLine(rect.x, rect.y + 1, rect.x + rect.width - 1,
165 // gc.drawLine(rect.x, rect.y + rect.height - 2, rect.x
166 // + rect.width - 1, rect.y + rect.height - 2);
169 // selected rectangle area is not visible but can be represented
170 // with a broken vertical line of specified width.
173 // check if height is greater than zero.
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
185 gc
.drawLine(rect
.x
, rect
.y
, rect
.x
, rect
.y
+ rect
.height
);
192 * Uses the abstract method getEventcolor to obtain an enum value and
193 * convert it to an internal color index
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
;
232 return TraceColorScheme
.BLACK_STATE
;
236 * Select the color for the different internal variants of events.
241 public abstract StateColor
getEventColor(ITimeEvent event
);
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
251 public abstract String
getTraceClassName(ITmfTimeAnalysisEntry trace
);
253 public String
getEventName(ITimeEvent event
) {
254 return getEventName(event
, true, false);
258 * Specify a Name for the event depending on its type or state e.g. blocked,
263 * True return String value in Upper case
265 * Verbose, add additional information if applicable
268 public abstract String
getEventName(ITimeEvent event
, boolean upper
,
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
+ "]";
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) + ")";
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
+ "]";
293 name
+= " (" + getEventName(event
, false, true) + ")";
297 public abstract Map
<String
, String
> getEventHoverToolTipInfo(
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
307 public Image
getItemImage(Object obj
) {
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);
316 return getImage(IMG_THREAD_RUNNING);
318 if (obj instanceof TimeEvent) {
319 return getImage(IMG_THREAD_RUNNING);
325 public abstract String
getStateName(StateColor color
);