1 /* MetalLookAndFeel.java
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
39 package javax.swing.plaf.metal;
41 import java.awt.Color;
42 import java.awt.Insets;
44 import javax.swing.UIDefaults;
45 import javax.swing.plaf.ColorUIResource;
46 import javax.swing.plaf.FontUIResource;
47 import javax.swing.plaf.basic.BasicLookAndFeel;
49 public class MetalLookAndFeel extends BasicLookAndFeel
51 private static final long serialVersionUID = 6680646159193457980L;
52 private static MetalTheme theme;
53 private UIDefaults LAF_defaults;
55 public MetalLookAndFeel()
60 protected void createDefaultTheme()
62 setCurrentTheme(new DefaultMetalTheme());
65 public boolean isNativeLookAndFeel()
70 public boolean isSupportedLookAndFeel()
75 public String getDescription()
77 return "Metal look and feel";
82 return "MetalLookAndFeel";
85 public String getName()
87 return "MetalLookAndFeel";
90 public UIDefaults getDefaults()
92 if (LAF_defaults == null)
93 LAF_defaults = super.getDefaults();
95 // add custom theme entries to the table
96 theme.addCustomEntriesToTable(LAF_defaults);
98 // Returns the default values for this look and feel.
102 public static ColorUIResource getAcceleratorForeground()
104 return theme.getAcceleratorForeground();
107 public static ColorUIResource getAcceleratorSelectedForeground()
109 return theme.getAcceleratorSelectedForeground();
112 public static ColorUIResource getBlack()
114 return theme.getBlack();
117 public static ColorUIResource getControl()
119 return theme.getControl();
122 public static ColorUIResource getControlDarkShadow()
124 return theme.getControlDarkShadow();
127 public static ColorUIResource getControlDisabled()
129 return theme.getControlDisabled();
132 public static ColorUIResource getControlHighlight()
134 return theme.getControlHighlight();
137 public static ColorUIResource getControlInfo()
139 return theme.getControlInfo();
142 public static ColorUIResource getControlShadow()
144 return theme.getControlShadow();
147 public static ColorUIResource getControlTextColor()
149 return theme.getControlTextColor();
152 public static FontUIResource getControlTextFont()
154 return theme.getControlTextFont();
157 public static ColorUIResource getDesktopColor()
159 return theme.getDesktopColor();
162 public static ColorUIResource getFocusColor()
164 return theme.getFocusColor();
167 public static ColorUIResource getHighlightedTextColor()
169 return theme.getHighlightedTextColor();
172 public static ColorUIResource getInactiveControlTextColor()
174 return theme.getInactiveControlTextColor();
177 public static ColorUIResource getInactiveSystemTextColor()
179 return theme.getInactiveSystemTextColor();
182 public static ColorUIResource getMenuBackground()
184 return theme.getMenuBackground();
187 public static ColorUIResource getMenuDisabledForeground()
189 return theme.getMenuDisabledForeground();
192 public static ColorUIResource getMenuForeground()
194 return theme.getMenuForeground();
197 public static ColorUIResource getMenuSelectedBackground()
199 return theme.getMenuSelectedBackground();
202 public static ColorUIResource getMenuSelectedForeground()
204 return theme.getMenuSelectedForeground();
207 public static FontUIResource getMenuTextFont()
209 return theme.getMenuTextFont();
212 public static ColorUIResource getPrimaryControl()
214 return theme.getPrimaryControl();
217 public static ColorUIResource getPrimaryControlDarkShadow()
219 return theme.getPrimaryControlDarkShadow();
222 public static ColorUIResource getPrimaryControlHighlight()
224 return theme.getPrimaryControlHighlight();
227 public static ColorUIResource getPrimaryControlInfo()
229 return theme.getPrimaryControlInfo();
232 public static ColorUIResource getPrimaryControlShadow()
234 return theme.getPrimaryControlShadow();
237 public static ColorUIResource getSeparatorBackground()
239 return theme.getSeparatorBackground();
242 public static ColorUIResource getSeparatorForeground()
244 return theme.getSeparatorForeground();
247 public static FontUIResource getSubTextFont()
249 return theme.getSubTextFont();
252 public static ColorUIResource getSystemTextColor()
254 return theme.getSystemTextColor();
257 public static FontUIResource getSystemTextFont()
259 return theme.getSystemTextFont();
262 public static ColorUIResource getTextHighlightColor()
264 return theme.getTextHighlightColor();
267 public static ColorUIResource getUserTextColor()
269 return theme.getUserTextColor();
272 public static FontUIResource getUserTextFont()
274 return theme.getUserTextFont();
277 public static ColorUIResource getWhite()
279 return theme.getWhite();
282 public static ColorUIResource getWindowBackground()
284 return theme.getWindowBackground();
287 public static ColorUIResource getWindowTitleBackground()
289 return theme.getWindowTitleBackground();
292 public static FontUIResource getWindowTitleFont()
294 return theme.getWindowTitleFont();
297 public static ColorUIResource getWindowTitleForeground()
299 return theme.getWindowTitleForeground();
302 public static ColorUIResource getWindowTitleInactiveBackground()
304 return theme.getWindowTitleInactiveBackground();
307 public static ColorUIResource getWindowTitleInactiveForeground()
309 return theme.getWindowTitleInactiveForeground();
312 public static void setCurrentTheme(MetalTheme theme)
314 MetalLookAndFeel.theme = theme;
318 * Sets the ComponentUI classes for all Swing components to the Metal
321 * In particular this sets the following keys:
325 * <th>Key</th><th>Value</th>
327 * <td>ButtonUI</td><td>{@link MetalButtonUI}</td>
329 * <td>CheckBoxUI</td><td>{@link MetalCheckBoxUI}</td>
331 * <td>ComboBoxUI</td><td>{@link MetalComboBoxUI}</td>
333 * <td>DesktopIconUI</td><td>{@link MetalDesktopIconUI}</td>
335 * <td>InternalFrameUI</td><td>{@link MetalInternalFrameUI}</td>
337 * <td>LabelUI</td><td>{@link MetalLabelUI}</td>
339 * <td>PopupMenuSeparatorUI</td><td>{@link MetalPopupMenuSeparatorUI}</td>
341 * <td>ProgressBarUI</td><td>{@link MetalProgressBarUI}</td>
343 * <td>RadioButtonUI</td><td>{@link MetalRadioButtonUI}</td>
345 * <td>RootPaneUI</td><td>{@link MetalRootPaneUI}</td>
347 * <td>ScrollBarUI</td><td>{@link MetalScrollBarUI}</td>
349 * <td>ScrollPaneUI</td><td>{@link MetalScrollPaneUI}</td>
351 * <td>SeparatorUI</td><td>{@link MetalSeparatorUI}</td>
353 * <td>SliderUI</td><td>{@link MetalSliderUI}</td>
355 * <td>SplitPaneUI</td><td>{@link MetalSplitPaneUI}</td>
357 * <td>TabbedPaneUI</td><td>{@link MetalTabbedPaneUI}</td>
359 * <td>TextFieldUI</td><td>{@link MetalTextFieldUI}</td>
361 * <td>ToggleButtonUI</td><td>{@link MetalToggleButtonUI}</td>
363 * <td>ToolBarUI</td><td>{@link MetalToolBarUI}</td>
365 * <td>ToolTipUI</td><td>{@link MetalToolTipUI}</td>
367 * <td>TreeUI</td><td>{@link MetalTreeUI}</td>
371 * @param defaults the UIDefaults where the class defaults are added
373 protected void initClassDefaults(UIDefaults defaults)
375 super.initClassDefaults(defaults);
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",
404 // Add Class Defaults to UI Defaults table
405 defaults.putDefaults(uiDefaults);
409 * Initializes the component defaults for the Metal Look & Feel.
411 * In particular this sets the following keys (the colors are given
412 * as RGB hex values):
416 * <th>Key</th><th>Value</th>
418 * <td>Button.background</td><td>0xcccccc</td>
420 * <td>Button.border</td><td>{@link MetalBorders.ButtonBorder}</td>
422 * <td>Button.font</td><td>{@link #getControlTextFont}</td>
424 * <td>Button.margin</td><td><code>new java.awt.Insets(2, 14, 2, 14)</code>
427 * <td>CheckBox.background</td><td>0xcccccc</td>
429 * <td>CheckBoxMenuItem.background</td><td>0xcccccc</td>
431 * <td>ToolBar.background</td><td>0xcccccc</td>
433 * <td>Panel.background</td><td>0xcccccc</td>
435 * <td>Slider.background</td><td>0xcccccc</td>
437 * <td>OptionPane.background</td><td>0xcccccc</td>
439 * <td>ProgressBar.background</td><td>0xcccccc</td>
441 * <td>TabbedPane.background</td><td>0xcccccc</td>
443 * <td>Label.background</td><td>0xcccccc</td>
445 * <td>Label.font</td><td>{@link #getControlTextFont}</td>
447 * <td>Menu.background</td><td>0xcccccc</td>
449 * <td>MenuBar.background</td><td>0xcccccc</td>
451 * <td>MenuItem.background</td><td>0xcccccc</td>
453 * <td>ScrollBar.background</td><td>0xcccccc</td>
455 * <td>PopupMenu.border</td>
456 * <td><code>new javax.swing.plaf.metal.MetalBorders.PopupMenuBorder()</td>
460 * @param defaults the UIDefaults instance to which the values are added
462 protected void initComponentDefaults(UIDefaults defaults)
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()
490 defaults.putDefaults(myDefaults);
494 * Initializes the system color defaults.
496 * In particular this sets the following keys:
500 * <th>Key</th><th>Value</th><th>Description</th>
502 * <td>control</td><td>0xcccccc</td><td>The default color for components</td>
506 protected void initSystemColorDefaults(UIDefaults defaults)
508 super.initSystemColorDefaults(defaults);
510 uiDefaults = new Object[] {
511 "control", new ColorUIResource(getControl())
513 defaults.putDefaults(uiDefaults);