OSDN Git Service

edeff18247a38aa0b749e65ed2d29f29d57a3754
[pf3gnuchains/gcc-fork.git] / libjava / javax / swing / plaf / metal / MetalLookAndFeel.java
1 /* MetalLookAndFeel.java
2    Copyright (C) 2002 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
20
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37
38
39 package javax.swing.plaf.metal;
40
41 import java.awt.Color;
42 import java.awt.Insets;
43
44 import javax.swing.UIDefaults;
45 import javax.swing.plaf.ColorUIResource;
46 import javax.swing.plaf.FontUIResource;
47 import javax.swing.plaf.basic.BasicLookAndFeel;
48
49 public class MetalLookAndFeel extends BasicLookAndFeel
50 {          
51   private static final long serialVersionUID = 6680646159193457980L;
52   private static MetalTheme theme;
53   private UIDefaults LAF_defaults;
54
55   public MetalLookAndFeel()
56   {
57     createDefaultTheme();
58   }
59
60   protected void createDefaultTheme()
61   {
62     setCurrentTheme(new DefaultMetalTheme());
63   }
64
65   public boolean isNativeLookAndFeel()
66   {
67     return true;
68   }
69
70   public boolean isSupportedLookAndFeel()
71   {
72     return true;
73   }
74
75   public String getDescription()
76   {
77     return "Metal look and feel";
78   }
79
80   public String getID()
81   {
82     return "MetalLookAndFeel";
83   }
84
85   public String getName()
86   {
87     return "MetalLookAndFeel";
88   }
89
90   public UIDefaults getDefaults()
91   {
92     if (LAF_defaults == null)
93       LAF_defaults = super.getDefaults();
94
95     // add custom theme entries to the table
96     theme.addCustomEntriesToTable(LAF_defaults);
97     
98     // Returns the default values for this look and feel. 
99     return LAF_defaults;
100   }
101
102   public static ColorUIResource getAcceleratorForeground()
103   {
104     return theme.getAcceleratorForeground();
105   }
106
107   public static ColorUIResource getAcceleratorSelectedForeground()
108   {
109     return theme.getAcceleratorSelectedForeground();
110   }
111
112   public static ColorUIResource getBlack()
113   {
114     return theme.getBlack();
115   }
116
117   public static ColorUIResource getControl()
118   {
119     return theme.getControl();
120   }
121
122   public static ColorUIResource getControlDarkShadow()
123   {
124     return theme.getControlDarkShadow();
125   }
126
127   public static ColorUIResource getControlDisabled()
128   {
129     return theme.getControlDisabled();
130   }
131
132   public static ColorUIResource getControlHighlight()
133   {
134     return theme.getControlHighlight();
135   }
136
137   public static ColorUIResource getControlInfo()
138   {
139     return theme.getControlInfo();
140   }
141
142   public static ColorUIResource getControlShadow()
143   {
144     return theme.getControlShadow();
145   }
146
147   public static ColorUIResource getControlTextColor()
148   {
149     return theme.getControlTextColor();
150   }
151
152   public static FontUIResource getControlTextFont()
153   {
154     return theme.getControlTextFont();
155   }
156
157   public static ColorUIResource getDesktopColor()
158   {
159     return theme.getDesktopColor();
160   }
161
162   public static ColorUIResource getFocusColor()
163   {
164     return theme.getFocusColor();
165   }
166
167   public static ColorUIResource getHighlightedTextColor()
168   {
169     return theme.getHighlightedTextColor();
170   }
171
172   public static ColorUIResource getInactiveControlTextColor()
173   {
174     return theme.getInactiveControlTextColor();
175   }
176
177   public static ColorUIResource getInactiveSystemTextColor()
178   {
179     return theme.getInactiveSystemTextColor();
180   }
181
182   public static ColorUIResource getMenuBackground()
183   {
184     return theme.getMenuBackground();
185   }
186
187   public static ColorUIResource getMenuDisabledForeground()
188   {
189     return theme.getMenuDisabledForeground();
190   }
191
192   public static ColorUIResource getMenuForeground()
193   {
194     return theme.getMenuForeground();
195   }
196
197   public static ColorUIResource getMenuSelectedBackground()
198   {
199     return theme.getMenuSelectedBackground();
200   }
201
202   public static ColorUIResource getMenuSelectedForeground()
203   {
204     return theme.getMenuSelectedForeground();
205   }
206
207   public static FontUIResource getMenuTextFont()
208   {
209     return theme.getMenuTextFont();
210   }
211
212   public static ColorUIResource getPrimaryControl()
213   {
214     return theme.getPrimaryControl();
215   }
216
217   public static ColorUIResource getPrimaryControlDarkShadow()
218   {
219     return theme.getPrimaryControlDarkShadow();
220   }
221
222   public static ColorUIResource getPrimaryControlHighlight()
223   {
224     return theme.getPrimaryControlHighlight();
225   }
226
227   public static ColorUIResource getPrimaryControlInfo()
228   {
229     return theme.getPrimaryControlInfo();
230   }
231
232   public static ColorUIResource getPrimaryControlShadow()
233   {
234     return theme.getPrimaryControlShadow();
235   }
236
237   public static ColorUIResource getSeparatorBackground()
238   {
239     return theme.getSeparatorBackground();
240   }
241
242   public static ColorUIResource getSeparatorForeground()
243   {
244     return theme.getSeparatorForeground();
245   }
246
247   public static FontUIResource getSubTextFont()
248   {
249     return theme.getSubTextFont();
250   }
251
252   public static ColorUIResource getSystemTextColor()
253   {
254     return theme.getSystemTextColor();
255   }
256
257   public static FontUIResource getSystemTextFont()
258   {
259     return theme.getSystemTextFont();
260   }
261
262   public static ColorUIResource getTextHighlightColor()
263   {
264     return theme.getTextHighlightColor();
265   }
266
267   public static ColorUIResource getUserTextColor()
268   {
269     return theme.getUserTextColor();
270   }
271
272   public static FontUIResource getUserTextFont()
273   {
274     return theme.getUserTextFont();
275   }
276
277   public static ColorUIResource getWhite()
278   {
279     return theme.getWhite();
280   }
281
282   public static ColorUIResource getWindowBackground()
283   {
284     return theme.getWindowBackground();
285   }
286
287   public static ColorUIResource getWindowTitleBackground()
288   {
289     return theme.getWindowTitleBackground();
290   }
291
292   public static FontUIResource getWindowTitleFont()
293   {
294     return theme.getWindowTitleFont();
295   }
296
297   public static ColorUIResource getWindowTitleForeground()
298   {
299     return theme.getWindowTitleForeground();
300   }
301
302   public static ColorUIResource getWindowTitleInactiveBackground()
303   {
304     return theme.getWindowTitleInactiveBackground();
305   }
306
307   public static ColorUIResource getWindowTitleInactiveForeground()
308   {
309     return theme.getWindowTitleInactiveForeground();
310   }
311
312   public static void setCurrentTheme(MetalTheme theme)
313   {
314     MetalLookAndFeel.theme = theme;
315   }
316
317   /**
318    * Sets the ComponentUI classes for all Swing components to the Metal
319    * implementations.
320    *
321    * In particular this sets the following keys:
322    *
323    * <table>
324    * <tr>
325    * <th>Key</th><th>Value</th>
326    * </tr><tr>
327    * <td>ButtonUI</td><td>{@link MetalButtonUI}</td>
328    * </tr><tr>
329    * <td>CheckBoxUI</td><td>{@link MetalCheckBoxUI}</td>
330    * </tr><tr>
331    * <td>ComboBoxUI</td><td>{@link MetalComboBoxUI}</td>
332    * </tr><tr>
333    * <td>DesktopIconUI</td><td>{@link MetalDesktopIconUI}</td>
334    * </tr><tr>
335    * <td>InternalFrameUI</td><td>{@link MetalInternalFrameUI}</td>
336    * </tr><tr>
337    * <td>LabelUI</td><td>{@link MetalLabelUI}</td>
338    * </tr><tr>
339    * <td>PopupMenuSeparatorUI</td><td>{@link MetalPopupMenuSeparatorUI}</td>
340    * </tr><tr>
341    * <td>ProgressBarUI</td><td>{@link MetalProgressBarUI}</td>
342    * </tr><tr>
343    * <td>RadioButtonUI</td><td>{@link MetalRadioButtonUI}</td>
344    * </tr><tr>
345    * <td>RootPaneUI</td><td>{@link MetalRootPaneUI}</td>
346    * </tr><tr>
347    * <td>ScrollBarUI</td><td>{@link MetalScrollBarUI}</td>
348    * </tr><tr>
349    * <td>ScrollPaneUI</td><td>{@link MetalScrollPaneUI}</td>
350    * </tr><tr>
351    * <td>SeparatorUI</td><td>{@link MetalSeparatorUI}</td>
352    * </tr><tr>
353    * <td>SliderUI</td><td>{@link MetalSliderUI}</td>
354    * </tr><tr>
355    * <td>SplitPaneUI</td><td>{@link MetalSplitPaneUI}</td>
356    * </tr><tr>
357    * <td>TabbedPaneUI</td><td>{@link MetalTabbedPaneUI}</td>
358    * </tr><tr>
359    * <td>TextFieldUI</td><td>{@link MetalTextFieldUI}</td>
360    * </tr><tr>
361    * <td>ToggleButtonUI</td><td>{@link MetalToggleButtonUI}</td>
362    * </tr><tr>
363    * <td>ToolBarUI</td><td>{@link MetalToolBarUI}</td>
364    * </tr><tr>
365    * <td>ToolTipUI</td><td>{@link MetalToolTipUI}</td>
366    * </tr><tr>
367    * <td>TreeUI</td><td>{@link MetalTreeUI}</td>
368    * </tr><tr>
369    * </table>
370    *
371    * @param defaults the UIDefaults where the class defaults are added
372    */
373   protected void initClassDefaults(UIDefaults defaults)
374   {
375     super.initClassDefaults(defaults);
376
377     // Variables
378     Object[] uiDefaults;
379     // Initialize Class Defaults
380     uiDefaults = new Object[] {
381       "ButtonUI", "javax.swing.plaf.metal.MetalButtonUI",
382       "CheckBoxUI", "javax.swing.plaf.metal.MetalCheckBoxUI",
383       "ComboBoxUI", "javax.swing.plaf.metal.MetalComboBoxUI",
384       "DesktopIconUI", "javax.swing.plaf.metal.MetalDesktopIconUI",
385       "InternalFrameUI", "javax.swing.plaf.metal.MetalInternalFrameUI",
386       "LabelUI", "javax.swing.plaf.metal.MetalLabelUI",
387       "PopupMenuSeparatorUI",
388       "javax.swing.plaf.metal.MetalPopupMenuSeparatorUI",
389       "ProgressBarUI", "javax.swing.plaf.metal.MetalProgressBarUI",
390       "RadioButtonUI", "javax.swing.plaf.metal.MetalRadioButtonUI",
391       "RootPaneUI", "javax.swing.plaf.metal.MetalRootPaneUI",
392       "ScrollBarUI", "javax.swing.plaf.metal.MetalScrollBarUI",
393       "ScrollPaneUI", "javax.swing.plaf.metal.MetalScrollPaneUI",
394       "SeparatorUI", "javax.swing.plaf.metal.MetalSeparatorUI",
395       "SliderUI", "javax.swing.plaf.metal.MetalSliderUI",
396       "SplitPaneUI", "javax.swing.plaf.metal.MetalSplitPaneUI",
397       "TabbedPaneUI", "javax.swing.plaf.metal.MetalTabbedPaneUI",
398       "TextFieldUI", "javax.swing.plaf.metal.MetalTextFieldUI",
399       "ToggleButtonUI", "javax.swing.plaf.metal.MetalToggleButtonUI",
400       "ToolBarUI", "javax.swing.plaf.metal.MetalToolBarUI",
401       "ToolTipUI", "javax.swing.plaf.metal.MetalToolTipUI",
402       "TreeUI", "javax.swing.plaf.metal.MetalTreeUI",
403     };
404     // Add Class Defaults to UI Defaults table
405     defaults.putDefaults(uiDefaults);
406   }
407
408   /**
409    * Initializes the component defaults for the Metal Look &amp; Feel.
410    *
411    * In particular this sets the following keys (the colors are given
412    * as RGB hex values):
413    *
414    * <table>
415    * <tr>
416    * <th>Key</th><th>Value</th>
417    * </tr><tr>
418    * <td>Button.background</td><td>0xcccccc</td>
419    * </tr><tr>
420    * <td>Button.border</td><td>{@link MetalBorders.ButtonBorder}</td>
421    * </tr><tr>
422    * <td>Button.font</td><td>{@link #getControlTextFont}</td>
423    * </tr><tr>
424    * <td>Button.margin</td><td><code>new java.awt.Insets(2, 14, 2, 14)</code>
425    * </td>
426    * </tr><tr>
427    * <td>CheckBox.background</td><td>0xcccccc</td>
428    * </tr><tr>
429    * <td>CheckBoxMenuItem.background</td><td>0xcccccc</td>
430    * </tr><tr>
431    * <td>ToolBar.background</td><td>0xcccccc</td>
432    * </tr><tr>
433    * <td>Panel.background</td><td>0xcccccc</td>
434    * </tr><tr>
435    * <td>Slider.background</td><td>0xcccccc</td>
436    * </tr><tr>
437    * <td>OptionPane.background</td><td>0xcccccc</td>
438    * </tr><tr>
439    * <td>ProgressBar.background</td><td>0xcccccc</td>
440    * </tr><tr>
441    * <td>TabbedPane.background</td><td>0xcccccc</td>
442    * </tr><tr>
443    * <td>Label.background</td><td>0xcccccc</td>
444    * </tr><tr>
445    * <td>Label.font</td><td>{@link #getControlTextFont}</td>
446    * </tr><tr>
447    * <td>Menu.background</td><td>0xcccccc</td>
448    * </tr><tr>
449    * <td>MenuBar.background</td><td>0xcccccc</td>
450    * </tr><tr>
451    * <td>MenuItem.background</td><td>0xcccccc</td>
452    * </tr><tr>
453    * <td>ScrollBar.background</td><td>0xcccccc</td>
454    * </tr><tr>
455    * <td>PopupMenu.border</td>
456    * <td><code>new javax.swing.plaf.metal.MetalBorders.PopupMenuBorder()</td>
457    * </tr><tr>
458    * </table>
459    *
460    * @param defaults the UIDefaults instance to which the values are added
461    */
462   protected void initComponentDefaults(UIDefaults defaults)
463   {
464     super.initComponentDefaults(defaults);
465     Object[] myDefaults = new Object[] {
466       "Button.background", new ColorUIResource(getControl()),
467       "Button.border", MetalBorders.getButtonBorder(),
468       "Button.font", getControlTextFont(),
469       "Button.margin", new Insets(2, 14, 2, 14),
470       "CheckBox.background", new ColorUIResource(getControl()),
471       "CheckBoxMenuItem.background", new ColorUIResource(getControl()),
472       "ToolBar.background", new ColorUIResource(getControl()),
473       "Panel.background", new ColorUIResource(getControl()),
474       "Slider.background", new ColorUIResource(getControl()),
475       "OptionPane.background", new ColorUIResource(getControl()),
476       "ProgressBar.background", new ColorUIResource(getControl()),
477       "ScrollPane.border", new MetalBorders.ScrollPaneBorder(),
478       "TabbedPane.background", new ColorUIResource(getControl()),
479       "Label.background", new ColorUIResource(getControl()),
480       "Label.font", getControlTextFont(),
481       "Menu.background", new ColorUIResource(getControl()),
482       "Menu.font", getControlTextFont(),
483       "MenuBar.background", new ColorUIResource(getControl()),
484       "MenuBar.font", getControlTextFont(),
485       "MenuItem.background", new ColorUIResource(getControl()),
486       "MenuItem.font", getControlTextFont(),
487       "ScrollBar.background", new ColorUIResource(getControl()),
488       "PopupMenu.border", new MetalBorders.PopupMenuBorder()
489     };
490     defaults.putDefaults(myDefaults);
491   }
492
493   /**
494    * Initializes the system color defaults.
495    *
496    * In particular this sets the following keys:
497    *
498    * <table>
499    * <tr>
500    * <th>Key</th><th>Value</th><th>Description</th>
501    * </tr><tr>
502    * <td>control</td><td>0xcccccc</td><td>The default color for components</td>
503    * </tr>
504    * </table>
505    */
506   protected void initSystemColorDefaults(UIDefaults defaults)
507   {
508     super.initSystemColorDefaults(defaults);
509     Object[] uiDefaults;
510     uiDefaults = new Object[] {
511       "control", new ColorUIResource(getControl())
512     };
513     defaults.putDefaults(uiDefaults);
514   }
515
516 }