KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > forms > FormColors


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  *******************************************************************************/

11 package org.eclipse.ui.forms;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Map JavaDoc;
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 /**
23  * Manages colors that will be applied to forms and form widgets. The colors are
24  * chosen to make the widgets look correct in the editor area. If a different
25  * set of colors is needed, subclass this class and override 'initialize' and/or
26  * 'initializeColors'.
27  *
28  * @since 3.0
29  */

30 public class FormColors {
31     /**
32      * Key for the form title foreground color.
33      *
34      * @deprecated use <code>IFormColors.TITLE</code>.
35      */

36     public static final String JavaDoc TITLE = IFormColors.TITLE;
37
38     /**
39      * Key for the tree/table border color.
40      *
41      * @deprecated use <code>IFormColors.BORDER</code>
42      */

43     public static final String JavaDoc BORDER = IFormColors.BORDER;
44
45     /**
46      * Key for the section separator color.
47      *
48      * @deprecated use <code>IFormColors.SEPARATOR</code>.
49      */

50     public static final String JavaDoc SEPARATOR = IFormColors.SEPARATOR;
51
52     /**
53      * Key for the section title bar background.
54      *
55      * @deprecated use <code>IFormColors.TB_BG
56      */

57     public static final String JavaDoc TB_BG = IFormColors.TB_BG;
58
59     /**
60      * Key for the section title bar foreground.
61      *
62      * @deprecated use <code>IFormColors.TB_FG</code>
63      */

64     public static final String JavaDoc TB_FG = IFormColors.TB_FG;
65
66     /**
67      * Key for the section title bar gradient.
68      *
69      * @deprecated use <code>IFormColors.TB_GBG</code>
70      */

71     public static final String JavaDoc TB_GBG = IFormColors.TB_GBG;
72
73     /**
74      * Key for the section title bar border.
75      *
76      * @deprecated use <code>IFormColors.TB_BORDER</code>.
77      */

78     public static final String JavaDoc TB_BORDER = IFormColors.TB_BORDER;
79
80     /**
81      * Key for the section toggle color. Since 3.1, this color is used for all
82      * section styles.
83      *
84      * @deprecated use <code>IFormColors.TB_TOGGLE</code>.
85      */

86     public static final String JavaDoc TB_TOGGLE = IFormColors.TB_TOGGLE;
87
88     /**
89      * Key for the section toggle hover color.
90      *
91      * @since 3.1
92      * @deprecated use <code>IFormColors.TB_TOGGLE_HOVER</code>.
93      */

94     public static final String JavaDoc TB_TOGGLE_HOVER = IFormColors.TB_TOGGLE_HOVER;
95
96     protected Map JavaDoc colorRegistry = new HashMap JavaDoc(10);
97
98     protected Color background;
99
100     protected Color foreground;
101
102     private boolean shared;
103
104     protected Display display;
105
106     protected Color border;
107
108     /**
109      * Creates form colors using the provided display.
110      *
111      * @param display
112      * the display to use
113      */

114     public FormColors(Display display) {
115         this.display = display;
116         initialize();
117     }
118
119     /**
120      * Returns the display used to create colors.
121      *
122      * @return the display
123      */

124     public Display getDisplay() {
125         return display;
126     }
127
128     /**
129      * Initializes the colors. Subclasses can override this method to change the
130      * way colors are created. Alternatively, only the color table can be
131      * modified by overriding <code>initializeColorTable()</code>.
132      *
133      * @see #initializeColorTable
134      */

135     protected void initialize() {
136         background = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
137         foreground = display.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
138         initializeColorTable();
139         updateBorderColor();
140     }
141
142     /**
143      * Allocates colors for the following keys: BORDER, SEPARATOR and
144      * TITLE. Subclasses can override to allocate these colors differently.
145      */

146     protected void initializeColorTable() {
147         createTitleColor();
148         createColor(IFormColors.SEPARATOR, getColor(IFormColors.TITLE).getRGB());
149         RGB black = getSystemColor(SWT.COLOR_BLACK);
150         RGB borderRGB = getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT);
151         createColor(IFormColors.BORDER, blend(borderRGB, black, 80));
152     }
153
154     /**
155      * Allocates colors for the section tool bar (all the keys that start with
156      * TB). Since these colors are only needed when TITLE_BAR style is used with
157      * the Section widget, they are not needed all the time and are allocated on
158      * demand. Consequently, this method will do nothing if the colors have been
159      * already initialized. Call this method prior to using colors with the TB
160      * keys to ensure they are available.
161      */

