KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > metal > MetalHighContrastTheme


1 /*
2  * @(#)MetalHighContrastTheme.java 1.4 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  
8 package javax.swing.plaf.metal;
9
10 import javax.swing.plaf.*;
11 import javax.swing.plaf.basic.*;
12 import javax.swing.plaf.metal.*;
13 import javax.swing.*;
14 import javax.swing.border.*;
15 import java.awt.*;
16
17 /**
18  * A high contrast theme. This is used on Windows if the system property
19  * awt.highContrast.on is true.
20  *
21  * @version @(#)MetalHighContrastTheme.java 1.4 03/12/19
22  * @author Michael C. Albers
23  */

24 class MetalHighContrastTheme extends DefaultMetalTheme JavaDoc {
25     private static final ColorUIResource primary1 = new
26                               ColorUIResource(0, 0, 0);
27     private static final ColorUIResource primary2 = new ColorUIResource(
28                               204, 204, 204);
29     private static final ColorUIResource primary3 = new ColorUIResource(255,
30                               255, 255);
31     private static final ColorUIResource primaryHighlight = new
32                               ColorUIResource(102, 102, 102);
33     private static final ColorUIResource secondary2 = new ColorUIResource(
34                               204, 204, 204);
35     private static final ColorUIResource secondary3 = new ColorUIResource(
36                               255, 255, 255);
37     private static final ColorUIResource controlHighlight = new
38                               ColorUIResource(102, 102, 102);
39
40
41     // This does not override getSecondary1 (102,102,102)
42

43     public String JavaDoc getName() {
44         return "Contrast";
45     }
46
47     protected ColorUIResource getPrimary1() {
48         return primary1;
49     }
50
51     protected ColorUIResource getPrimary2() {
52         return primary2;
53     }
54
55     protected ColorUIResource getPrimary3() {
56         return primary3;
57     }
58
59     public ColorUIResource getPrimaryControlHighlight() {
60         return primaryHighlight;
61     }
62
63     protected ColorUIResource getSecondary2() {
64         return secondary2;
65     }
66
67     protected ColorUIResource getSecondary3() {
68         return secondary3;
69     }
70
71     public ColorUIResource getControlHighlight() {
72         // This was super.getSecondary3();
73
return secondary2;
74     }
75
76     public ColorUIResource getFocusColor() {
77         return getBlack();
78     }
79
80     public ColorUIResource getTextHighlightColor() {
81         return getBlack();
82     }
83
84     public ColorUIResource getHighlightedTextColor() {
85         return getWhite();
86     }
87   
88     public ColorUIResource getMenuSelectedBackground() {
89         return getBlack();
90     }
91
92     public ColorUIResource getMenuSelectedForeground() {
93         return getWhite();
94     }
95
96     public ColorUIResource getAcceleratorForeground() {
97         return getBlack();
98     }
99
100     public ColorUIResource getAcceleratorSelectedForeground() {
101         return getWhite();
102     }
103
104     public void addCustomEntriesToTable(UIDefaults table) {
105         Border blackLineBorder = new BorderUIResource(new LineBorder(
106                     getBlack()));
107         Border whiteLineBorder = new BorderUIResource(new LineBorder(
108                     getWhite()));
109     Object JavaDoc textBorder = new BorderUIResource(new CompoundBorder(
110                    blackLineBorder, new BasicBorders.MarginBorder()));
111
112         Object JavaDoc[] defaults = new Object JavaDoc[] {
113             "ToolTip.border", blackLineBorder,
114
115             "TitledBorder.border", blackLineBorder,
116
117             "TextField.border", textBorder,
118
119             "PasswordField.border", textBorder,
120
121             "TextArea.border", textBorder,
122
123             "TextPane.border", textBorder,
124
125             "EditorPane.border", textBorder,
126
127             "ComboBox.background", getWindowBackground(),
128             "ComboBox.foreground", getUserTextColor(),
129             "ComboBox.selectionBackground", getTextHighlightColor(),
130             "ComboBox.selectionForeground", getHighlightedTextColor(),
131
132         "ProgressBar.foreground", getUserTextColor(),
133         "ProgressBar.background", getWindowBackground(),
134         "ProgressBar.selectionForeground", getWindowBackground(),
135         "ProgressBar.selectionBackground", getUserTextColor(),
136
137             "OptionPane.errorDialog.border.background",
138                         getPrimary1(),
139             "OptionPane.errorDialog.titlePane.foreground",
140                         getPrimary3(),
141             "OptionPane.errorDialog.titlePane.background",
142                         getPrimary1(),
143             "OptionPane.errorDialog.titlePane.shadow",
144                         getPrimary2(),
145             "OptionPane.questionDialog.border.background",
146                         getPrimary1(),
147             "OptionPane.questionDialog.titlePane.foreground",
148                         getPrimary3(),
149             "OptionPane.questionDialog.titlePane.background",
150                         getPrimary1(),
151             "OptionPane.questionDialog.titlePane.shadow",
152                         getPrimary2(),
153             "OptionPane.warningDialog.border.background",
154                         getPrimary1(),
155             "OptionPane.warningDialog.titlePane.foreground",
156                         getPrimary3(),
157             "OptionPane.warningDialog.titlePane.background",
158                         getPrimary1(),
159             "OptionPane.warningDialog.titlePane.shadow",
160                         getPrimary2(),
161         };
162
163         table.putDefaults(defaults);
164     }
165
166     /**
167      * Returns true if this is a theme provided by the core platform.
168      */

169     boolean isSystemTheme() {
170         return (getClass() == MetalHighContrastTheme JavaDoc.class);
171     }
172 }
173
Popular Tags