1 /*****************************************************************************
2 * Copyright (c) 2008, 2012 Intel Corporation, Ericsson
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
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
13 *****************************************************************************/
15 package org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.graphics
.Color
;
21 * Color theme used by the timegraph view
24 * @author Patrick Tasse
26 @SuppressWarnings("javadoc")
27 public class TimeGraphColorScheme
{
29 // elements color indices
30 static public final int BLACK_STATE
= 0;
31 static public final int GREEN_STATE
= 1;
32 static public final int DARK_BLUE_STATE
= 2;
33 static public final int ORANGE_STATE
= 3;
34 static public final int GOLD_STATE
= 4;
35 static public final int RED_STATE
= 5;
36 static public final int GRAY_STATE
= 6;
37 static public final int DARK_GREEN_STATE
= 7;
38 static public final int DARK_YELLOW_STATE
= 8;
39 static public final int MAGENTA3_STATE
= 9;
40 static public final int PURPLE1_STATE
= 10;
41 static public final int PINK1_STATE
= 11;
42 static public final int AQUAMARINE_STATE
= 12;
43 static public final int LIGHT_BLUE_STATE
= 13;
44 static public final int CADET_BLUE_STATE
= 14;
45 static public final int OLIVE_STATE
= 15;
47 static public final int STATES0
= 0;
48 static public final int STATES1
= 15;
50 // selected state elements color indices
51 static public final int BLACK_STATE_SEL
= 16;
52 static public final int GREEN_STATE_SEL
= 17;
53 static public final int DARK_BLUE_STATE_SEL
= 18;
54 static public final int ORANGE_STATE_SEL
= 19;
55 static public final int GOLD_STATE_SEL
= 20;
56 static public final int RED_STATE_SEL
= 21;
57 static public final int GRAY_STATE_SEL
= 22;
58 static public final int DARK_GREEN_STATE_SEL
= 23;
59 static public final int DARK_YELLOW_STATE_SEL
= 24;
60 static public final int MAGENTA3_STATE_SEL
= 25;
61 static public final int PURPLE1_STATE_SEL
= 26;
62 static public final int PINK1_STATE_SEL
= 27;
63 static public final int AQUAMARINE_STATE_SEL
= 28;
64 static public final int LIGHT_BLUE_STATE_SEL
= 29;
65 static public final int CADET_BLUE_STATE_SEL
= 30;
66 static public final int OLIVE_STATE_SEL
= 31;
68 static public final int STATES_SEL0
= 16;
69 static public final int STATES_SEL1
= 31;
71 // colors indices for viewer controls
72 static public final int BACKGROUND
= 32;
73 static public final int FOREGROUND
= 33;
74 static public final int BACKGROUND_SEL
= 34;
75 static public final int FOREGROUND_SEL
= 35;
76 static public final int BACKGROUND_SEL_NOFOCUS
= 36;
77 static public final int FOREGROUND_SEL_NOFOCUS
= 37;
78 static public final int TOOL_BACKGROUND
= 38;
79 static public final int TOOL_FOREGROUND
= 39;
82 static public final int FIX_COLOR
= 40;
83 static public final int WHITE
= 41;
84 static public final int GRAY
= 42;
85 static public final int BLACK
= 43;
86 static public final int DARK_GRAY
= 44;
88 // selected border color indices
89 static public final int BLACK_BORDER
= 45;
90 static public final int GREEN_BORDER
= 46;
91 static public final int DARK_BLUE_BORDER
= 47;
92 static public final int ORANGE_BORDER
= 48;
93 static public final int GOLD_BORDER
= 49;
94 static public final int RED_BORDER
= 50;
95 static public final int GRAY_BORDER
= 51;
96 static public final int DARK_GREEN_BORDER1
= 52;
97 static public final int DARK_YELLOW_BORDER1
= 53;
98 static public final int MAGENTA3_BORDER1
= 54;
99 static public final int PURPLE1_BORDER1
= 55;
100 static public final int PINK1_BORDER1
= 56;
101 static public final int AQUAMARINE_BORDER1
= 57;
102 static public final int LIGHT_BLUE_BORDER1
= 58;
103 static public final int CADET_BLUE_STATE_BORDER
= 59;
104 static public final int OLIVE_BORDER2
= 60;
106 static public final int STATES_BORDER0
= 45;
107 static public final int STATES_BORDER1
= 60;
109 static public final int MID_LINE
= 61;
110 static public final int RED
= 62;
111 static public final int GREEN
= 63;
112 static public final int BLUE
= 64;
113 static public final int YELLOW
= 65;
114 static public final int CYAN
= 66;
115 static public final int MAGENTA
= 67;
117 static public final int SELECTED_TIME
= 68;
118 static public final int LEGEND_BACKGROUND
= 69;
119 static public final int LEGEND_FOREGROUND
= 70;
121 // group items' colors
122 static public final int GR_BACKGROUND
= 71;
123 static public final int GR_FOREGROUND
= 72;
124 static public final int GR_BACKGROUND_SEL
= 73;
125 static public final int GR_FOREGROUND_SEL
= 74;
126 static public final int GR_BACKGROUND_SEL_NOFOCUS
= 75;
127 static public final int GR_FOREGROUND_SEL_NOFOCUS
= 76;
129 static public final int LIGHT_LINE
= 77;
130 static public final int BACKGROUND_NAME
= 78;
131 static public final int BACKGROUND_NAME_SEL
= 79;
132 static public final int BACKGROUND_NAME_SEL_NOFOCUS
= 80;
134 // Interraction's colors
135 static public final int TI_START_THREAD
= BLACK
;
136 static public final int TI_HANDOFF_LOCK
= BLUE
;
137 static public final int TI_NOTIFY_ALL
= GREEN
;
138 static public final int TI_NOTIFY
= GREEN
;
139 static public final int TI_NOTIFY_JOINED
= DARK_GRAY
;
140 static public final int TI_INTERRUPT
= RED
;
141 static public final int TI_WAIT_EXCEEDED
= BLUE
;
143 static interface IColorProvider
{
147 static class SysCol
implements IColorProvider
{
151 this.syscol
= syscol
;
156 return Utils
.getSysColor(syscol
);
160 static class RGB
implements IColorProvider
{
165 RGB(int r
, int g
, int b
) {
173 return new Color(null, r
, g
, b
);
177 static class Mix
implements IColorProvider
{
183 Mix(IColorProvider cp1
, IColorProvider cp2
, int w1
, int w2
) {
190 Mix(IColorProvider cp1
, IColorProvider cp2
) {
199 Color col1
= cp1
.get();
200 Color col2
= cp2
.get();
201 Color col
= Utils
.mixColors(col1
, col2
, w1
, w2
);
206 static private final IColorProvider _providersMap
[] = {
208 new RGB(100, 100, 100), // UNKNOWN
209 new RGB(174, 200, 124), // RUNNING
210 new Mix(new SysCol(SWT
.COLOR_BLUE
), new SysCol(SWT
.COLOR_GRAY
), 1, 3), // SLEEPING
211 new RGB(210, 150, 60), // WAITING
212 new RGB(242, 225, 168), // BLOCKED
213 new Mix(new SysCol(SWT
.COLOR_RED
), new SysCol(SWT
.COLOR_GRAY
), 1, 3), // DEADLOCK
214 new RGB(200, 200, 200), // STOPPED
215 new RGB(35, 107, 42), // STEEL BLUE
216 new RGB(205,205,0), // DARK YELLOW
217 new RGB(205, 0, 205), // MAGENTA
218 new RGB(171, 130, 255), // PURPLE
219 new RGB(255, 181, 197), // PINK
220 new RGB(112, 219, 147), // AQUAMARINE
221 new RGB(198, 226, 255), // SLATEGRAY
222 new RGB(95, 158, 160), // CADET BLUE
223 new RGB(107, 142, 35), // OLIVE
226 //TODO: Does not seem to be used, check during clean-up
227 new SysCol(SWT
.COLOR_WHITE
), // UNKNOWN_SEL
228 new SysCol(SWT
.COLOR_GREEN
), // RUNNING_SEL
229 new SysCol(SWT
.COLOR_BLUE
), // SLEEPING_SEL
230 new SysCol(SWT
.COLOR_CYAN
), // WAITING_SEL
231 new SysCol(SWT
.COLOR_YELLOW
), // BLOCKED_SEL
232 new SysCol(SWT
.COLOR_RED
), // DEADLOCK_SEL
233 new SysCol(SWT
.COLOR_DARK_GRAY
), // STOPPED_SEL
234 new SysCol(SWT
.COLOR_WHITE
),
235 new SysCol(SWT
.COLOR_GREEN
),
236 new SysCol(SWT
.COLOR_BLUE
),
237 new SysCol(SWT
.COLOR_CYAN
),
238 new SysCol(SWT
.COLOR_YELLOW
),
239 new SysCol(SWT
.COLOR_RED
),
240 new SysCol(SWT
.COLOR_DARK_GRAY
),
241 new SysCol(SWT
.COLOR_WHITE
),
242 new SysCol(SWT
.COLOR_GREEN
),
245 new SysCol(SWT
.COLOR_LIST_BACKGROUND
), // BACKGROUND
246 new SysCol(SWT
.COLOR_LIST_FOREGROUND
), // FOREGROUND
247 new RGB(232, 242, 254), // BACKGROUND_SEL
248 new SysCol(SWT
.COLOR_LIST_FOREGROUND
), // FOREGROUND_SEL
249 new SysCol(SWT
.COLOR_WIDGET_BACKGROUND
), // BACKGROUND_SEL_NOFOCUS
250 new SysCol(SWT
.COLOR_WIDGET_FOREGROUND
), // FOREGROUND_SEL_NOFOCUS
251 new SysCol(SWT
.COLOR_WIDGET_BACKGROUND
), // TOOL_BACKGROUND
252 new SysCol(SWT
.COLOR_WIDGET_DARK_SHADOW
), // TOOL_FOREGROUND
254 new SysCol(SWT
.COLOR_GRAY
), // FIX_COLOR
255 new SysCol(SWT
.COLOR_WHITE
), // WHITE
256 new SysCol(SWT
.COLOR_GRAY
), // GRAY
257 new SysCol(SWT
.COLOR_BLACK
), // BLACK
258 new SysCol(SWT
.COLOR_DARK_GRAY
), // DARK_GRAY
260 new SysCol(SWT
.COLOR_DARK_GRAY
), // BLACK_BORDER
261 new RGB(75, 115, 120), // GREEN_BORDER
262 new SysCol(SWT
.COLOR_DARK_BLUE
), // DARK_BLUE_BORDER
263 new RGB(242, 225, 168), // ORANGE_BORDER
264 new RGB(210, 150, 60), // GOLD_BORDER
265 new SysCol(SWT
.COLOR_DARK_RED
), // RED_BORDER
266 new SysCol(SWT
.COLOR_BLACK
), // GRAY_BORDER
267 new SysCol(SWT
.COLOR_DARK_GRAY
), // DARK_GREEN_BORDER
268 new RGB(75, 115, 120), // DARK_YELLOW_BORDER
269 new SysCol(SWT
.COLOR_DARK_BLUE
), // MAGENTA3_BORDER
270 new RGB(242, 225, 168), // PURPLE1_BORDER
271 new RGB(210, 150, 60), // PINK1_BORDER
272 new SysCol(SWT
.COLOR_DARK_RED
), // AQUAMARINE_BORDER
273 new SysCol(SWT
.COLOR_BLACK
), // LIGHT_BLUE_BORDER
274 new SysCol(SWT
.COLOR_DARK_GRAY
), // BLUE_BORDER
275 new RGB(75, 115, 120), // OLIVE_BORDER
278 new SysCol(SWT
.COLOR_GRAY
), // MID_LINE
279 new SysCol(SWT
.COLOR_RED
), // RED
280 new SysCol(SWT
.COLOR_GREEN
), // GREEN
281 new SysCol(SWT
.COLOR_BLUE
), // BLUE
282 new SysCol(SWT
.COLOR_YELLOW
), // YELLOW
283 new SysCol(SWT
.COLOR_CYAN
), // CYAN
284 new SysCol(SWT
.COLOR_MAGENTA
), // MAGENTA
286 new SysCol(SWT
.COLOR_BLUE
), // SELECTED_TIME
287 new SysCol(SWT
.COLOR_WIDGET_BACKGROUND
), // LEGEND_BACKGROUND
288 new SysCol(SWT
.COLOR_WIDGET_DARK_SHADOW
), // LEGEND_FOREGROUND
290 new Mix(new RGB(150, 200, 240), new SysCol(SWT
.COLOR_LIST_BACKGROUND
)), // GR_BACKGROUND
291 new RGB(0, 0, 50), // GR_FOREGROUND
292 new Mix(new RGB(150, 200, 240), new SysCol(SWT
.COLOR_WHITE
), 6, 1), // GR_BACKGROUND_SEL
293 new RGB(0, 0, 50), // GR_FOREGROUND_SEL
294 new Mix(new RGB(150, 200, 240), new SysCol(SWT
.COLOR_WHITE
), 6, 1), // GR_BACKGROUND_SEL_NOFOCUS
295 new RGB(0, 0, 50), // GR_FOREGROUND_SEL_NOFOCUS
297 new Mix(new SysCol(SWT
.COLOR_GRAY
), new SysCol(SWT
.COLOR_LIST_BACKGROUND
), 1, 3), // LIGHT_LINE
299 new Mix(new SysCol(SWT
.COLOR_GRAY
), new SysCol(SWT
.COLOR_LIST_BACKGROUND
), 1, 6), // BACKGROUND_NAME
300 new Mix(new SysCol(SWT
.COLOR_GRAY
), new RGB(232, 242, 254), 1, 6), // BACKGROUND_NAME_SEL
301 new Mix(new SysCol(SWT
.COLOR_GRAY
), new SysCol(SWT
.COLOR_WIDGET_BACKGROUND
), 1, 6), // BACKGROUND_NAME_SEL_NOFOCUS
304 private final Color _colors
[];
307 * Default constructor
309 public TimeGraphColorScheme() {
310 _colors
= new Color
[_providersMap
.length
];
314 * Dispose this color scheme
316 public void dispose() {
317 for (int i
= 0; i
< _colors
.length
; i
++) {
318 Utils
.dispose(_colors
[i
]);
324 * Get the color matching the given index
328 * @return The matching color
330 public Color
getColor(int idx
) {
331 if (null == _colors
[idx
]) {
332 if (idx
>= STATES_SEL0
&& idx
<= STATES_SEL1
) {
333 Color col1
= getColor(idx
- STATES_SEL0
);
334 Color col2
= getColor(BACKGROUND_SEL
);
335 _colors
[idx
] = Utils
.mixColors(col1
, col2
, 3, 1);
337 _colors
[idx
] = _providersMap
[idx
].get();
344 * Get an entry's background color based on its status.
347 * If the entry is selected
349 * If the entry is focused
351 * Get the color of the name column (false for other columns)
352 * @return The matching color
354 public Color
getBkColor(boolean selected
, boolean focused
, boolean name
) {
356 if (selected
&& focused
) {
357 return getColor(BACKGROUND_NAME_SEL
);
360 return getColor(BACKGROUND_NAME_SEL_NOFOCUS
);
362 return getColor(BACKGROUND_NAME
);
364 if (selected
&& focused
) {
365 return getColor(BACKGROUND_SEL
);
368 return getColor(BACKGROUND_SEL_NOFOCUS
);
370 return getColor(BACKGROUND
);
374 * Get the correct foreground color
377 * Is the entry selected
379 * Is the entry focused
380 * @return The matching color
382 public Color
getFgColor(boolean selected
, boolean focused
) {
383 if (selected
&& focused
) {
384 return getColor(FOREGROUND_SEL
);
387 return getColor(FOREGROUND_SEL_NOFOCUS
);
389 return getColor(FOREGROUND
);
393 * Get the correct background color group
396 * Is the entry selected
398 * Is the entry focused
399 * @return The matching color
401 public Color
getBkColorGroup(boolean selected
, boolean focused
) {
402 if (selected
&& focused
) {
403 return getColor(GR_BACKGROUND_SEL
);
406 return getColor(GR_BACKGROUND_SEL_NOFOCUS
);
408 return getColor(GR_BACKGROUND
);
412 * Get the correct foreground color group
415 * Is the entry selected
417 * Is the entry focused
418 * @return The matching color
420 public Color
getFgColorGroup(boolean selected
, boolean focused
) {
421 if (selected
&& focused
) {
422 return getColor(GR_FOREGROUND_SEL
);
425 return getColor(GR_FOREGROUND_SEL_NOFOCUS
);
427 return getColor(GR_FOREGROUND
);