162     public void initializeSectionToolBarColors() {
163         if (colorRegistry.containsKey(IFormColors.TB_BG))
164             return;
165         createTitleBarGradientColors();
166         createTitleBarOutlineColors();
167         createTwistieColors();
168     }
169
170     /**
171      * Allocates additional colors for the form header, namely background
172      * gradients, bottom separator keylines and DND highlights. Since these
173      * colors are only needed for clients that want to use these particular
174      * style of header rendering, they are not needed all the time and are
175      * allocated on demand. Consequently, this method will do nothing if the
176      * colors have been already initialized. Call this method prior to using
177      * color keys with the H_ prefix to ensure they are available.
178      *
179      * @since 3.3
180      */

181     protected void initializeFormHeaderColors() {
182         if (colorRegistry.containsKey(IFormColors.H_BOTTOM_KEYLINE2))
183             return;
184         createFormHeaderColors();
185     }
186
187     /**
188      * Returns the RGB value of the system color represented by the code
189      * argument, as defined in <code>SWT</code> class.
190      *
191      * @param code
192      * the system color constant as defined in <code>SWT</code>
193      * class.
194      * @return the RGB value of the system color
195      */

196     public RGB getSystemColor(int code) {
197         return getDisplay().getSystemColor(code).getRGB();
198     }
199
200     /**
201      * Creates the color for the specified key using the provided RGB object.
202      * The color object will be returned and also put into the registry. When
203      * the class is disposed, the color will be disposed with it.
204      *
205      * @param key
206      * the unique color key
207      * @param rgb
208      * the RGB object
209      * @return the allocated color object
210      */

211     public Color createColor(String JavaDoc key, RGB rgb) {
212         return createColor(key, rgb.red, rgb.green, rgb.blue);
213     }
214
215     /**
216      * Creates a color that can be used for areas of the form that is inactive.
217      * These areas can contain images, links, controls and other content but are
218      * considered auxilliary to the main content area.
219      *
220      * <p>
221      * The color should not be disposed because it is managed by this class.
222      *
223      * @return the inactive form color
224      * @since 3.1
225      */

226     public Color getInactiveBackground() {
227         String JavaDoc key = "__ncbg__"; //$NON-NLS-1$
228
Color color = getColor(key);
229         if (color == null) {
230             RGB sel = getSystemColor(SWT.COLOR_LIST_SELECTION);
231             // a blend of 95% white and 5% list selection system color
232
RGB ncbg = blend(sel, getSystemColor(SWT.COLOR_WHITE), 5);
233             color = createColor(key, ncbg);
234         }
235         return color;
236     }
237
238     /**
239      * Creates the color for the specified key using the provided RGB values.
240      * The color object will be returned and also put into the registry. If
241      * there is already another color object under the same key in the registry,
242      * the existing object will be disposed. When the class is disposed, the
243      * color will be disposed with it.
244      *
245      * @param key
246      * the unique color key
247      * @param r
248      * red value
249      * @param g
250      * green value
251      * @param b
252      * blue value
253      * @return the allocated color object
254      */

255     public Color createColor(String JavaDoc key, int r, int g, int b) {
256         Color c = new Color(display, r, g, b);
257         Color prevC = (Color) colorRegistry.get(key);
258         if (prevC != null)
259             prevC.dispose();
260         colorRegistry.put(key, c);
261         return c;
262     }
263
264     /**
265      * Computes the border color relative to the background. Allocated border
266      * color is designed to work well with white. Otherwise, stanard widget
267      * background color will be used.
268      */

269     protected void updateBorderColor() {
270         if (isWhiteBackground())
271             border = getColor(IFormColors.BORDER);
272         else {
273             border = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
274             Color bg = getImpliedBackground();
275             if (border.getRed() == bg.getRed()
276                     && border.getGreen() == bg.getGreen()
277                     && border.getBlue() == bg.getBlue())
278                 border = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
279         }
280     }
281
282     /**
283      * Sets the background color. All the toolkits that use this class will
284      * share the same background.
285      *
286      * @param bg
287      * background color
288      */

