KickJava   Java API By Example, From Geeks To Geeks.

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


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.Color JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Collections JavaDoc;
36 import java.util.Comparator JavaDoc;
37 import java.util.List JavaDoc;
38
39 import javax.swing.Icon JavaDoc;
40 import javax.swing.UIDefaults JavaDoc;
41 import javax.swing.border.Border JavaDoc;
42 import javax.swing.plaf.BorderUIResource JavaDoc;
43 import javax.swing.plaf.ColorUIResource JavaDoc;
44 import javax.swing.plaf.FontUIResource JavaDoc;
45 import javax.swing.plaf.InsetsUIResource JavaDoc;
46 import javax.swing.plaf.basic.BasicBorders JavaDoc;
47 import javax.swing.plaf.metal.MetalLookAndFeel JavaDoc;
48 import javax.swing.plaf.metal.MetalTheme JavaDoc;
49
50 import com.jgoodies.looks.FontSizeHints;
51 import com.jgoodies.looks.LookUtils;
52 import com.jgoodies.looks.Options;
53 import com.jgoodies.looks.common.MinimumSizedIcon;
54 import com.jgoodies.looks.common.ShadowPopupFactory;
55 import com.jgoodies.looks.plastic.theme.SkyBluerTahoma;
56
57 /**
58  * Initializes class and component defaults for the
59  * JGoodies Plastic look&feel.
60  *
61  * @author Karsten Lentzsch
62  * @version $Revision: 1.7 $
63  */

