KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > swing > plaf > LFCustoms


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.swing.plaf;
21
22 /** Look and feel customizations interface.
23  * For various look and feels, there is a need to customize colors,
24  * borders etc. to provide 'native-like' UI.
25  * Implementers of this interface should install and uninstall custom
26  * UI elements into UIManager on request.
27  *
28  * There are three types of customization possible:
29  * <ol>
30  * <li>Guaranteeing values code expects to be non-null but the look and feel (i.e. GTK) may not provide.</li>
31  * <li>Customizing values that are already present (such as changing the default font for labels)</li>
32  * <li>Adding values used by custom components which are not part of Swing, but use UIDefaults to fetch their colors,
33  * fonts, uis, borders, etc.</li>
34  * </ol>
35  * Each type of customization is a separate method on this interface. On startup, first the customizations for
36  * all look and feels are run, then the customizations for the specific look and feel that is currently set.
37  * <p>
38  * A non-standard look and feel that wishes to provide some custom colors for NetBeans window system, etc., can
39  * do so by placing an instance of its implementation of LFCustoms into UIDefaults under the key
40  * &quot;Nb.[return value of the custom look and feel's getID() method]LFCustoms&quot;.
41  * <p>
42  * Given that all this class does is return some keys and values, in the future it may be replaced by an
43  * XML file similar to <a HREF="ui.netbeans.org/project/ui/docs/ui/themes/themes.html">theme files</a>.
44  * <p>
45  * This class defines a number of relatively self-explanatory UIManager keys for things used in various parts
46  * of NetBeans.
47  *
48  * @author Dafe Simonek, Tim Boudreau
49  */