289     public void setBackground(Color bg) {
290         this.background = bg;
291         updateBorderColor();
292         updateFormHeaderColors();
293     }
294
295     /**
296      * Sets the foreground color. All the toolkits that use this class will
297      * share the same foreground.
298      *
299      * @param fg
300      * foreground color
301      */

302     public void setForeground(Color fg) {
303         this.foreground = fg;
304     }
305
306     /**
307      * Returns the current background color.
308      *
309      * @return the background color
310      */

311     public Color getBackground() {
312         return background;
313     }
314
315     /**
316      * Returns the current foreground color.
317      *
318      * @return the foreground color
319      */

320     public Color getForeground() {
321         return foreground;
322     }
323
324     /**
325      * Returns the computed border color. Border color depends on the background
326      * and is recomputed whenever the background changes.
327      *
328      * @return the current border color
329      */

330     public Color getBorderColor() {
331         return border;
332     }
333
334     /**
335      * Tests if the background is white. White background has RGB value
336      * 255,255,255.
337      *
338      * @return <samp>true</samp> if background is white, <samp>false</samp>
339      * otherwise.
340      */

341     public boolean isWhiteBackground() {
342         Color bg = getImpliedBackground();
343         return bg.getRed() == 255 && bg.getGreen() == 255
344                 && bg.getBlue() == 255;
345     }
346
347     /**
348      * Returns the color object for the provided key or <samp>null </samp> if
349      * not in the registry.
350      *
351      * @param key
352      * the color key
353      * @return color object if found, or <samp>null </samp> if not.
354      */

355     public Color getColor(String JavaDoc key) {
356         if (key.startsWith(IFormColors.TB_PREFIX))
357             initializeSectionToolBarColors();
358         else if (key.startsWith(IFormColors.H_PREFIX))
359             initializeFormHeaderColors();
360         return (Color) colorRegistry.get(key);
361     }
362
363     /**
364      * Disposes all the colors in the registry.
365      */

366     public void dispose() {
367         Iterator JavaDoc e = colorRegistry.values().iterator();
368         while (e.hasNext())
369             ((Color) e.next()).dispose();
370         colorRegistry = null;
371     }
372
373     /**
374      * Marks the colors shared. This prevents toolkits that share this object
375      * from disposing it.
376      */

377     public void markShared() {
378         this.shared = true;
379     }
380
381     /**
382      * Tests if the colors are shared.
383      *
384      * @return <code>true</code> if shared, <code>false</code> otherwise.
385      */

386     public boolean isShared() {
387         return shared;
388     }
389
390     /**
391      * Blends c1 and c2 based in the provided ratio.
392      *
393      * @param c1
394      * first color
395      * @param c2
396      * second color
397      * @param ratio
398      * percentage of the first color in the blend (0-100)
399      * @return the RGB value of the blended color
400      * @since 3.1
401      */

402     public static RGB blend(RGB c1, RGB c2, int ratio) {
403         int r = blend(c1.red, c2.red, ratio);
404         int g = blend(c1.green, c2.green, ratio);
405         int b = blend(c1.blue, c2.blue, ratio);
406         return new RGB(r, g, b);
407     }
408
409     /**
410      * Tests the source RGB for range.
411      *
412      * @param rgb
413      * the tested RGB
414      * @param from
415      * range start (excluding the value itself)
416      * @param to
417      * range end (excluding the value itself)
418      * @return <code>true</code> if at least one of the primary colors in the
419      * source RGB are within the provided range, <code>false</code>
420      * otherwise.
421      * @since 3.1
422      */

423     public static boolean testAnyPrimaryColor(RGB rgb, int from, int to) {
424         if (testPrimaryColor(rgb.red, from, to))
425             return true;
426         if (testPrimaryColor(rgb.green, from, to))
427             return true;
428         if (testPrimaryColor(rgb.blue, from, to))
429             return true;
430         return false;
431     }
432
433     /**
434      * Tests the source RGB for range.
435      *
436      * @param rgb
437      * the tested RGB
438      * @param from
439      * range start (excluding the value itself)
440      * @param to
441      * tange end (excluding the value itself)
442      * @return <code>true</code> if at least two of the primary colors in the
443      * source RGB are within the provided range, <code>false</code>
444      * otherwise.
445      * @since 3.1
446      */

