Mercurial > projects > dwt2
comparison org.eclipse.ui.forms/src/org/eclipse/ui/forms/FormColors.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | |
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 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.ui.forms.FormColors; | |
14 | |
15 import org.eclipse.ui.forms.IFormColors; | |
16 | |
17 import org.eclipse.swt.SWT; | |
18 import org.eclipse.swt.graphics.Color; | |
19 import org.eclipse.swt.graphics.RGB; | |
20 import org.eclipse.swt.widgets.Display; | |
21 | |
22 import java.lang.all; | |
23 import java.util.Iterator; | |
24 import java.util.Map; | |
25 import java.util.HashMap; | |
26 import java.util.Set; | |
27 | |
28 /** | |
29 * Manages colors that will be applied to forms and form widgets. The colors are | |
30 * chosen to make the widgets look correct in the editor area. If a different | |
31 * set of colors is needed, subclass this class and override 'initialize' and/or | |
32 * 'initializeColors'. | |
33 * | |
34 * @since 3.0 | |
35 */ | |
36 public class FormColors { | |
37 /** | |
38 * Key for the form title foreground color. | |
39 * | |
40 * @deprecated use <code>IFormColors.TITLE</code>. | |
41 */ | |
42 public static const String TITLE = IFormColors.TITLE; | |
43 | |
44 /** | |
45 * Key for the tree/table border color. | |
46 * | |
47 * @deprecated use <code>IFormColors.BORDER</code> | |
48 */ | |
49 public static const String BORDER = IFormColors.BORDER; | |
50 | |
51 /** | |
52 * Key for the section separator color. | |
53 * | |
54 * @deprecated use <code>IFormColors.SEPARATOR</code>. | |
55 */ | |
56 public static const String SEPARATOR = IFormColors.SEPARATOR; | |
57 | |
58 /** | |
59 * Key for the section title bar background. | |
60 * | |
61 * @deprecated use <code>IFormColors.TB_BG | |
62 */ | |
63 public static const String TB_BG = IFormColors.TB_BG; | |
64 | |
65 /** | |
66 * Key for the section title bar foreground. | |
67 * | |
68 * @deprecated use <code>IFormColors.TB_FG</code> | |
69 */ | |
70 public static const String TB_FG = IFormColors.TB_FG; | |
71 | |
72 /** | |
73 * Key for the section title bar gradient. | |
74 * | |
75 * @deprecated use <code>IFormColors.TB_GBG</code> | |
76 */ | |
77 public static const String TB_GBG = IFormColors.TB_GBG; | |
78 | |
79 /** | |
80 * Key for the section title bar border. | |
81 * | |
82 * @deprecated use <code>IFormColors.TB_BORDER</code>. | |
83 */ | |
84 public static const String TB_BORDER = IFormColors.TB_BORDER; | |
85 | |
86 /** | |
87 * Key for the section toggle color. Since 3.1, this color is used for all | |
88 * section styles. | |
89 * | |
90 * @deprecated use <code>IFormColors.TB_TOGGLE</code>. | |
91 */ | |
92 public static const String TB_TOGGLE = IFormColors.TB_TOGGLE; | |
93 | |
94 /** | |
95 * Key for the section toggle hover color. | |
96 * | |
97 * @since 3.1 | |
98 * @deprecated use <code>IFormColors.TB_TOGGLE_HOVER</code>. | |
99 */ | |
100 public static const String TB_TOGGLE_HOVER = IFormColors.TB_TOGGLE_HOVER; | |
101 | |
102 protected Map colorRegistry; | |
103 | |
104 protected Color background; | |
105 | |
106 protected Color foreground; | |
107 | |
108 private bool shared; | |
109 | |
110 protected Display display; | |
111 | |
112 protected Color border; | |
113 | |
114 /** | |
115 * Creates form colors using the provided display. | |
116 * | |
117 * @param display | |
118 * the display to use | |
119 */ | |
120 public this(Display display) { | |
121 colorRegistry = new HashMap(10); | |
122 this.display = display; | |
123 initialize(); | |
124 } | |
125 | |
126 /** | |
127 * Returns the display used to create colors. | |
128 * | |
129 * @return the display | |
130 */ | |
131 public Display getDisplay() { | |
132 return display; | |
133 } | |
134 | |
135 /** | |
136 * Initializes the colors. Subclasses can override this method to change the | |
137 * way colors are created. Alternatively, only the color table can be | |
138 * modified by overriding <code>initializeColorTable()</code>. | |
139 * | |
140 * @see #initializeColorTable | |
141 */ | |
142 protected void initialize() { | |
143 background = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND); | |
144 foreground = display.getSystemColor(SWT.COLOR_LIST_FOREGROUND); | |
145 initializeColorTable(); | |
146 updateBorderColor(); | |
147 } | |
148 | |
149 /** | |
150 * Allocates colors for the following keys: BORDER, SEPARATOR and | |
151 * TITLE. Subclasses can override to allocate these colors differently. | |
152 */ | |
153 protected void initializeColorTable() { | |
154 createTitleColor(); | |
155 createColor(IFormColors.SEPARATOR, getColor(IFormColors.TITLE).getRGB()); | |
156 RGB black = getSystemColor(SWT.COLOR_BLACK); | |
157 RGB borderRGB = getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT); | |
158 createColor(IFormColors.BORDER, blend(borderRGB, black, 80)); | |
159 } | |
160 | |
161 /** | |
162 * Allocates colors for the section tool bar (all the keys that start with | |
163 * TB). Since these colors are only needed when TITLE_BAR style is used with | |
164 * the Section widget, they are not needed all the time and are allocated on | |
165 * demand. Consequently, this method will do nothing if the colors have been | |
166 * already initialized. Call this method prior to using colors with the TB | |
167 * keys to ensure they are available. | |
168 */ | |
169 public void initializeSectionToolBarColors() { | |
170 if (colorRegistry.containsKey(IFormColors.TB_BG)) | |
171 return; | |
172 createTitleBarGradientColors(); | |
173 createTitleBarOutlineColors(); | |
174 createTwistieColors(); | |
175 } | |
176 | |
177 /** | |
178 * Allocates additional colors for the form header, namely background | |
179 * gradients, bottom separator keylines and DND highlights. Since these | |
180 * colors are only needed for clients that want to use these particular | |
181 * style of header rendering, they are not needed all the time and are | |
182 * allocated on demand. Consequently, this method will do nothing if the | |
183 * colors have been already initialized. Call this method prior to using | |
184 * color keys with the H_ prefix to ensure they are available. | |
185 * | |
186 * @since 3.3 | |
187 */ | |
188 protected void initializeFormHeaderColors() { | |
189 if (colorRegistry.containsKey(IFormColors.H_BOTTOM_KEYLINE2)) | |
190 return; | |
191 createFormHeaderColors(); | |
192 } | |
193 | |
194 /** | |
195 * Returns the RGB value of the system color represented by the code | |
196 * argument, as defined in <code>SWT</code> class. | |
197 * | |
198 * @param code | |
199 * the system color constant as defined in <code>SWT</code> | |
200 * class. | |
201 * @return the RGB value of the system color | |
202 */ | |
203 public RGB getSystemColor(int code) { | |
204 return getDisplay().getSystemColor(code).getRGB(); | |
205 } | |
206 | |
207 /** | |
208 * Creates the color for the specified key using the provided RGB object. | |
209 * The color object will be returned and also put into the registry. When | |
210 * the class is disposed, the color will be disposed with it. | |
211 * | |
212 * @param key | |
213 * the unique color key | |
214 * @param rgb | |
215 * the RGB object | |
216 * @return the allocated color object | |
217 */ | |
218 public Color createColor(String key, RGB rgb) { | |
219 return createColor(key, rgb.red, rgb.green, rgb.blue); | |
220 } | |
221 | |
222 /** | |
223 * Creates a color that can be used for areas of the form that is inactive. | |
224 * These areas can contain images, links, controls and other content but are | |
225 * considered auxilliary to the main content area. | |
226 * | |
227 * <p> | |
228 * The color should not be disposed because it is managed by this class. | |
229 * | |
230 * @return the inactive form color | |
231 * @since 3.1 | |
232 */ | |
233 public Color getInactiveBackground() { | |
234 String key = "__ncbg__"; //$NON-NLS-1$ | |
235 Color color = getColor(key); | |
236 if (color is null) { | |
237 RGB sel = getSystemColor(SWT.COLOR_LIST_SELECTION); | |
238 // a blend of 95% white and 5% list selection system color | |
239 RGB ncbg = blend(sel, getSystemColor(SWT.COLOR_WHITE), 5); | |
240 color = createColor(key, ncbg); | |
241 } | |
242 return color; | |
243 } | |
244 | |
245 /** | |
246 * Creates the color for the specified key using the provided RGB values. | |
247 * The color object will be returned and also put into the registry. If | |
248 * there is already another color object under the same key in the registry, | |
249 * the existing object will be disposed. When the class is disposed, the | |
250 * color will be disposed with it. | |
251 * | |
252 * @param key | |
253 * the unique color key | |
254 * @param r | |
255 * red value | |
256 * @param g | |
257 * green value | |
258 * @param b | |
259 * blue value | |
260 * @return the allocated color object | |
261 */ | |
262 public Color createColor(String key, int r, int g, int b) { | |
263 Color c = new Color(display, r, g, b); | |
264 Color prevC = cast(Color) colorRegistry.get(key); | |
265 if (prevC !is null) | |
266 prevC.dispose(); | |
267 colorRegistry.put(key, c); | |
268 return c; | |
269 } | |
270 | |
271 /** | |
272 * Computes the border color relative to the background. Allocated border | |
273 * color is designed to work well with white. Otherwise, stanard widget | |
274 * background color will be used. | |
275 */ | |
276 protected void updateBorderColor() { | |
277 if (isWhiteBackground()) | |
278 border = getColor(IFormColors.BORDER); | |
279 else { | |
280 border = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); | |
281 Color bg = getImpliedBackground(); | |
282 if (border.getRed() is bg.getRed() | |
283 && border.getGreen() is bg.getGreen() | |
284 && border.getBlue() is bg.getBlue()) | |
285 border = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW); | |
286 } | |
287 } | |
288 | |
289 /** | |
290 * Sets the background color. All the toolkits that use this class will | |
291 * share the same background. | |
292 * | |
293 * @param bg | |
294 * background color | |
295 */ | |
296 public void setBackground(Color bg) { | |
297 this.background = bg; | |
298 updateBorderColor(); | |
299 updateFormHeaderColors(); | |
300 } | |
301 | |
302 /** | |
303 * Sets the foreground color. All the toolkits that use this class will | |
304 * share the same foreground. | |
305 * | |
306 * @param fg | |
307 * foreground color | |
308 */ | |
309 public void setForeground(Color fg) { | |
310 this.foreground = fg; | |
311 } | |
312 | |
313 /** | |
314 * Returns the current background color. | |
315 * | |
316 * @return the background color | |
317 */ | |
318 public Color getBackground() { | |
319 return background; | |
320 } | |
321 | |
322 /** | |
323 * Returns the current foreground color. | |
324 * | |
325 * @return the foreground color | |
326 */ | |
327 public Color getForeground() { | |
328 return foreground; | |
329 } | |
330 | |
331 /** | |
332 * Returns the computed border color. Border color depends on the background | |
333 * and is recomputed whenever the background changes. | |
334 * | |
335 * @return the current border color | |
336 */ | |
337 public Color getBorderColor() { | |
338 return border; | |
339 } | |
340 | |
341 /** | |
342 * Tests if the background is white. White background has RGB value | |
343 * 255,255,255. | |
344 * | |
345 * @return <samp>true</samp> if background is white, <samp>false</samp> | |
346 * otherwise. | |
347 */ | |
348 public bool isWhiteBackground() { | |
349 Color bg = getImpliedBackground(); | |
350 return bg.getRed() is 255 && bg.getGreen() is 255 | |
351 && bg.getBlue() is 255; | |
352 } | |
353 | |
354 /** | |
355 * Returns the color object for the provided key or <samp>null </samp> if | |
356 * not in the registry. | |
357 * | |
358 * @param key | |
359 * the color key | |
360 * @return color object if found, or <samp>null </samp> if not. | |
361 */ | |
362 public Color getColor(String key) { | |
363 if (key.startsWith(IFormColors.TB_PREFIX)) | |
364 initializeSectionToolBarColors(); | |
365 else if (key.startsWith(IFormColors.H_PREFIX)) | |
366 initializeFormHeaderColors(); | |
367 return cast(Color) colorRegistry.get(key); | |
368 } | |
369 | |
370 /** | |
371 * Disposes all the colors in the registry. | |
372 */ | |
373 public void dispose() { | |
374 Iterator e = colorRegistry.values().iterator(); | |
375 while (e.hasNext()) | |
376 (cast(Color) e.next()).dispose(); | |
377 colorRegistry = null; | |
378 } | |
379 | |
380 /** | |
381 * Marks the colors shared. This prevents toolkits that share this object | |
382 * from disposing it. | |
383 */ | |
384 public void markShared() { | |
385 this.shared = true; | |
386 } | |
387 | |
388 /** | |
389 * Tests if the colors are shared. | |
390 * | |
391 * @return <code>true</code> if shared, <code>false</code> otherwise. | |
392 */ | |
393 public bool isShared() { | |
394 return shared; | |
395 } | |
396 | |
397 /** | |
398 * Blends c1 and c2 based in the provided ratio. | |
399 * | |
400 * @param c1 | |
401 * first color | |
402 * @param c2 | |
403 * second color | |
404 * @param ratio | |
405 * percentage of the first color in the blend (0-100) | |
406 * @return the RGB value of the blended color | |
407 * @since 3.1 | |
408 */ | |
409 public static RGB blend(RGB c1, RGB c2, int ratio) { | |
410 int r = blend(c1.red, c2.red, ratio); | |
411 int g = blend(c1.green, c2.green, ratio); | |
412 int b = blend(c1.blue, c2.blue, ratio); | |
413 return new RGB(r, g, b); | |
414 } | |
415 | |
416 /** | |
417 * Tests the source RGB for range. | |
418 * | |
419 * @param rgb | |
420 * the tested RGB | |
421 * @param from | |
422 * range start (excluding the value itself) | |
423 * @param to | |
424 * range end (excluding the value itself) | |
425 * @return <code>true</code> if at least one of the primary colors in the | |
426 * source RGB are within the provided range, <code>false</code> | |
427 * otherwise. | |
428 * @since 3.1 | |
429 */ | |
430 public static bool testAnyPrimaryColor(RGB rgb, int from, int to) { | |
431 if (testPrimaryColor(rgb.red, from, to)) | |
432 return true; | |
433 if (testPrimaryColor(rgb.green, from, to)) | |
434 return true; | |
435 if (testPrimaryColor(rgb.blue, from, to)) | |
436 return true; | |
437 return false; | |
438 } | |
439 | |
440 /** | |
441 * Tests the source RGB for range. | |
442 * | |
443 * @param rgb | |
444 * the tested RGB | |
445 * @param from | |
446 * range start (excluding the value itself) | |
447 * @param to | |
448 * tange end (excluding the value itself) | |
449 * @return <code>true</code> if at least two of the primary colors in the | |
450 * source RGB are within the provided range, <code>false</code> | |
451 * otherwise. | |
452 * @since 3.1 | |
453 */ | |
454 public static bool testTwoPrimaryColors(RGB rgb, int from, int to) { | |
455 int total = 0; | |
456 if (testPrimaryColor(rgb.red, from, to)) | |
457 total++; | |
458 if (testPrimaryColor(rgb.green, from, to)) | |
459 total++; | |
460 if (testPrimaryColor(rgb.blue, from, to)) | |
461 total++; | |
462 return total >= 2; | |
463 } | |
464 | |
465 /** | |
466 * Blends two primary color components based on the provided ratio. | |
467 * | |
468 * @param v1 | |
469 * first component | |
470 * @param v2 | |
471 * second component | |
472 * @param ratio | |
473 * percentage of the first component in the blend | |
474 * @return | |
475 */ | |
476 private static int blend(int v1, int v2, int ratio) { | |
477 int b = (ratio * v1 + (100 - ratio) * v2) / 100; | |
478 return Math.min(255, b); | |
479 } | |
480 | |
481 private Color getImpliedBackground() { | |
482 if (getBackground() !is null) | |
483 return getBackground(); | |
484 return getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); | |
485 } | |
486 | |
487 private static bool testPrimaryColor(int value, int from, int to) { | |
488 return value > from && value < to; | |
489 } | |
490 | |
491 private void createTitleColor() { | |
492 /* | |
493 * RGB rgb = getSystemColor(SWT.COLOR_LIST_SELECTION); // test too light | |
494 * if (testTwoPrimaryColors(rgb, 120, 151)) rgb = blend(rgb, BLACK, 80); | |
495 * else if (testTwoPrimaryColors(rgb, 150, 256)) rgb = blend(rgb, BLACK, | |
496 * 50); createColor(TITLE, rgb); | |
497 */ | |
498 RGB bg = getImpliedBackground().getRGB(); | |
499 RGB listSelection = getSystemColor(SWT.COLOR_LIST_SELECTION); | |
500 RGB listForeground = getSystemColor(SWT.COLOR_LIST_FOREGROUND); | |
501 RGB rgb = listSelection; | |
502 | |
503 // Group 1 | |
504 // Rule: If at least 2 of the LIST_SELECTION RGB values are equal to or | |
505 // between 0 and 120, then use 100% LIST_SELECTION as it is (no | |
506 // additions) | |
507 // Examples: XP Default, Win Classic Standard, Win High Con White, Win | |
508 // Classic Marine | |
509 if (testTwoPrimaryColors(listSelection, -1, 121)) | |
510 rgb = listSelection; | |
511 // Group 2 | |
512 // When LIST_BACKGROUND = white (255, 255, 255) or not black, text | |
513 // colour = LIST_SELECTION @ 100% Opacity + 50% LIST_FOREGROUND over | |
514 // LIST_BACKGROUND | |
515 // Rule: If at least 2 of the LIST_SELECTION RGB values are equal to or | |
516 // between 121 and 255, then add 50% LIST_FOREGROUND to LIST_SELECTION | |
517 // foreground colour | |
518 // Examples: Win Vista, XP Silver, XP Olive , Win Classic Plum, OSX | |
519 // Aqua, OSX Graphite, Linux GTK | |
520 else if (testTwoPrimaryColors(listSelection, 120, 256) | |
521 || (bg.red is 0 && bg.green is 0 && bg.blue is 0)) | |
522 rgb = blend(listSelection, listForeground, 50); | |
523 // Group 3 | |
524 // When LIST_BACKGROUND = black (0, 0, 0), text colour = LIST_SELECTION | |
525 // @ 100% Opacity + 50% LIST_FOREGROUND over LIST_BACKGROUND | |
526 // Rule: If LIST_BACKGROUND = 0, 0, 0, then add 50% LIST_FOREGROUND to | |
527 // LIST_SELECTION foreground colour | |
528 // Examples: Win High Con Black, Win High Con #1, Win High Con #2 | |
529 // (covered in the second part of the OR clause above) | |
530 createColor(IFormColors.TITLE, rgb); | |
531 } | |
532 | |
533 private void createTwistieColors() { | |
534 RGB rgb = getColor(IFormColors.TITLE).getRGB(); | |
535 RGB white = getSystemColor(SWT.COLOR_WHITE); | |
536 createColor(TB_TOGGLE, rgb); | |
537 rgb = blend(rgb, white, 60); | |
538 createColor(TB_TOGGLE_HOVER, rgb); | |
539 } | |
540 | |
541 private void createTitleBarGradientColors() { | |
542 RGB tbBg = getSystemColor(SWT.COLOR_TITLE_BACKGROUND); | |
543 RGB bg = getImpliedBackground().getRGB(); | |
544 | |
545 // Group 1 | |
546 // Rule: If at least 2 of the RGB values are equal to or between 180 and | |
547 // 255, then apply specified opacity for Group 1 | |
548 // Examples: Vista, XP Silver, Wn High Con #2 | |
549 // Gradient Bottom = TITLE_BACKGROUND @ 30% Opacity over LIST_BACKGROUND | |
550 // Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND | |
551 if (testTwoPrimaryColors(tbBg, 179, 256)) | |
552 tbBg = blend(tbBg, bg, 30); | |
553 | |
554 // Group 2 | |
555 // Rule: If at least 2 of the RGB values are equal to or between 121 and | |
556 // 179, then apply specified opacity for Group 2 | |
557 // Examples: XP Olive, OSX Graphite, Linux GTK, Wn High Con Black | |
558 // Gradient Bottom = TITLE_BACKGROUND @ 20% Opacity over LIST_BACKGROUND | |
559 // Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND | |
560 else if (testTwoPrimaryColors(tbBg, 120, 180)) | |
561 tbBg = blend(tbBg, bg, 20); | |
562 | |
563 // Group 3 | |
564 // Rule: Everything else | |
565 // Examples: XP Default, Wn Classic Standard, Wn Marine, Wn Plum, OSX | |
566 // Aqua, Wn High Con White, Wn High Con #1 | |
567 // Gradient Bottom = TITLE_BACKGROUND @ 10% Opacity over LIST_BACKGROUND | |
568 // Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND | |
569 else { | |
570 tbBg = blend(tbBg, bg, 10); | |
571 } | |
572 | |
573 createColor(IFormColors.TB_BG, tbBg); | |
574 | |
575 // for backward compatibility | |
576 createColor(TB_GBG, tbBg); | |
577 } | |
578 | |
579 private void createTitleBarOutlineColors() { | |
580 // title bar outline - border color | |
581 RGB tbBorder = getSystemColor(SWT.COLOR_TITLE_BACKGROUND); | |
582 RGB bg = getImpliedBackground().getRGB(); | |
583 // Group 1 | |
584 // Rule: If at least 2 of the RGB values are equal to or between 180 and | |
585 // 255, then apply specified opacity for Group 1 | |
586 // Examples: Vista, XP Silver, Wn High Con #2 | |
587 // Keyline = TITLE_BACKGROUND @ 70% Opacity over LIST_BACKGROUND | |
588 if (testTwoPrimaryColors(tbBorder, 179, 256)) | |
589 tbBorder = blend(tbBorder, bg, 70); | |
590 | |
591 // Group 2 | |
592 // Rule: If at least 2 of the RGB values are equal to or between 121 and | |
593 // 179, then apply specified opacity for Group 2 | |
594 // Examples: XP Olive, OSX Graphite, Linux GTK, Wn High Con Black | |
595 | |
596 // Keyline = TITLE_BACKGROUND @ 50% Opacity over LIST_BACKGROUND | |
597 else if (testTwoPrimaryColors(tbBorder, 120, 180)) | |
598 tbBorder = blend(tbBorder, bg, 50); | |
599 | |
600 // Group 3 | |
601 // Rule: Everything else | |
602 // Examples: XP Default, Wn Classic Standard, Wn Marine, Wn Plum, OSX | |
603 // Aqua, Wn High Con White, Wn High Con #1 | |
604 | |
605 // Keyline = TITLE_BACKGROUND @ 30% Opacity over LIST_BACKGROUND | |
606 else { | |
607 tbBorder = blend(tbBorder, bg, 30); | |
608 } | |
609 createColor(FormColors.TB_BORDER, tbBorder); | |
610 } | |
611 | |
612 private void updateFormHeaderColors() { | |
613 if (colorRegistry.containsKey(IFormColors.H_GRADIENT_END)) { | |
614 disposeIfFound(IFormColors.H_GRADIENT_END); | |
615 disposeIfFound(IFormColors.H_GRADIENT_START); | |
616 disposeIfFound(IFormColors.H_BOTTOM_KEYLINE1); | |
617 disposeIfFound(IFormColors.H_BOTTOM_KEYLINE2); | |
618 disposeIfFound(IFormColors.H_HOVER_LIGHT); | |
619 disposeIfFound(IFormColors.H_HOVER_FULL); | |
620 initializeFormHeaderColors(); | |
621 } | |
622 } | |
623 | |
624 private void disposeIfFound(String key) { | |
625 Color color = getColor(key); | |
626 if (color !is null) { | |
627 colorRegistry.remove(key); | |
628 color.dispose(); | |
629 } | |
630 } | |
631 | |
632 private void createFormHeaderColors() { | |
633 createFormHeaderGradientColors(); | |
634 createFormHeaderKeylineColors(); | |
635 createFormHeaderDNDColors(); | |
636 } | |
637 | |
638 private void createFormHeaderGradientColors() { | |
639 RGB titleBg = getSystemColor(SWT.COLOR_TITLE_BACKGROUND); | |
640 Color bgColor = getImpliedBackground(); | |
641 RGB bg = bgColor.getRGB(); | |
642 RGB bottom, top; | |
643 // Group 1 | |
644 // Rule: If at least 2 of the RGB values are equal to or between 180 and | |
645 // 255, then apply specified opacity for Group 1 | |
646 // Examples: Vista, XP Silver, Wn High Con #2 | |
647 // Gradient Bottom = TITLE_BACKGROUND @ 30% Opacity over LIST_BACKGROUND | |
648 // Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND | |
649 if (testTwoPrimaryColors(titleBg, 179, 256)) { | |
650 bottom = blend(titleBg, bg, 30); | |
651 top = bg; | |
652 } | |
653 | |
654 // Group 2 | |
655 // Rule: If at least 2 of the RGB values are equal to or between 121 and | |
656 // 179, then apply specified opacity for Group 2 | |
657 // Examples: XP Olive, OSX Graphite, Linux GTK, Wn High Con Black | |
658 // Gradient Bottom = TITLE_BACKGROUND @ 20% Opacity over LIST_BACKGROUND | |
659 // Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND | |
660 else if (testTwoPrimaryColors(titleBg, 120, 180)) { | |
661 bottom = blend(titleBg, bg, 20); | |
662 top = bg; | |
663 } | |
664 | |
665 // Group 3 | |
666 // Rule: If at least 2 of the RGB values are equal to or between 0 and | |
667 // 120, then apply specified opacity for Group 3 | |
668 // Examples: XP Default, Wn Classic Standard, Wn Marine, Wn Plum, OSX | |
669 // Aqua, Wn High Con White, Wn High Con #1 | |
670 // Gradient Bottom = TITLE_BACKGROUND @ 10% Opacity over LIST_BACKGROUND | |
671 // Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND | |
672 else { | |
673 bottom = blend(titleBg, bg, 10); | |
674 top = bg; | |
675 } | |
676 createColor(IFormColors.H_GRADIENT_END, top); | |
677 createColor(IFormColors.H_GRADIENT_START, bottom); | |
678 } | |
679 | |
680 private void createFormHeaderKeylineColors() { | |
681 RGB titleBg = getSystemColor(SWT.COLOR_TITLE_BACKGROUND); | |
682 Color bgColor = getImpliedBackground(); | |
683 RGB bg = bgColor.getRGB(); | |
684 RGB keyline2; | |
685 // H_BOTTOM_KEYLINE1 | |
686 createColor(IFormColors.H_BOTTOM_KEYLINE1, new RGB(255, 255, 255)); | |
687 | |
688 // H_BOTTOM_KEYLINE2 | |
689 // Group 1 | |
690 // Rule: If at least 2 of the RGB values are equal to or between 180 and | |
691 // 255, then apply specified opacity for Group 1 | |
692 // Examples: Vista, XP Silver, Wn High Con #2 | |
693 // Keyline = TITLE_BACKGROUND @ 70% Opacity over LIST_BACKGROUND | |
694 if (testTwoPrimaryColors(titleBg, 179, 256)) | |
695 keyline2 = blend(titleBg, bg, 70); | |
696 | |
697 // Group 2 | |
698 // Rule: If at least 2 of the RGB values are equal to or between 121 and | |
699 // 179, then apply specified opacity for Group 2 | |
700 // Examples: XP Olive, OSX Graphite, Linux GTK, Wn High Con Black | |
701 // Keyline = TITLE_BACKGROUND @ 50% Opacity over LIST_BACKGROUND | |
702 else if (testTwoPrimaryColors(titleBg, 120, 180)) | |
703 keyline2 = blend(titleBg, bg, 50); | |
704 | |
705 // Group 3 | |
706 // Rule: If at least 2 of the RGB values are equal to or between 0 and | |
707 // 120, then apply specified opacity for Group 3 | |
708 // Examples: XP Default, Wn Classic Standard, Wn Marine, Wn Plum, OSX | |
709 // Aqua, Wn High Con White, Wn High Con #1 | |
710 | |
711 // Keyline = TITLE_BACKGROUND @ 30% Opacity over LIST_BACKGROUND | |
712 else | |
713 keyline2 = blend(titleBg, bg, 30); | |
714 // H_BOTTOM_KEYLINE2 | |
715 createColor(IFormColors.H_BOTTOM_KEYLINE2, keyline2); | |
716 } | |
717 | |
718 private void createFormHeaderDNDColors() { | |
719 RGB titleBg = getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT); | |
720 Color bgColor = getImpliedBackground(); | |
721 RGB bg = bgColor.getRGB(); | |
722 RGB light, full; | |
723 // ALL Themes | |
724 // | |
725 // Light Highlight | |
726 // When *near* the 'hot' area | |
727 // Rule: If near the title in the 'hot' area, show background highlight | |
728 // TITLE_BACKGROUND_GRADIENT @ 40% | |
729 light = blend(titleBg, bg, 40); | |
730 // Full Highlight | |
731 // When *on* the title area (regions 1 and 2) | |
732 // Rule: If near the title in the 'hot' area, show background highlight | |
733 // TITLE_BACKGROUND_GRADIENT @ 60% | |
734 full = blend(titleBg, bg, 60); | |
735 // H_DND_LIGHT | |
736 // H_DND_FULL | |
737 createColor(IFormColors.H_HOVER_LIGHT, light); | |
738 createColor(IFormColors.H_HOVER_FULL, full); | |
739 } | |
740 } |