001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.forms;
011:
012: import java.util.HashMap;
013: import java.util.Iterator;
014: import java.util.Map;
015:
016: import org.eclipse.swt.SWT;
017: import org.eclipse.swt.graphics.Color;
018: import org.eclipse.swt.graphics.RGB;
019: import org.eclipse.swt.widgets.Display;
020:
021: /**
022: * Manages colors that will be applied to forms and form widgets. The colors are
023: * chosen to make the widgets look correct in the editor area. If a different
024: * set of colors is needed, subclass this class and override 'initialize' and/or
025: * 'initializeColors'.
026: *
027: * @since 3.0
028: */
029: public class FormColors {
030: /**
031: * Key for the form title foreground color.
032: *
033: * @deprecated use <code>IFormColors.TITLE</code>.
034: */
035: public static final String TITLE = IFormColors.TITLE;
036:
037: /**
038: * Key for the tree/table border color.
039: *
040: * @deprecated use <code>IFormColors.BORDER</code>
041: */
042: public static final String BORDER = IFormColors.BORDER;
043:
044: /**
045: * Key for the section separator color.
046: *
047: * @deprecated use <code>IFormColors.SEPARATOR</code>.
048: */
049: public static final String SEPARATOR = IFormColors.SEPARATOR;
050:
051: /**
052: * Key for the section title bar background.
053: *
054: * @deprecated use <code>IFormColors.TB_BG
055: */
056: public static final String TB_BG = IFormColors.TB_BG;
057:
058: /**
059: * Key for the section title bar foreground.
060: *
061: * @deprecated use <code>IFormColors.TB_FG</code>
062: */
063: public static final String TB_FG = IFormColors.TB_FG;
064:
065: /**
066: * Key for the section title bar gradient.
067: *
068: * @deprecated use <code>IFormColors.TB_GBG</code>
069: */
070: public static final String TB_GBG = IFormColors.TB_GBG;
071:
072: /**
073: * Key for the section title bar border.
074: *
075: * @deprecated use <code>IFormColors.TB_BORDER</code>.
076: */
077: public static final String TB_BORDER = IFormColors.TB_BORDER;
078:
079: /**
080: * Key for the section toggle color. Since 3.1, this color is used for all
081: * section styles.
082: *
083: * @deprecated use <code>IFormColors.TB_TOGGLE</code>.
084: */
085: public static final String TB_TOGGLE = IFormColors.TB_TOGGLE;
086:
087: /**
088: * Key for the section toggle hover color.
089: *
090: * @since 3.1
091: * @deprecated use <code>IFormColors.TB_TOGGLE_HOVER</code>.
092: */
093: public static final String TB_TOGGLE_HOVER = IFormColors.TB_TOGGLE_HOVER;
094:
095: protected Map colorRegistry = new HashMap(10);
096:
097: protected Color background;
098:
099: protected Color foreground;
100:
101: private boolean shared;
102:
103: protected Display display;
104:
105: protected Color border;
106:
107: /**
108: * Creates form colors using the provided display.
109: *
110: * @param display
111: * the display to use
112: */
113: public FormColors(Display display) {
114: this .display = display;
115: initialize();
116: }
117:
118: /**
119: * Returns the display used to create colors.
120: *
121: * @return the display
122: */
123: public Display getDisplay() {
124: return display;
125: }
126:
127: /**
128: * Initializes the colors. Subclasses can override this method to change the
129: * way colors are created. Alternatively, only the color table can be
130: * modified by overriding <code>initializeColorTable()</code>.
131: *
132: * @see #initializeColorTable
133: */
134: protected void initialize() {
135: background = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
136: foreground = display.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
137: initializeColorTable();
138: updateBorderColor();
139: }
140:
141: /**
142: * Allocates colors for the following keys: BORDER, SEPARATOR and
143: * TITLE. Subclasses can override to allocate these colors differently.
144: */
145: protected void initializeColorTable() {
146: createTitleColor();
147: createColor(IFormColors.SEPARATOR, getColor(IFormColors.TITLE)
148: .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 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 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 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
274: .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
275: Color bg = getImpliedBackground();
276: if (border.getRed() == bg.getRed()
277: && border.getGreen() == bg.getGreen()
278: && border.getBlue() == bg.getBlue())
279: border = display
280: .getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
281: }
282: }
283:
284: /**
285: * Sets the background color. All the toolkits that use this class will
286: * share the same background.
287: *
288: * @param bg
289: * background color
290: */
291: public void setBackground(Color bg) {
292: this .background = bg;
293: updateBorderColor();
294: updateFormHeaderColors();
295: }
296:
297: /**
298: * Sets the foreground color. All the toolkits that use this class will
299: * share the same foreground.
300: *
301: * @param fg
302: * foreground color
303: */
304: public void setForeground(Color fg) {
305: this .foreground = fg;
306: }
307:
308: /**
309: * Returns the current background color.
310: *
311: * @return the background color
312: */
313: public Color getBackground() {
314: return background;
315: }
316:
317: /**
318: * Returns the current foreground color.
319: *
320: * @return the foreground color
321: */
322: public Color getForeground() {
323: return foreground;
324: }
325:
326: /**
327: * Returns the computed border color. Border color depends on the background
328: * and is recomputed whenever the background changes.
329: *
330: * @return the current border color
331: */
332: public Color getBorderColor() {
333: return border;
334: }
335:
336: /**
337: * Tests if the background is white. White background has RGB value
338: * 255,255,255.
339: *
340: * @return <samp>true</samp> if background is white, <samp>false</samp>
341: * otherwise.
342: */
343: public boolean isWhiteBackground() {
344: Color bg = getImpliedBackground();
345: return bg.getRed() == 255 && bg.getGreen() == 255
346: && bg.getBlue() == 255;
347: }
348:
349: /**
350: * Returns the color object for the provided key or <samp>null </samp> if
351: * not in the registry.
352: *
353: * @param key
354: * the color key
355: * @return color object if found, or <samp>null </samp> if not.
356: */
357: public Color getColor(String key) {
358: if (key.startsWith(IFormColors.TB_PREFIX))
359: initializeSectionToolBarColors();
360: else if (key.startsWith(IFormColors.H_PREFIX))
361: initializeFormHeaderColors();
362: return (Color) colorRegistry.get(key);
363: }
364:
365: /**
366: * Disposes all the colors in the registry.
367: */
368: public void dispose() {
369: Iterator e = colorRegistry.values().iterator();
370: while (e.hasNext())
371: ((Color) e.next()).dispose();
372: colorRegistry = null;
373: }
374:
375: /**
376: * Marks the colors shared. This prevents toolkits that share this object
377: * from disposing it.
378: */
379: public void markShared() {
380: this .shared = true;
381: }
382:
383: /**
384: * Tests if the colors are shared.
385: *
386: * @return <code>true</code> if shared, <code>false</code> otherwise.
387: */
388: public boolean isShared() {
389: return shared;
390: }
391:
392: /**
393: * Blends c1 and c2 based in the provided ratio.
394: *
395: * @param c1
396: * first color
397: * @param c2
398: * second color
399: * @param ratio
400: * percentage of the first color in the blend (0-100)
401: * @return the RGB value of the blended color
402: * @since 3.1
403: */
404: public static RGB blend(RGB c1, RGB c2, int ratio) {
405: int r = blend(c1.red, c2.red, ratio);
406: int g = blend(c1.green, c2.green, ratio);
407: int b = blend(c1.blue, c2.blue, ratio);
408: return new RGB(r, g, b);
409: }
410:
411: /**
412: * Tests the source RGB for range.
413: *
414: * @param rgb
415: * the tested RGB
416: * @param from
417: * range start (excluding the value itself)
418: * @param to
419: * range end (excluding the value itself)
420: * @return <code>true</code> if at least one of the primary colors in the
421: * source RGB are within the provided range, <code>false</code>
422: * otherwise.
423: * @since 3.1
424: */
425: public static boolean testAnyPrimaryColor(RGB rgb, int from, int to) {
426: if (testPrimaryColor(rgb.red, from, to))
427: return true;
428: if (testPrimaryColor(rgb.green, from, to))
429: return true;
430: if (testPrimaryColor(rgb.blue, from, to))
431: return true;
432: return false;
433: }
434:
435: /**
436: * Tests the source RGB for range.
437: *
438: * @param rgb
439: * the tested RGB
440: * @param from
441: * range start (excluding the value itself)
442: * @param to
443: * tange end (excluding the value itself)
444: * @return <code>true</code> if at least two of the primary colors in the
445: * source RGB are within the provided range, <code>false</code>
446: * otherwise.
447: * @since 3.1
448: */
449: public static boolean testTwoPrimaryColors(RGB rgb, int from, int to) {
450: int total = 0;
451: if (testPrimaryColor(rgb.red, from, to))
452: total++;
453: if (testPrimaryColor(rgb.green, from, to))
454: total++;
455: if (testPrimaryColor(rgb.blue, from, to))
456: total++;
457: return total >= 2;
458: }
459:
460: /**
461: * Blends two primary color components based on the provided ratio.
462: *
463: * @param v1
464: * first component
465: * @param v2
466: * second component
467: * @param ratio
468: * percentage of the first component in the blend
469: * @return
470: */
471: private static int blend(int v1, int v2, int ratio) {
472: int b = (ratio * v1 + (100 - ratio) * v2) / 100;
473: return Math.min(255, b);
474: }
475:
476: private Color getImpliedBackground() {
477: if (getBackground() != null)
478: return getBackground();
479: return getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
480: }
481:
482: private static boolean testPrimaryColor(int value, int from, int to) {
483: return value > from && value < to;
484: }
485:
486: private void createTitleColor() {
487: /*
488: * RGB rgb = getSystemColor(SWT.COLOR_LIST_SELECTION); // test too light
489: * if (testTwoPrimaryColors(rgb, 120, 151)) rgb = blend(rgb, BLACK, 80);
490: * else if (testTwoPrimaryColors(rgb, 150, 256)) rgb = blend(rgb, BLACK,
491: * 50); createColor(TITLE, rgb);
492: */
493: RGB bg = getImpliedBackground().getRGB();
494: RGB listSelection = getSystemColor(SWT.COLOR_LIST_SELECTION);
495: RGB listForeground = getSystemColor(SWT.COLOR_LIST_FOREGROUND);
496: RGB rgb = listSelection;
497:
498: // Group 1
499: // Rule: If at least 2 of the LIST_SELECTION RGB values are equal to or
500: // between 0 and 120, then use 100% LIST_SELECTION as it is (no
501: // additions)
502: // Examples: XP Default, Win Classic Standard, Win High Con White, Win
503: // Classic Marine
504: if (testTwoPrimaryColors(listSelection, -1, 121))
505: rgb = listSelection;
506: // Group 2
507: // When LIST_BACKGROUND = white (255, 255, 255) or not black, text
508: // colour = LIST_SELECTION @ 100% Opacity + 50% LIST_FOREGROUND over
509: // LIST_BACKGROUND
510: // Rule: If at least 2 of the LIST_SELECTION RGB values are equal to or
511: // between 121 and 255, then add 50% LIST_FOREGROUND to LIST_SELECTION
512: // foreground colour
513: // Examples: Win Vista, XP Silver, XP Olive , Win Classic Plum, OSX
514: // Aqua, OSX Graphite, Linux GTK
515: else if (testTwoPrimaryColors(listSelection, 120, 256)
516: || (bg.red == 0 && bg.green == 0 && bg.blue == 0))
517: rgb = blend(listSelection, listForeground, 50);
518: // Group 3
519: // When LIST_BACKGROUND = black (0, 0, 0), text colour = LIST_SELECTION
520: // @ 100% Opacity + 50% LIST_FOREGROUND over LIST_BACKGROUND
521: // Rule: If LIST_BACKGROUND = 0, 0, 0, then add 50% LIST_FOREGROUND to
522: // LIST_SELECTION foreground colour
523: // Examples: Win High Con Black, Win High Con #1, Win High Con #2
524: // (covered in the second part of the OR clause above)
525: createColor(IFormColors.TITLE, rgb);
526: }
527:
528: private void createTwistieColors() {
529: RGB rgb = getColor(IFormColors.TITLE).getRGB();
530: RGB white = getSystemColor(SWT.COLOR_WHITE);
531: createColor(TB_TOGGLE, rgb);
532: rgb = blend(rgb, white, 60);
533: createColor(TB_TOGGLE_HOVER, rgb);
534: }
535:
536: private void createTitleBarGradientColors() {
537: RGB tbBg = getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
538: RGB bg = getImpliedBackground().getRGB();
539:
540: // Group 1
541: // Rule: If at least 2 of the RGB values are equal to or between 180 and
542: // 255, then apply specified opacity for Group 1
543: // Examples: Vista, XP Silver, Wn High Con #2
544: // Gradient Bottom = TITLE_BACKGROUND @ 30% Opacity over LIST_BACKGROUND
545: // Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND
546: if (testTwoPrimaryColors(tbBg, 179, 256))
547: tbBg = blend(tbBg, bg, 30);
548:
549: // Group 2
550: // Rule: If at least 2 of the RGB values are equal to or between 121 and
551: // 179, then apply specified opacity for Group 2
552: // Examples: XP Olive, OSX Graphite, Linux GTK, Wn High Con Black
553: // Gradient Bottom = TITLE_BACKGROUND @ 20% Opacity over LIST_BACKGROUND
554: // Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND
555: else if (testTwoPrimaryColors(tbBg, 120, 180))
556: tbBg = blend(tbBg, bg, 20);
557:
558: // Group 3
559: // Rule: Everything else
560: // Examples: XP Default, Wn Classic Standard, Wn Marine, Wn Plum, OSX
561: // Aqua, Wn High Con White, Wn High Con #1
562: // Gradient Bottom = TITLE_BACKGROUND @ 10% Opacity over LIST_BACKGROUND
563: // Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND
564: else {
565: tbBg = blend(tbBg, bg, 10);
566: }
567:
568: createColor(IFormColors.TB_BG, tbBg);
569:
570: // for backward compatibility
571: createColor(TB_GBG, tbBg);
572: }
573:
574: private void createTitleBarOutlineColors() {
575: // title bar outline - border color
576: RGB tbBorder = getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
577: RGB bg = getImpliedBackground().getRGB();
578: // Group 1
579: // Rule: If at least 2 of the RGB values are equal to or between 180 and
580: // 255, then apply specified opacity for Group 1
581: // Examples: Vista, XP Silver, Wn High Con #2
582: // Keyline = TITLE_BACKGROUND @ 70% Opacity over LIST_BACKGROUND
583: if (testTwoPrimaryColors(tbBorder, 179, 256))
584: tbBorder = blend(tbBorder, bg, 70);
585:
586: // Group 2
587: // Rule: If at least 2 of the RGB values are equal to or between 121 and
588: // 179, then apply specified opacity for Group 2
589: // Examples: XP Olive, OSX Graphite, Linux GTK, Wn High Con Black
590:
591: // Keyline = TITLE_BACKGROUND @ 50% Opacity over LIST_BACKGROUND
592: else if (testTwoPrimaryColors(tbBorder, 120, 180))
593: tbBorder = blend(tbBorder, bg, 50);
594:
595: // Group 3
596: // Rule: Everything else
597: // Examples: XP Default, Wn Classic Standard, Wn Marine, Wn Plum, OSX
598: // Aqua, Wn High Con White, Wn High Con #1
599:
600: // Keyline = TITLE_BACKGROUND @ 30% Opacity over LIST_BACKGROUND
601: else {
602: tbBorder = blend(tbBorder, bg, 30);
603: }
604: createColor(FormColors.TB_BORDER, tbBorder);
605: }
606:
607: private void updateFormHeaderColors() {
608: if (colorRegistry.containsKey(IFormColors.H_GRADIENT_END)) {
609: disposeIfFound(IFormColors.H_GRADIENT_END);
610: disposeIfFound(IFormColors.H_GRADIENT_START);
611: disposeIfFound(IFormColors.H_BOTTOM_KEYLINE1);
612: disposeIfFound(IFormColors.H_BOTTOM_KEYLINE2);
613: disposeIfFound(IFormColors.H_HOVER_LIGHT);
614: disposeIfFound(IFormColors.H_HOVER_FULL);
615: initializeFormHeaderColors();
616: }
617: }
618:
619: private void disposeIfFound(String key) {
620: Color color = getColor(key);
621: if (color != null) {
622: colorRegistry.remove(key);
623: color.dispose();
624: }
625: }
626:
627: private void createFormHeaderColors() {
628: createFormHeaderGradientColors();
629: createFormHeaderKeylineColors();
630: createFormHeaderDNDColors();
631: }
632:
633: private void createFormHeaderGradientColors() {
634: RGB titleBg = getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
635: Color bgColor = getImpliedBackground();
636: RGB bg = bgColor.getRGB();
637: RGB bottom, top;
638: // Group 1
639: // Rule: If at least 2 of the RGB values are equal to or between 180 and
640: // 255, then apply specified opacity for Group 1
641: // Examples: Vista, XP Silver, Wn High Con #2
642: // Gradient Bottom = TITLE_BACKGROUND @ 30% Opacity over LIST_BACKGROUND
643: // Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND
644: if (testTwoPrimaryColors(titleBg, 179, 256)) {
645: bottom = blend(titleBg, bg, 30);
646: top = bg;
647: }
648:
649: // Group 2
650: // Rule: If at least 2 of the RGB values are equal to or between 121 and
651: // 179, then apply specified opacity for Group 2
652: // Examples: XP Olive, OSX Graphite, Linux GTK, Wn High Con Black
653: // Gradient Bottom = TITLE_BACKGROUND @ 20% Opacity over LIST_BACKGROUND
654: // Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND
655: else if (testTwoPrimaryColors(titleBg, 120, 180)) {
656: bottom = blend(titleBg, bg, 20);
657: top = bg;
658: }
659:
660: // Group 3
661: // Rule: If at least 2 of the RGB values are equal to or between 0 and
662: // 120, then apply specified opacity for Group 3
663: // Examples: XP Default, Wn Classic Standard, Wn Marine, Wn Plum, OSX
664: // Aqua, Wn High Con White, Wn High Con #1
665: // Gradient Bottom = TITLE_BACKGROUND @ 10% Opacity over LIST_BACKGROUND
666: // Gradient Top = TITLE BACKGROUND @ 0% Opacity over LIST_BACKGROUND
667: else {
668: bottom = blend(titleBg, bg, 10);
669: top = bg;
670: }
671: createColor(IFormColors.H_GRADIENT_END, top);
672: createColor(IFormColors.H_GRADIENT_START, bottom);
673: }
674:
675: private void createFormHeaderKeylineColors() {
676: RGB titleBg = getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
677: Color bgColor = getImpliedBackground();
678: RGB bg = bgColor.getRGB();
679: RGB keyline2;
680: // H_BOTTOM_KEYLINE1
681: createColor(IFormColors.H_BOTTOM_KEYLINE1, new RGB(255, 255,
682: 255));
683:
684: // H_BOTTOM_KEYLINE2
685: // Group 1
686: // Rule: If at least 2 of the RGB values are equal to or between 180 and
687: // 255, then apply specified opacity for Group 1
688: // Examples: Vista, XP Silver, Wn High Con #2
689: // Keyline = TITLE_BACKGROUND @ 70% Opacity over LIST_BACKGROUND
690: if (testTwoPrimaryColors(titleBg, 179, 256))
691: keyline2 = blend(titleBg, bg, 70);
692:
693: // Group 2
694: // Rule: If at least 2 of the RGB values are equal to or between 121 and
695: // 179, then apply specified opacity for Group 2
696: // Examples: XP Olive, OSX Graphite, Linux GTK, Wn High Con Black
697: // Keyline = TITLE_BACKGROUND @ 50% Opacity over LIST_BACKGROUND
698: else if (testTwoPrimaryColors(titleBg, 120, 180))
699: keyline2 = blend(titleBg, bg, 50);
700:
701: // Group 3
702: // Rule: If at least 2 of the RGB values are equal to or between 0 and
703: // 120, then apply specified opacity for Group 3
704: // Examples: XP Default, Wn Classic Standard, Wn Marine, Wn Plum, OSX
705: // Aqua, Wn High Con White, Wn High Con #1
706:
707: // Keyline = TITLE_BACKGROUND @ 30% Opacity over LIST_BACKGROUND
708: else
709: keyline2 = blend(titleBg, bg, 30);
710: // H_BOTTOM_KEYLINE2
711: createColor(IFormColors.H_BOTTOM_KEYLINE2, keyline2);
712: }
713:
714: private void createFormHeaderDNDColors() {
715: RGB titleBg = getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT);
716: Color bgColor = getImpliedBackground();
717: RGB bg = bgColor.getRGB();
718: RGB light, full;
719: // ALL Themes
720: //
721: // Light Highlight
722: // When *near* the 'hot' area
723: // Rule: If near the title in the 'hot' area, show background highlight
724: // TITLE_BACKGROUND_GRADIENT @ 40%
725: light = blend(titleBg, bg, 40);
726: // Full Highlight
727: // When *on* the title area (regions 1 and 2)
728: // Rule: If near the title in the 'hot' area, show background highlight
729: // TITLE_BACKGROUND_GRADIENT @ 60%
730: full = blend(titleBg, bg, 60);
731: // H_DND_LIGHT
732: // H_DND_FULL
733: createColor(IFormColors.H_HOVER_LIGHT, light);
734: createColor(IFormColors.H_HOVER_FULL, full);
735: }
736: }
|