447     public static boolean testTwoPrimaryColors(RGB rgb, int from, int to) {
448         int total = 0;
449         if (testPrimaryColor(rgb.red, from, to))
450             total++;
451         if (testPrimaryColor(rgb.green, from, to))
452             total++;
453         if (testPrimaryColor(rgb.blue, from, to))
454             total++;
455         return total >= 2;
456     }
457
458     /**
459      * Blends two primary color components based on the provided ratio.
460      *
461      * @param v1
462      * first component
463      * @param v2
464      * second component
465      * @param ratio
466      * percentage of the first component in the blend
467      * @return
468      */

469     private static int blend(int v1, int v2, int ratio) {
470         int b = (ratio * v1 + (100 - ratio) * v2) / 100;
471         return Math.min(255, b);
472     }
473
474     private Color getImpliedBackground() {
475         if (getBackground() != null)
476             return getBackground();
477         return getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
478     }
479
480     private static boolean testPrimaryColor(int value, int from, int to) {
481         return value > from && value < to;
482     }
483
484     private void createTitleColor() {
485         /*
486          * RGB rgb = getSystemColor(SWT.COLOR_LIST_SELECTION); // test too light
487          * if (testTwoPrimaryColors(rgb, 120, 151)) rgb = blend(rgb, BLACK, 80);
488          * else if (testTwoPrimaryColors(rgb, 150, 256)) rgb = blend(rgb, BLACK,
489          * 50); createColor(TITLE, rgb);
490          */

491         RGB bg = getImpliedBackground().getRGB();
492         RGB listSelection = getSystemColor(SWT.COLOR_LIST_SELECTION);
493         RGB listForeground = getSystemColor(SWT.COLOR_LIST_FOREGROUND);
494         RGB rgb = listSelection;
495
496         // Group 1
497
// Rule: If at least 2 of the LIST_SELECTION RGB values are equal to or
498
// between 0 and 120, then use 100% LIST_SELECTION as it is (no
499
// additions)
500
// Examples: XP Default, Win Classic Standard, Win High Con White, Win
501
// Classic Marine
502
if (testTwoPrimaryColors(listSelection, -1, 121))
503             rgb = listSelection;
504         // Group 2
505
// When LIST_BACKGROUND = white (255, 255, 255) or not black, text
506
// colour = LIST_SELECTION @ 100% Opacity + 50% LIST_FOREGROUND over
507
// LIST_BACKGROUND
508
// Rule: If at least 2 of the LIST_SELECTION RGB values are equal to or
509
// between 121 and 255, then add 50% LIST_FOREGROUND to LIST_SELECTION
510
// foreground colour
511
// Examples: Win Vista, XP Silver, XP Olive , Win Classic Plum, OSX
512
// Aqua, OSX Graphite, Linux GTK
513
else if (testTwoPrimaryColors(listSelection, 120, 256)
514                 || (bg.red == 0 && bg.green == 0 && bg.blue == 0))
515             rgb = blend(listSelection, listForeground, 50);
516         // Group 3
517
// When LIST_BACKGROUND = black (0, 0, 0), text colour = LIST_SELECTION
518
// @ 100% Opacity + 50% LIST_FOREGROUND over LIST_BACKGROUND
519
// Rule: If LIST_BACKGROUND = 0, 0, 0, then add 50% LIST_FOREGROUND to
520
// LIST_SELECTION foreground colour
521
// Examples: Win High Con Black, Win High Con #1, Win High Con #2
522
// (covered in the second part of the OR clause above)
523
createColor(IFormColors.TITLE, rgb);
524     }
525
526     private void createTwistieColors() {
527         RGB rgb = getColor(IFormColors.TITLE).getRGB();
528         RGB white = getSystemColor(SWT.COLOR_WHITE);
529         createColor(TB_TOGGLE, rgb);
530         rgb = blend(rgb, white, 60);
531         createColor(TB_TOGGLE_HOVER, rgb);
532     }
533
534     private void createTitleBarGradientColors() {
535         RGB tbBg = getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
536         RGB bg = getImpliedBackground().getRGB();
537
538         // Group 1
539
// Rule: If at least 2 of the RGB values are equal to or between 180 and
540
// 255, then apply specified opacity for Group 1
541
// Examples: Vista, XP Silver, Wn High Con #2
542
// Gradient Bottom = TITLE_BACKGROUND @ 30% Opacity over LIST_BACKGROUND
543
// Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND
544
if (testTwoPrimaryColors(tbBg, 179, 256))
545             tbBg = blend(tbBg, bg, 30);
546
547         // Group 2
548
// Rule: If at least 2 of the RGB values are equal to or between 121 and
549
// 179, then apply specified opacity for Group 2
550
// Examples: XP Olive, OSX Graphite, Linux GTK, Wn High Con Black
551
// Gradient Bottom = TITLE_BACKGROUND @ 20% Opacity over LIST_BACKGROUND
552
// Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND
553
else if (testTwoPrimaryColors(tbBg, 120, 180))
554             tbBg = blend(tbBg, bg, 20);
555
556         // Group 3
557
// Rule: Everything else
558
// Examples: XP Default, Wn Classic Standard, Wn Marine, Wn Plum, OSX
559
// Aqua, Wn High Con White, Wn High Con #1
560
// Gradient Bottom = TITLE_BACKGROUND @ 10% Opacity over LIST_BACKGROUND
561
// Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND
562
else {
563             tbBg = blend(tbBg, bg, 10);
564         }
565
566         createColor(IFormColors.TB_BG, tbBg);
567         
568         // for backward compatibility
569
createColor(TB_GBG, tbBg);
570     }
571
572     private void createTitleBarOutlineColors() {
573         // title bar outline - border color
574
RGB tbBorder = getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
575         RGB bg = getImpliedBackground().getRGB();
576         // Group 1
577
// Rule: If at least 2 of the RGB values are equal to or between 180 and
578
// 255, then apply specified opacity for Group 1
579
// Examples: Vista, XP Silver, Wn High Con #2
580
// Keyline = TITLE_BACKGROUND @ 70% Opacity over LIST_BACKGROUND
581
if (testTwoPrimaryColors(tbBorder, 179, 256))
582             tbBorder = blend(tbBorder, bg, 70);
583
584         // Group 2
585
// Rule: If at least 2 of the RGB values are equal to or between 121 and
586
// 179, then apply specified opacity for Group 2
587
// Examples: XP Olive, OSX Graphite, Linux GTK, Wn High Con Black
588

589         // Keyline = TITLE_BACKGROUND @ 50% Opacity over LIST_BACKGROUND
590
else if (testTwoPrimaryColors(tbBorder, 120, 180))
591             tbBorder = blend(tbBorder, bg, 50);
592
593         // Group 3
594
// Rule: Everything else
595
// Examples: XP Default, Wn Classic Standard, Wn Marine, Wn Plum, OSX
596
// Aqua, Wn High Con White, Wn High Con #1
597

598         // Keyline = TITLE_BACKGROUND @ 30% Opacity over LIST_BACKGROUND
599
else {
600             tbBorder = blend(tbBorder, bg, 30);
601         }
602         createColor(FormColors.TB_BORDER, tbBorder);
603     }
604
605     private void updateFormHeaderColors() {
606         if (colorRegistry.containsKey(IFormColors.H_GRADIENT_END)) {
607             disposeIfFound(IFormColors.H_GRADIENT_END);
608             disposeIfFound(IFormColors.H_GRADIENT_START);
609             disposeIfFound(IFormColors.H_BOTTOM_KEYLINE1);
610             disposeIfFound(IFormColors.H_BOTTOM_KEYLINE2);
611             disposeIfFound(IFormColors.H_HOVER_LIGHT);
612             disposeIfFound(IFormColors.H_HOVER_FULL);
613             initializeFormHeaderColors();
614         }
615     }
616
617     private void disposeIfFound(String JavaDoc key) {
618         Color color = getColor(key);
619         if (color != null) {
620             colorRegistry.remove(key);
621             color.dispose();
622         }
623     }
624
625     private void createFormHeaderColors() {
626         createFormHeaderGradientColors();
627         createFormHeaderKeylineColors();
628         createFormHeaderDNDColors();
629     }
630
631     private void createFormHeaderGradientColors() {
632         RGB titleBg = getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
633         Color bgColor = getImpliedBackground();
634         RGB bg = bgColor.getRGB();
635         RGB bottom, top;
636         // Group 1
637
// Rule: If at least 2 of the RGB values are equal to or between 180 and
638
// 255, then apply specified opacity for Group 1
639
// Examples: Vista, XP Silver, Wn High Con #2
640
// Gradient Bottom = TITLE_BACKGROUND @ 30% Opacity over LIST_BACKGROUND
641
// Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND
642
if (testTwoPrimaryColors(titleBg, 179, 256)) {
643             bottom = blend(titleBg, bg, 30);
644             top = bg;
645         }
646
647         // Group 2
648
// Rule: If at least 2 of the RGB values are equal to or between 121 and
649
// 179, then apply specified opacity for Group 2
650
// Examples: XP Olive, OSX Graphite, Linux GTK, Wn High Con Black
651
// Gradient Bottom = TITLE_BACKGROUND @ 20% Opacity over LIST_BACKGROUND
652
// Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND
653
else if (testTwoPrimaryColors(titleBg, 120, 180)) {
654             bottom = blend(titleBg, bg, 20);
655             top = bg;
656         }
657
658         // Group 3
659
// Rule: If at least 2 of the RGB values are equal to or between 0 and
660
// 120, then apply specified opacity for Group 3
661
// Examples: XP Default, Wn Classic Standard, Wn Marine, Wn Plum, OSX
662
// Aqua, Wn High Con White, Wn High Con #1
663
// Gradient Bottom = TITLE_BACKGROUND @ 10% Opacity over LIST_BACKGROUND
664
// Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND
665
else {
666             bottom = blend(titleBg, bg, 10);
667             top = bg;
668         }
669         createColor(IFormColors.H_GRADIENT_END, top);
670         createColor(IFormColors.H_GRADIENT_START, bottom);
671     }
672
673     private void createFormHeaderKeylineColors() {
674         RGB titleBg = getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
675         Color bgColor = getImpliedBackground();
676         RGB bg = bgColor.getRGB();
677         RGB keyline2;
678         // H_BOTTOM_KEYLINE1
679
createColor(IFormColors.H_BOTTOM_KEYLINE1, new RGB(255, 255, 255));
680
681         // H_BOTTOM_KEYLINE2
682
// Group 1
683
// Rule: If at least 2 of the RGB values are equal to or between 180 and
684
// 255, then apply specified opacity for Group 1
685
// Examples: Vista, XP Silver, Wn High Con #2
686
// Keyline = TITLE_BACKGROUND @ 70% Opacity over LIST_BACKGROUND
687
if (testTwoPrimaryColors(titleBg, 179, 256))
688             keyline2 = blend(titleBg, bg, 70);
689
690         // Group 2
691
// Rule: If at least 2 of the RGB values are equal to or between 121 and
692
// 179, then apply specified opacity for Group 2
693
// Examples: XP Olive, OSX Graphite, Linux GTK, Wn High Con Black
694
// Keyline = TITLE_BACKGROUND @ 50% Opacity over LIST_BACKGROUND
695
else if (testTwoPrimaryColors(titleBg, 120, 180))
696             keyline2 = blend(titleBg, bg, 50);
697
698         // Group 3
699
// Rule: If at least 2 of the RGB values are equal to or between 0 and
700
// 120, then apply specified opacity for Group 3
701
// Examples: XP Default, Wn Classic Standard, Wn Marine, Wn Plum, OSX
702
// Aqua, Wn High Con White, Wn High Con #1
703

704         // Keyline = TITLE_BACKGROUND @ 30% Opacity over LIST_BACKGROUND
705
else
706             keyline2 = blend(titleBg, bg, 30);
707         // H_BOTTOM_KEYLINE2
708
createColor(IFormColors.H_BOTTOM_KEYLINE2, keyline2);
709     }
710
711     private void createFormHeaderDNDColors() {
712         RGB titleBg = getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT);
713         Color bgColor = getImpliedBackground();
714         RGB bg = bgColor.getRGB();
715         RGB light, full;
716         // ALL Themes
717
//
718
// Light Highlight
719
// When *near* the 'hot' area
720
// Rule: If near the title in the 'hot' area, show background highlight
721
// TITLE_BACKGROUND_GRADIENT @ 40%
722
light = blend(titleBg, bg, 40);
723         // Full Highlight
724
// When *on* the title area (regions 1 and 2)
725
// Rule: If near the title in the 'hot' area, show background highlight
726
// TITLE_BACKGROUND_GRADIENT @ 60%
727
full = blend(titleBg, bg, 60);
728         // H_DND_LIGHT
729
// H_DND_FULL
730
createColor(IFormColors.H_HOVER_LIGHT, light);
731         createColor(IFormColors.H_HOVER_FULL, full);
732     }
733 }
734
Popular Tags