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