Source Code Cross Referenced for SystemColor.java in  » 6.0-JDK-Core » AWT » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 1996-2007 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025        package java.awt;
026
027        import java.io.ObjectStreamException;
028
029        /**
030         * A class to encapsulate symbolic colors representing the color of
031         * native GUI objects on a system.  For systems which support the dynamic
032         * update of the system colors (when the user changes the colors)
033         * the actual RGB values of these symbolic colors will also change
034         * dynamically.  In order to compare the "current" RGB value of a
035         * <code>SystemColor</code> object with a non-symbolic Color object,
036         * <code>getRGB</code> should be used rather than <code>equals</code>.
037         * <p>
038         * Note that the way in which these system colors are applied to GUI objects
039         * may vary slightly from platform to platform since GUI objects may be
040         * rendered differently on each platform.
041         * <p>
042         * System color values may also be available through the <code>getDesktopProperty</code>
043         * method on <code>java.awt.Toolkit</code>.
044         *
045         * @see Toolkit#getDesktopProperty
046         *
047         * @version 	1.36, 06/06/07
048         * @author 	Carl Quinn
049         * @author      Amy Fowler
050         */
051        public final class SystemColor extends Color implements 
052                java.io.Serializable {
053
054            /**
055             * The array index for the
056             * {@link #desktop} system color.
057             * @see SystemColor#desktop
058             */
059            public final static int DESKTOP = 0;
060
061            /**
062             * The array index for the
063             * {@link #activeCaption} system color.
064             * @see SystemColor#activeCaption
065             */
066            public final static int ACTIVE_CAPTION = 1;
067
068            /**
069             * The array index for the
070             * {@link #activeCaptionText} system color.
071             * @see SystemColor#activeCaptionText
072             */
073            public final static int ACTIVE_CAPTION_TEXT = 2;
074
075            /**
076             * The array index for the
077             * {@link #activeCaptionBorder} system color.
078             * @see SystemColor#activeCaptionBorder
079             */
080            public final static int ACTIVE_CAPTION_BORDER = 3;
081
082            /**
083             * The array index for the
084             * {@link #inactiveCaption} system color.
085             * @see SystemColor#inactiveCaption
086             */
087            public final static int INACTIVE_CAPTION = 4;
088
089            /**
090             * The array index for the
091             * {@link #inactiveCaptionText} system color.
092             * @see SystemColor#inactiveCaptionText
093             */
094            public final static int INACTIVE_CAPTION_TEXT = 5;
095
096            /**
097             * The array index for the
098             * {@link #inactiveCaptionBorder} system color.
099             * @see SystemColor#inactiveCaptionBorder
100             */
101            public final static int INACTIVE_CAPTION_BORDER = 6;
102
103            /**
104             * The array index for the
105             * {@link #window} system color.
106             * @see SystemColor#window
107             */
108            public final static int WINDOW = 7;
109
110            /**
111             * The array index for the
112             * {@link #windowBorder} system color.
113             * @see SystemColor#windowBorder
114             */
115            public final static int WINDOW_BORDER = 8;
116
117            /**
118             * The array index for the
119             * {@link #windowText} system color.
120             * @see SystemColor#windowText
121             */
122            public final static int WINDOW_TEXT = 9;
123
124            /**
125             * The array index for the
126             * {@link #menu} system color.
127             * @see SystemColor#menu
128             */
129            public final static int MENU = 10;
130
131            /**
132             * The array index for the
133             * {@link #menuText} system color.
134             * @see SystemColor#menuText
135             */
136            public final static int MENU_TEXT = 11;
137
138            /**
139             * The array index for the
140             * {@link #text} system color.
141             * @see SystemColor#text
142             */
143            public final static int TEXT = 12;
144
145            /**
146             * The array index for the
147             * {@link #textText} system color.
148             * @see SystemColor#textText
149             */
150            public final static int TEXT_TEXT = 13;
151
152            /**
153             * The array index for the
154             * {@link #textHighlight} system color.
155             * @see SystemColor#textHighlight
156             */
157            public final static int TEXT_HIGHLIGHT = 14;
158
159            /**
160             * The array index for the
161             * {@link #textHighlightText} system color.
162             * @see SystemColor#textHighlightText
163             */
164            public final static int TEXT_HIGHLIGHT_TEXT = 15;
165
166            /**
167             * The array index for the
168             * {@link #textInactiveText} system color.
169             * @see SystemColor#textInactiveText
170             */
171            public final static int TEXT_INACTIVE_TEXT = 16;
172
173            /**
174             * The array index for the
175             * {@link #control} system color.
176             * @see SystemColor#control
177             */
178            public final static int CONTROL = 17;
179
180            /**
181             * The array index for the
182             * {@link #controlText} system color.
183             * @see SystemColor#controlText
184             */
185            public final static int CONTROL_TEXT = 18;
186
187            /**
188             * The array index for the
189             * {@link #controlHighlight} system color.
190             * @see SystemColor#controlHighlight
191             */
192            public final static int CONTROL_HIGHLIGHT = 19;
193
194            /**
195             * The array index for the
196             * {@link #controlLtHighlight} system color.
197             * @see SystemColor#controlLtHighlight
198             */
199            public final static int CONTROL_LT_HIGHLIGHT = 20;
200
201            /**
202             * The array index for the
203             * {@link #controlShadow} system color.
204             * @see SystemColor#controlShadow
205             */
206            public final static int CONTROL_SHADOW = 21;
207
208            /**
209             * The array index for the
210             * {@link #controlDkShadow} system color.
211             * @see SystemColor#controlDkShadow
212             */
213            public final static int CONTROL_DK_SHADOW = 22;
214
215            /**
216             * The array index for the
217             * {@link #scrollbar} system color.
218             * @see SystemColor#scrollbar
219             */
220            public final static int SCROLLBAR = 23;
221
222            /**
223             * The array index for the
224             * {@link #info} system color.
225             * @see SystemColor#info
226             */
227            public final static int INFO = 24;
228
229            /**
230             * The array index for the
231             * {@link #infoText} system color.
232             * @see SystemColor#infoText
233             */
234            public final static int INFO_TEXT = 25;
235
236            /**
237             * The number of system colors in the array.
238             */
239            public final static int NUM_COLORS = 26;
240
241            /******************************************************************************************/
242
243            /*
244             * System colors with default initial values, overwritten by toolkit if
245             * system values differ and are available.
246             * Should put array initialization above first field that is using 
247             * SystemColor constructor to initialize.
248             */
249            private static int[] systemColors = { 0xFF005C5C, // desktop = new Color(0,92,92);
250                    0xFF000080, // activeCaption = new Color(0,0,128);
251                    0xFFFFFFFF, // activeCaptionText = Color.white;
252                    0xFFC0C0C0, // activeCaptionBorder = Color.lightGray;
253                    0xFF808080, // inactiveCaption = Color.gray;
254                    0xFFC0C0C0, // inactiveCaptionText = Color.lightGray;
255                    0xFFC0C0C0, // inactiveCaptionBorder = Color.lightGray;
256                    0xFFFFFFFF, // window = Color.white;
257                    0xFF000000, // windowBorder = Color.black;
258                    0xFF000000, // windowText = Color.black;
259                    0xFFC0C0C0, // menu = Color.lightGray;
260                    0xFF000000, // menuText = Color.black;
261                    0xFFC0C0C0, // text = Color.lightGray;
262                    0xFF000000, // textText = Color.black;
263                    0xFF000080, // textHighlight = new Color(0,0,128);
264                    0xFFFFFFFF, // textHighlightText = Color.white;
265                    0xFF808080, // textInactiveText = Color.gray;
266                    0xFFC0C0C0, // control = Color.lightGray;
267                    0xFF000000, // controlText = Color.black;
268                    0xFFFFFFFF, // controlHighlight = Color.white;
269                    0xFFE0E0E0, // controlLtHighlight = new Color(224,224,224);
270                    0xFF808080, // controlShadow = Color.gray;
271                    0xFF000000, // controlDkShadow = Color.black;
272                    0xFFE0E0E0, // scrollbar = new Color(224,224,224);
273                    0xFFE0E000, // info = new Color(224,224,0);
274                    0xFF000000, // infoText = Color.black;
275            };
276
277            /**
278             * The color rendered for the background of the desktop.
279             */
280            public final static SystemColor desktop = new SystemColor(
281                    (byte) DESKTOP);
282
283            /**
284             * The color rendered for the window-title background of the currently active window.
285             */
286            public final static SystemColor activeCaption = new SystemColor(
287                    (byte) ACTIVE_CAPTION);
288
289            /**
290             * The color rendered for the window-title text of the currently active window.
291             */
292            public final static SystemColor activeCaptionText = new SystemColor(
293                    (byte) ACTIVE_CAPTION_TEXT);
294
295            /**
296             * The color rendered for the border around the currently active window.
297             */
298            public final static SystemColor activeCaptionBorder = new SystemColor(
299                    (byte) ACTIVE_CAPTION_BORDER);
300
301            /**
302             * The color rendered for the window-title background of inactive windows.
303             */
304            public final static SystemColor inactiveCaption = new SystemColor(
305                    (byte) INACTIVE_CAPTION);
306
307            /**
308             * The color rendered for the window-title text of inactive windows.
309             */
310            public final static SystemColor inactiveCaptionText = new SystemColor(
311                    (byte) INACTIVE_CAPTION_TEXT);
312
313            /**
314             * The color rendered for the border around inactive windows.
315             */
316            public final static SystemColor inactiveCaptionBorder = new SystemColor(
317                    (byte) INACTIVE_CAPTION_BORDER);
318
319            /**
320             * The color rendered for the background of interior regions inside windows.
321             */
322            public final static SystemColor window = new SystemColor(
323                    (byte) WINDOW);
324
325            /**
326             * The color rendered for the border around interior regions inside windows.
327             */
328            public final static SystemColor windowBorder = new SystemColor(
329                    (byte) WINDOW_BORDER);
330
331            /**
332             * The color rendered for text of interior regions inside windows.
333             */
334            public final static SystemColor windowText = new SystemColor(
335                    (byte) WINDOW_TEXT);
336
337            /**
338             * The color rendered for the background of menus.
339             */
340            public final static SystemColor menu = new SystemColor((byte) MENU);
341
342            /**
343             * The color rendered for the text of menus.
344             */
345            public final static SystemColor menuText = new SystemColor(
346                    (byte) MENU_TEXT);
347
348            /**
349             * The color rendered for the background of text control objects, such as
350             * textfields and comboboxes.
351             */
352            public final static SystemColor text = new SystemColor((byte) TEXT);
353
354            /**
355             * The color rendered for the text of text control objects, such as textfields
356             * and comboboxes.
357             */
358            public final static SystemColor textText = new SystemColor(
359                    (byte) TEXT_TEXT);
360
361            /**
362             * The color rendered for the background of selected items, such as in menus,
363             * comboboxes, and text.
364             */
365            public final static SystemColor textHighlight = new SystemColor(
366                    (byte) TEXT_HIGHLIGHT);
367
368            /**
369             * The color rendered for the text of selected items, such as in menus, comboboxes,
370             * and text.
371             */
372            public final static SystemColor textHighlightText = new SystemColor(
373                    (byte) TEXT_HIGHLIGHT_TEXT);
374
375            /**
376             * The color rendered for the text of inactive items, such as in menus.
377             */
378            public final static SystemColor textInactiveText = new SystemColor(
379                    (byte) TEXT_INACTIVE_TEXT);
380
381            /**
382             * The color rendered for the background of control panels and control objects,
383             * such as pushbuttons.
384             */
385            public final static SystemColor control = new SystemColor(
386                    (byte) CONTROL);
387
388            /**
389             * The color rendered for the text of control panels and control objects,
390             * such as pushbuttons.
391             */
392            public final static SystemColor controlText = new SystemColor(
393                    (byte) CONTROL_TEXT);
394
395            /**
396             * The color rendered for light areas of 3D control objects, such as pushbuttons.
397             * This color is typically derived from the <code>control</code> background color
398             * to provide a 3D effect.
399             */
400            public final static SystemColor controlHighlight = new SystemColor(
401                    (byte) CONTROL_HIGHLIGHT);
402
403            /**
404             * The color rendered for highlight areas of 3D control objects, such as pushbuttons.
405             * This color is typically derived from the <code>control</code> background color
406             * to provide a 3D effect.
407             */
408            public final static SystemColor controlLtHighlight = new SystemColor(
409                    (byte) CONTROL_LT_HIGHLIGHT);
410
411            /**
412             * The color rendered for shadow areas of 3D control objects, such as pushbuttons.
413             * This color is typically derived from the <code>control</code> background color
414             * to provide a 3D effect.
415             */
416            public final static SystemColor controlShadow = new SystemColor(
417                    (byte) CONTROL_SHADOW);
418
419            /**
420             * The color rendered for dark shadow areas on 3D control objects, such as pushbuttons.
421             * This color is typically derived from the <code>control</code> background color
422             * to provide a 3D effect.
423             */
424            public final static SystemColor controlDkShadow = new SystemColor(
425                    (byte) CONTROL_DK_SHADOW);
426
427            /**
428             * The color rendered for the background of scrollbars.
429             */
430            public final static SystemColor scrollbar = new SystemColor(
431                    (byte) SCROLLBAR);
432
433            /**
434             * The color rendered for the background of tooltips or spot help.
435             */
436            public final static SystemColor info = new SystemColor((byte) INFO);
437
438            /**
439             * The color rendered for the text of tooltips or spot help.
440             */
441            public final static SystemColor infoText = new SystemColor(
442                    (byte) INFO_TEXT);
443
444            /*
445             * JDK 1.1 serialVersionUID.
446             */
447            private static final long serialVersionUID = 4503142729533789064L;
448
449            /* 
450             * An index into either array of SystemColor objects or values.
451             */
452            private transient int index;
453
454            private static SystemColor systemColorObjects[] = {
455                    SystemColor.desktop, SystemColor.activeCaption,
456                    SystemColor.activeCaptionText,
457                    SystemColor.activeCaptionBorder,
458                    SystemColor.inactiveCaption,
459                    SystemColor.inactiveCaptionText,
460                    SystemColor.inactiveCaptionBorder, SystemColor.window,
461                    SystemColor.windowBorder, SystemColor.windowText,
462                    SystemColor.menu, SystemColor.menuText, SystemColor.text,
463                    SystemColor.textText, SystemColor.textHighlight,
464                    SystemColor.textHighlightText,
465                    SystemColor.textInactiveText, SystemColor.control,
466                    SystemColor.controlText, SystemColor.controlHighlight,
467                    SystemColor.controlLtHighlight, SystemColor.controlShadow,
468                    SystemColor.controlDkShadow, SystemColor.scrollbar,
469                    SystemColor.info, SystemColor.infoText };
470
471            static {
472                updateSystemColors();
473            }
474
475            /**
476             * Called from <init> & toolkit to update the above systemColors cache.
477             */
478            private static void updateSystemColors() {
479                if (!GraphicsEnvironment.isHeadless()) {
480                    Toolkit.getDefaultToolkit().loadSystemColors(systemColors);
481                }
482                for (int i = 0; i < systemColors.length; i++) {
483                    systemColorObjects[i].value = systemColors[i];
484                }
485            }
486
487            /**
488             * Creates a symbolic color that represents an indexed entry into system
489             * color cache. Used by above static system colors.
490             */
491            private SystemColor(byte index) {
492                super (systemColors[index]);
493                this .index = index;
494            }
495
496            /**
497             * Returns a string representation of this <code>Color</code>'s values.
498             * This method is intended to be used only for debugging purposes,
499             * and the content and format of the returned string may vary between
500             * implementations.
501             * The returned string may be empty but may not be <code>null</code>.
502             *
503             * @return  a string representation of this <code>Color</code>
504             */
505            public String toString() {
506                return getClass().getName() + "[i=" + (index) + "]";
507            }
508
509            /**
510             * The design of the {@code SystemColor} class assumes that
511             * the {@code SystemColor} object instances stored in the
512             * static final fields above are the only instances that can
513             * be used by developers.
514             * This method helps maintain those limits on instantiation
515             * by using the index stored in the value field of the
516             * serialized form of the object to replace the serialized
517             * object with the equivalent static object constant field
518             * of {@code SystemColor}.
519             * See the {@link #writeReplace} method for more information
520             * on the serialized form of these objects.
521             * @return one of the {@code SystemColor} static object
522             *         fields that refers to the same system color.
523             */
524            private Object readResolve() {
525                // The instances of SystemColor are tightly controlled and
526                // only the canonical instances appearing above as static
527                // constants are allowed.  The serial form of SystemColor
528                // objects stores the color index as the value.  Here we
529                // map that index back into the canonical instance.
530                return systemColorObjects[value];
531            }
532
533            /**
534             * Returns a specialized version of the {@code SystemColor}
535             * object for writing to the serialized stream.
536             * @serialData
537             * The value field of a serialized {@code SystemColor} object
538             * contains the array index of the system color instead of the
539             * rgb data for the system color.
540             * This index is used by the {@link #readResolve} method to
541             * resolve the deserialized objects back to the original
542             * static constant versions to ensure unique instances of
543             * each {@code SystemColor} object.
544             * @return a proxy {@code SystemColor} object with its value
545             *         replaced by the corresponding system color index.
546             */
547            private Object writeReplace() throws ObjectStreamException {
548                // we put an array index in the SystemColor.value while serialize
549                // to keep compatibility.
550                SystemColor color = new SystemColor((byte) index);
551                color.value = index;
552                return color;
553            }
554        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.