(no commit message)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / viewers / timeAnalysis / dialogs / TmfTimeLegend.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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.dialogs;
14
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;
35
36
37 public class TmfTimeLegend extends TitleAreaDialog {
38
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",
47 // };
48
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
55 // };
56
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 };
61
62 protected TraceColorScheme colors;
63 private TmfTimeAnalysisProvider ifUtil;
64
65 public static void open(Shell parent, TmfTimeAnalysisProvider rifUtil) {
66 (new TmfTimeLegend(parent, rifUtil)).open();
67 }
68
69 public TmfTimeLegend(Shell parent, TmfTimeAnalysisProvider rifUtil) {
70 super(parent);
71 colors = new TraceColorScheme();
72 this.ifUtil = rifUtil;
73 }
74
75 @Override
76 protected Control createDialogArea(Composite parent) {
77 Composite dlgArea = (Composite) super.createDialogArea(parent);
78 Composite composite = new Composite(dlgArea, SWT.NONE);
79
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);
85
86 createThreadStatesGroup(composite);
87 // createThreadInteractionsGroup(composite);
88
89 setMessage(Messages._LEGEND);
90 setTitle(Messages.TRACE_STATES_TITLE);
91 setDialogHelpAvailable(false);
92 setHelpAvailable(false);
93
94 // setTitleImage(org.eclipse.hyades.trace.internal.ui.PDPluginImages.DESC_IMG_UI_WZ_EDITPROFSET.createImage());
95
96 return composite;
97 }
98
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);
104
105 GridLayout layout = new GridLayout();
106 layout.numColumns = 2;
107 layout.marginWidth = 20;
108 layout.marginBottom = 10;
109 gs.setLayout(layout);
110
111 for (int i = 0; i < 7; i++) {
112 Bar bar = new Bar(gs, i);
113 gd = new GridData();
114 gd.widthHint = 40;
115 gd.heightHint = 20;
116 gd.verticalIndent = 8;
117 bar.setLayoutData(gd);
118
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));
124 gd = new GridData();
125 gd.horizontalIndent = 10;
126 gd.verticalIndent = 8;
127 name.setLayoutData(gd);
128 }
129 }
130
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);
136 //
137 // GridLayout layout = new GridLayout();
138 // layout.numColumns = 2;
139 // layout.marginWidth = 20;
140 // layout.marginBottom = 10;
141 // g.setLayout(layout);
142 //
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);
150 //
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);
157 // }
158 //
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);
165 //
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);
172 // }
173
174 @Override
175 protected void configureShell(Shell shell) {
176 super.configureShell(shell);
177 shell.setText(Messages._WINDOW_TITLE);
178 }
179
180 @Override
181 protected void createButtonsForButtonBar(Composite parent) {
182 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
183 true);
184 }
185
186 class Bar extends Canvas {
187 private int colorIdx;
188 private Color color;
189
190 public Bar(Composite parent, int colorIdx) {
191 super(parent, SWT.NONE);
192
193 this.colorIdx = colorIdx;
194 color = colors.getColor(colorIdx);
195 addListener(SWT.Paint, new Listener() {
196 public void handleEvent(Event event) {
197 draw(event.gc);
198 }
199 });
200 }
201
202 private void draw(GC gc) {
203 Rectangle r = getClientArea();
204 gc.setBackground(color);
205 gc.fillRectangle(r);
206
207 int my = r.height / 2;
208
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);
214 gc.setLineWidth(2);
215 gc.drawLine(0, my, r.width - 1, my);
216 gc.setLineStyle(s);
217 gc.setLineWidth(w);
218 } else if (TraceColorScheme.RED_STATE == colorIdx
219 || TraceColorScheme.GRAY_STATE == colorIdx) {
220 int w = gc.getLineWidth();
221 gc.setLineWidth(2);
222 gc.drawLine(0, my, r.width - 1, my);
223 gc.setLineWidth(w);
224 }
225
226 gc.setForeground(colors.getColor(TraceColorScheme.BLACK));
227 gc.drawRectangle(0, 0, r.width - 1, r.height - 1);
228 }
229 }
230
231 class Arrow extends Canvas {
232 public final static int HEIGHT = 12;
233 public final static int DX = 3;
234
235 private Color color;
236
237 public Arrow(Composite parent, int colorIdx) {
238 super(parent, SWT.NONE);
239
240 color = colors.getColor(colorIdx);
241 addListener(SWT.Paint, new Listener() {
242 public void handleEvent(Event event) {
243 draw(event.gc);
244 }
245 });
246 }
247
248 private void draw(GC gc) {
249 Rectangle r = getClientArea();
250 gc.setForeground(color);
251
252 int y0, y1;
253 if (r.height > HEIGHT) {
254 y0 = (r.height - HEIGHT) / 2;
255 y1 = y0 + HEIGHT;
256 } else {
257 y0 = 0;
258 y1 = r.height;
259 }
260
261 gc.drawLine(DX, y0, DX, y1);
262
263 gc.drawLine(0, y0 + 3, DX, y0);
264 gc.drawLine(2 * DX, y0 + 3, DX, y0);
265 }
266 }
267
268 class Mark extends Canvas {
269 public final static int DX = 3;
270
271 private Color color;
272
273 public Mark(Composite parent, int colorIdx) {
274 super(parent, SWT.NONE);
275
276 color = colors.getColor(colorIdx);
277 addListener(SWT.Paint, new Listener() {
278 public void handleEvent(Event event) {
279 draw(event.gc);
280 }
281 });
282 }
283
284 private void draw(GC gc) {
285 Rectangle r = getClientArea();
286 gc.setBackground(color);
287
288 int y = (r.height - DX) / 2;
289 int c[] = { 0, y, DX, y + DX, 2 * DX, y };
290 gc.fillPolygon(c);
291 }
292 }
293 }
This page took 0.036749 seconds and 5 git commands to generate.