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