1 /*****************************************************************************
2 * Copyright (c) 2008 Intel Corporation.
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 Sanchex-Leon - Udpated for TMF
13 * $Id: TraceColorScheme.java,v 1.3 2008/05/09 16:11:24 jkubasta Exp $
14 *****************************************************************************/
16 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.viewers
.timeAnalysis
.widgets
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.timeAnalysis
.TmfTimeAnalysisProvider
.StateColor
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.graphics
.Color
;
23 public class TraceColorScheme
{
25 // elements color indices
26 static public final int BLACK_STATE
= 0;
27 static public final int GREEN_STATE
= 1;
28 static public final int DARK_BLUE_STATE
= 2;
29 static public final int ORANGE_STATE
= 3;
30 static public final int GOLD_STATE
= 4;
31 static public final int RED_STATE
= 5;
32 static public final int GRAY_STATE
= 6;
33 static public final int DARK_GREEN_STATE
= 7;
34 static public final int DARK_YELLOW_STATE
= 8;
35 static public final int MAGENTA3_STATE
= 9;
36 static public final int PURPLE1_STATE
= 10;
37 static public final int PINK1_STATE
= 11;
38 static public final int AQUAMARINE_STATE
= 12;
39 static public final int LIGHT_BLUE_STATE
= 13;
40 static public final int CADET_BLUE_STATE
= 14;
41 static public final int OLIVE_STATE
= 15;
43 static public final int STATES0
= 0;
44 static public final int STATES1
= 15;
46 // State element index to name mapping, must keep the same order as above
47 public static final StateColor stateColors
[] = { StateColor
.BLACK
,
48 StateColor
.GREEN
, StateColor
.DARK_BLUE
, StateColor
.ORANGE
,
49 StateColor
.GOLD
, StateColor
.RED
, StateColor
.GRAY
, StateColor
.DARK_GREEN
, StateColor
.DARK_YELLOW
, StateColor
.MAGENTA3
, StateColor
.PURPLE1
,
50 StateColor
.PINK1
, StateColor
.AQUAMARINE
, StateColor
.LIGHT_BLUE
, StateColor
.CADET_BLUE
, StateColor
.OLIVE
53 // selected state elements color indices
54 static public final int BLACK_STATE_SEL
= 16;
55 static public final int GREEN_STATE_SEL
= 17;
56 static public final int DARK_BLUE_STATE_SEL
= 18;
57 static public final int ORANGE_STATE_SEL
= 19;
58 static public final int GOLD_STATE_SEL
= 20;
59 static public final int RED_STATE_SEL
= 21;
60 static public final int GRAY_STATE_SEL
= 22;
61 static public final int DARK_GREEN_STATE_SEL
= 23;
62 static public final int DARK_YELLOW_STATE_SEL
= 24;
63 static public final int MAGENTA3_STATE_SEL
= 25;
64 static public final int PURPLE1_STATE_SEL
= 26;
65 static public final int PINK1_STATE_SEL
= 27;
66 static public final int AQUAMARINE_STATE_SEL
= 28;
67 static public final int LIGHT_BLUE_STATE_SEL
= 29;
68 static public final int CADET_BLUE_STATE_SEL
= 30;
69 static public final int OLIVE_STATE_SEL
= 31;
71 static public final int STATES_SEL0
= 16;
72 static public final int STATES_SEL1
= 31;
74 // colors indices for viewer controls
75 static public final int BACKGROUND
= 32;
76 static public final int FOREGROUND
= 33;
77 static public final int BACKGROUND_SEL
= 34;
78 static public final int FOREGROUND_SEL
= 35;
79 static public final int BACKGROUND_SEL_NOFOCUS
= 36;
80 static public final int FOREGROUND_SEL_NOFOCUS
= 37;
81 static public final int TOOL_BACKGROUND
= 38;
82 static public final int TOOL_FOREGROUND
= 39;
85 static public final int FIX_COLOR
= 40;
86 static public final int WHITE
= 41;
87 static public final int GRAY
= 42;
88 static public final int BLACK
= 43;
89 static public final int DARK_GRAY
= 44;
91 // selected border color indices
92 static public final int BLACK_BORDER
= 45;
93 static public final int GREEN_BORDER
= 46;
94 static public final int DARK_BLUE_BORDER
= 47;
95 static public final int ORANGE_BORDER
= 48;
96 static public final int GOLD_BORDER
= 49;
97 static public final int RED_BORDER
= 50;
98 static public final int GRAY_BORDER
= 51;
99 static public final int DARK_GREEN_BORDER1
= 52;
100 static public final int DARK_YELLOW_BORDER1
= 53;
101 static public final int MAGENTA3_BORDER1
= 54;
102 static public final int PURPLE1_BORDER1
= 55;
103 static public final int PINK1_BORDER1
= 56;
104 static public final int AQUAMARINE_BORDER1
= 57;
105 static public final int LIGHT_BLUE_BORDER1
= 58;
106 static public final int CADET_BLUE_STATE_BORDER
= 59;
107 static public final int OLIVE_BORDER2
= 60;
109 static public final int STATES_BORDER0
= 45;
110 static public final int STATES_BORDER1
= 60;
112 static public final int MID_LINE
= 61;
113 static public final int RED
= 62;
114 static public final int GREEN
= 63;
115 static public final int BLUE
= 64;
116 static public final int YELLOW
= 65;
117 static public final int CYAN
= 66;
118 static public final int MAGENTA
= 67;
120 static public final int SELECTED_TIME
= 68;
121 static public final int LEGEND_BACKGROUND
= 69;
122 static public final int LEGEND_FOREGROUND
= 70;
124 // group items' colors
125 static public final int GR_BACKGROUND
= 71;
126 static public final int GR_FOREGROUND
= 72;
127 static public final int GR_BACKGROUND_SEL
= 73;
128 static public final int GR_FOREGROUND_SEL
= 74;
129 static public final int GR_BACKGROUND_SEL_NOFOCUS
= 75;
130 static public final int GR_FOREGROUND_SEL_NOFOCUS
= 76;
132 static public final int LIGHT_LINE
= 77;
133 static public final int BACKGROUND_NAME
= 78;
134 static public final int BACKGROUND_NAME_SEL
= 79;
135 static public final int BACKGROUND_NAME_SEL_NOFOCUS
= 80;
137 // Interraction's colors
138 static public final int TI_START_THREAD
= BLACK
;
139 static public final int TI_HANDOFF_LOCK
= BLUE
;
140 static public final int TI_NOTIFY_ALL
= GREEN
;
141 static public final int TI_NOTIFY
= GREEN
;
142 static public final int TI_NOTIFY_JOINED
= DARK_GRAY
;
143 static public final int TI_INTERRUPT
= RED
;
144 static public final int TI_WAIT_EXCEEDED
= BLUE
;
146 static interface IColorProvider
{
150 static class SysCol
implements IColorProvider
{
154 this.syscol
= syscol
;
159 return Utils
.getSysColor(syscol
);
163 static class RGB
implements IColorProvider
{
168 RGB(int r
, int g
, int b
) {
176 return new Color(null, r
, g
, b
);
180 static class Mix
implements IColorProvider
{
186 Mix(IColorProvider cp1
, IColorProvider cp2
, int w1
, int w2
) {
193 Mix(IColorProvider cp1
, IColorProvider cp2
) {
202 Color col1
= cp1
.get();
203 Color col2
= cp2
.get();
204 Color col
= Utils
.mixColors(col1
, col2
, w1
, w2
);
209 static private final IColorProvider _providersMap
[] = {
211 new RGB(100, 100, 100), // UNKNOWN
212 new RGB(174, 200, 124), // RUNNING
213 new Mix(new SysCol(SWT
.COLOR_BLUE
), new SysCol(SWT
.COLOR_GRAY
), 1, 3), // SLEEPING
214 new RGB(210, 150, 60), // WAITING
215 new RGB(242, 225, 168), // BLOCKED
216 new Mix(new SysCol(SWT
.COLOR_RED
), new SysCol(SWT
.COLOR_GRAY
), 1, 3), // DEADLOCK
217 new RGB(200, 200, 200), // STOPPED
218 new RGB(35, 107, 42), // STEEL BLUE
219 new RGB(205,205,0), // DARK YELLOW
220 new RGB(205, 0, 205), // MAGENTA
221 new RGB(171, 130, 255), // PURPLE
222 new RGB(255, 181, 197), // PINK
223 new RGB(112, 219, 147), // AQUAMARINE
224 new RGB(198, 226, 255), // SLATEGRAY
225 new RGB(95, 158, 160), // CADET BLUE
226 new RGB(107, 142, 35), // OLIVE
229 //TODO: Does not seem to be used, check during clean-up
230 new SysCol(SWT
.COLOR_WHITE
), // UNKNOWN_SEL
231 new SysCol(SWT
.COLOR_GREEN
), // RUNNING_SEL
232 new SysCol(SWT
.COLOR_BLUE
), // SLEEPING_SEL
233 new SysCol(SWT
.COLOR_CYAN
), // WAITING_SEL
234 new SysCol(SWT
.COLOR_YELLOW
), // BLOCKED_SEL
235 new SysCol(SWT
.COLOR_RED
), // DEADLOCK_SEL
236 new SysCol(SWT
.COLOR_DARK_GRAY
), // STOPPED_SEL
237 new SysCol(SWT
.COLOR_WHITE
),
238 new SysCol(SWT
.COLOR_GREEN
),
239 new SysCol(SWT
.COLOR_BLUE
),
240 new SysCol(SWT
.COLOR_CYAN
),
241 new SysCol(SWT
.COLOR_YELLOW
),
242 new SysCol(SWT
.COLOR_RED
),
243 new SysCol(SWT
.COLOR_DARK_GRAY
),
244 new SysCol(SWT
.COLOR_WHITE
),
245 new SysCol(SWT
.COLOR_GREEN
),
248 new SysCol(SWT
.COLOR_LIST_BACKGROUND
), // BACKGROUND
249 new SysCol(SWT
.COLOR_LIST_FOREGROUND
), // FOREGROUND
250 new RGB(232, 242, 254), // BACKGROUND_SEL
251 new SysCol(SWT
.COLOR_LIST_FOREGROUND
), // FOREGROUND_SEL
252 new SysCol(SWT
.COLOR_WIDGET_BACKGROUND
), // BACKGROUND_SEL_NOFOCUS
253 new SysCol(SWT
.COLOR_WIDGET_FOREGROUND
), // FOREGROUND_SEL_NOFOCUS
254 new SysCol(SWT
.COLOR_WIDGET_BACKGROUND
), // TOOL_BACKGROUND
255 new SysCol(SWT
.COLOR_WIDGET_DARK_SHADOW
), // TOOL_FOREGROUND
257 new SysCol(SWT
.COLOR_GRAY
), // FIX_COLOR
258 new SysCol(SWT
.COLOR_WHITE
), // WHITE
259 new SysCol(SWT
.COLOR_GRAY
), // GRAY
260 new SysCol(SWT
.COLOR_BLACK
), // BLACK
261 new SysCol(SWT
.COLOR_DARK_GRAY
), // DARK_GRAY
263 new SysCol(SWT
.COLOR_DARK_GRAY
), // BLACK_BORDER
264 new RGB(75, 115, 120), // GREEN_BORDER
265 new SysCol(SWT
.COLOR_DARK_BLUE
), // DARK_BLUE_BORDER
266 new RGB(242, 225, 168), // ORANGE_BORDER
267 new RGB(210, 150, 60), // GOLD_BORDER
268 new SysCol(SWT
.COLOR_DARK_RED
), // RED_BORDER
269 new SysCol(SWT
.COLOR_BLACK
), // GRAY_BORDER
270 new SysCol(SWT
.COLOR_DARK_GRAY
), // DARK_GREEN_BORDER
271 new RGB(75, 115, 120), // DARK_YELLOW_BORDER
272 new SysCol(SWT
.COLOR_DARK_BLUE
), // MAGENTA3_BORDER
273 new RGB(242, 225, 168), // PURPLE1_BORDER
274 new RGB(210, 150, 60), // PINK1_BORDER
275 new SysCol(SWT
.COLOR_DARK_RED
), // AQUAMARINE_BORDER
276 new SysCol(SWT
.COLOR_BLACK
), // LIGHT_BLUE_BORDER
277 new SysCol(SWT
.COLOR_DARK_GRAY
), // BLUE_BORDER
278 new RGB(75, 115, 120), // OLIVE_BORDER
281 new SysCol(SWT
.COLOR_GRAY
), // MID_LINE
282 new SysCol(SWT
.COLOR_RED
), // RED
283 new SysCol(SWT
.COLOR_GREEN
), // GREEN
284 new SysCol(SWT
.COLOR_BLUE
), // BLUE
285 new SysCol(SWT
.COLOR_YELLOW
), // YELLOW
286 new SysCol(SWT
.COLOR_CYAN
), // CYAN
287 new SysCol(SWT
.COLOR_MAGENTA
), // MAGENTA
289 new SysCol(SWT
.COLOR_BLUE
), // SELECTED_TIME
290 new SysCol(SWT
.COLOR_WIDGET_BACKGROUND
), // LEGEND_BACKGROUND
291 new SysCol(SWT
.COLOR_WIDGET_DARK_SHADOW
), // LEGEND_FOREGROUND
293 new Mix(new RGB(150, 200, 240), new SysCol(
294 SWT
.COLOR_LIST_BACKGROUND
)),// GR_BACKGROUND
295 new RGB(0, 0, 50), // GR_FOREGROUND
296 new Mix(new RGB(200, 200, 100),
297 new SysCol(SWT
.COLOR_LIST_SELECTION
)), // GR_BACKGROUND_SEL
298 new Mix(new RGB(150, 200, 240), new SysCol(
299 SWT
.COLOR_LIST_SELECTION_TEXT
)), // GR_FOREGROUND_SEL
300 new Mix(new RGB(222, 222, 155), new SysCol(
301 SWT
.COLOR_WIDGET_BACKGROUND
)), // GR_BACKGROUND_SEL_NOFOCUS
302 new RGB(0, 0, 50), // GR_FOREGROUND_SEL_NOFOCUS
304 new Mix(new SysCol(SWT
.COLOR_GRAY
), new SysCol(
305 SWT
.COLOR_LIST_BACKGROUND
), 1, 3), // LIGHT_LINE
307 new Mix(new SysCol(SWT
.COLOR_GRAY
), new SysCol(SWT
.COLOR_LIST_BACKGROUND
), 1, 6), // BACKGROUND_NAME
308 new Mix(new SysCol(SWT
.COLOR_GRAY
), new RGB(232, 242, 254), 1, 6), // BACKGROUND_NAME_SEL
309 new Mix(new SysCol(SWT
.COLOR_GRAY
), new SysCol(SWT
.COLOR_WIDGET_BACKGROUND
), 1, 6), // BACKGROUND_NAME_SEL_NOFOCUS
312 private Color _colors
[];
314 public TraceColorScheme() {
315 _colors
= new Color
[_providersMap
.length
];
318 public void dispose() {
319 for (int i
= 0; i
< _colors
.length
; i
++) {
320 Utils
.dispose(_colors
[i
]);
325 public Color
getColor(int idx
) {
326 if (null == _colors
[idx
]) {
327 if (idx
>= STATES_SEL0
&& idx
<= STATES_SEL1
) {
328 Color col1
= getColor(idx
- STATES_SEL0
);
329 Color col2
= getColor(BACKGROUND_SEL
);
330 _colors
[idx
] = Utils
.mixColors(col1
, col2
, 3, 1);
332 _colors
[idx
] = _providersMap
[idx
].get();
338 public Color
getBkColor(boolean selected
, boolean focused
, boolean name
) {
340 if (selected
&& focused
)
341 return getColor(BACKGROUND_NAME_SEL
);
343 return getColor(BACKGROUND_NAME_SEL_NOFOCUS
);
344 return getColor(BACKGROUND_NAME
);
346 if (selected
&& focused
)
347 return getColor(BACKGROUND_SEL
);
349 return getColor(BACKGROUND_SEL_NOFOCUS
);
350 return getColor(BACKGROUND
);
354 public Color
getFgColor(boolean selected
, boolean focused
) {
355 if (selected
&& focused
)
356 return getColor(FOREGROUND_SEL
);
358 return getColor(FOREGROUND_SEL_NOFOCUS
);
359 return getColor(FOREGROUND
);
362 public Color
getBkColorGroup(boolean selected
, boolean focused
) {
363 if (selected
&& focused
)
364 return getColor(GR_BACKGROUND_SEL
);
366 return getColor(GR_BACKGROUND_SEL_NOFOCUS
);
367 return getColor(GR_BACKGROUND
);
370 public Color
getFgColorGroup(boolean selected
, boolean focused
) {
371 if (selected
&& focused
)
372 return getColor(GR_FOREGROUND_SEL
);
374 return getColor(GR_FOREGROUND_SEL_NOFOCUS
);
375 return getColor(GR_FOREGROUND
);
378 public static StateColor
[] getStateColors() {