KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)OceanTheme.java 1.16 05/01/04
3  *
4  * Copyright 2005 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 java.awt.*;
11 import java.net.URL JavaDoc;
12 import java.util.*;
13 import javax.swing.*;
14 import javax.swing.plaf.*;
15 import com.sun.java.swing.SwingUtilities2;
16 import sun.swing.PrintColorUIResource;
17
18 /**
19  * This class provides an updated look for applications using
20  * <code>MetalLookAndFeel<code>. The designers of the Metal
21  * Look and Feel strive to keep the default look up to date,
22  * possibly through the use of new themes in the future.
23  * Therefore, developers should only use this class directly
24  * when they wish to customize the "Ocean" look, or force
25  * it to be the current theme, regardless of future updates.
26  *
27  * @version 1.16 01/04/05
28  * @since 1.5
29  * @see MetalLookAndFeel#setCurrentTheme
30  */

31 public class OceanTheme extends DefaultMetalTheme JavaDoc {
32     private static final ColorUIResource PRIMARY1 =
33                               new ColorUIResource(0x6382BF);
34     private static final ColorUIResource PRIMARY2 =
35                               new ColorUIResource(0xA3B8CC);
36     private static final ColorUIResource PRIMARY3 =
37                               new ColorUIResource(0xB8CFE5);
38     private static final ColorUIResource SECONDARY1 =
39                               new ColorUIResource(0x7A8A99);
40     private static final ColorUIResource SECONDARY2 =
41                               new ColorUIResource(0xB8CFE5);
42     private static final ColorUIResource SECONDARY3 =
43                               new ColorUIResource(0xEEEEEE);
44
45     private static final ColorUIResource CONTROL_TEXT_COLOR =
46                               new PrintColorUIResource(0x333333, Color.BLACK);
47     private static final ColorUIResource INACTIVE_CONTROL_TEXT_COLOR =
48                               new ColorUIResource(0x999999);
49     private static final ColorUIResource MENU_DISABLED_FOREGROUND =
50                               new ColorUIResource(0x999999);
51     private static final ColorUIResource OCEAN_BLACK =
52                               new PrintColorUIResource(0x333333, Color.BLACK);
53
54     // ComponentOrientation Icon
55
// Delegates to different icons based on component orientation
56
private static class COIcon extends IconUIResource {
57         private Icon rtl;
58
59         public COIcon(Icon ltr, Icon rtl) {
60             super(ltr);
61             this.rtl = rtl;
62         }
63
64         public void paintIcon(Component c, Graphics g, int x, int y) {
65             if (MetalUtils.isLeftToRight(c)) {
66                 super.paintIcon(c, g, x, y);
67             } else {
68                 rtl.paintIcon(c, g, x, y);
69             }
70         }
71     }
72
73     // InternalFrame Icon
74
// Delegates to different icons based on button state
75
private static class IFIcon extends IconUIResource {
76         private Icon pressed;
77
78         public IFIcon(Icon normal, Icon pressed) {
79             super(normal);
80             this.pressed = pressed;
81         }
82         
83         public void paintIcon(Component c, Graphics g, int x, int y) {
84             ButtonModel model = ((AbstractButton)c).getModel();
85             if (model.isPressed() && model.isArmed()) {
86                 pressed.paintIcon(c, g, x, y);
87             } else {
88                 super.paintIcon(c, g, x, y);
89             }
90         }
91     }
92
93     /**
94      * Construct an instance of <code>OceanTheme</code>
95      */

96     public OceanTheme() {
97     }
98
99     /**
100      * Add this theme's custom entries to the defaults table.
101      *
102      * @param table the defaults table, non-null
103      * @throws NullPointerException if the parameter is null
104      */

105     public void addCustomEntriesToTable(UIDefaults table) {
106         Object JavaDoc focusBorder = new UIDefaults.ProxyLazyValue(
107                       "javax.swing.plaf.BorderUIResource$LineBorderUIResource",
108                       new Object JavaDoc[] {getPrimary1()});
109         // .30 0 DDE8F3 white secondary2
110
java.util.List JavaDoc buttonGradient = Arrays.asList(
111                  new Object JavaDoc[] {new Float JavaDoc(.3f), new Float JavaDoc(0f),
112                  new ColorUIResource(0xDDE8F3), getWhite(), getSecondary2() });
113
114         // Other possible properties that aren't defined:
115
//
116
// Used when generating the disabled Icons, provides the region to
117
// constrain grays to.
118
// Button.disabledGrayRange -> Object[] of Integers giving min/max
119
// InternalFrame.inactiveTitleGradient -> Gradient when the
120
// internal frame is inactive.
121
Color cccccc = new ColorUIResource(0xCCCCCC);
122         Color dadada = new ColorUIResource(0xDADADA);
123         Color c8ddf2 = new ColorUIResource(0xC8DDF2);
124         Object JavaDoc directoryIcon = getIconResource("icons/ocean/directory.gif");
125         Object JavaDoc fileIcon = getIconResource("icons/ocean/file.gif");
126         java.util.List JavaDoc sliderGradient = Arrays.asList(new Object JavaDoc[] {
127             new Float JavaDoc(.3f), new Float JavaDoc(.2f),
128             c8ddf2, getWhite(), new ColorUIResource(SECONDARY2) });
129
130         Object JavaDoc[] defaults = new Object JavaDoc[] {
131             "Button.gradient", buttonGradient,
132             "Button.rollover", Boolean.TRUE,
133             "Button.toolBarBorderBackground", INACTIVE_CONTROL_TEXT_COLOR,
134             "Button.disabledToolBarBorderBackground", cccccc,
135             "Button.rolloverIconType", "ocean",
136
137             "CheckBox.rollover", Boolean.TRUE,
138             "CheckBox.gradient", buttonGradient,
139
140             "CheckBoxMenuItem.gradient", buttonGradient,
141
142             // home2
143
"FileChooser.homeFolderIcon",
144                  getIconResource("icons/ocean/homeFolder.gif"),
145             // directory2
146
"FileChooser.newFolderIcon",
147                  getIconResource("icons/ocean/newFolder.gif"),
148             // updir2
149
"FileChooser.upFolderIcon",
150                  getIconResource("icons/ocean/upFolder.gif"),
151
152             // computer2
153
"FileView.computerIcon",
154                  getIconResource("icons/ocean/computer.gif"),
155             "FileView.directoryIcon", directoryIcon,
156             // disk2
157
"FileView.hardDriveIcon",
158                  getIconResource("icons/ocean/hardDrive.gif"),
159             "FileView.fileIcon", fileIcon,
160             // floppy2
161
"FileView.floppyDriveIcon",
162                  getIconResource("icons/ocean/floppy.gif"),
163
164             "Label.disabledForeground", getInactiveControlTextColor(),
165             
166             "Menu.opaque", Boolean.FALSE,
167
168             "MenuBar.gradient", Arrays.asList(new Object JavaDoc[] {
169                      new Float JavaDoc(1f), new Float JavaDoc(0f),
170                      getWhite(), dadada,
171                      new ColorUIResource(dadada) }),
172             "MenuBar.borderColor", cccccc,
173
174             "InternalFrame.activeTitleGradient", buttonGradient,
175             // close2
176
"InternalFrame.closeIcon",
177                      new UIDefaults.LazyValue() {
178                          public Object JavaDoc createValue(UIDefaults table) {
179                              return new IFIcon(getHastenedIcon("icons/ocean/close.gif", table),
180                                                getHastenedIcon("icons/ocean/close-pressed.gif", table));
181                          }
182                      },
183             // minimize
184
"InternalFrame.iconifyIcon",
185                      new UIDefaults.LazyValue() {
186                          public Object JavaDoc createValue(UIDefaults table) {
187                              return new IFIcon(getHastenedIcon("icons/ocean/iconify.gif", table),
188                                                getHastenedIcon("icons/ocean/iconify-pressed.gif", table));
189                          }
190                      },
191             // restore
192
"InternalFrame.minimizeIcon",
193                      new UIDefaults.LazyValue() {
194                          public Object JavaDoc createValue(UIDefaults table) {
195                              return new IFIcon(getHastenedIcon("icons/ocean/minimize.gif", table),
196                                                getHastenedIcon("icons/ocean/minimize-pressed.gif", table));
197                          }
198                      },
199             // menubutton3
200
"InternalFrame.icon",
201                      getIconResource("icons/ocean/menu.gif"),
202             // maximize2
203
"InternalFrame.maximizeIcon",
204                      new UIDefaults.LazyValue() {
205                          public Object JavaDoc createValue(UIDefaults table) {
206                              return new IFIcon(getHastenedIcon("icons/ocean/maximize.gif", table),
207                                                getHastenedIcon("icons/ocean/maximize-pressed.gif", table));
208                          }
209                      },
210             // paletteclose
211
"InternalFrame.paletteCloseIcon",
212                      new UIDefaults.LazyValue() {
213                          public Object JavaDoc createValue(UIDefaults table) {
214                              return new IFIcon(getHastenedIcon("icons/ocean/paletteClose.gif", table),
215                                                getHastenedIcon("icons/ocean/paletteClose-pressed.gif", table));
216                          }
217                      },
218
219             "List.focusCellHighlightBorder", focusBorder,
220
221             "MenuBarUI", "javax.swing.plaf.metal.MetalMenuBarUI",
222
223             "OptionPane.errorIcon",
224                    getIconResource("icons/ocean/error.png"),
225             "OptionPane.informationIcon",
226                    getIconResource("icons/ocean/info.png"),
227             "OptionPane.questionIcon",
228                    getIconResource("icons/ocean/question.png"),
229             "OptionPane.warningIcon",
230                    getIconResource("icons/ocean/warning.png"),
231
232             "RadioButton.gradient", buttonGradient,
233             "RadioButton.rollover", Boolean.TRUE,
234
235             "RadioButtonMenuItem.gradient", buttonGradient,
236
237             "ScrollBar.gradient", buttonGradient,
238
239             "Slider.altTrackColor", new ColorUIResource(0xD2E2EF),
240             "Slider.gradient", sliderGradient,
241             "Slider.focusGradient", sliderGradient,
242
243             "SplitPane.oneTouchButtonsOpaque", Boolean.FALSE,
244             "SplitPane.dividerFocusColor", c8ddf2,
245
246             "TabbedPane.borderHightlightColor", getPrimary1(),
247             "TabbedPane.contentAreaColor", c8ddf2,
248             "TabbedPane.contentBorderInsets", new Insets(4, 2, 3, 3),
249             "TabbedPane.selected", c8ddf2,
250             "TabbedPane.tabAreaBackground", dadada,
251             "TabbedPane.tabAreaInsets", new Insets(2, 2, 0, 6),
252             "TabbedPane.unselectedBackground", SECONDARY3,
253
254             "Table.focusCellHighlightBorder", focusBorder,
255             "Table.gridColor", SECONDARY1,
256
257             "ToggleButton.gradient", buttonGradient,
258
259             "ToolBar.borderColor", cccccc,
260             "ToolBar.isRollover", Boolean.TRUE,
261
262             "Tree.closedIcon", directoryIcon,
263
264             "Tree.collapsedIcon",
265                   new UIDefaults.LazyValue() {
266                       public Object JavaDoc createValue(UIDefaults table) {
267                           return new COIcon(getHastenedIcon("icons/ocean/collapsed.gif", table),
268                                             getHastenedIcon("icons/ocean/collapsed-rtl.gif", table));
269                       }
270                   },
271
272             "Tree.expandedIcon",
273                   getIconResource("icons/ocean/expanded.gif"),
274             "Tree.leafIcon", fileIcon,
275             "Tree.openIcon", directoryIcon,
276             "Tree.selectionBorderColor", getPrimary1()
277         };
278         table.putDefaults(defaults);
279     }
280
281     /**
282      * Overriden to enable picking up the system fonts, if applicable.
283      */

284     boolean isSystemTheme() {
285         return true;
286     }
287
288     /**
289      * Return the name of this theme, "Ocean".
290      *
291      * @return "Ocean"
292      */

293     public String JavaDoc getName() {
294         return "Ocean";
295     }
296
297     /**
298      * Return the color that the Metal Look and Feel should use
299      * as "Primary 1". The Look and Feel will use this color
300      * in painting as it sees fit.
301      *
302      * @return the "Primary 1" color.
303      */

304     protected ColorUIResource getPrimary1() {
305         return PRIMARY1;
306     }
307
308     /**
309      * Return the color that the Metal Look and Feel should use
310      * as "Primary 2". The Look and Feel will use this color
311      * in painting as it sees fit.
312      *
313      * @return the "Primary 2" color.
314      */

315     protected ColorUIResource getPrimary2() {
316         return PRIMARY2;
317     }
318
319     /**
320      * Return the color that the Metal Look and Feel should use
321      * as "Primary 3". The Look and Feel will use this color
322      * in painting as it sees fit.
323      *
324      * @return the "Primary 3" color.
325      */

326     protected ColorUIResource getPrimary3() {
327         return PRIMARY3;
328     }
329
330     /**
331      * Return the color that the Metal Look and Feel should use
332      * as "Secondary 1". The Look and Feel will use this color
333      * in painting as it sees fit.
334      *
335      * @return the "Secondary 1" color.
336      */

337     protected ColorUIResource getSecondary1() {
338         return SECONDARY1;
339     }
340
341     /**
342      * Return the color that the Metal Look and Feel should use
343      * as "Secondary 2". The Look and Feel will use this color
344      * in painting as it sees fit.
345      *
346      * @return the "Secondary 2" color.
347      */

348     protected ColorUIResource getSecondary2() {
349         return SECONDARY2;
350     }
351
352     /**
353      * Return the color that the Metal Look and Feel should use
354      * as "Secondary 3". The Look and Feel will use this color
355      * in painting as it sees fit.
356      *
357      * @return the "Secondary 3" color.
358      */

359     protected ColorUIResource getSecondary3() {
360         return SECONDARY3;
361     }
362
363     /**
364      * Return the color that the Metal Look and Feel should use
365      * as "Black". The Look and Feel will use this color
366      * in painting as it sees fit. This color does not necessarily
367      * synch up with the typical concept of black, nor is
368      * it necessarily used for all black items.
369      *
370      * @return the "Black" color.
371      */

372     protected ColorUIResource getBlack() {
373         return OCEAN_BLACK;
374     }
375
376     /**
377      * Return the color that the Metal Look and Feel should use
378      * for the desktop background. The Look and Feel will use this color
379      * in painting as it sees fit.
380      *
381      * @return the "Desktop" color.
382      */

383     public ColorUIResource getDesktopColor() {
384         return MetalTheme.white;
385     }
386
387     /**
388      * Return the color that the Metal Look and Feel should use as the default
389      * color for inactive controls. The Look and Feel will use this color
390      * in painting as it sees fit.
391      *
392      * @return the "Inactive Control Text" color.
393      */

394     public ColorUIResource getInactiveControlTextColor() {
395         return INACTIVE_CONTROL_TEXT_COLOR;
396     }
397
398     /**
399      * Return the color that the Metal Look and Feel should use as the default
400      * color for controls. The Look and Feel will use this color
401      * in painting as it sees fit.
402      *
403      * @return the "Control Text" color.
404      */

405     public ColorUIResource getControlTextColor() {
406         return CONTROL_TEXT_COLOR;
407     }
408
409     /**
410      * Return the color that the Metal Look and Feel should use as the
411      * foreground color for disabled menu items. The Look and Feel will use
412      * this color in painting as it sees fit.
413      *
414      * @return the "Menu Disabled Foreground" color.
415      */

416     public ColorUIResource getMenuDisabledForeground() {
417         return MENU_DISABLED_FOREGROUND;
418     }
419
420     private Object JavaDoc getIconResource(String JavaDoc iconID) {
421         return SwingUtilities2.makeIcon(getClass(), OceanTheme JavaDoc.class, iconID);
422     }
423
424     // makes use of getIconResource() to fetch an icon and then hastens it
425
// - calls createValue() on it and returns the actual icon
426
private Icon getHastenedIcon(String JavaDoc iconID, UIDefaults table) {
427         Object JavaDoc res = getIconResource(iconID);
428         return (Icon)((UIDefaults.LazyValue)res).createValue(table);
429     }
430 }
431
Popular Tags