Commit | Line | Data |
---|---|---|
b0d3496e ASL |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2009 Ericsson\r | |
3 | * \r | |
4 | * All rights reserved. This program and the accompanying materials are\r | |
5 | * made available under the terms of the Eclipse Public License v1.0 which\r | |
6 | * accompanies this distribution, and is available at\r | |
7 | * http://www.eclipse.org/legal/epl-v10.html\r | |
8 | * \r | |
9 | * Contributors:\r | |
10 | * Alvaro Sanchez-Leon - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
13 | package org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.dialogs;\r | |
14 | \r | |
15 | import org.eclipse.jface.dialogs.IDialogConstants;\r | |
16 | import org.eclipse.jface.dialogs.TitleAreaDialog;\r | |
7995b722 | 17 | import org.eclipse.linuxtools.tmf.ui.internal.Messages;\r |
b0d3496e | 18 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider;\r |
b0d3496e ASL |
19 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider.StateColor;\r |
20 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.TraceColorScheme;\r | |
21 | import org.eclipse.swt.SWT;\r | |
22 | import org.eclipse.swt.graphics.Color;\r | |
23 | import org.eclipse.swt.graphics.GC;\r | |
24 | import org.eclipse.swt.graphics.Rectangle;\r | |
25 | import org.eclipse.swt.layout.GridData;\r | |
26 | import org.eclipse.swt.layout.GridLayout;\r | |
27 | import org.eclipse.swt.widgets.Canvas;\r | |
28 | import org.eclipse.swt.widgets.Composite;\r | |
29 | import org.eclipse.swt.widgets.Control;\r | |
30 | import org.eclipse.swt.widgets.Event;\r | |
31 | import org.eclipse.swt.widgets.Group;\r | |
32 | import org.eclipse.swt.widgets.Label;\r | |
33 | import org.eclipse.swt.widgets.Listener;\r | |
34 | import org.eclipse.swt.widgets.Shell;\r | |
35 | \r | |
36 | \r | |
37 | public class TmfTimeLegend extends TitleAreaDialog {\r | |
38 | \r | |
39 | // public static final String stateNames[] = {\r | |
40 | // UIMessages._Unknown, // "Unknown",\r | |
41 | // UIMessages._Running, // "Running",\r | |
42 | // UIMessages._Sleeping, // "Sleeping",\r | |
43 | // UIMessages._Waiting, // "Waiting",\r | |
44 | // UIMessages._Blocked, // "Blocked",\r | |
45 | // UIMessages._Deadlocked, // "Deadlock",\r | |
46 | // UIMessages._Stopped, // "Stopped",\r | |
47 | // };\r | |
48 | \r | |
49 | // public static final String interactionNames[] = {\r | |
50 | // UIMessages._START_THREAD,\r | |
51 | // UIMessages._JOIN_TERMINATE,\r | |
52 | // UIMessages._WAIT_NOTIFY,\r | |
53 | // UIMessages._INTERRUPT,\r | |
54 | // UIMessages._RELEASE_ACQUIRE\r | |
55 | // };\r | |
56 | \r | |
57 | public static final int interactionColors[] = {\r | |
58 | TraceColorScheme.TI_START_THREAD,\r | |
59 | TraceColorScheme.TI_NOTIFY_JOINED, TraceColorScheme.TI_NOTIFY,\r | |
60 | TraceColorScheme.TI_INTERRUPT, TraceColorScheme.TI_HANDOFF_LOCK };\r | |
61 | \r | |
62 | protected TraceColorScheme colors;\r | |
63 | private TmfTimeAnalysisProvider ifUtil;\r | |
64 | \r | |
65 | public static void open(Shell parent, TmfTimeAnalysisProvider rifUtil) {\r | |
66 | (new TmfTimeLegend(parent, rifUtil)).open();\r | |
67 | }\r | |
68 | \r | |
69 | public TmfTimeLegend(Shell parent, TmfTimeAnalysisProvider rifUtil) {\r | |
70 | super(parent);\r | |
71 | colors = new TraceColorScheme();\r | |
72 | this.ifUtil = rifUtil;\r | |
73 | }\r | |
74 | \r | |
4e3aa37d | 75 | @Override\r |
b0d3496e ASL |
76 | protected Control createDialogArea(Composite parent) {\r |
77 | Composite dlgArea = (Composite) super.createDialogArea(parent);\r | |
78 | Composite composite = new Composite(dlgArea, SWT.NONE);\r | |
79 | \r | |
80 | GridLayout layout = new GridLayout();\r | |
81 | layout.numColumns = 2;\r | |
82 | composite.setLayout(layout);\r | |
83 | GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);\r | |
84 | composite.setLayoutData(gd);\r | |
85 | \r | |
86 | createThreadStatesGroup(composite);\r | |
87 | // createThreadInteractionsGroup(composite);\r | |
88 | \r | |
7995b722 FC |
89 | setMessage(Messages.TmfTimeLegend_LEGEND);\r |
90 | setTitle(Messages.TmfTimeLegend_TRACE_STATES_TITLE);\r | |
b0d3496e ASL |
91 | setDialogHelpAvailable(false);\r |
92 | setHelpAvailable(false);\r | |
93 | \r | |
c48abe58 | 94 | //setTitleImage(org.eclipse.hyades.trace.internal.ui.PDPluginImages.DESC_IMG_UI_WZ_EDITPROFSET.createImage());\r |
b0d3496e ASL |
95 | \r |
96 | return composite;\r | |
97 | }\r | |
98 | \r | |
99 | private void createThreadStatesGroup(Composite composite) {\r | |
100 | Group gs = new Group(composite, SWT.NONE);\r | |
7995b722 | 101 | gs.setText(Messages.TmfTimeLegend_TRACE_STATES);\r |
b0d3496e ASL |
102 | GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);\r |
103 | gs.setLayoutData(gd);\r | |
104 | \r | |
105 | GridLayout layout = new GridLayout();\r | |
106 | layout.numColumns = 2;\r | |
107 | layout.marginWidth = 20;\r | |
108 | layout.marginBottom = 10;\r | |
109 | gs.setLayout(layout);\r | |
110 | \r | |
c48abe58 FC |
111 | // Go through all the defined colors and only add the ones you need. \r |
112 | // This will not handle several colors assigned to a color, we have \r | |
113 | // 16 mil colors, and should not pick two to mean the same thing. \r | |
114 | for (int i = 0; i < TraceColorScheme.getStateColors().length; i++) {\r | |
b0d3496e ASL |
115 | //Get the color enum related to the index\r |
116 | StateColor stateColor = TraceColorScheme.getStateColors()[i];\r | |
117 | //Get the given name, provided by the interface to the application\r | |
c48abe58 | 118 | String stateName = ifUtil.getStateName(stateColor);\r |
a79913eb | 119 | if( stateName != "Not mapped" ) { //$NON-NLS-1$\r |
c48abe58 FC |
120 | Bar bar = new Bar(gs, i);\r |
121 | gd = new GridData();\r | |
122 | gd.widthHint = 40;\r | |
123 | gd.heightHint = 20;\r | |
124 | gd.verticalIndent = 8;\r | |
125 | bar.setLayoutData(gd);\r | |
126 | Label name = new Label(gs, SWT.NONE);\r | |
127 | name.setText(stateName);\r | |
128 | gd = new GridData();\r | |
129 | gd.horizontalIndent = 10;\r | |
130 | gd.verticalIndent = 8;\r | |
131 | name.setLayoutData(gd);\r | |
132 | }\r | |
b0d3496e ASL |
133 | }\r |
134 | }\r | |
135 | \r | |
136 | // private void createThreadInteractionsGroup(Composite composite) {\r | |
137 | // Group g = new Group (composite, SWT.NONE);\r | |
138 | // g.setText(UIMessages._THREAD_INTERACTIONS);\r | |
139 | // GridData gd = new GridData (SWT.FILL, SWT.FILL, true, true);\r | |
140 | // g.setLayoutData(gd);\r | |
141 | //\r | |
142 | // GridLayout layout = new GridLayout();\r | |
143 | // layout.numColumns = 2;\r | |
144 | // layout.marginWidth = 20;\r | |
145 | // layout.marginBottom = 10;\r | |
146 | // g.setLayout(layout);\r | |
147 | // \r | |
148 | // for (int i=0; i<5; i++) {\r | |
149 | // Arrow a = new Arrow(g, interactionColors[i]);\r | |
150 | // gd = new GridData();\r | |
151 | // gd.widthHint = 10;\r | |
152 | // gd.heightHint = 20;\r | |
153 | // gd.verticalIndent = 8;\r | |
154 | // a.setLayoutData(gd);\r | |
155 | // \r | |
156 | // Label name = new Label (g, SWT.NONE);\r | |
157 | // name.setText(interactionNames[i]);\r | |
158 | // gd = new GridData ();\r | |
159 | // gd.horizontalIndent = 4;\r | |
160 | // gd.verticalIndent = 8;\r | |
161 | // name.setLayoutData(gd);\r | |
162 | // }\r | |
163 | //\r | |
164 | // Mark m = new Mark(g, TraceColorScheme.TI_WAIT_EXCEEDED);\r | |
165 | // gd = new GridData();\r | |
166 | // gd.widthHint = 10;\r | |
167 | // gd.heightHint = 20;\r | |
168 | // gd.verticalIndent = 8;\r | |
169 | // m.setLayoutData(gd);\r | |
170 | // \r | |
171 | // Label name = new Label (g, SWT.NONE);\r | |
172 | // name.setText(UIMessages._WAIT_TIMEOUT_EXCEED);\r | |
173 | // gd = new GridData ();\r | |
174 | // gd.horizontalIndent = 4;\r | |
175 | // gd.verticalIndent = 8;\r | |
176 | // name.setLayoutData(gd);\r | |
177 | // }\r | |
178 | \r | |
4e3aa37d | 179 | @Override\r |
b0d3496e ASL |
180 | protected void configureShell(Shell shell) {\r |
181 | super.configureShell(shell);\r | |
7995b722 | 182 | shell.setText(Messages.TmfTimeLegend_WINDOW_TITLE);\r |
b0d3496e ASL |
183 | }\r |
184 | \r | |
4e3aa37d | 185 | @Override\r |
b0d3496e ASL |
186 | protected void createButtonsForButtonBar(Composite parent) {\r |
187 | createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,\r | |
188 | true);\r | |
189 | }\r | |
190 | \r | |
191 | class Bar extends Canvas {\r | |
b0d3496e ASL |
192 | private Color color;\r |
193 | \r | |
194 | public Bar(Composite parent, int colorIdx) {\r | |
195 | super(parent, SWT.NONE);\r | |
196 | \r | |
b0d3496e ASL |
197 | color = colors.getColor(colorIdx);\r |
198 | addListener(SWT.Paint, new Listener() {\r | |
d4011df2 | 199 | @Override\r |
b0d3496e ASL |
200 | public void handleEvent(Event event) {\r |
201 | draw(event.gc);\r | |
202 | }\r | |
203 | });\r | |
204 | }\r | |
205 | \r | |
206 | private void draw(GC gc) {\r | |
207 | Rectangle r = getClientArea();\r | |
208 | gc.setBackground(color);\r | |
209 | gc.fillRectangle(r);\r | |
b0d3496e ASL |
210 | gc.setForeground(colors.getColor(TraceColorScheme.BLACK));\r |
211 | gc.drawRectangle(0, 0, r.width - 1, r.height - 1);\r | |
212 | }\r | |
213 | }\r | |
214 | \r | |
215 | class Arrow extends Canvas {\r | |
216 | public final static int HEIGHT = 12;\r | |
217 | public final static int DX = 3;\r | |
218 | \r | |
219 | private Color color;\r | |
220 | \r | |
221 | public Arrow(Composite parent, int colorIdx) {\r | |
222 | super(parent, SWT.NONE);\r | |
223 | \r | |
224 | color = colors.getColor(colorIdx);\r | |
225 | addListener(SWT.Paint, new Listener() {\r | |
d4011df2 | 226 | @Override\r |
b0d3496e ASL |
227 | public void handleEvent(Event event) {\r |
228 | draw(event.gc);\r | |
229 | }\r | |
230 | });\r | |
231 | }\r | |
232 | \r | |
233 | private void draw(GC gc) {\r | |
234 | Rectangle r = getClientArea();\r | |
235 | gc.setForeground(color);\r | |
236 | \r | |
237 | int y0, y1;\r | |
238 | if (r.height > HEIGHT) {\r | |
239 | y0 = (r.height - HEIGHT) / 2;\r | |
240 | y1 = y0 + HEIGHT;\r | |
241 | } else {\r | |
242 | y0 = 0;\r | |
243 | y1 = r.height;\r | |
244 | }\r | |
245 | \r | |
246 | gc.drawLine(DX, y0, DX, y1);\r | |
247 | \r | |
248 | gc.drawLine(0, y0 + 3, DX, y0);\r | |
249 | gc.drawLine(2 * DX, y0 + 3, DX, y0);\r | |
250 | }\r | |
251 | }\r | |
252 | \r | |
253 | class Mark extends Canvas {\r | |
254 | public final static int DX = 3;\r | |
255 | \r | |
256 | private Color color;\r | |
257 | \r | |
258 | public Mark(Composite parent, int colorIdx) {\r | |
259 | super(parent, SWT.NONE);\r | |
260 | \r | |
261 | color = colors.getColor(colorIdx);\r | |
262 | addListener(SWT.Paint, new Listener() {\r | |
d4011df2 | 263 | @Override\r |
b0d3496e ASL |
264 | public void handleEvent(Event event) {\r |
265 | draw(event.gc);\r | |
266 | }\r | |
267 | });\r | |
268 | }\r | |
269 | \r | |
270 | private void draw(GC gc) {\r | |
271 | Rectangle r = getClientArea();\r | |
272 | gc.setBackground(color);\r | |
273 | \r | |
274 | int y = (r.height - DX) / 2;\r | |
275 | int c[] = { 0, y, DX, y + DX, 2 * DX, y };\r | |
276 | gc.fillPolygon(c);\r | |
277 | }\r | |
278 | }\r | |
279 | }\r |