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