tmf: Use tabs in statistics view for each traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / internal / lttng / 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.internal.lttng.ui.viewers.timeAnalysis.dialogs;
14
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.jface.dialogs.TitleAreaDialog;
17 import org.eclipse.linuxtools.internal.lttng.ui.viewers.timeAnalysis.Messages;
18 import org.eclipse.linuxtools.internal.lttng.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider;
19 import org.eclipse.linuxtools.internal.lttng.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider.StateColor;
20 import org.eclipse.linuxtools.internal.lttng.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.TmfTimeLegend_LEGEND);
90 setTitle(Messages.TmfTimeLegend_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.TmfTimeLegend_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 // Go through all the defined colors and only add the ones you need.
112 // This will not handle several colors assigned to a color, we have
113 // 16 mil colors, and should not pick two to mean the same thing.
114 for (int i = 0; i < TraceColorScheme.getStateColors().length; i++) {
115 //Get the color enum related to the index
116 StateColor stateColor = TraceColorScheme.getStateColors()[i];
117 //Get the given name, provided by the interface to the application
118 String stateName = ifUtil.getStateName(stateColor);
119 if( stateName != "Not mapped" ) { //$NON-NLS-1$
120 Bar bar = new Bar(gs, i);
121 gd = new GridData();
122 gd.widthHint = 40;
123 gd.heightHint = 20;
124 gd.verticalIndent = 8;
125 bar.setLayoutData(gd);
126 Label name = new Label(gs, SWT.NONE);
127 name.setText(stateName);
128 gd = new GridData();
129 gd.horizontalIndent = 10;
130 gd.verticalIndent = 8;
131 name.setLayoutData(gd);
132 }
133 }
134 }
135
136 // private void createThreadInteractionsGroup(Composite composite) {
137 // Group g = new Group (composite, SWT.NONE);
138 // g.setText(UIMessages._THREAD_INTERACTIONS);
139 // GridData gd = new GridData (SWT.FILL, SWT.FILL, true, true);
140 // g.setLayoutData(gd);
141 //
142 // GridLayout layout = new GridLayout();
143 // layout.numColumns = 2;
144 // layout.marginWidth = 20;
145 // layout.marginBottom = 10;
146 // g.setLayout(layout);
147 //
148 // for (int i=0; i<5; i++) {
149 // Arrow a = new Arrow(g, interactionColors[i]);
150 // gd = new GridData();
151 // gd.widthHint = 10;
152 // gd.heightHint = 20;
153 // gd.verticalIndent = 8;
154 // a.setLayoutData(gd);
155 //
156 // Label name = new Label (g, SWT.NONE);
157 // name.setText(interactionNames[i]);
158 // gd = new GridData ();
159 // gd.horizontalIndent = 4;
160 // gd.verticalIndent = 8;
161 // name.setLayoutData(gd);
162 // }
163 //
164 // Mark m = new Mark(g, TraceColorScheme.TI_WAIT_EXCEEDED);
165 // gd = new GridData();
166 // gd.widthHint = 10;
167 // gd.heightHint = 20;
168 // gd.verticalIndent = 8;
169 // m.setLayoutData(gd);
170 //
171 // Label name = new Label (g, SWT.NONE);
172 // name.setText(UIMessages._WAIT_TIMEOUT_EXCEED);
173 // gd = new GridData ();
174 // gd.horizontalIndent = 4;
175 // gd.verticalIndent = 8;
176 // name.setLayoutData(gd);
177 // }
178
179 @Override
180 protected void configureShell(Shell shell) {
181 super.configureShell(shell);
182 shell.setText(Messages.TmfTimeLegend_WINDOW_TITLE);
183 }
184
185 @Override
186 protected void createButtonsForButtonBar(Composite parent) {
187 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
188 true);
189 }
190
191 class Bar extends Canvas {
192 private Color color;
193
194 public Bar(Composite parent, int colorIdx) {
195 super(parent, SWT.NONE);
196
197 color = colors.getColor(colorIdx);
198 addListener(SWT.Paint, new Listener() {
199 @Override
200 public void handleEvent(Event event) {
201 draw(event.gc);
202 }
203 });
204 }
205
206 private void draw(GC gc) {
207 Rectangle r = getClientArea();
208 gc.setBackground(color);
209 gc.fillRectangle(r);
210 gc.setForeground(colors.getColor(TraceColorScheme.BLACK));
211 gc.drawRectangle(0, 0, r.width - 1, r.height - 1);
212 }
213 }
214
215 class Arrow extends Canvas {
216 public final static int HEIGHT = 12;
217 public final static int DX = 3;
218
219 private Color color;
220
221 public Arrow(Composite parent, int colorIdx) {
222 super(parent, SWT.NONE);
223
224 color = colors.getColor(colorIdx);
225 addListener(SWT.Paint, new Listener() {
226 @Override
227 public void handleEvent(Event event) {
228 draw(event.gc);
229 }
230 });
231 }
232
233 private void draw(GC gc) {
234 Rectangle r = getClientArea();
235 gc.setForeground(color);
236
237 int y0, y1;
238 if (r.height > HEIGHT) {
239 y0 = (r.height - HEIGHT) / 2;
240 y1 = y0 + HEIGHT;
241 } else {
242 y0 = 0;
243 y1 = r.height;
244 }
245
246 gc.drawLine(DX, y0, DX, y1);
247
248 gc.drawLine(0, y0 + 3, DX, y0);
249 gc.drawLine(2 * DX, y0 + 3, DX, y0);
250 }
251 }
252
253 class Mark extends Canvas {
254 public final static int DX = 3;
255
256 private Color color;
257
258 public Mark(Composite parent, int colorIdx) {
259 super(parent, SWT.NONE);
260
261 color = colors.getColor(colorIdx);
262 addListener(SWT.Paint, new Listener() {
263 @Override
264 public void handleEvent(Event event) {
265 draw(event.gc);
266 }
267 });
268 }
269
270 private void draw(GC gc) {
271 Rectangle r = getClientArea();
272 gc.setBackground(color);
273
274 int y = (r.height - DX) / 2;
275 int c[] = { 0, y, DX, y + DX, 2 * DX, y };
276 gc.fillPolygon(c);
277 }
278 }
279 }
This page took 0.037871 seconds and 5 git commands to generate.