Commit | Line | Data |
---|---|---|
be222f56 PT |
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 | * Color theme used by the timegraph view | |
23 | * | |
24 | * @version 1.0 | |
25 | * @author Patrick Tasse | |
26 | */ | |
27 | @SuppressWarnings("javadoc") | |
28 | public class TimeGraphColorScheme { | |
29 | ||
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; | |
47 | ||
48 | static public final int STATES0 = 0; | |
49 | static public final int STATES1 = 15; | |
50 | ||
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; | |
68 | ||
69 | static public final int STATES_SEL0 = 16; | |
70 | static public final int STATES_SEL1 = 31; | |
71 | ||
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; | |
81 | ||
82 | // misc colors | |
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; | |
88 | ||
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; | |
106 | ||
107 | static public final int STATES_BORDER0 = 45; | |
108 | static public final int STATES_BORDER1 = 60; | |
109 | ||
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; | |
117 | ||
118 | static public final int SELECTED_TIME = 68; | |
119 | static public final int LEGEND_BACKGROUND = 69; | |
120 | static public final int LEGEND_FOREGROUND = 70; | |
121 | ||
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; | |
129 | ||
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; | |
134 | ||
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; | |
143 | ||
144 | static interface IColorProvider { | |
145 | public Color get(); | |
146 | } | |
147 | ||
148 | static class SysCol implements IColorProvider { | |
149 | int syscol; | |
150 | ||
151 | SysCol(int syscol) { | |
152 | this.syscol = syscol; | |
153 | } | |
154 | ||
155 | @Override | |
156 | public Color get() { | |
157 | return Utils.getSysColor(syscol); | |
158 | } | |
159 | } | |
160 | ||
161 | static class RGB implements IColorProvider { | |
162 | int r; | |
163 | int g; | |
164 | int b; | |
165 | ||
166 | RGB(int r, int g, int b) { | |
167 | this.r = r; | |
168 | this.g = g; | |
169 | this.b = b; | |
170 | } | |
171 | ||
172 | @Override | |
173 | public Color get() { | |
174 | return new Color(null, r, g, b); | |
175 | } | |
176 | } | |
177 | ||
178 | static class Mix implements IColorProvider { | |
179 | IColorProvider cp1; | |
180 | IColorProvider cp2; | |
181 | int w1; | |
182 | int w2; | |
183 | ||
184 | Mix(IColorProvider cp1, IColorProvider cp2, int w1, int w2) { | |
185 | this.cp1 = cp1; | |
186 | this.cp2 = cp2; | |
187 | this.w1 = w1; | |
188 | this.w2 = w2; | |
189 | } | |
190 | ||
191 | Mix(IColorProvider cp1, IColorProvider cp2) { | |
192 | this.cp1 = cp1; | |
193 | this.cp2 = cp2; | |
194 | this.w1 = 1; | |
195 | this.w2 = 1; | |
196 | } | |
197 | ||
198 | @Override | |
199 | public Color get() { | |
200 | Color col1 = cp1.get(); | |
201 | Color col2 = cp2.get(); | |
202 | Color col = Utils.mixColors(col1, col2, w1, w2); | |
203 | return col; | |
204 | } | |
205 | } | |
206 | ||
207 | static private final IColorProvider _providersMap[] = { | |
208 | // | |
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 | |
225 | ||
226 | ||
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), | |
244 | ||
245 | ||
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 | |
254 | ||
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 | |
260 | ||
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 | |
277 | ||
278 | ||
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 | |
286 | ||
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 | |
290 | ||
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 | |
297 | ||
298 | new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_LIST_BACKGROUND), 1, 3), // LIGHT_LINE | |
299 | ||
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 | |
303 | }; | |
304 | ||
305 | private final Color _colors[]; | |
306 | ||
307 | /** | |
308 | * Default constructor | |
309 | */ | |
310 | public TimeGraphColorScheme() { | |
311 | _colors = new Color[_providersMap.length]; | |
312 | } | |
313 | ||
314 | /** | |
315 | * Dispose this color scheme | |
316 | */ | |
317 | public void dispose() { | |
318 | for (int i = 0; i < _colors.length; i++) { | |
319 | Utils.dispose(_colors[i]); | |
320 | _colors[i] = null; | |
321 | } | |
322 | } | |
323 | ||
324 | /** | |
325 | * Get the color matching the given index | |
326 | * | |
327 | * @param idx | |
328 | * The index | |
329 | * @return The matching color | |
330 | */ | |
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); | |
337 | } else { | |
338 | _colors[idx] = _providersMap[idx].get(); | |
339 | } | |
340 | } | |
341 | return _colors[idx]; | |
342 | } | |
343 | ||
344 | /** | |
345 | * Get an entry's background color based on its status. | |
346 | * | |
347 | * @param selected | |
348 | * If the entry is selected | |
349 | * @param focused | |
350 | * If the entry is focused | |
351 | * @param name | |
352 | * Get the color of the name column (false for other columns) | |
353 | * @return The matching color | |
354 | */ | |
355 | public Color getBkColor(boolean selected, boolean focused, boolean name) { | |
356 | if (name) { | |
357 | if (selected && focused) { | |
358 | return getColor(BACKGROUND_NAME_SEL); | |
359 | } | |
360 | if (selected) { | |
361 | return getColor(BACKGROUND_NAME_SEL_NOFOCUS); | |
362 | } | |
363 | return getColor(BACKGROUND_NAME); | |
364 | } | |
365 | if (selected && focused) { | |
366 | return getColor(BACKGROUND_SEL); | |
367 | } | |
368 | if (selected) { | |
369 | return getColor(BACKGROUND_SEL_NOFOCUS); | |
370 | } | |
371 | return getColor(BACKGROUND); | |
372 | } | |
373 | ||
374 | /** | |
375 | * Get the correct foreground color | |
376 | * | |
377 | * @param selected | |
378 | * Is the entry selected | |
379 | * @param focused | |
380 | * Is the entry focused | |
381 | * @return The matching color | |
382 | */ | |
383 | public Color getFgColor(boolean selected, boolean focused) { | |
384 | if (selected && focused) { | |
385 | return getColor(FOREGROUND_SEL); | |
386 | } | |
387 | if (selected) { | |
388 | return getColor(FOREGROUND_SEL_NOFOCUS); | |
389 | } | |
390 | return getColor(FOREGROUND); | |
391 | } | |
392 | ||
393 | /** | |
394 | * Get the correct background color group | |
395 | * | |
396 | * @param selected | |
397 | * Is the entry selected | |
398 | * @param focused | |
399 | * Is the entry focused | |
400 | * @return The matching color | |
401 | */ | |
402 | public Color getBkColorGroup(boolean selected, boolean focused) { | |
403 | if (selected && focused) { | |
404 | return getColor(GR_BACKGROUND_SEL); | |
405 | } | |
406 | if (selected) { | |
407 | return getColor(GR_BACKGROUND_SEL_NOFOCUS); | |
408 | } | |
409 | return getColor(GR_BACKGROUND); | |
410 | } | |
411 | ||
412 | /** | |
413 | * Get the correct foreground color group | |
414 | * | |
415 | * @param selected | |
416 | * Is the entry selected | |
417 | * @param focused | |
418 | * Is the entry focused | |
419 | * @return The matching color | |
420 | */ | |
421 | public Color getFgColorGroup(boolean selected, boolean focused) { | |
422 | if (selected && focused) { | |
423 | return getColor(GR_FOREGROUND_SEL); | |
424 | } | |
425 | if (selected) { | |
426 | return getColor(GR_FOREGROUND_SEL_NOFOCUS); | |
427 | } | |
428 | return getColor(GR_FOREGROUND); | |
429 | } | |
430 | } |