KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > looks > plastic > PlasticXPLookAndFeel


1 /*
2  * Copyright (c) 2001-2005 JGoodies Karsten Lentzsch. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * o Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * o Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * o Neither the name of JGoodies Karsten Lentzsch nor the names of
15  * its contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.jgoodies.looks.plastic;
32
33 import java.awt.Insets JavaDoc;
34
35 import javax.swing.UIDefaults JavaDoc;
36 import javax.swing.plaf.ColorUIResource JavaDoc;
37 import javax.swing.plaf.InsetsUIResource JavaDoc;
38
39 import com.jgoodies.looks.LookUtils;
40 import com.jgoodies.looks.Options;
41
42
43 /**
44  * Intializes class and component defaults for the
45  * JGoodies PlasticXP look&feel.
46  *
47  * @author Karsten Lentzsch
48  * @version $Revision: 1.4 $
49  */

50 public class PlasticXPLookAndFeel extends Plastic3DLookAndFeel {
51     
52     /**
53      * Constructs the JGoodies PlasticXP look&feel.
54      */

55     public PlasticXPLookAndFeel() {
56         // Provide an empty constructor for subclassing.
57
}
58
59     public String JavaDoc getID() {
60         return "JGoodies Plastic XP";
61     }
62     
63     public String JavaDoc getName() {
64         return "JGoodies Plastic XP";
65     }
66     
67     public String JavaDoc getDescription() {
68         return "The JGoodies Plastic XP Look and Feel"
69             + " - \u00a9 2001-2005 JGoodies Karsten Lentzsch";
70     }
71     
72     /**
73      * Initializes the PlasticXP class defaults.
74      * Overrides the check box and radio button UIs.
75      *
76      * @param table the UIDefaults table to work with
77      */

78     protected void initClassDefaults(UIDefaults JavaDoc table) {
79         super.initClassDefaults(table);
80
81         String JavaDoc UI_CLASSNAME_PREFIX = "com.jgoodies.looks.plastic.PlasticXP";
82         Object JavaDoc[] uiDefaults = {
83             // Uses a smooth icon
84
"CheckBoxUI", UI_CLASSNAME_PREFIX + "CheckBoxUI",
85             
86             // Renders a circle, not the star ("*") character
87
"PasswordFieldUI", UI_CLASSNAME_PREFIX + "PasswordFieldUI",
88             
89             // Uses a smooth icon
90
"RadioButtonUI", UI_CLASSNAME_PREFIX + "RadioButtonUI",
91             
92             // Changed buttons
93
"SpinnerUI", UI_CLASSNAME_PREFIX + "SpinnerUI",
94         };
95
96         table.putDefaults(uiDefaults);
97     }
98     
99     
100     /**
101      * Initializes the PlasticXP component defaults.
102      *
103      * @param table the UIDefaults table to work with
104      */

105     protected void initComponentDefaults(UIDefaults JavaDoc table) {
106         super.initComponentDefaults(table);
107
108         Object JavaDoc buttonBorder = PlasticXPBorders.getButtonBorder();
109         Object JavaDoc checkBoxIcon = PlasticXPIconFactory.getCheckBoxIcon();
110         Object JavaDoc comboBoxButtonBorder = PlasticXPBorders.getComboBoxArrowButtonBorder();
111         Object JavaDoc comboBoxEditorBorder = PlasticXPBorders.getComboBoxEditorBorder();
112         Object JavaDoc radioButtonIcon = PlasticXPIconFactory.getRadioButtonIcon();
113         Object JavaDoc scrollPaneBorder = PlasticXPBorders.getScrollPaneBorder();
114         Object JavaDoc textFieldBorder = PlasticXPBorders.getTextFieldBorder();
115         Object JavaDoc toggleButtonBorder = PlasticXPBorders.getToggleButtonBorder();
116
117         Object JavaDoc defaultButtonMargin = createButtonMargin(false);
118         Object JavaDoc narrowButtonMargin = createButtonMargin(true);
119
120         String JavaDoc radioCheckIconName = LookUtils.IS_LOW_RESOLUTION
121                                             ? "icons/RadioLight5x5.png"
122                                             : "icons/RadioLight7x7.png";
123                                             
124         // Windows uses 2,2,2,2, but we try to adjust baselines of text and label.
125
Object JavaDoc textInsets = new InsetsUIResource JavaDoc(2, 3, 2, 2);
126                                             
127         Object JavaDoc[] defaults = {
128             "Button.border", buttonBorder,
129             "Button.margin", defaultButtonMargin,
130             "Button.narrowMargin", narrowButtonMargin,
131             "Button.borderPaintsFocus", Boolean.TRUE,
132             
133             "CheckBox.icon", checkBoxIcon,
134             "CheckBox.check", getToggleButtonCheckColor(),
135             
136             "ComboBox.arrowButtonBorder", comboBoxButtonBorder,
137             "ComboBox.editorBorder", comboBoxEditorBorder,
138             "ComboBox.borderPaintsFocus", Boolean.TRUE,
139
140             "EditorPane.margin", textInsets,
141
142             "FormattedTextField.border", textFieldBorder,
143             "FormattedTextField.margin", textInsets,
144             "PasswordField.border", textFieldBorder,
145             "PasswordField.margin", textInsets,
146             "Spinner.border", scrollPaneBorder,
147             "Spinner.defaultEditorInsets", textInsets,
148             "Spinner.arrowButtonInsets", null,
149             
150             "ScrollPane.border", scrollPaneBorder,
151             "Table.scrollPaneBorder", scrollPaneBorder,
152             
153             "RadioButton.icon", radioButtonIcon,
154             "RadioButton.check", getToggleButtonCheckColor(),
155             "RadioButton.interiorBackground", getControlHighlight(),
156             "RadioButton.checkIcon", makeIcon(getClass(), radioCheckIconName),
157             
158             "TextArea.margin", textInsets,
159             "TextField.border", textFieldBorder,
160             "TextField.margin", textInsets,
161             
162             "ToggleButton.border", toggleButtonBorder,
163             "ToggleButton.margin", defaultButtonMargin,
164             "ToggleButton.narrowMargin", narrowButtonMargin,
165             "ToggleButton.borderPaintsFocus", Boolean.TRUE,
166         };
167         table.putDefaults(defaults);
168     }
169     
170     protected static void installDefaultThemes() {}
171     
172     /**
173      * Creates and answers the margin used by <code>JButton</code>
174      * and <code>JToggleButton</code>. Honors the screen resolution
175      * and the global <code>isNarrowButtonsEnabled</code> property.<p>
176      *
177      * Sun's L&F implementations use wide button margins.
178      *
179      * @param narrow true indicates a narrow margin, false a wide margin
180      * @return an Insets object that describes the button margin
181      * @see Options#getUseNarrowButtons()
182      */

183     private static Insets JavaDoc createButtonMargin(boolean narrow) {
184         int pad = narrow || Options.getUseNarrowButtons() ? 4 : 14;
185         return LookUtils.IS_LOW_RESOLUTION
186             ? new InsetsUIResource JavaDoc(1, pad, 1, pad)
187             : new InsetsUIResource JavaDoc(2, pad, 2, pad);
188     }
189
190
191     private ColorUIResource JavaDoc getToggleButtonCheckColor() {
192         return getMyCurrentTheme().getToggleButtonCheckColor();
193     }
194
195
196 }
Popular Tags