64 public class PlasticLookAndFeel extends MetalLookAndFeel JavaDoc {
65     
66     // System and Client Property Keys ****************************************
67

68     /**
69      * Client property key to set a border style - shadows the header style.
70      */

71     public static final String JavaDoc BORDER_STYLE_KEY = "Plastic.borderStyle";
72     
73     /**
74      * Client property key to disable the pseudo 3D effect.
75      */

76     public static final String JavaDoc IS_3D_KEY = "Plastic.is3D";
77
78     /**
79      * A System property key to set the default theme.
80      */

81     public static final String JavaDoc DEFAULT_THEME_KEY =
82         "Plastic.defaultTheme";
83         
84     /**
85      * A System property key that indicates that the high contrast
86      * focus colors shall be choosen - if applicable.
87      * If not set, some focus colors look good but have low contrast.
88      * Basically, the low contrast scheme uses the Plastic colors
89      * before 1.0.7, and the high contrast scheme is 1.0.7 - 1.0.9.
90      */

91     public static final String JavaDoc HIGH_CONTRAST_FOCUS_ENABLED_KEY =
92         "Plastic.highContrastFocus";
93         
94     /**
95      * A System property key for the rendering style of the Plastic
96      * TabbedPane. Valid values are: <tt>default</tt> for the
97      * Plastic 1.0 tabs, and <tt>metal</tt> for the Metal L&amp;F tabs.
98      */

99     protected static final String JavaDoc TAB_STYLE_KEY =
100         "Plastic.tabStyle";
101
102     /**
103      * A System property value that indicates that Plastic shall render
104      * tabs in the Plastic 1.0 style. This is the default.
105      */

106     public static final String JavaDoc TAB_STYLE_DEFAULT_VALUE =
107         "default";
108
109     /**
110      * A System property value that indicates that Plastic shall
111      * render tabs in the Metal L&amp;F style.
112      */

113     public static final String JavaDoc TAB_STYLE_METAL_VALUE =
114         "metal";
115
116         
117     // State *****************************************************************
118

119     /**
120      * Holds whether Plastic uses Metal or Plastic tabbed panes.
121      */

122     private static boolean useMetalTabs =
123         LookUtils.getSystemProperty(TAB_STYLE_KEY, "").
124             equalsIgnoreCase(TAB_STYLE_METAL_VALUE);
125                     
126     /**
127      * Holds whether we are using the high contrast focus colors.
128      */

129     public static boolean useHighContrastFocusColors =
130         LookUtils.getSystemProperty(HIGH_CONTRAST_FOCUS_ENABLED_KEY) != null;
131                 
132     /**
133      * The <code>List</code> of installed color themes.
134      */

135     private static List JavaDoc installedThemes;
136
137     /** The current color theme. */
138     private static PlasticTheme myCurrentTheme;
139     
140     
141     /** The look-global state for the 3D enabledment. */
142     private static boolean is3DEnabled = false;
143     
144     
145     /** The look dependent <code>FontSizeHints</code> */
146     private static FontSizeHints fontSizeHints;
147
148     
149     /**
150      * Constructs the <code>PlasticLookAndFeel</code>.
151      */

152     public PlasticLookAndFeel() {
153         if (null == myCurrentTheme)
154             setMyCurrentTheme(createMyDefaultTheme());
155     }
156
157     public String JavaDoc getID() {
158         return "JGoodies Plastic";
159     }
160     
161     public String JavaDoc getName() {
162         return "JGoodies Plastic";
163     }
164     
165     public String JavaDoc getDescription() {
166         return "The JGoodies Plastic Look and Feel"
167             + " - \u00a9 2001-2005 JGoodies Karsten Lentzsch";
168     }
169     
170     // Special Properties ***************************************************
171

172     /**
173      * Returns the current <code>FontSizeHints</code>,
174      * where look specific settings shadow the global users defaults
175      * as stored under key <code>FontSizeHints.KEY</code>.
176      *
177      * @return the current FontSizeHints
178      * @see Options#setGlobalFontSizeHints(FontSizeHints)
179      * @see FontSizeHints
180      */

181     public static FontSizeHints getFontSizeHints() {
182         return fontSizeHints != null
183             ? fontSizeHints
184             : Options.getGlobalFontSizeHints();
185     }
186
187     /**
188      * Sets <code>FontSizeHints</code> that shadow the global font size hints.
189      *
190      * @param newHints the font size hints to be set
191      * @see Options#setGlobalFontSizeHints(FontSizeHints)
192      * @see FontSizeHints
193      */

194     public static void setFontSizeHints(FontSizeHints newHints) {
195         fontSizeHints = newHints;
196     }
197
198     protected boolean is3DEnabled() {
199         return is3DEnabled;
200     }
201
202     public static void set3DEnabled(boolean b) {
203         is3DEnabled = b;
204     }
205     
206     public static String JavaDoc getTabStyle() {
207         return useMetalTabs ? TAB_STYLE_METAL_VALUE : TAB_STYLE_DEFAULT_VALUE;
208     }
209
210     public static void setTabStyle(String JavaDoc tabStyle) {
211         useMetalTabs = tabStyle.equalsIgnoreCase(TAB_STYLE_METAL_VALUE);
212     }
213
214     public static boolean getHighContrastFocusColorsEnabled() {
215         return useHighContrastFocusColors;
216     }
217
218     public static void setHighContrastFocusColorsEnabled(boolean b) {
219         useHighContrastFocusColors = b;
220     }
221     
222     // Overriding Superclass Behavior ***************************************
223

224     /**
225      * Invoked during <code>UIManager#setLookAndFeel</code>. In addition
226      * to the superclass behavior, we install the ShadowPopupFactory.
227      *
228      * @see #uninitialize
229      */

230     public void initialize() {
231         super.initialize();
232         ShadowPopupFactory.install();
233     }
234     
235     
236     /**
237      * Invoked during <code>UIManager#setLookAndFeel</code>. In addition
238      * to the superclass behavior, we uninstall the ShadowPopupFactory.
239      *
240      * @see #initialize
241      */

242     public void uninitialize() {
243         super.uninitialize();
244         ShadowPopupFactory.uninstall();
245     }
246     
247     
248     /**
249      * Initializes the class defaults, that is, overrides some UI delegates
250      * with JGoodies Plastic implementations.
251      *
252      * @param table the UIDefaults table to work with
253      * @see javax.swing.plaf.basic.BasicLookAndFeel#getDefaults()
254      */

255     protected void initClassDefaults(UIDefaults JavaDoc table) {
256         super.initClassDefaults(table);
257
258         String JavaDoc PLASTIC_PREFIX = "com.jgoodies.looks.plastic.Plastic";
259         String JavaDoc COMMON_PREFIX = "com.jgoodies.looks.common.ExtBasic";
260         
261         // Overwrite some of the uiDefaults.
262
Object JavaDoc[] uiDefaults = {
263                 // 3D effect; optional narrow margins
264
"ButtonUI", PLASTIC_PREFIX + "ButtonUI",
265                 "ToggleButtonUI", PLASTIC_PREFIX + "ToggleButtonUI",
266
267                 // 3D effect
268
"ComboBoxUI", PLASTIC_PREFIX + "ComboBoxUI",
269                 "ScrollBarUI", PLASTIC_PREFIX + "ScrollBarUI",
270                 "SpinnerUI", PLASTIC_PREFIX + "SpinnerUI",
271                 
272                 // Special borders defined by border style or header style, see LookUtils
273
"MenuBarUI", PLASTIC_PREFIX + "MenuBarUI",
274                 "ToolBarUI", PLASTIC_PREFIX + "ToolBarUI",
275                 
276                 // Aligns menu icons
277
"MenuUI", PLASTIC_PREFIX + "MenuUI",
278                 "MenuItemUI", COMMON_PREFIX + "MenuItemUI",
279                 "CheckBoxMenuItemUI", COMMON_PREFIX + "CheckBoxMenuItemUI",
280                 "RadioButtonMenuItemUI", COMMON_PREFIX + "RadioButtonMenuItemUI",
281
282                 // Has padding above and below the separator lines
283
"PopupMenuSeparatorUI", COMMON_PREFIX + "PopupMenuSeparatorUI",
284                
285                 // Honors the screen resolution and uses a minimum button width
286
"OptionPaneUI", PLASTIC_PREFIX + "OptionPaneUI",
287                
288                 // Can installs an optional etched border
289
"ScrollPaneUI", PLASTIC_PREFIX + "ScrollPaneUI",
290                    
291                 // Uses a modified split divider
292
"SplitPaneUI", PLASTIC_PREFIX + "SplitPaneUI",
293                 
294                 // Modified icons and lines
295
"TreeUI", PLASTIC_PREFIX + "TreeUI",
296                 
297                 // Just to use Plastic colors
298
"InternalFrameUI", PLASTIC_PREFIX + "InternalFrameUI",
299                 
300                 // Share the UI delegate instances
301
"SeparatorUI", PLASTIC_PREFIX + "SeparatorUI",
302                 "ToolBarSeparatorUI", PLASTIC_PREFIX + "ToolBarSeparatorUI"
303
304             };
305         table.putDefaults(uiDefaults);
306         if (!useMetalTabs) {
307             // Modified tabs and ability use a version with reduced borders.
308
table.put("TabbedPaneUI", PLASTIC_PREFIX + "TabbedPaneUI");
309         }
310     }
311
312
313     protected void initComponentDefaults(UIDefaults JavaDoc table) {
314         super.initComponentDefaults(table);
315         
316         Object JavaDoc marginBorder = new BasicBorders.MarginBorder JavaDoc();
317         
318         Object JavaDoc buttonBorder = PlasticBorders.getButtonBorder();
319         Object JavaDoc menuItemBorder = PlasticBorders.getMenuItemBorder();
320         Object JavaDoc textFieldBorder = PlasticBorders.getTextFieldBorder();
321         Object JavaDoc toggleButtonBorder = PlasticBorders.getToggleButtonBorder();
322
323         Object JavaDoc popupMenuBorder = PlasticBorders.getPopupMenuBorder();
324         
325         Object JavaDoc scrollPaneBorder = PlasticBorders.getScrollPaneBorder();
326         Object JavaDoc tableHeaderBorder = new BorderUIResource JavaDoc(
327                                            (Border JavaDoc) table.get("TableHeader.cellBorder"));
328
329         Object JavaDoc menuBarEmptyBorder = marginBorder;
330         Object JavaDoc menuBarSeparatorBorder = PlasticBorders.getSeparatorBorder();
331         Object JavaDoc menuBarEtchedBorder = PlasticBorders.getEtchedBorder();
332         Object JavaDoc menuBarHeaderBorder = PlasticBorders.getMenuBarHeaderBorder();
333         
334         Object JavaDoc toolBarEmptyBorder = marginBorder;
335         Object JavaDoc toolBarSeparatorBorder = PlasticBorders.getSeparatorBorder();
336         Object JavaDoc toolBarEtchedBorder = PlasticBorders.getEtchedBorder();
337         Object JavaDoc toolBarHeaderBorder = PlasticBorders.getToolBarHeaderBorder();
338         
339         Object JavaDoc internalFrameBorder = getInternalFrameBorder();
340         Object JavaDoc paletteBorder = getPaletteBorder();
341         
342         Color JavaDoc controlColor = table.getColor("control");
343         
344         Object JavaDoc checkBoxIcon = PlasticIconFactory.getCheckBoxIcon();
345         Object JavaDoc checkBoxMargin = new InsetsUIResource JavaDoc(2, 0, 2, 1); // 1.4.1 uses 2,2,2,2
346

347         Object JavaDoc defaultButtonMargin = LookUtils.createButtonMargin(false);
348         Object JavaDoc narrowButtonMargin = LookUtils.createButtonMargin(true);
349         
350         // Windows uses 2,2,2,2, but we try to adjust baselines of text and label.
351
Object JavaDoc textInsets = new InsetsUIResource JavaDoc(1, 2, 1, 2);
352         Object JavaDoc wrappedTextInsets = new InsetsUIResource JavaDoc(2, 3, 1, 2);
353                                                 
354         Object JavaDoc menuItemMargin = LookUtils.IS_LOW_RESOLUTION
355                                             ? new InsetsUIResource JavaDoc(3, 0, 3, 0)
356                                             : new InsetsUIResource JavaDoc(2, 0, 2, 0);
357         Object JavaDoc menuMargin = new InsetsUIResource JavaDoc(2, 4, 2, 4);
358
359         Icon JavaDoc menuItemCheckIcon = new MinimumSizedIcon();
360         Icon JavaDoc checkBoxMenuItemIcon = PlasticIconFactory.getCheckBoxMenuItemIcon();
361         Icon JavaDoc radioButtonMenuItemIcon = PlasticIconFactory.getRadioButtonMenuItemIcon();
362         
363         Color JavaDoc menuItemForeground = table.getColor("MenuItem.foreground");
364
365         // Should be active.
366
int treeFontSize = table.getFont("Tree.font").getSize();
367         Integer JavaDoc rowHeight = new Integer JavaDoc(treeFontSize + 6);
368         Object JavaDoc treeExpandedIcon = PlasticIconFactory.getExpandedTreeIcon();
369         Object JavaDoc treeCollapsedIcon = PlasticIconFactory.getCollapsedTreeIcon();
370         ColorUIResource JavaDoc gray = new ColorUIResource JavaDoc(Color.GRAY);
371         
372         Boolean JavaDoc is3D = Boolean.valueOf(is3DEnabled());
373         
374         Object JavaDoc[] defaults = {
375         "Button.border", buttonBorder,
376         "Button.margin", defaultButtonMargin,
377         "Button.narrowMargin", narrowButtonMargin,
378
379         "CheckBox.margin", checkBoxMargin,
380
381         // Use a modified check
382
"CheckBox.icon", checkBoxIcon,
383             
384         "CheckBoxMenuItem.border", menuItemBorder,
385         "CheckBoxMenuItem.margin", menuItemMargin, // 1.4.1 Bug
386
"CheckBoxMenuItem.checkIcon", checkBoxMenuItemIcon,
387         "CheckBoxMenuItem.background", getMenuItemBackground(),// Added by JGoodies
388
"CheckBoxMenuItem.selectionForeground", getMenuItemSelectedForeground(),
389         "CheckBoxMenuItem.selectionBackground", getMenuItemSelectedBackground(),
390         "CheckBoxMenuItem.acceleratorForeground", menuItemForeground,
391         "CheckBoxMenuItem.acceleratorSelectionForeground",getMenuItemSelectedForeground(),
392         "CheckBoxMenuItem.acceleratorSelectionBackground",getMenuItemSelectedBackground(),
393
394         // ComboBox uses menu item selection colors
395
"ComboBox.selectionForeground", getMenuSelectedForeground(),
396         "ComboBox.selectionBackground", getMenuSelectedBackground(),
397         "ComboBox.arrowButtonBorder", PlasticBorders.getComboBoxArrowButtonBorder(),
398         "ComboBox.editorBorder", PlasticBorders.getComboBoxEditorBorder(),
399         "ComboBox.editorColumns", new Integer JavaDoc(5),
400         
401         "EditorPane.margin", wrappedTextInsets,
402
403         "InternalFrame.border", internalFrameBorder,
404         "InternalFrame.paletteBorder", paletteBorder,
405
406         "List.font", getControlTextFont(),
407         "Menu.border", PlasticBorders.getMenuBorder(),
408         "Menu.margin", menuMargin,
409         "Menu.arrowIcon", PlasticIconFactory.getMenuArrowIcon(),
410
411         "MenuBar.emptyBorder", menuBarEmptyBorder, // Added by JGoodies
412
"MenuBar.separatorBorder", menuBarSeparatorBorder, // Added by JGoodies
413
"MenuBar.etchedBorder", menuBarEtchedBorder, // Added by JGoodies
414
"MenuBar.headerBorder", menuBarHeaderBorder, // Added by JGoodies
415

416         "MenuItem.border", menuItemBorder,
417         "MenuItem.checkIcon", menuItemCheckIcon, // Aligns menu items
418
"MenuItem.margin", menuItemMargin, // 1.4.1 Bug
419
"MenuItem.background", getMenuItemBackground(),// Added by JGoodies
420
"MenuItem.selectionForeground", getMenuItemSelectedForeground(),// Added by JGoodies
421
"MenuItem.selectionBackground", getMenuItemSelectedBackground(),// Added by JGoodies
422
"MenuItem.acceleratorForeground", menuItemForeground,
423         "MenuItem.acceleratorSelectionForeground", getMenuItemSelectedForeground(),
424         "MenuItem.acceleratorSelectionBackground", getMenuItemSelectedBackground(),
425
426         "OptionPane.errorIcon", makeIcon(getClass(), "icons/Error.png"),
427         "OptionPane.informationIcon", makeIcon(getClass(), "icons/Inform.png"),
428         "OptionPane.warningIcon", makeIcon(getClass(), "icons/Warn.png"),
429         "OptionPane.questionIcon", makeIcon(getClass(), "icons/Question.png"),
430         
431         //"DesktopIcon.icon", makeIcon(superclass, "icons/DesktopIcon.gif"),
432
"FileView.computerIcon", makeIcon(getClass(), "icons/Computer.gif"),
433         "FileView.directoryIcon", makeIcon(getClass(), "icons/TreeClosed.gif"),
434         "FileView.fileIcon", makeIcon(getClass(), "icons/File.gif"),
435         "FileView.floppyDriveIcon", makeIcon(getClass(), "icons/FloppyDrive.gif"),
436         "FileView.hardDriveIcon", makeIcon(getClass(), "icons/HardDrive.gif"),
437         "FileChooser.homeFolderIcon", makeIcon(getClass(), "icons/HomeFolder.gif"),
438         "FileChooser.newFolderIcon", makeIcon(getClass(), "icons/NewFolder.gif"),
439         "FileChooser.upFolderIcon", makeIcon(getClass(), "icons/UpFolder.gif"),
440         "Tree.closedIcon", makeIcon(getClass(), "icons/TreeClosed.gif"),
441         "Tree.openIcon", makeIcon(getClass(), "icons/TreeOpen.gif"),
442         "Tree.leafIcon", makeIcon(getClass(), "icons/TreeLeaf.gif"),
443             
444         "FormattedTextField.border", textFieldBorder,
445         "FormattedTextField.margin", textInsets,
446
447         "PasswordField.border", textFieldBorder,
448         "PasswordField.margin", textInsets,
449
450         "PopupMenu.border", popupMenuBorder,
451         "PopupMenuSeparator.margin", new InsetsUIResource JavaDoc(3, 4, 3, 4),
452
453         "RadioButton.margin", checkBoxMargin,
454         "RadioButtonMenuItem.border", menuItemBorder,
455         "RadioButtonMenuItem.checkIcon", radioButtonMenuItemIcon,
456         "RadioButtonMenuItem.margin", menuItemMargin, // 1.4.1 Bug
457
"RadioButtonMenuItem.background", getMenuItemBackground(),// Added by JGoodies
458
"RadioButtonMenuItem.selectionForeground", getMenuItemSelectedForeground(),
459         "RadioButtonMenuItem.selectionBackground", getMenuItemSelectedBackground(),
460         "RadioButtonMenuItem.acceleratorForeground", menuItemForeground,
461         "RadioButtonMenuItem.acceleratorSelectionForeground", getMenuItemSelectedForeground(),
462         "RadioButtonMenuItem.acceleratorSelectionBackground", getMenuItemSelectedBackground(),
463         "Separator.foreground", getControlDarkShadow(),
464         "ScrollPane.border", scrollPaneBorder,
465         "ScrollPane.etchedBorder", scrollPaneBorder,
466 // "ScrollPane.background", table.get("window"),
467

468         "SimpleInternalFrame.activeTitleForeground", getSimpleInternalFrameForeground(),
469         "SimpleInternalFrame.activeTitleBackground", getSimpleInternalFrameBackground(),
470         
471         "Spinner.border", PlasticBorders.getFlush3DBorder(),
472         "Spinner.defaultEditorInsets", textInsets,
473         
474         "SplitPane.dividerSize", new Integer JavaDoc(7),
475         "TabbedPane.focus", getFocusColor(),
476         "TabbedPane.tabInsets", new InsetsUIResource JavaDoc(1, 9, 1, 8),
477         "Table.foreground", table.get("textText"),
478         "Table.gridColor", controlColor, //new ColorUIResource(new Color(216, 216, 216)),
479
"Table.scrollPaneBorder", scrollPaneBorder,
480         "TableHeader.cellBorder", tableHeaderBorder,
481         "TextArea.margin", wrappedTextInsets,
482         "TextField.border", textFieldBorder,
483         "TextField.margin", textInsets,
484         "TitledBorder.font", getTitleTextFont(),
485         "TitledBorder.titleColor", getTitleTextColor(),
486         "ToggleButton.border", toggleButtonBorder,
487         "ToggleButton.margin", defaultButtonMargin,
488         "ToggleButton.narrowMargin", narrowButtonMargin,
489
490         "ToolBar.emptyBorder", toolBarEmptyBorder, // Added by JGoodies
491
"ToolBar.separatorBorder", toolBarSeparatorBorder, // Added by JGoodies
492
"ToolBar.etchedBorder", toolBarEtchedBorder, // Added by JGoodies
493
"ToolBar.headerBorder", toolBarHeaderBorder, // Added by JGoodies
494

495         "ToolTip.hideAccelerator", Boolean.TRUE,
496         
497         "Tree.expandedIcon", treeExpandedIcon,
498         "Tree.collapsedIcon", treeCollapsedIcon,
499         "Tree.line", gray,
500         "Tree.hash", gray,
501         "Tree.rowHeight", rowHeight,
502         
503         "Button.is3DEnabled", is3D,
504         "ComboBox.is3DEnabled", is3D,
505         "MenuBar.is3DEnabled", is3D,
506         "ToolBar.is3DEnabled", is3D,
507         "ScrollBar.is3DEnabled", is3D,
508         "ToggleButton.is3DEnabled", is3D,
509
510         // 1.4.1 uses a 2 pixel non-standard border, that leads to bad
511
// alignment in the typical case that the border is not painted
512
"CheckBox.border", marginBorder,
513         "RadioButton.border", marginBorder,
514         
515         // Fix of the issue #21
516
"ProgressBar.selectionForeground", getSystemTextColor(),
517         "ProgressBar.selectionBackground", getSystemTextColor()
518         };
519         table.putDefaults(defaults);
520         
521         // Set paths to sounds for auditory feedback
522
String JavaDoc soundPathPrefix = "/javax/swing/plaf/metal/";
523         Object JavaDoc[] auditoryCues = (Object JavaDoc[]) table.get("AuditoryCues.allAuditoryCues");
524         if (auditoryCues != null) {
525             Object JavaDoc[] audioDefaults = new String JavaDoc[auditoryCues.length * 2];
526             for (int i = 0; i < auditoryCues.length; i++) {
527                 Object JavaDoc auditoryCue = auditoryCues[i];
528                 audioDefaults[2*i] = auditoryCue;
529                 audioDefaults[2*i + 1] = soundPathPrefix + table.getString(auditoryCue);
530             }
531             table.putDefaults(audioDefaults);
532         }
533     }
534
535
536     /**
537      * Unlike my superclass I register a unified shadow color.
538      * This color is used by my ThinBevelBorder class.
539      *
540      * @param table the UIDefaults table to work with
541      */

542     protected void initSystemColorDefaults(UIDefaults JavaDoc table) {
543         super.initSystemColorDefaults(table);
544         table.put("unifiedControlShadow", table.getColor("controlDkShadow"));
545         table.put("primaryControlHighlight", getPrimaryControlHighlight());
546     }
547
548
549     // Color Theme Behavior *************************************************************
550

551     private static final String JavaDoc THEME_CLASSNAME_PREFIX = "com.jgoodies.looks.plastic.theme.";
552     
553     /**
554      * Creates and returns the default color theme. Honors the current platform
555      * and platform flavor - if available.
556      *
557      * @return the default color theme for the current environemt
558      */

559     public static PlasticTheme createMyDefaultTheme() {
560         String JavaDoc defaultName = LookUtils.IS_LAF_WINDOWS_XP_ENABLED
561                                 ? "ExperienceBlue"
562                                 : (LookUtils.IS_OS_WINDOWS_MODERN ? "DesertBluer" : "SkyBlue");
563         // Don't use the default now, so we can detect that the users tried to set one.
564
String JavaDoc userName = LookUtils.getSystemProperty(DEFAULT_THEME_KEY, "");
565         boolean overridden = userName.length() > 0;
566         String JavaDoc themeName = overridden ? userName : defaultName;
567         PlasticTheme theme = createTheme(themeName);
568         PlasticTheme result = theme != null ? theme : new SkyBluerTahoma();
569         
570         // In case the user tried to set a theme, log a message.
571
if (overridden) {
572             String JavaDoc className = theme.getClass().getName().substring(
573                                                     THEME_CLASSNAME_PREFIX.length());
574             if (className.equals(userName)) {
575                 LookUtils.log("I have successfully installed the '" + theme.getName() + "' theme.");
576             } else {
577                 LookUtils.log("I could not install the Plastic theme '" + userName + "'.");
578                 LookUtils.log("I have installed the '" + theme.getName() + "' theme, instead.");
579             }
580         }
581         return result;
582         
583     }
584     
585     
586     /**
587      * Lazily initializes and returns the <code>List</code> of installed
588      * color themes.
589      *
590      * @return a list of installed color/font themes
591      */

592     public static List JavaDoc getInstalledThemes() {
593         if (null == installedThemes)
594             installDefaultThemes();
595
596         Collections.sort(installedThemes, new Comparator JavaDoc() {
597             public int compare(Object JavaDoc o1, Object JavaDoc o2) {
598                 MetalTheme JavaDoc theme1 = (MetalTheme JavaDoc) o1;
599                 MetalTheme JavaDoc theme2 = (MetalTheme JavaDoc) o2;
600                 return theme1.getName().compareTo(theme2.getName());
601             }
602         });
603
604         return installedThemes;
605     }
606     
607     
608     /**
609      * Install the default color themes.
610      */

611     protected static void installDefaultThemes() {
612         installedThemes = new ArrayList JavaDoc();
613         String JavaDoc[] themeNames = {
614             "BrownSugar",
615             "DarkStar",
616             "DesertBlue",
617             "DesertBluer",
618             "DesertGreen",
619             "DesertRed",
620             "DesertYellow",
621             "ExperienceBlue",
622             "ExperienceGreen",
623             "Silver",
624             "SkyBlue",
625             "SkyBluer",
626             "SkyBluerTahoma",
627             "SkyGreen",
628             "SkyKrupp",
629             "SkyPink",
630             "SkyRed",
631             "SkyYellow"};
632         for (int i=themeNames.length - 1; i >= 0; i--)
633             installTheme(createTheme(themeNames[i]));
634     }
635     
636     
637     /**
638      * Creates and returns a color theme from the specified theme name.
639      *
640      * @param themeName the unqualified name of the theme to create
641      * @return the associated color theme or <code>null</code> in case of
642      * a problem
643      */

644     protected static PlasticTheme createTheme(String JavaDoc themeName) {
645         String JavaDoc className = THEME_CLASSNAME_PREFIX + themeName;
646         try {
647             Class JavaDoc cl = Class.forName(className);
648             return (PlasticTheme) (cl.newInstance());
649         } catch (ClassNotFoundException JavaDoc e) {
650             // Ignore the exception here and log below.
651
} catch (IllegalAccessException JavaDoc e) {
652             // Ignore the exception here and log below.
653
} catch (InstantiationException JavaDoc e) {
654             // Ignore the exception here and log below.
655
}
656         LookUtils.log("Can't create theme " + className);
657         return null;
658     }
659
660
661     /**
662      * Installs a color theme.
663      *
664      * @param theme the theme to install
665      */

666     public static void installTheme(PlasticTheme theme) {
667         if (null == installedThemes)
668             installDefaultThemes();
669         installedThemes.add(theme);
670     }
671
672
673     /**
674      * Gets the current <code>PlasticTheme</code>.
675      *
676      * @return the current PlasticTheme
677      */

678     public static PlasticTheme getMyCurrentTheme() {
679         return myCurrentTheme;
680     }
681     
682     
683     /**
684      * Sets a new <code>PlasticTheme</code> for colors and fonts.
685      *
686      * @param theme the PlasticTheme to be set
687      */

688     public static void setMyCurrentTheme(PlasticTheme theme) {
689         myCurrentTheme = theme;
690         setCurrentTheme(theme);
691     }
692     
693     
694     // Accessed by ProxyLazyValues ******************************************
695

696     public static BorderUIResource JavaDoc getInternalFrameBorder() {
697         return new BorderUIResource JavaDoc(PlasticBorders.getInternalFrameBorder());
698     }
699     
700     public static BorderUIResource JavaDoc getPaletteBorder() {
701         return new BorderUIResource JavaDoc(PlasticBorders.getPaletteBorder());
702     }
703     
704     
705
706     // Accessing Theme Colors and Fonts *************************************
707

708      
709     public static ColorUIResource JavaDoc getPrimaryControlDarkShadow() {
710         return getMyCurrentTheme().getPrimaryControlDarkShadow();
711     }
712     
713     public static ColorUIResource JavaDoc getPrimaryControlHighlight() {
714         return getMyCurrentTheme().getPrimaryControlHighlight();
715     }
716     
717     public static ColorUIResource JavaDoc getPrimaryControlInfo() {
718         return getMyCurrentTheme().getPrimaryControlInfo();
719     }
720     
721     public static ColorUIResource JavaDoc getPrimaryControlShadow() {
722         return getMyCurrentTheme().getPrimaryControlShadow();
723     }
724     
725     public static ColorUIResource JavaDoc getPrimaryControl() {
726         return getMyCurrentTheme().getPrimaryControl();
727     }
728     
729     public static ColorUIResource JavaDoc getControlHighlight() {
730         return getMyCurrentTheme().getControlHighlight();
731     }
732     
733     public static ColorUIResource JavaDoc getControlDarkShadow() {
734         return getMyCurrentTheme().getControlDarkShadow();
735     }
736     
737     public static ColorUIResource JavaDoc getControl() {
738         return getMyCurrentTheme().getControl();
739     }
740     
741     public static ColorUIResource JavaDoc getFocusColor() {
742         return getMyCurrentTheme().getFocusColor();
743     }
744     
745     public static ColorUIResource JavaDoc getMenuItemBackground() {
746         return getMyCurrentTheme().getMenuItemBackground();
747     }
748     
749     public static ColorUIResource JavaDoc getMenuItemSelectedBackground() {
750         return getMyCurrentTheme().getMenuItemSelectedBackground();
751     }
752     
753     public static ColorUIResource JavaDoc getMenuItemSelectedForeground() {
754         return getMyCurrentTheme().getMenuItemSelectedForeground();
755     }
756     
757     public static ColorUIResource JavaDoc getWindowTitleBackground() {
758         return getMyCurrentTheme().getWindowTitleBackground();
759     }
760     
761     public static ColorUIResource JavaDoc getWindowTitleForeground() {
762         return getMyCurrentTheme().getWindowTitleForeground();
763     }
764     
765     public static ColorUIResource JavaDoc getWindowTitleInactiveBackground() {
766         return getMyCurrentTheme().getWindowTitleInactiveBackground();
767     }
768     
769     public static ColorUIResource JavaDoc getWindowTitleInactiveForeground() {
770         return getMyCurrentTheme().getWindowTitleInactiveForeground();
771     }
772     
773     public static ColorUIResource JavaDoc getSimpleInternalFrameForeground() {
774         return getMyCurrentTheme().getSimpleInternalFrameForeground();
775     }
776     
777     public static ColorUIResource JavaDoc getSimpleInternalFrameBackground() {
778         return getMyCurrentTheme().getSimpleInternalFrameBackground();
779     }
780     
781     public static ColorUIResource JavaDoc getTitleTextColor() {
782         return getMyCurrentTheme().getTitleTextColor();
783     }
784
785     public static FontUIResource JavaDoc getTitleTextFont() {
786         return getMyCurrentTheme().getTitleTextFont();
787     }
788
789 }
Popular Tags