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.internal.lttng.ui.viewers.timeAnalysis.dialogs;
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;
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.TmfTimeLegend_LEGEND);
90
setTitle(Messages.TmfTimeLegend_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.TmfTimeLegend_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
// 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);
124
gd.verticalIndent = 8;
125
bar.setLayoutData(gd);
126
Label name = new Label(gs, SWT.NONE);
127
name.setText(stateName);
129
gd.horizontalIndent = 10;
130
gd.verticalIndent = 8;
131
name.setLayoutData(gd);
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);
142
// GridLayout layout = new GridLayout();
143
// layout.numColumns = 2;
144
// layout.marginWidth = 20;
145
// layout.marginBottom = 10;
146
// g.setLayout(layout);
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);
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);
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);
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);
180
protected void configureShell(Shell shell) {
181
super.configureShell(shell);
182
shell.setText(Messages.TmfTimeLegend_WINDOW_TITLE);
186
protected void createButtonsForButtonBar(Composite parent) {
187
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
191
class Bar extends Canvas {
194
public Bar(Composite parent, int colorIdx) {
195
super(parent, SWT.NONE);
197
color = colors.getColor(colorIdx);
198
addListener(SWT.Paint, new Listener() {
200
public void handleEvent(Event event) {
206
private void draw(GC gc) {
207
Rectangle r = getClientArea();
208
gc.setBackground(color);
210
gc.setForeground(colors.getColor(TraceColorScheme.BLACK));
211
gc.drawRectangle(0, 0, r.width - 1, r.height - 1);
215
class Arrow extends Canvas {
216
public final static int HEIGHT = 12;
217
public final static int DX = 3;
221
public Arrow(Composite parent, int colorIdx) {
222
super(parent, SWT.NONE);
224
color = colors.getColor(colorIdx);
225
addListener(SWT.Paint, new Listener() {
227
public void handleEvent(Event event) {
233
private void draw(GC gc) {
234
Rectangle r = getClientArea();
235
gc.setForeground(color);
238
if (r.height > HEIGHT) {
239
y0 = (r.height - HEIGHT) / 2;
246
gc.drawLine(DX, y0, DX, y1);
248
gc.drawLine(0, y0 + 3, DX, y0);
249
gc.drawLine(2 * DX, y0 + 3, DX, y0);
253
class Mark extends Canvas {
254
public final static int DX = 3;
258
public Mark(Composite parent, int colorIdx) {
259
super(parent, SWT.NONE);
261
color = colors.getColor(colorIdx);
262
addListener(SWT.Paint, new Listener() {
264
public void handleEvent(Event event) {
270
private void draw(GC gc) {
271
Rectangle r = getClientArea();
272
gc.setBackground(color);
274
int y = (r.height - DX) / 2;
275
int c[] = { 0, y, DX, y + DX, 2 * DX, y };