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