Commit | Line | Data |
---|---|---|
be222f56 | 1 | /***************************************************************************** |
8910dea2 | 2 | * Copyright (c) 2008, 2016 Intel Corporation, Ericsson |
be222f56 PT |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Intel Corporation - Initial API and implementation | |
10 | * Ruslan A. Scherbakov, Intel - Initial API and implementation | |
11 | * Alvaro Sanchez-Leon - Updated for TMF | |
12 | * Patrick Tasse - Refactoring | |
be222f56 PT |
13 | *****************************************************************************/ |
14 | ||
2bdf0193 | 15 | package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets; |
be222f56 | 16 | |
8910dea2 PT |
17 | import java.util.HashMap; |
18 | import java.util.Map; | |
19 | ||
be222f56 PT |
20 | import org.eclipse.swt.SWT; |
21 | import org.eclipse.swt.graphics.Color; | |
8910dea2 PT |
22 | import org.eclipse.swt.graphics.RGBA; |
23 | import org.eclipse.swt.widgets.Display; | |
be222f56 PT |
24 | |
25 | /** | |
26 | * Color theme used by the timegraph view | |
27 | * | |
28 | * @version 1.0 | |
29 | * @author Patrick Tasse | |
30 | */ | |
31 | @SuppressWarnings("javadoc") | |
32 | public class TimeGraphColorScheme { | |
33 | ||
34 | // elements color indices | |
f1fae91f PT |
35 | public static final int BLACK_STATE = 0; |
36 | public static final int GREEN_STATE = 1; | |
37 | public static final int DARK_BLUE_STATE = 2; | |
38 | public static final int ORANGE_STATE = 3; | |
39 | public static final int GOLD_STATE = 4; | |
40 | public static final int RED_STATE = 5; | |
41 | public static final int GRAY_STATE = 6; | |
42 | public static final int DARK_GREEN_STATE = 7; | |
43 | public static final int DARK_YELLOW_STATE = 8; | |
44 | public static final int MAGENTA3_STATE = 9; | |
45 | public static final int PURPLE1_STATE = 10; | |
46 | public static final int PINK1_STATE = 11; | |
47 | public static final int AQUAMARINE_STATE = 12; | |
48 | public static final int LIGHT_BLUE_STATE = 13; | |
49 | public static final int CADET_BLUE_STATE = 14; | |
50 | public static final int OLIVE_STATE = 15; | |
51 | ||
52 | public static final int STATES0 = 0; | |
53 | public static final int STATES1 = 15; | |
be222f56 PT |
54 | |
55 | // selected state elements color indices | |
f1fae91f PT |
56 | public static final int BLACK_STATE_SEL = 16; |
57 | public static final int GREEN_STATE_SEL = 17; | |
58 | public static final int DARK_BLUE_STATE_SEL = 18; | |
59 | public static final int ORANGE_STATE_SEL = 19; | |
60 | public static final int GOLD_STATE_SEL = 20; | |
61 | public static final int RED_STATE_SEL = 21; | |
62 | public static final int GRAY_STATE_SEL = 22; | |
63 | public static final int DARK_GREEN_STATE_SEL = 23; | |
64 | public static final int DARK_YELLOW_STATE_SEL = 24; | |
65 | public static final int MAGENTA3_STATE_SEL = 25; | |
66 | public static final int PURPLE1_STATE_SEL = 26; | |
67 | public static final int PINK1_STATE_SEL = 27; | |
68 | public static final int AQUAMARINE_STATE_SEL = 28; | |
69 | public static final int LIGHT_BLUE_STATE_SEL = 29; | |
70 | public static final int CADET_BLUE_STATE_SEL = 30; | |
71 | public static final int OLIVE_STATE_SEL = 31; | |
72 | ||
73 | public static final int STATES_SEL0 = 16; | |
74 | public static final int STATES_SEL1 = 31; | |
be222f56 PT |
75 | |
76 | // colors indices for viewer controls | |
f1fae91f PT |
77 | public static final int BACKGROUND = 32; |
78 | public static final int FOREGROUND = 33; | |
79 | public static final int BACKGROUND_SEL = 34; | |
80 | public static final int FOREGROUND_SEL = 35; | |
81 | public static final int BACKGROUND_SEL_NOFOCUS = 36; | |
82 | public static final int FOREGROUND_SEL_NOFOCUS = 37; | |
83 | public static final int TOOL_BACKGROUND = 38; | |
84 | public static final int TOOL_FOREGROUND = 39; | |
be222f56 PT |
85 | |
86 | // misc colors | |
f1fae91f PT |
87 | public static final int FIX_COLOR = 40; |
88 | public static final int WHITE = 41; | |
89 | public static final int GRAY = 42; | |
90 | public static final int BLACK = 43; | |
91 | public static final int DARK_GRAY = 44; | |
be222f56 PT |
92 | |
93 | // selected border color indices | |
f1fae91f PT |
94 | public static final int BLACK_BORDER = 45; |
95 | public static final int GREEN_BORDER = 46; | |
96 | public static final int DARK_BLUE_BORDER = 47; | |
97 | public static final int ORANGE_BORDER = 48; | |
98 | public static final int GOLD_BORDER = 49; | |
99 | public static final int RED_BORDER = 50; | |
100 | public static final int GRAY_BORDER = 51; | |
101 | public static final int DARK_GREEN_BORDER1 = 52; | |
102 | public static final int DARK_YELLOW_BORDER1 = 53; | |
103 | public static final int MAGENTA3_BORDER1 = 54; | |
104 | public static final int PURPLE1_BORDER1 = 55; | |
105 | public static final int PINK1_BORDER1 = 56; | |
106 | public static final int AQUAMARINE_BORDER1 = 57; | |
107 | public static final int LIGHT_BLUE_BORDER1 = 58; | |
108 | public static final int CADET_BLUE_STATE_BORDER = 59; | |
109 | public static final int OLIVE_BORDER2 = 60; | |
110 | ||
111 | public static final int STATES_BORDER0 = 45; | |
112 | public static final int STATES_BORDER1 = 60; | |
113 | ||
114 | public static final int MID_LINE = 61; | |
115 | public static final int RED = 62; | |
116 | public static final int GREEN = 63; | |
117 | public static final int BLUE = 64; | |
118 | public static final int YELLOW = 65; | |
119 | public static final int CYAN = 66; | |
120 | public static final int MAGENTA = 67; | |
121 | ||
122 | public static final int SELECTED_TIME = 68; | |
123 | public static final int LEGEND_BACKGROUND = 69; | |
124 | public static final int LEGEND_FOREGROUND = 70; | |
be222f56 PT |
125 | |
126 | // group items' colors | |
f1fae91f PT |
127 | public static final int GR_BACKGROUND = 71; |
128 | public static final int GR_FOREGROUND = 72; | |
129 | public static final int GR_BACKGROUND_SEL = 73; | |
130 | public static final int GR_FOREGROUND_SEL = 74; | |
131 | public static final int GR_BACKGROUND_SEL_NOFOCUS = 75; | |
132 | public static final int GR_FOREGROUND_SEL_NOFOCUS = 76; | |
133 | ||
134 | public static final int LIGHT_LINE = 77; | |
135 | public static final int BACKGROUND_NAME = 78; | |
136 | public static final int BACKGROUND_NAME_SEL = 79; | |
137 | public static final int BACKGROUND_NAME_SEL_NOFOCUS = 80; | |
be222f56 PT |
138 | |
139 | // Interraction's colors | |
f1fae91f PT |
140 | public static final int TI_START_THREAD = BLACK; |
141 | public static final int TI_HANDOFF_LOCK = BLUE; | |
142 | public static final int TI_NOTIFY_ALL = GREEN; | |
143 | public static final int TI_NOTIFY = GREEN; | |
144 | public static final int TI_NOTIFY_JOINED = DARK_GRAY; | |
145 | public static final int TI_INTERRUPT = RED; | |
146 | public static final int TI_WAIT_EXCEEDED = BLUE; | |
147 | ||
ca2675a9 JR |
148 | /** |
149 | * Color for the selection line when in a pinned state. | |
150 | * @since 2.2 | |
151 | */ | |
152 | public static final int SELECTED_TIME_PINNED = DARK_GRAY; | |
153 | ||
f1fae91f PT |
154 | interface IColorProvider { |
155 | Color get(); | |
be222f56 PT |
156 | } |
157 | ||
158 | static class SysCol implements IColorProvider { | |
f1fae91f | 159 | private int syscol; |
be222f56 PT |
160 | |
161 | SysCol(int syscol) { | |
162 | this.syscol = syscol; | |
163 | } | |
164 | ||
165 | @Override | |
166 | public Color get() { | |
167 | return Utils.getSysColor(syscol); | |
168 | } | |
169 | } | |
170 | ||
171 | static class RGB implements IColorProvider { | |
f1fae91f PT |
172 | private int r; |
173 | private int g; | |
174 | private int b; | |
be222f56 PT |
175 | |
176 | RGB(int r, int g, int b) { | |
177 | this.r = r; | |
178 | this.g = g; | |
179 | this.b = b; | |
180 | } | |
181 | ||
182 | @Override | |
183 | public Color get() { | |
184 | return new Color(null, r, g, b); | |
185 | } | |
186 | } | |
187 | ||
188 | static class Mix implements IColorProvider { | |
f1fae91f PT |
189 | private IColorProvider cp1; |
190 | private IColorProvider cp2; | |
191 | private int w1; | |
192 | private int w2; | |
be222f56 PT |
193 | |
194 | Mix(IColorProvider cp1, IColorProvider cp2, int w1, int w2) { | |
195 | this.cp1 = cp1; | |
196 | this.cp2 = cp2; | |
197 | this.w1 = w1; | |
198 | this.w2 = w2; | |
199 | } | |
200 | ||
201 | Mix(IColorProvider cp1, IColorProvider cp2) { | |
202 | this.cp1 = cp1; | |
203 | this.cp2 = cp2; | |
204 | this.w1 = 1; | |
205 | this.w2 = 1; | |
206 | } | |
207 | ||
208 | @Override | |
209 | public Color get() { | |
210 | Color col1 = cp1.get(); | |
211 | Color col2 = cp2.get(); | |
f1fae91f | 212 | return Utils.mixColors(col1, col2, w1, w2); |
be222f56 PT |
213 | } |
214 | } | |
215 | ||
f1fae91f | 216 | private static final IColorProvider PROVIDERS_MAP[] = { |
be222f56 PT |
217 | // |
218 | new RGB(100, 100, 100), // UNKNOWN | |
219 | new RGB(174, 200, 124), // RUNNING | |
220 | new Mix(new SysCol(SWT.COLOR_BLUE), new SysCol(SWT.COLOR_GRAY), 1, 3), // SLEEPING | |
221 | new RGB(210, 150, 60), // WAITING | |
222 | new RGB(242, 225, 168), // BLOCKED | |
223 | new Mix(new SysCol(SWT.COLOR_RED), new SysCol(SWT.COLOR_GRAY), 1, 3), // DEADLOCK | |
224 | new RGB(200, 200, 200), // STOPPED | |
225 | new RGB(35, 107, 42), // STEEL BLUE | |
226 | new RGB(205,205,0), // DARK YELLOW | |
227 | new RGB(205, 0, 205), // MAGENTA | |
228 | new RGB(171, 130, 255), // PURPLE | |
229 | new RGB(255, 181, 197), // PINK | |
230 | new RGB(112, 219, 147), // AQUAMARINE | |
231 | new RGB(198, 226, 255), // SLATEGRAY | |
232 | new RGB(95, 158, 160), // CADET BLUE | |
233 | new RGB(107, 142, 35), // OLIVE | |
234 | ||
235 | ||
236 | //TODO: Does not seem to be used, check during clean-up | |
237 | new SysCol(SWT.COLOR_WHITE), // UNKNOWN_SEL | |
238 | new SysCol(SWT.COLOR_GREEN), // RUNNING_SEL | |
239 | new SysCol(SWT.COLOR_BLUE), // SLEEPING_SEL | |
240 | new SysCol(SWT.COLOR_CYAN), // WAITING_SEL | |
241 | new SysCol(SWT.COLOR_YELLOW), // BLOCKED_SEL | |
242 | new SysCol(SWT.COLOR_RED), // DEADLOCK_SEL | |
243 | new SysCol(SWT.COLOR_DARK_GRAY), // STOPPED_SEL | |
244 | new SysCol(SWT.COLOR_WHITE), | |
245 | new SysCol(SWT.COLOR_GREEN), | |
246 | new SysCol(SWT.COLOR_BLUE), | |
247 | new SysCol(SWT.COLOR_CYAN), | |
248 | new SysCol(SWT.COLOR_YELLOW), | |
249 | new SysCol(SWT.COLOR_RED), | |
250 | new SysCol(SWT.COLOR_DARK_GRAY), | |
251 | new SysCol(SWT.COLOR_WHITE), | |
252 | new SysCol(SWT.COLOR_GREEN), | |
253 | ||
254 | ||
255 | new SysCol(SWT.COLOR_LIST_BACKGROUND), // BACKGROUND | |
256 | new SysCol(SWT.COLOR_LIST_FOREGROUND), // FOREGROUND | |
257 | new RGB(232, 242, 254), // BACKGROUND_SEL | |
258 | new SysCol(SWT.COLOR_LIST_FOREGROUND), // FOREGROUND_SEL | |
259 | new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // BACKGROUND_SEL_NOFOCUS | |
260 | new SysCol(SWT.COLOR_WIDGET_FOREGROUND), // FOREGROUND_SEL_NOFOCUS | |
261 | new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // TOOL_BACKGROUND | |
262 | new SysCol(SWT.COLOR_WIDGET_DARK_SHADOW), // TOOL_FOREGROUND | |
263 | ||
264 | new SysCol(SWT.COLOR_GRAY), // FIX_COLOR | |
265 | new SysCol(SWT.COLOR_WHITE), // WHITE | |
266 | new SysCol(SWT.COLOR_GRAY), // GRAY | |
267 | new SysCol(SWT.COLOR_BLACK), // BLACK | |
268 | new SysCol(SWT.COLOR_DARK_GRAY), // DARK_GRAY | |
269 | ||
270 | new SysCol(SWT.COLOR_DARK_GRAY), // BLACK_BORDER | |
271 | new RGB(75, 115, 120), // GREEN_BORDER | |
272 | new SysCol(SWT.COLOR_DARK_BLUE), // DARK_BLUE_BORDER | |
273 | new RGB(242, 225, 168), // ORANGE_BORDER | |
274 | new RGB(210, 150, 60), // GOLD_BORDER | |
275 | new SysCol(SWT.COLOR_DARK_RED), // RED_BORDER | |
276 | new SysCol(SWT.COLOR_BLACK), // GRAY_BORDER | |
277 | new SysCol(SWT.COLOR_DARK_GRAY), // DARK_GREEN_BORDER | |
278 | new RGB(75, 115, 120), // DARK_YELLOW_BORDER | |
279 | new SysCol(SWT.COLOR_DARK_BLUE), // MAGENTA3_BORDER | |
280 | new RGB(242, 225, 168), // PURPLE1_BORDER | |
281 | new RGB(210, 150, 60), // PINK1_BORDER | |
282 | new SysCol(SWT.COLOR_DARK_RED), // AQUAMARINE_BORDER | |
283 | new SysCol(SWT.COLOR_BLACK), // LIGHT_BLUE_BORDER | |
284 | new SysCol(SWT.COLOR_DARK_GRAY), // BLUE_BORDER | |
285 | new RGB(75, 115, 120), // OLIVE_BORDER | |
286 | ||
287 | ||
288 | new SysCol(SWT.COLOR_GRAY), // MID_LINE | |
289 | new SysCol(SWT.COLOR_RED), // RED | |
290 | new SysCol(SWT.COLOR_GREEN), // GREEN | |
291 | new SysCol(SWT.COLOR_BLUE), // BLUE | |
292 | new SysCol(SWT.COLOR_YELLOW), // YELLOW | |
293 | new SysCol(SWT.COLOR_CYAN), // CYAN | |
294 | new SysCol(SWT.COLOR_MAGENTA), // MAGENTA | |
295 | ||
296 | new SysCol(SWT.COLOR_BLUE), // SELECTED_TIME | |
297 | new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // LEGEND_BACKGROUND | |
298 | new SysCol(SWT.COLOR_WIDGET_DARK_SHADOW), // LEGEND_FOREGROUND | |
299 | ||
300 | new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_LIST_BACKGROUND)), // GR_BACKGROUND | |
301 | new RGB(0, 0, 50), // GR_FOREGROUND | |
302 | new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_WHITE), 6, 1), // GR_BACKGROUND_SEL | |
303 | new RGB(0, 0, 50), // GR_FOREGROUND_SEL | |
304 | new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_WHITE), 6, 1), // GR_BACKGROUND_SEL_NOFOCUS | |
305 | new RGB(0, 0, 50), // GR_FOREGROUND_SEL_NOFOCUS | |
306 | ||
307 | new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_LIST_BACKGROUND), 1, 3), // LIGHT_LINE | |
308 | ||
309 | new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_LIST_BACKGROUND), 1, 6), // BACKGROUND_NAME | |
310 | new Mix(new SysCol(SWT.COLOR_GRAY), new RGB(232, 242, 254), 1, 6), // BACKGROUND_NAME_SEL | |
311 | new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_WIDGET_BACKGROUND), 1, 6), // BACKGROUND_NAME_SEL_NOFOCUS | |
312 | }; | |
313 | ||
8910dea2 | 314 | /** Fixed scheme colors */ |
f1fae91f | 315 | private final Color fColors[]; |
8910dea2 PT |
316 | /** Dynamic RGBA to Color map */ |
317 | private final Map<RGBA, Color> fColorMap; | |
be222f56 PT |
318 | |
319 | /** | |
320 | * Default constructor | |
321 | */ | |
322 | public TimeGraphColorScheme() { | |
f1fae91f | 323 | fColors = new Color[PROVIDERS_MAP.length]; |
8910dea2 | 324 | fColorMap = new HashMap<>(); |
be222f56 PT |
325 | } |
326 | ||
327 | /** | |
328 | * Dispose this color scheme | |
329 | */ | |
330 | public void dispose() { | |
f1fae91f PT |
331 | for (int i = 0; i < fColors.length; i++) { |
332 | Utils.dispose(fColors[i]); | |
333 | fColors[i] = null; | |
be222f56 | 334 | } |
8910dea2 PT |
335 | for (Color color : fColorMap.values()) { |
336 | color.dispose(); | |
337 | } | |
be222f56 PT |
338 | } |
339 | ||
340 | /** | |
341 | * Get the color matching the given index | |
342 | * | |
343 | * @param idx | |
344 | * The index | |
345 | * @return The matching color | |
346 | */ | |
347 | public Color getColor(int idx) { | |
f1fae91f | 348 | if (null == fColors[idx]) { |
be222f56 PT |
349 | if (idx >= STATES_SEL0 && idx <= STATES_SEL1) { |
350 | Color col1 = getColor(idx - STATES_SEL0); | |
351 | Color col2 = getColor(BACKGROUND_SEL); | |
f1fae91f | 352 | fColors[idx] = Utils.mixColors(col1, col2, 3, 1); |
be222f56 | 353 | } else { |
f1fae91f | 354 | fColors[idx] = PROVIDERS_MAP[idx].get(); |
be222f56 PT |
355 | } |
356 | } | |
f1fae91f | 357 | return fColors[idx]; |
be222f56 PT |
358 | } |
359 | ||
360 | /** | |
361 | * Get an entry's background color based on its status. | |
362 | * | |
363 | * @param selected | |
364 | * If the entry is selected | |
365 | * @param focused | |
366 | * If the entry is focused | |
367 | * @param name | |
368 | * Get the color of the name column (false for other columns) | |
369 | * @return The matching color | |
370 | */ | |
371 | public Color getBkColor(boolean selected, boolean focused, boolean name) { | |
372 | if (name) { | |
373 | if (selected && focused) { | |
374 | return getColor(BACKGROUND_NAME_SEL); | |
375 | } | |
376 | if (selected) { | |
377 | return getColor(BACKGROUND_NAME_SEL_NOFOCUS); | |
378 | } | |
379 | return getColor(BACKGROUND_NAME); | |
380 | } | |
381 | if (selected && focused) { | |
382 | return getColor(BACKGROUND_SEL); | |
383 | } | |
384 | if (selected) { | |
385 | return getColor(BACKGROUND_SEL_NOFOCUS); | |
386 | } | |
387 | return getColor(BACKGROUND); | |
388 | } | |
389 | ||
390 | /** | |
391 | * Get the correct foreground color | |
392 | * | |
393 | * @param selected | |
394 | * Is the entry selected | |
395 | * @param focused | |
396 | * Is the entry focused | |
397 | * @return The matching color | |
398 | */ | |
399 | public Color getFgColor(boolean selected, boolean focused) { | |
400 | if (selected && focused) { | |
401 | return getColor(FOREGROUND_SEL); | |
402 | } | |
403 | if (selected) { | |
404 | return getColor(FOREGROUND_SEL_NOFOCUS); | |
405 | } | |
406 | return getColor(FOREGROUND); | |
407 | } | |
408 | ||
409 | /** | |
410 | * Get the correct background color group | |
411 | * | |
412 | * @param selected | |
413 | * Is the entry selected | |
414 | * @param focused | |
415 | * Is the entry focused | |
416 | * @return The matching color | |
417 | */ | |
418 | public Color getBkColorGroup(boolean selected, boolean focused) { | |
419 | if (selected && focused) { | |
420 | return getColor(GR_BACKGROUND_SEL); | |
421 | } | |
422 | if (selected) { | |
423 | return getColor(GR_BACKGROUND_SEL_NOFOCUS); | |
424 | } | |
425 | return getColor(GR_BACKGROUND); | |
426 | } | |
427 | ||
428 | /** | |
429 | * Get the correct foreground color group | |
430 | * | |
431 | * @param selected | |
432 | * Is the entry selected | |
433 | * @param focused | |
434 | * Is the entry focused | |
435 | * @return The matching color | |
436 | */ | |
437 | public Color getFgColorGroup(boolean selected, boolean focused) { | |
438 | if (selected && focused) { | |
439 | return getColor(GR_FOREGROUND_SEL); | |
440 | } | |
441 | if (selected) { | |
442 | return getColor(GR_FOREGROUND_SEL_NOFOCUS); | |
443 | } | |
444 | return getColor(GR_FOREGROUND); | |
445 | } | |
8910dea2 PT |
446 | |
447 | /** | |
448 | * Get a color resource for the specified RGBA color descriptor | |
449 | * | |
450 | * @param rgba | |
451 | * the color descriptor | |
452 | * @return a color resource | |
453 | * @since 2.0 | |
454 | */ | |
455 | public Color getColor(RGBA rgba) { | |
456 | Color color = fColorMap.get(rgba); | |
457 | if (color == null) { | |
458 | color = new Color(Display.getDefault(), rgba); | |
459 | fColorMap.put(rgba, color); | |
460 | } | |
461 | return color; | |
462 | } | |
463 | ||
be222f56 | 464 | } |