001 /* DefaultMetalTheme.java -- 002 Copyright (C) 2004, 2005 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package javax.swing.plaf.metal; 040 041 import gnu.classpath.SystemProperties; 042 043 import java.awt.Font; 044 045 import javax.swing.UIManager; 046 import javax.swing.plaf.ColorUIResource; 047 import javax.swing.plaf.FontUIResource; 048 049 /** 050 * The default theme for the {@link MetalLookAndFeel}. 051 * 052 * @see MetalLookAndFeel#setCurrentTheme(MetalTheme) 053 */ 054 public class DefaultMetalTheme extends MetalTheme 055 { 056 private static final ColorUIResource PRIMARY1 = 057 new ColorUIResource(102, 102, 153); 058 private static final ColorUIResource PRIMARY2 = 059 new ColorUIResource(153, 153, 204); 060 private static final ColorUIResource PRIMARY3 = 061 new ColorUIResource(204, 204, 255); 062 private static final ColorUIResource SECONDARY1 = 063 new ColorUIResource(102, 102, 102); 064 private static final ColorUIResource SECONDARY2 = 065 new ColorUIResource(153, 153, 153); 066 private static final ColorUIResource SECONDARY3 = 067 new ColorUIResource(204, 204, 204); 068 069 private static final FontUIResource SUB_TEXT_FONT = 070 new FontUIResource("Dialog", Font.PLAIN, 10); 071 private static final FontUIResource SYSTEM_TEXT_FONT = 072 new FontUIResource("Dialog", Font.PLAIN, 12); 073 private static final FontUIResource USER_TEXT_FONT = 074 new FontUIResource("Dialog", Font.PLAIN, 12); 075 private static final FontUIResource WINDOW_TITLE_FONT = 076 new FontUIResource("Dialog", Font.BOLD, 12); 077 078 /** 079 * The control text font for swing.boldMetal=false. 080 */ 081 private static final FontUIResource PLAIN_CONTROL_TEXT_FONT = 082 new FontUIResource("Dialog", Font.PLAIN, 12); 083 084 /** 085 * The standard control text font. 086 */ 087 private static final FontUIResource BOLD_CONTROL_TEXT_FONT = 088 new FontUIResource("Dialog", Font.BOLD, 12); 089 090 /** 091 * The menu text font for swing.boldMetal=false. 092 */ 093 private static final FontUIResource PLAIN_MENU_TEXT_FONT = 094 new FontUIResource("Dialog", Font.PLAIN, 12); 095 096 /** 097 * The menu control text font. 098 */ 099 private static final FontUIResource BOLD_MENU_TEXT_FONT = 100 new FontUIResource("Dialog", Font.BOLD, 12); 101 102 /** 103 * Indicates the control text font. 104 */ 105 static final int CONTROL_TEXT_FONT = 1; 106 107 /** 108 * Indicates the menu text font. 109 */ 110 static final int MENU_TEXT_FONT = 2; 111 112 /** 113 * Creates a new instance of this theme. 114 */ 115 public DefaultMetalTheme() 116 { 117 // Do nothing here. 118 } 119 120 /** 121 * Returns the name of the theme. 122 * 123 * @return <code>"Steel"</code>. 124 */ 125 public String getName() 126 { 127 return "Steel"; 128 } 129 130 /** 131 * Returns the first primary color for this theme. 132 * 133 * @return The first primary color. 134 */ 135 protected ColorUIResource getPrimary1() 136 { 137 return PRIMARY1; 138 } 139 140 /** 141 * Returns the second primary color for this theme. 142 * 143 * @return The second primary color. 144 */ 145 protected ColorUIResource getPrimary2() 146 { 147 return PRIMARY2; 148 } 149 150 /** 151 * Returns the third primary color for this theme. 152 * 153 * @return The third primary color. 154 */ 155 protected ColorUIResource getPrimary3() 156 { 157 return PRIMARY3; 158 } 159 160 /** 161 * Returns the first secondary color for this theme. 162 * 163 * @return The first secondary color. 164 */ 165 protected ColorUIResource getSecondary1() 166 { 167 return SECONDARY1; 168 } 169 170 /** 171 * Returns the second secondary color for this theme. 172 * 173 * @return The second secondary color. 174 */ 175 protected ColorUIResource getSecondary2() 176 { 177 return SECONDARY2; 178 } 179 180 /** 181 * Returns the third secondary color for this theme. 182 * 183 * @return The third secondary color. 184 */ 185 protected ColorUIResource getSecondary3() 186 { 187 return SECONDARY3; 188 } 189 190 /** 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>. 195 * 196 * @return The font. 197 */ 198 public FontUIResource getControlTextFont() 199 { 200 return getFont(CONTROL_TEXT_FONT); 201 } 202 203 /** 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>. 208 * 209 * @return The font used for text in menus. 210 */ 211 public FontUIResource getMenuTextFont() 212 { 213 return getFont(MENU_TEXT_FONT); 214 } 215 216 /** 217 * Returns the font used for sub text. In this case, the font is 218 * <code>FontUIResource("Dialog", Font.PLAIN, 10)</code>. 219 * 220 * @return The font used for sub text. 221 */ 222 public FontUIResource getSubTextFont() 223 { 224 return SUB_TEXT_FONT; 225 } 226 227 /** 228 * Returns the font used for system text. In this case, the font is 229 * <code>FontUIResource("Dialog", Font.PLAIN, 12)</code>. 230 * 231 * @return The font used for system text. 232 */ 233 public FontUIResource getSystemTextFont() 234 { 235 return SYSTEM_TEXT_FONT; 236 } 237 238 /** 239 * Returns the font used for user text. In this case, the font is 240 * <code>FontUIResource("Dialog", Font.PLAIN, 12)</code>. 241 * 242 * @return The font used for user text. 243 */ 244 public FontUIResource getUserTextFont() 245 { 246 return USER_TEXT_FONT; 247 } 248 249 /** 250 * Returns the font used for window titles. In this case, the font is 251 * <code>FontUIResource("Dialog", Font.BOLD, 12)</code>. 252 * 253 * @return The font used for window titles. 254 */ 255 public FontUIResource getWindowTitleFont() 256 { 257 return WINDOW_TITLE_FONT; 258 } 259 260 /** 261 * Returns the appropriate font. The font type to return is identified 262 * by the specified id. 263 * 264 * @param id the font type to return 265 * 266 * @return the correct font 267 */ 268 private FontUIResource getFont(int id) 269 { 270 FontUIResource font = null; 271 switch (id) 272 { 273 case CONTROL_TEXT_FONT: 274 if (isBoldMetal()) 275 font = BOLD_CONTROL_TEXT_FONT; 276 else 277 font = PLAIN_CONTROL_TEXT_FONT; 278 break; 279 case MENU_TEXT_FONT: 280 if (isBoldMetal()) 281 font = BOLD_MENU_TEXT_FONT; 282 else 283 font = PLAIN_MENU_TEXT_FONT; 284 break; 285 // TODO: Add other font types and their mapping here. 286 } 287 return font; 288 } 289 290 /** 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. 295 * 296 * @return <code>true</code>, when the theme is bold, <code>false</code> 297 * otherwise 298 */ 299 private boolean isBoldMetal() 300 { 301 Object boldMetal = UIManager.get("swing.boldMetal"); 302 return (boldMetal == null || ! Boolean.FALSE.equals(boldMetal)) 303 && ! ("false".equals(SystemProperties.getProperty("swing.boldMetal"))); 304 } 305 }