50 public abstract class LFCustoms {
51     private Object JavaDoc[] lfKeysAndValues = null;
52     private Object JavaDoc[] appKeysAndValues = null;
53     private Object JavaDoc[] guaranteedKeysAndValues = null;
54     protected static final String JavaDoc WORKPLACE_FILL = "nb_workplace_fill"; //NOI18N
55

56     //TODO: A nice idea would be to replace these classes with XML files - minor rewrite of NbTheme to do it
57

58     /** Fetch and cache keys and values */
59     Object JavaDoc[] getLookAndFeelCustomizationKeysAndValues () {
60         if (lfKeysAndValues == null) {
61             //System.err.println (getClass() + " getLfKeysAndValues");
62
lfKeysAndValues = createLookAndFeelCustomizationKeysAndValues();
63         }
64         return lfKeysAndValues;
65     }
66
67     /** Fetch and cache keys and values */
68     Object JavaDoc[] getApplicationSpecificKeysAndValues () {
69         if (appKeysAndValues == null) {
70             //System.err.println (getClass() + " getAppSpecificKeysAndValues");
71
appKeysAndValues = createApplicationSpecificKeysAndValues();
72         }
73         return appKeysAndValues;
74     }
75
76     /** Fetch and cache keys and values */
77     Object JavaDoc[] getGuaranteedKeysAndValues () {
78         if (guaranteedKeysAndValues == null) {
79             //System.err.println (getClass() + " getGuaranteedKeysAndValues");
80
guaranteedKeysAndValues = createGuaranteedKeysAndValues();
81         }
82         return guaranteedKeysAndValues;
83     }
84
85     /**
86      * Get all keys this LFCustoms installs in UIManager. This is used to
87      * delete unneeded elements from UIManager if the look and feel is changed
88      * on the fly (for example, the user switches Windows from Classic to XP
89      * look).
90      */

91     Object JavaDoc[] allKeys() {
92         Object JavaDoc[] additional = additionalKeys();
93         int size = additional == null ? 0 : additional.length;
94         if (appKeysAndValues != null) {
95             size += appKeysAndValues.length / 2;
96         }
97         if (guaranteedKeysAndValues != null) {
98             size += guaranteedKeysAndValues.length / 2;
99         }
100         if (lfKeysAndValues != null) {
101             size += (lfKeysAndValues.length / 2);
102         }
103         Object JavaDoc[] result = new Object JavaDoc [size];
104
105         int ct = 0;
106         if (lfKeysAndValues != null) {
107             //may be null, if the flag to not customize was set
108
for (int i=0; i < lfKeysAndValues.length; i+=2) {
109                 result[ct++] = lfKeysAndValues[i];
110             }
111         }
112         if (guaranteedKeysAndValues != null) {
113             for (int i=0; i < guaranteedKeysAndValues.length; i+=2) {
114                 result[ct++] = guaranteedKeysAndValues[i];
115             }
116         }
117         if (appKeysAndValues != null) {
118             for (int i=0; i < appKeysAndValues.length; i+=2) {
119                 result[ct++] = appKeysAndValues[i];
120             }
121         }
122         if (additional != null) {
123             for (int i=0; i < additional.length; i++) {
124                 result[ct++] = additional[i];
125             }
126         }
127         return result;
128     }
129     
130     /**
131      * LFCustoms implementations which use UIBootstrapValue.Lazy should return
132      * any keys that it will install here, so they can be merged into the list
133      * of things to clear on L&F change.
134      *
135      * @return an array of objects or null.
136      */

137     protected Object JavaDoc[] additionalKeys() {
138         return null;
139     }
140
141     /** Dispose the value part of all arrays - no need to hold onto lazy value instances
142      * or GuaranteedValue instances - they should disappear once dereferenced. We only
143      * need the keys to uninstall the customizations later.
144      */

145     void disposeValues() {
146         if (lfKeysAndValues != null) {
147             //may be null, if the flag to not customize was set
148
disposeValues (lfKeysAndValues);
149         }
150         disposeValues (appKeysAndValues);
151         disposeValues (guaranteedKeysAndValues);
152     }
153
154     /** Null every other element of an array */
155     private void disposeValues (Object JavaDoc[] arr) {
156         for (int i=1; i < arr.length; i+=2) {
157             arr[i] = null;
158         }
159     }
160
161     /**
162      * Create any objects to put into UIDefaults to <strong>replace</strong> values normally supplied by the look
163      * and feel, to customize application appearance.
164      *
165      * @return An array of key-value pairs to put into UIDefaults
166      */

167     public Object JavaDoc[] createLookAndFeelCustomizationKeysAndValues () {
168         return new Object JavaDoc[0];
169     }
170
171     /**
172      * Create any objects to put into UIDefaults for custom components which use UIManager to find values, UIs, etc.
173      *
174      * @return An array of key-value pairs to put into UIDefaults
175      */

176     public Object JavaDoc[] createApplicationSpecificKeysAndValues () {
177         return new Object JavaDoc[0];
178     }
179
180     /**
181      * Provide UIDefaults entries for things which components rely on being non-null, but which may be null on some
182      * look and feels or some versions of the look and feel in question. For example, if you have a component that
183      * sets its background by calling <code>UIManager.get(&quot;controlShadow&quot;)</code>, you need to guarantee
184      * that this will be non-null when fetched from UIManager - but look and feels do not guarantee this. The typical
185      * pattern here is to put into UIManager an instance of <code>GuaranteedValue</code>, i.e.
186      * <code>new GuaranteedValue ("controlShadow", Color.GRAY)</code> which will take on the value already present
187      * if it's there, and provide a fallback if it's not.
188      *
189      * @see org.netbeans.swing.plaf.util.GuaranteedValue
190      * @return An array of key-value pairs to put into UIDefaults
191      *
192      **/

193     public Object JavaDoc[] createGuaranteedKeysAndValues () {
194         return new Object JavaDoc[0];
195     }
196
197     /** Integer value which LFCustoms will <i>read</i>. On startup, if a
198      * custom font size is specified, the core will put this into UIDefaults.
199      * We then read it out if present and use it to set up a custom font size. */

200     protected static final String JavaDoc CUSTOM_FONT_SIZE = "customFontSize"; //NOI18N
201

202     //Default font size - some classes use this to handle creating appropriate
203
//custom fonts based on this value
204
protected static final String JavaDoc DEFAULT_FONT_SIZE = "nbDefaultFontSize"; //NOI18N
205

206     //Editor
207
protected static final String JavaDoc EDITOR_STATUS_LEFT_BORDER = "Nb.Editor.Status.leftBorder"; //NOI18N
208
protected static final String JavaDoc EDITOR_STATUS_INNER_BORDER = "Nb.Editor.Status.innerBorder"; //NOI18N
209
protected static final String JavaDoc EDITOR_STATUS_RIGHT_BORDER = "Nb.Editor.Status.rightBorder"; //NOI18N
210
protected static final String JavaDoc EDITOR_STATUS_ONLYONEBORDER = "Nb.Editor.Status.onlyOneBorder"; //NOI18N
211
protected static final String JavaDoc EDITOR_TOOLBAR_BORDER = "Nb.Editor.Toolbar.border"; //NOI18N
212
protected static final String JavaDoc EDITOR_ERRORSTRIPE_SCROLLBAR_INSETS = "Nb.Editor.ErrorStripe.ScrollBar.Insets"; //NOI18N
213

214     //Explorer
215
protected static final String JavaDoc EXPLORER_STATUS_BORDER = "Nb.Explorer.Status.border"; //NOI18N
216
protected static final String JavaDoc EXPLORER_FOLDER_ICON = "Nb.Explorer.Folder.icon"; //NOI18N
217
protected static final String JavaDoc EXPLORER_FOLDER_OPENED_ICON = "Nb.Explorer.Folder.openedIcon"; //NOI18N
218

219     //Winsys
220
protected static final String JavaDoc DESKTOP_BORDER = "Nb.Desktop.border"; //NOI18N
221
public static final String JavaDoc SCROLLPANE_BORDER = "Nb.ScrollPane.border"; //NOI18N
222
protected static final String JavaDoc TOOLBAR_UI = "Nb.Toolbar.ui"; //NOI18N
223
protected static final String JavaDoc DESKTOP_BACKGROUND = "Nb.Desktop.background"; //NOI18N
224
public static final String JavaDoc SCROLLPANE_BORDER_COLOR = "Nb.ScrollPane.Border.color"; //NOI18N
225

226     //Output window
227
protected static final String JavaDoc OUTPUT_SELECTION_BACKGROUND = "nb.output.selectionBackground"; //NOI18N
228
protected static final String JavaDoc OUTPUT_HYPERLINK_FOREGROUND = "nb.hyperlink.foreground"; //NOI18N
229
protected static final String JavaDoc OUTPUT_BACKGROUND = "nb.output.background"; //NOI18N
230
protected static final String JavaDoc OUTPUT_FOREGROUND = "nb.output.foreground"; //NOI18N
231

232     //Property sheet
233
protected static final String JavaDoc PROPSHEET_ALTERNATE_ROW_COLOR = "Tree.altbackground"; //NOI18N
234
protected static final String JavaDoc PROPSHEET_SET_BACKGROUND = "PropSheet.setBackground"; //NOI18N
235
protected static final String JavaDoc PROPSHEET_SELECTED_SET_BACKGROUND = "PropSheet.selectedSetBackground"; //NOI18N
236
protected static final String JavaDoc PROPSHEET_SET_FOREGROUND = "PropSheet.setForeground"; //NOI18N
237
protected static final String JavaDoc PROPSHEET_SELECTED_SET_FOREGROUND = "PropSheet.selectedSetForeground"; //NOI18N
238
protected static final String JavaDoc PROPSHEET_DISABLED_FOREGROUND = "PropSheet.disabledForeground"; //NOI18N
239
protected static final String JavaDoc PROPSHEET_SELECTION_BACKGROUND = "PropSheet.selectionBackground"; //NOI18N
240
protected static final String JavaDoc PROPSHEET_SELECTION_FOREGROUND = "PropSheet.selectionForeground"; //NOI18N
241
protected static final String JavaDoc PROPSHEET_BUTTON_FOREGROUND = "PropSheet.customButtonForeground"; //NOI18N
242
protected static final String JavaDoc PROPSHEET_BUTTON_COLOR = "netbeans.ps.buttonColor"; //NOI18N
243
protected static final String JavaDoc PROPSHEET_BACKGROUND = "netbeans.ps.background"; //NOI18N
244

245     protected static final String JavaDoc PROPSHEET_ICON_MARGIN = "netbeans.ps.iconmargin"; //NOI18N //Integer
246
protected static final String JavaDoc PROPSHEET_ROWHEIGHT = "netbeans.ps.rowheight"; //NOI18N
247

248     //General
249
protected static final String JavaDoc ERROR_FOREGROUND = "nb.errorForeground"; //NOI18N
250
protected static final String JavaDoc WARNING_FOREGROUND = "nb.warningForeground"; //NOI18N
251

252     //Tab control
253
protected static final String JavaDoc EDITOR_TABBED_CONTAINER_UI = "TabbedContainerUI"; //NOI18N
254
protected static final String JavaDoc EDITOR_TAB_DISPLAYER_UI = "EditorTabDisplayerUI"; //NOI18N
255
protected static final String JavaDoc VIEW_TAB_DISPLAYER_UI = "ViewTabDisplayerUI"; //NOI18N
256
protected static final String JavaDoc SLIDING_TAB_DISPLAYER_UI = "SlidingTabDisplayerUI"; //NOI18N
257
protected static final String JavaDoc SLIDING_TAB_BUTTON_UI = "IndexButtonUI";
258     protected static final String JavaDoc SLIDING_BUTTON_UI = "SlidingButtonUI"; //NOI18N
259

260     //Tab control colors - see org.netbeans.swing.plaf.DefaultTabbedContainerUI
261
protected static final String JavaDoc EDITOR_TAB_CONTENT_BORDER = "TabbedContainer.editor.contentBorder"; //NOI18N
262
protected static final String JavaDoc EDITOR_TAB_TABS_BORDER = "TabbedContainer.editor.tabsBorder"; //NOI18N
263
protected static final String JavaDoc EDITOR_TAB_OUTER_BORDER = "TabbedContainer.editor.outerBorder"; //NOI18N
264

265     //Tab control colors - see org.netbeans.swing.plaf.DefaultTabbedContainerUI
266
protected static final String JavaDoc VIEW_TAB_CONTENT_BORDER = "TabbedContainer.view.contentBorder"; //NOI18N
267
protected static final String JavaDoc VIEW_TAB_TABS_BORDER = "TabbedContainer.view.tabsBorder"; //NOI18N
268
protected static final String JavaDoc VIEW_TAB_OUTER_BORDER = "TabbedContainer.view.outerBorder"; //NOI18N
269

270     //Tab control colors - see org.netbeans.swing.plaf.DefaultTabbedContainerUI
271
protected static final String JavaDoc SLIDING_TAB_CONTENT_BORDER = "TabbedContainer.sliding.contentBorder"; //NOI18N
272
protected static final String JavaDoc SLIDING_TAB_TABS_BORDER = "TabbedContainer.sliding.tabsBorder"; //NOI18N
273
protected static final String JavaDoc SLIDING_TAB_OUTER_BORDER = "TabbedContainer.sliding.outerBorder"; //NOI18N
274

275
276     //Tab control borders
277
protected static final String JavaDoc TAB_ACTIVE_SELECTION_BACKGROUND = "TabRenderer.selectedActivatedBackground"; //NOI18N
278
protected static final String JavaDoc TAB_ACTIVE_SELECTION_FOREGROUND = "TabRenderer.selectedActivatedForeground"; //NOI18N
279
protected static final String JavaDoc TAB_SELECTION_FOREGROUND = "TabRenderer.selectedForeground"; //NOI18N
280
protected static final String JavaDoc TAB_SELECTION_BACKGROUND = "TabRenderer.selectedBackground"; //NOI18N
281

282     protected static final String JavaDoc EXPLORER_MINISTATUSBAR_BORDER = "nb.explorer.ministatusbar.border"; //NOI18N
283

284     protected static final String JavaDoc DESKTOP_SPLITPANE_BORDER = "nb.desktop.splitpane.border"; //NOI18N
285

286     //Enables lazy loading of defaults for the property sheet - since it's not actually shown on startup
287
//anymore, no need to install its keys and values on startup
288
protected static final String JavaDoc PROPERTYSHEET_BOOTSTRAP = "nb.propertysheet";
289     
290     // keys used to store theme values in UIDefaults
291
public static final String JavaDoc CONTROLFONT = "controlFont"; // NOI18N
292
public static final String JavaDoc SYSTEMFONT = "systemFont"; //NOI18N
293
public static final String JavaDoc USERFONT = "userFont"; //NOI18N
294
public static final String JavaDoc MENUFONT = "menuFont"; //NOI18N
295
public static final String JavaDoc WINDOWTITLEFONT = "windowTitleFont"; //NOI18N
296
public static final String JavaDoc SUBFONT = "subFont"; //NOI18N
297
public static final String JavaDoc LISTFONT = "List.font"; //NOI18N
298
public static final String JavaDoc TREEFONT = "Tree.font"; //NOI18N
299
public static final String JavaDoc PANELFONT = "Panel.font"; //NOI18N
300
public static final String JavaDoc SPINNERFONT = "Spinner.font"; //NOI18N
301

302     // keys used by the progressbar api module.
303
public static final String JavaDoc PROGRESS_CANCEL_BUTTON_ICON = "nb.progress.cancel.icon";
304     public static final String JavaDoc PROGRESS_CANCEL_BUTTON_ROLLOVER_ICON = "nb.progress.cancel.icon.mouseover";
305     public static final String JavaDoc PROGRESS_CANCEL_BUTTON_PRESSED_ICON = "nb.progress.cancel.icon.pressed";
306 }
307
Popular Tags