KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > SystemColor


1 /*
2  * @(#)SystemColor.java 1.24 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package java.awt;
8
9 import java.awt.geom.AffineTransform JavaDoc;
10 import java.awt.geom.Rectangle2D JavaDoc;
11 import java.awt.image.ColorModel JavaDoc;
12
13 /**
14  * A class to encapsulate symbolic colors representing the color of
15  * native GUI objects on a system. For systems which support the dynamic
16  * update of the system colors (when the user changes the colors)
17  * the actual RGB values of these symbolic colors will also change
18  * dynamically. In order to compare the "current" RGB value of a
19  * <code>SystemColor</code> object with a non-symbolic Color object,
20  * <code>getRGB</code> should be used rather than <code>equals</code>.
21  * <p>
22  * Note that the way in which these system colors are applied to GUI objects
23  * may vary slightly from platform to platform since GUI objects may be
24  * rendered differently on each platform.
25  * <p>
26  * System color values may also be available through the <code>getDesktopProperty</code>
27  * method on <code>java.awt.Toolkit</code>.
28  *
29  * @see Toolkit#getDesktopProperty
30  *
31  * @version 1.24, 12/19/03
32  * @author Carl Quinn
33  * @author Amy Fowler
34  */

35 public final class SystemColor extends Color JavaDoc implements java.io.Serializable JavaDoc {
36
37    /**
38      * The array index for the
39      * <a HREF="#desktop"><code>desktop</code></a> system color.
40      * @see SystemColor#desktop
41      */

42     public final static int DESKTOP = 0;
43
44     /**
45      * The array index for the
46      * <a HREF="#activeCaption"><code>activeCaption</code></a> system color.
47      * @see SystemColor#activeCaption
48      */

49     public final static int ACTIVE_CAPTION = 1;
50
51     /**
52      * The array index for the
53      * <a HREF="#activeCaptionText"><code>activeCaptionText</code></a> system color.
54      * @see SystemColor#activeCaptionText
55      */

56     public final static int ACTIVE_CAPTION_TEXT = 2;
57
58     /**
59      * The array index for the
60      * <a HREF="#activeCaptionBorder"><code>activeCaptionBorder</code></a> system color.
61      * @see SystemColor#activeCaptionBorder
62      */

63     public final static int ACTIVE_CAPTION_BORDER = 3;
64
65     /**
66      * The array index for the
67      * <a HREF="#inactiveCaption"><code>inactiveCaption</code></a> system color.
68      * @see SystemColor#inactiveCaption
69      */

70     public final static int INACTIVE_CAPTION = 4;
71
72     /**
73      * The array index for the
74      * <a HREF="#inactiveCaptionText"><code>inactiveCaptionText</code></a> system color.
75      * @see SystemColor#inactiveCaptionText
76      */

77     public final static int INACTIVE_CAPTION_TEXT = 5;
78
79     /**
80      * The array index for the
81      * <a HREF="#inactiveCaptionBorder"><code>inactiveCaptionBorder</code></a> system color.
82      * @see SystemColor#inactiveCaptionBorder
83      */

84     public final static int INACTIVE_CAPTION_BORDER = 6;
85
86     /**
87      * The array index for the
88      * <a HREF="#window"><code>window</code></a> system color.
89      * @see SystemColor#window
90      */

91     public final static int WINDOW = 7;
92
93     /**
94      * The array index for the
95      * <a HREF="#windowBorder"><code>windowBorder</code></a> system color.
96      * @see SystemColor#windowBorder
97      */

98     public final static int WINDOW_BORDER = 8;
99
100     /**
101      * The array index for the
102      * <a HREF="#windowText"><code>windowText</code></a> system color.
103      * @see SystemColor#windowText
104      */

105     public final static int WINDOW_TEXT = 9;
106
107     /**
108      * The array index for the
109      * <a HREF="#menu"><code>menu</code></a> system color.
110      * @see SystemColor#menu
111      */

112     public final static int MENU = 10;
113
114     /**
115      * The array index for the
116      * <a HREF="#menuText"><code>menuText</code></a> system color.
117      * @see SystemColor#menuText
118      */

119     public final static int MENU_TEXT = 11;
120
121     /**
122      * The array index for the
123      * <a HREF="#text"><code>text</code></a> system color.
124      * @see SystemColor#text
125      */

126     public final static int TEXT = 12;
127
128     /**
129      * The array index for the
130      * <a HREF="#textText"><code>textText</code></a> system color.
131      * @see SystemColor#textText
132      */

133     public final static int TEXT_TEXT = 13;
134
135     /**
136      * The array index for the
137      * <a HREF="#textHighlight"><code>textHighlight</code></a> system color.
138      * @see SystemColor#textHighlight
139      */

140     public final static int TEXT_HIGHLIGHT = 14;
141
142     /**
143      * The array index for the
144      * <a HREF="#textHighlightText"><code>textHighlightText</code></a> system color.
145      * @see SystemColor#textHighlightText
146      */

147     public final static int TEXT_HIGHLIGHT_TEXT = 15;
148
149     /**
150      * The array index for the
151      * <a HREF="#textInactiveText"><code>textInactiveText</code></a> system color.
152      * @see SystemColor#textInactiveText
153      */

154     public final static int TEXT_INACTIVE_TEXT = 16;
155
156     /**
157      * The array index for the
158      * <a HREF="#control"><code>control</code></a> system color.
159      * @see SystemColor#control
160      */

161     public final static int CONTROL = 17;
162
163     /**
164      * The array index for the
165      * <a HREF="#controlText"><code>controlText</code></a> system color.
166      * @see SystemColor#controlText
167      */

168     public final static int CONTROL_TEXT = 18;
169
170     /**
171      * The array index for the
172      * <a HREF="#controlHighlight"><code>controlHighlight</code></a> system color.
173      * @see SystemColor#controlHighlight
174      */

175     public final static int CONTROL_HIGHLIGHT = 19;
176
177     /**
178      * The array index for the
179      * <a HREF="#controlLtHighlight"><code>controlLtHighlight</code></a> system color.
180      * @see SystemColor#controlLtHighlight
181      */

182     public final static int CONTROL_LT_HIGHLIGHT = 20;
183
184     /**
185      * The array index for the
186      * <a HREF="#controlShadow"><code>controlShadow</code></a> system color.
187      * @see SystemColor#controlShadow
188      */

189     public final static int CONTROL_SHADOW = 21;
190
191     /**
192      * The array index for the
193      * <a HREF="#controlDkShadow"><code>controlDkShadow</code></a> system color.
194      * @see SystemColor#controlDkShadow
195      */

196     public final static int CONTROL_DK_SHADOW = 22;
197
198     /**
199      * The array index for the
200      * <a HREF="#scrollbar"><code>scrollbar</code></a> system color.
201      * @see SystemColor#scrollbar
202      */

203     public final static int SCROLLBAR = 23;
204
205     /**
206      * The array index for the
207      * <a HREF="#info"><code>info</code></a> system color.
208      * @see SystemColor#info
209      */

210     public final static int INFO = 24;
211
212     /**
213      * The array index for the
214      * <a HREF="#infoText"><code>infoText</code></a> system color.
215      * @see SystemColor#infoText
216      */

217     public final static int INFO_TEXT = 25;
218
219     /**
220      * The number of system colors in the array.
221      */

222     public final static int NUM_COLORS = 26;
223
224     /******************************************************************************************/
225
226    /**
227      * The color rendered for the background of the desktop.
228      */

229     public final static SystemColor JavaDoc desktop = new SystemColor JavaDoc((byte)DESKTOP);
230
231     /**
232      * The color rendered for the window-title background of the currently active window.
233      */

234     public final static SystemColor JavaDoc activeCaption = new SystemColor JavaDoc((byte)ACTIVE_CAPTION);
235
236     /**
237      * The color rendered for the window-title text of the currently active window.
238      */

239     public final static SystemColor JavaDoc activeCaptionText = new SystemColor JavaDoc((byte)ACTIVE_CAPTION_TEXT);
240
241     /**
242      * The color rendered for the border around the currently active window.
243      */

244     public final static SystemColor JavaDoc activeCaptionBorder = new SystemColor JavaDoc((byte)ACTIVE_CAPTION_BORDER);
245
246     /**
247      * The color rendered for the window-title background of inactive windows.
248      */

249     public final static SystemColor JavaDoc inactiveCaption = new SystemColor JavaDoc((byte)INACTIVE_CAPTION);
250
251     /**
252      * The color rendered for the window-title text of inactive windows.
253      */

254     public final static SystemColor JavaDoc inactiveCaptionText = new SystemColor JavaDoc((byte)INACTIVE_CAPTION_TEXT);
255
256     /**
257      * The color rendered for the border around inactive windows.
258      */

259     public final static SystemColor JavaDoc inactiveCaptionBorder = new SystemColor JavaDoc((byte)INACTIVE_CAPTION_BORDER);
260
261     /**
262      * The color rendered for the background of interior regions inside windows.
263      */

264     public final static SystemColor JavaDoc window = new SystemColor JavaDoc((byte)WINDOW);
265
266     /**
267      * The color rendered for the border around interior regions inside windows.
268      */

269     public final static SystemColor JavaDoc windowBorder = new SystemColor JavaDoc((byte)WINDOW_BORDER);
270
271     /**
272      * The color rendered for text of interior regions inside windows.
273      */

274     public final static SystemColor JavaDoc windowText = new SystemColor JavaDoc((byte)WINDOW_TEXT);
275
276     /**
277      * The color rendered for the background of menus.
278      */

279     public final static SystemColor JavaDoc menu = new SystemColor JavaDoc((byte)MENU);
280
281     /**
282      * The color rendered for the text of menus.
283      */

284     public final static SystemColor JavaDoc menuText = new SystemColor JavaDoc((byte)MENU_TEXT);
285
286     /**
287      * The color rendered for the background of text control objects, such as
288      * textfields and comboboxes.
289      */

290     public final static SystemColor JavaDoc text = new SystemColor JavaDoc((byte)TEXT);
291
292     /**
293      * The color rendered for the text of text control objects, such as textfields
294      * and comboboxes.
295      */

296     public final static SystemColor JavaDoc textText = new SystemColor JavaDoc((byte)TEXT_TEXT);
297
298     /**
299      * The color rendered for the background of selected items, such as in menus,
300      * comboboxes, and text.
301      */

302     public final static SystemColor JavaDoc textHighlight = new SystemColor JavaDoc((byte)TEXT_HIGHLIGHT);
303
304     /**
305      * The color rendered for the text of selected items, such as in menus, comboboxes,
306      * and text.
307      */

308     public final static SystemColor JavaDoc textHighlightText = new SystemColor JavaDoc((byte)TEXT_HIGHLIGHT_TEXT);
309
310     /**
311      * The color rendered for the text of inactive items, such as in menus.
312      */

313     public final static SystemColor JavaDoc textInactiveText = new SystemColor JavaDoc((byte)TEXT_INACTIVE_TEXT);
314
315     /**
316      * The color rendered for the background of control panels and control objects,
317      * such as pushbuttons.
318      */

319     public final static SystemColor JavaDoc control = new SystemColor JavaDoc((byte)CONTROL);
320
321     /**
322      * The color rendered for the text of control panels and control objects,
323      * such as pushbuttons.
324      */

325     public final static SystemColor JavaDoc controlText = new SystemColor JavaDoc((byte)CONTROL_TEXT);
326
327     /**
328      * The color rendered for light areas of 3D control objects, such as pushbuttons.
329      * This color is typically derived from the <code>control</code> background color
330      * to provide a 3D effect.
331      */

332     public final static SystemColor JavaDoc controlHighlight = new SystemColor JavaDoc((byte)CONTROL_HIGHLIGHT);
333
334     /**
335      * The color rendered for highlight areas of 3D control objects, such as pushbuttons.
336      * This color is typically derived from the <code>control</code> background color
337      * to provide a 3D effect.
338      */

339     public final static SystemColor JavaDoc controlLtHighlight = new SystemColor JavaDoc((byte)CONTROL_LT_HIGHLIGHT);
340
341     /**
342      * The color rendered for shadow areas of 3D control objects, such as pushbuttons.
343      * This color is typically derived from the <code>control</code> background color
344      * to provide a 3D effect.
345      */

346     public final static SystemColor JavaDoc controlShadow = new SystemColor JavaDoc((byte)CONTROL_SHADOW);
347
348     /**
349      * The color rendered for dark shadow areas on 3D control objects, such as pushbuttons.
350      * This color is typically derived from the <code>control</code> background color
351      * to provide a 3D effect.
352      */

353     public final static SystemColor JavaDoc controlDkShadow = new SystemColor JavaDoc((byte)CONTROL_DK_SHADOW);
354
355     /**
356      * The color rendered for the background of scrollbars.
357      */

358     public final static SystemColor JavaDoc scrollbar = new SystemColor JavaDoc((byte)SCROLLBAR);
359
360     /**
361      * The color rendered for the background of tooltips or spot help.
362      */

363     public final static SystemColor JavaDoc info = new SystemColor JavaDoc((byte)INFO);
364
365     /**
366      * The color rendered for the text of tooltips or spot help.
367      */

368     public final static SystemColor JavaDoc infoText = new SystemColor JavaDoc((byte)INFO_TEXT);
369
370     /*
371      * System colors with default initial values, overwritten by toolkit if
372      * system values differ and are available.
373      */

374     private static int[] systemColors = {
375         0xFF005C5C, // desktop = new Color(0,92,92);
376
0xFF000080, // activeCaption = new Color(0,0,128);
377
0xFFFFFFFF, // activeCaptionText = Color.white;
378
0xFFC0C0C0, // activeCaptionBorder = Color.lightGray;
379
0xFF808080, // inactiveCaption = Color.gray;
380
0xFFC0C0C0, // inactiveCaptionText = Color.lightGray;
381
0xFFC0C0C0, // inactiveCaptionBorder = Color.lightGray;
382
0xFFFFFFFF, // window = Color.white;
383
0xFF000000, // windowBorder = Color.black;
384
0xFF000000, // windowText = Color.black;
385
0xFFC0C0C0, // menu = Color.lightGray;
386
0xFF000000, // menuText = Color.black;
387
0xFFC0C0C0, // text = Color.lightGray;
388
0xFF000000, // textText = Color.black;
389
0xFF000080, // textHighlight = new Color(0,0,128);
390
0xFFFFFFFF, // textHighlightText = Color.white;
391
0xFF808080, // textInactiveText = Color.gray;
392
0xFFC0C0C0, // control = Color.lightGray;
393
0xFF000000, // controlText = Color.black;
394
0xFFFFFFFF, // controlHighlight = Color.white;
395
0xFFE0E0E0, // controlLtHighlight = new Color(224,224,224);
396
0xFF808080, // controlShadow = Color.gray;
397
0xFF000000, // controlDkShadow = Color.black;
398
0xFFE0E0E0, // scrollbar = new Color(224,224,224);
399
0xFFE0E000, // info = new Color(224,224,0);
400
0xFF000000, // infoText = Color.black;
401
};
402
403     /*
404      * JDK 1.1 serialVersionUID.
405      */

406     private static final long serialVersionUID = 4503142729533789064L;
407
408     static {
409       updateSystemColors();
410     }
411
412     /**
413      * Called from <init> & toolkit to update the above systemColors cache.
414      */

415     private static void updateSystemColors() {
416         if (!GraphicsEnvironment.isHeadless()) {
417             Toolkit.getDefaultToolkit().loadSystemColors(systemColors);
418         }
419     }
420
421     /**
422      * Creates a symbolic color that represents an indexed entry into system
423      * color cache. Used by above static system colors.
424      */

425     private SystemColor(byte index) {
426         super(0, 0, 0);
427     value = index;
428     }
429
430     /**
431      * Gets the "current" RGB value representing the symbolic color.
432      * (Bits 24-31 are 0xff, 16-23 are red, 8-15 are green, 0-7 are blue).
433      * @see java.awt.image.ColorModel#getRGBdefault
434      * @see java.awt.Color#getBlue()
435      * @see java.awt.Color#getGreen()
436      * @see java.awt.Color#getRed()
437      */

438     // NOTE: This method may be called by privileged threads.
439
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
440
public int getRGB() {
441     return systemColors[value];
442     }
443
444     /**
445      * Creates and returns a <code>PaintContext</code> used to generate
446      * a solid color pattern. This enables a Color object to be used
447      * as an argument to any method requiring an object implementing
448      * the Paint interface.
449      * @see Paint
450      * @see PaintContext
451      * @see Graphics2D#setPaint
452      */

453     public PaintContext JavaDoc createContext(ColorModel JavaDoc cm, Rectangle JavaDoc r,
454                       Rectangle2D JavaDoc r2d, AffineTransform JavaDoc xform,
455                                       RenderingHints JavaDoc hints) {
456     return new ColorPaintContext JavaDoc(value, cm);
457     }
458
459     /**
460      * Returns a string representation of this <code>Color</code>'s values.
461      * This method is intended to be used only for debugging purposes,
462      * and the content and format of the returned string may vary between
463      * implementations.
464      * The returned string may be empty but may not be <code>null</code>.
465      *
466      * @return a string representation of this <code>Color</code>
467      */

468     public String JavaDoc toString() {
469         return getClass().getName() + "[i=" + (value) + "]";
470     }
471
472 }
473
Popular Tags