1 /* DefaultMetalTheme.java --
2 Copyright (C) 2004, 2005 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., 51 Franklin Street, Fifth Floor, 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 gnu.classpath.SystemProperties;
45 import javax.swing.UIManager;
46 import javax.swing.plaf.ColorUIResource;
47 import javax.swing.plaf.FontUIResource;
50 * The default theme for the {@link MetalLookAndFeel}.
52 * @see MetalLookAndFeel#setCurrentTheme(MetalTheme)
54 public class DefaultMetalTheme extends MetalTheme
56 private static final ColorUIResource PRIMARY1 =
57 new ColorUIResource(102, 102, 153);
58 private static final ColorUIResource PRIMARY2 =
59 new ColorUIResource(153, 153, 204);
60 private static final ColorUIResource PRIMARY3 =
61 new ColorUIResource(204, 204, 255);
62 private static final ColorUIResource SECONDARY1 =
63 new ColorUIResource(102, 102, 102);
64 private static final ColorUIResource SECONDARY2 =
65 new ColorUIResource(153, 153, 153);
66 private static final ColorUIResource SECONDARY3 =
67 new ColorUIResource(204, 204, 204);
69 private static final FontUIResource SUB_TEXT_FONT =
70 new FontUIResource("Dialog", Font.PLAIN, 10);
71 private static final FontUIResource SYSTEM_TEXT_FONT =
72 new FontUIResource("Dialog", Font.PLAIN, 12);
73 private static final FontUIResource USER_TEXT_FONT =
74 new FontUIResource("Dialog", Font.PLAIN, 12);
75 private static final FontUIResource WINDOW_TITLE_FONT =
76 new FontUIResource("Dialog", Font.BOLD, 12);
79 * The control text font for swing.boldMetal=false.
81 private static final FontUIResource PLAIN_CONTROL_TEXT_FONT =
82 new FontUIResource("Dialog", Font.PLAIN, 12);
85 * The standard control text font.
87 private static final FontUIResource BOLD_CONTROL_TEXT_FONT =
88 new FontUIResource("Dialog", Font.BOLD, 12);
91 * The menu text font for swing.boldMetal=false.
93 private static final FontUIResource PLAIN_MENU_TEXT_FONT =
94 new FontUIResource("Dialog", Font.PLAIN, 12);
97 * The menu control text font.
99 private static final FontUIResource BOLD_MENU_TEXT_FONT =
100 new FontUIResource("Dialog", Font.BOLD, 12);
103 * Indicates the control text font.
105 static final int CONTROL_TEXT_FONT = 1;
108 * Indicates the menu text font.
110 static final int MENU_TEXT_FONT = 2;
113 * Creates a new instance of this theme.
115 public DefaultMetalTheme()
121 * Returns the name of the theme.
123 * @return <code>"Steel"</code>.
125 public String getName()
131 * Returns the first primary color for this theme.
133 * @return The first primary color.
135 protected ColorUIResource getPrimary1()
141 * Returns the second primary color for this theme.
143 * @return The second primary color.
145 protected ColorUIResource getPrimary2()
151 * Returns the third primary color for this theme.
153 * @return The third primary color.
155 protected ColorUIResource getPrimary3()
161 * Returns the first secondary color for this theme.
163 * @return The first secondary color.
165 protected ColorUIResource getSecondary1()
171 * Returns the second secondary color for this theme.
173 * @return The second secondary color.
175 protected ColorUIResource getSecondary2()
181 * Returns the third secondary color for this theme.
183 * @return The third secondary color.
185 protected ColorUIResource getSecondary3()
191 * Returns the font used for text on controls. In this case, the font is
192 * <code>FontUIResource("Dialog", Font.BOLD, 12)</code>, unless the
193 * <code>swing.boldMetal</code> UI default is set to {@link Boolean#FALSE}
194 * in which case it is <code>FontUIResource("Dialog", Font.PLAIN, 12)</code>.
198 public FontUIResource getControlTextFont()
200 return getFont(CONTROL_TEXT_FONT);
204 * Returns the font used for text in menus. In this case, the font is
205 * <code>FontUIResource("Dialog", Font.BOLD, 12)</code>, unless the
206 * <code>swing.boldMetal</code> UI default is set to {@link Boolean#FALSE}
207 * in which case it is <code>FontUIResource("Dialog", Font.PLAIN, 12)</code>.
209 * @return The font used for text in menus.
211 public FontUIResource getMenuTextFont()
213 return getFont(MENU_TEXT_FONT);
217 * Returns the font used for sub text. In this case, the font is
218 * <code>FontUIResource("Dialog", Font.PLAIN, 10)</code>.
220 * @return The font used for sub text.
222 public FontUIResource getSubTextFont()
224 return SUB_TEXT_FONT;
228 * Returns the font used for system text. In this case, the font is
229 * <code>FontUIResource("Dialog", Font.PLAIN, 12)</code>.
231 * @return The font used for system text.
233 public FontUIResource getSystemTextFont()
235 return SYSTEM_TEXT_FONT;
239 * Returns the font used for user text. In this case, the font is
240 * <code>FontUIResource("Dialog", Font.PLAIN, 12)</code>.
242 * @return The font used for user text.
244 public FontUIResource getUserTextFont()
246 return USER_TEXT_FONT;
250 * Returns the font used for window titles. In this case, the font is
251 * <code>FontUIResource("Dialog", Font.BOLD, 12)</code>.
253 * @return The font used for window titles.
255 public FontUIResource getWindowTitleFont()
257 return WINDOW_TITLE_FONT;
261 * Returns the appropriate font. The font type to return is identified
262 * by the specified id.
264 * @param id the font type to return
266 * @return the correct font
268 private FontUIResource getFont(int id)
270 FontUIResource font = null;
273 case CONTROL_TEXT_FONT:
275 font = BOLD_CONTROL_TEXT_FONT;
277 font = PLAIN_CONTROL_TEXT_FONT;
281 font = BOLD_MENU_TEXT_FONT;
283 font = PLAIN_MENU_TEXT_FONT;
285 // TODO: Add other font types and their mapping here.
291 * Determines if the theme should be bold or not. The theme is bold by
292 * default, this can be turned off by setting the system property
293 * swing.boldMetal to true, or by putting the property with the same name
294 * into the current UIManager's defaults.
296 * @return <code>true</code>, when the theme is bold, <code>false</code>
299 private boolean isBoldMetal()
301 Object boldMetal = UIManager.get("swing.boldMetal");
302 return (boldMetal == null || ! Boolean.FALSE.equals(boldMetal))
303 && ! ("false".equals(SystemProperties.getProperty("swing.boldMetal")));