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
.dialogs
;
15 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
16 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
17 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeAnalysisProvider
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.Messages
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeAnalysisProvider
.StateColor
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.widgets
.TraceColorScheme
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.graphics
.Color
;
23 import org
.eclipse
.swt
.graphics
.GC
;
24 import org
.eclipse
.swt
.graphics
.Rectangle
;
25 import org
.eclipse
.swt
.layout
.GridData
;
26 import org
.eclipse
.swt
.layout
.GridLayout
;
27 import org
.eclipse
.swt
.widgets
.Canvas
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Control
;
30 import org
.eclipse
.swt
.widgets
.Event
;
31 import org
.eclipse
.swt
.widgets
.Group
;
32 import org
.eclipse
.swt
.widgets
.Label
;
33 import org
.eclipse
.swt
.widgets
.Listener
;
34 import org
.eclipse
.swt
.widgets
.Shell
;
37 public class TmfTimeLegend
extends TitleAreaDialog
{
39 // public static final String stateNames[] = {
40 // UIMessages._Unknown, // "Unknown",
41 // UIMessages._Running, // "Running",
42 // UIMessages._Sleeping, // "Sleeping",
43 // UIMessages._Waiting, // "Waiting",
44 // UIMessages._Blocked, // "Blocked",
45 // UIMessages._Deadlocked, // "Deadlock",
46 // UIMessages._Stopped, // "Stopped",
49 // public static final String interactionNames[] = {
50 // UIMessages._START_THREAD,
51 // UIMessages._JOIN_TERMINATE,
52 // UIMessages._WAIT_NOTIFY,
53 // UIMessages._INTERRUPT,
54 // UIMessages._RELEASE_ACQUIRE
57 public static final int interactionColors
[] = {
58 TraceColorScheme
.TI_START_THREAD
,
59 TraceColorScheme
.TI_NOTIFY_JOINED
, TraceColorScheme
.TI_NOTIFY
,
60 TraceColorScheme
.TI_INTERRUPT
, TraceColorScheme
.TI_HANDOFF_LOCK
};
62 protected TraceColorScheme colors
;
63 private TmfTimeAnalysisProvider ifUtil
;
65 public static void open(Shell parent
, TmfTimeAnalysisProvider rifUtil
) {
66 (new TmfTimeLegend(parent
, rifUtil
)).open();
69 public TmfTimeLegend(Shell parent
, TmfTimeAnalysisProvider rifUtil
) {
71 colors
= new TraceColorScheme();
72 this.ifUtil
= rifUtil
;
76 protected Control
createDialogArea(Composite parent
) {
77 Composite dlgArea
= (Composite
) super.createDialogArea(parent
);
78 Composite composite
= new Composite(dlgArea
, SWT
.NONE
);
80 GridLayout layout
= new GridLayout();
81 layout
.numColumns
= 2;
82 composite
.setLayout(layout
);
83 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
84 composite
.setLayoutData(gd
);
86 createThreadStatesGroup(composite
);
87 // createThreadInteractionsGroup(composite);
89 setMessage(Messages
._LEGEND
);
90 setTitle(Messages
.TRACE_STATES_TITLE
);
91 setDialogHelpAvailable(false);
92 setHelpAvailable(false);
94 // setTitleImage(org.eclipse.hyades.trace.internal.ui.PDPluginImages.DESC_IMG_UI_WZ_EDITPROFSET.createImage());
99 private void createThreadStatesGroup(Composite composite
) {
100 Group gs
= new Group(composite
, SWT
.NONE
);
101 gs
.setText(Messages
._TRACE_STATES
);
102 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
103 gs
.setLayoutData(gd
);
105 GridLayout layout
= new GridLayout();
106 layout
.numColumns
= 2;
107 layout
.marginWidth
= 20;
108 layout
.marginBottom
= 10;
109 gs
.setLayout(layout
);
111 for (int i
= 0; i
< 7; i
++) {
112 Bar bar
= new Bar(gs
, i
);
116 gd
.verticalIndent
= 8;
117 bar
.setLayoutData(gd
);
119 Label name
= new Label(gs
, SWT
.NONE
);
120 //Get the color enum related to the index
121 StateColor stateColor
= TraceColorScheme
.getStateColors()[i
];
122 //Get the given name, provided by the interface to the application
123 name
.setText(ifUtil
.getStateName(stateColor
));
125 gd
.horizontalIndent
= 10;
126 gd
.verticalIndent
= 8;
127 name
.setLayoutData(gd
);
131 // private void createThreadInteractionsGroup(Composite composite) {
132 // Group g = new Group (composite, SWT.NONE);
133 // g.setText(UIMessages._THREAD_INTERACTIONS);
134 // GridData gd = new GridData (SWT.FILL, SWT.FILL, true, true);
135 // g.setLayoutData(gd);
137 // GridLayout layout = new GridLayout();
138 // layout.numColumns = 2;
139 // layout.marginWidth = 20;
140 // layout.marginBottom = 10;
141 // g.setLayout(layout);
143 // for (int i=0; i<5; i++) {
144 // Arrow a = new Arrow(g, interactionColors[i]);
145 // gd = new GridData();
146 // gd.widthHint = 10;
147 // gd.heightHint = 20;
148 // gd.verticalIndent = 8;
149 // a.setLayoutData(gd);
151 // Label name = new Label (g, SWT.NONE);
152 // name.setText(interactionNames[i]);
153 // gd = new GridData ();
154 // gd.horizontalIndent = 4;
155 // gd.verticalIndent = 8;
156 // name.setLayoutData(gd);
159 // Mark m = new Mark(g, TraceColorScheme.TI_WAIT_EXCEEDED);
160 // gd = new GridData();
161 // gd.widthHint = 10;
162 // gd.heightHint = 20;
163 // gd.verticalIndent = 8;
164 // m.setLayoutData(gd);
166 // Label name = new Label (g, SWT.NONE);
167 // name.setText(UIMessages._WAIT_TIMEOUT_EXCEED);
168 // gd = new GridData ();
169 // gd.horizontalIndent = 4;
170 // gd.verticalIndent = 8;
171 // name.setLayoutData(gd);
175 protected void configureShell(Shell shell
) {
176 super.configureShell(shell
);
177 shell
.setText(Messages
._WINDOW_TITLE
);
181 protected void createButtonsForButtonBar(Composite parent
) {
182 createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.OK_LABEL
,
186 class Bar
extends Canvas
{
187 private int colorIdx
;
190 public Bar(Composite parent
, int colorIdx
) {
191 super(parent
, SWT
.NONE
);
193 this.colorIdx
= colorIdx
;
194 color
= colors
.getColor(colorIdx
);
195 addListener(SWT
.Paint
, new Listener() {
196 public void handleEvent(Event event
) {
202 private void draw(GC gc
) {
203 Rectangle r
= getClientArea();
204 gc
.setBackground(color
);
207 int my
= r
.height
/ 2;
209 if (TraceColorScheme
.GOLD_STATE
== colorIdx
210 || TraceColorScheme
.ORANGE_STATE
== colorIdx
) {
211 int s
= gc
.getLineStyle();
212 int w
= gc
.getLineWidth();
213 gc
.setLineStyle(SWT
.LINE_DOT
);
215 gc
.drawLine(0, my
, r
.width
- 1, my
);
218 } else if (TraceColorScheme
.RED_STATE
== colorIdx
219 || TraceColorScheme
.GRAY_STATE
== colorIdx
) {
220 int w
= gc
.getLineWidth();
222 gc
.drawLine(0, my
, r
.width
- 1, my
);
226 gc
.setForeground(colors
.getColor(TraceColorScheme
.BLACK
));
227 gc
.drawRectangle(0, 0, r
.width
- 1, r
.height
- 1);
231 class Arrow
extends Canvas
{
232 public final static int HEIGHT
= 12;
233 public final static int DX
= 3;
237 public Arrow(Composite parent
, int colorIdx
) {
238 super(parent
, SWT
.NONE
);
240 color
= colors
.getColor(colorIdx
);
241 addListener(SWT
.Paint
, new Listener() {
242 public void handleEvent(Event event
) {
248 private void draw(GC gc
) {
249 Rectangle r
= getClientArea();
250 gc
.setForeground(color
);
253 if (r
.height
> HEIGHT
) {
254 y0
= (r
.height
- HEIGHT
) / 2;
261 gc
.drawLine(DX
, y0
, DX
, y1
);
263 gc
.drawLine(0, y0
+ 3, DX
, y0
);
264 gc
.drawLine(2 * DX
, y0
+ 3, DX
, y0
);
268 class Mark
extends Canvas
{
269 public final static int DX
= 3;
273 public Mark(Composite parent
, int colorIdx
) {
274 super(parent
, SWT
.NONE
);
276 color
= colors
.getColor(colorIdx
);
277 addListener(SWT
.Paint
, new Listener() {
278 public void handleEvent(Event event
) {
284 private void draw(GC gc
) {
285 Rectangle r
= getClientArea();
286 gc
.setBackground(color
);
288 int y
= (r
.height
- DX
) / 2;
289 int c
[] = { 0, y
, DX
, y
+ DX
, 2 * DX
, y
};