1 30 31 package com.jgoodies.looks; 32 33 import java.awt.Dimension ; 34 import java.util.HashMap ; 35 import java.util.Map ; 36 37 import javax.swing.UIManager ; 38 39 import com.jgoodies.looks.common.ShadowPopup; 40 41 49 50 public final class Options { 51 52 54 public static final String PLASTIC_NAME = 55 "com.jgoodies.looks.plastic.PlasticLookAndFeel"; 56 57 public static final String PLASTIC3D_NAME = 58 "com.jgoodies.looks.plastic.Plastic3DLookAndFeel"; 59 60 public static final String PLASTICXP_NAME = 61 "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"; 62 63 public static final String JGOODIES_WINDOWS_NAME = 64 "com.jgoodies.looks.windows.WindowsLookAndFeel"; 65 66 71 public static final String EXT_WINDOWS_NAME = 72 JGOODIES_WINDOWS_NAME; 73 74 public static final String DEFAULT_LOOK_NAME = 75 PLASTIC3D_NAME; 76 77 82 private static final Map LAF_REPLACEMENTS; 83 static { 84 LAF_REPLACEMENTS = new HashMap (); 85 initializeDefaultReplacements(); 86 } 87 88 89 91 public static final String MENU_FONT_KEY = 92 "jgoodies.menuFont"; 93 94 public static final String CONTROL_FONT_KEY = 95 "jgoodies.controlFont"; 96 97 public static final String FONT_SIZE_HINTS_KEY = 98 "jgoodies.fontSizeHints"; 99 100 public static final String USE_SYSTEM_FONTS_KEY = 101 "swing.useSystemFontSettings"; 102 103 public static final String USE_SYSTEM_FONTS_APP_KEY = 104 "Application.useSystemFontSettings"; 105 106 107 109 public static final String DEFAULT_ICON_SIZE_KEY = 110 "jgoodies.defaultIconSize"; 111 112 public static final String USE_NARROW_BUTTONS_KEY = 113 "jgoodies.useNarrowButtons"; 114 115 public static final String TAB_ICONS_ENABLED_KEY = 116 "jgoodies.tabIconsEnabled"; 117 118 public static final String POPUP_DROP_SHADOW_ENABLED_KEY = 119 "jgoodies.popupDropShadowEnabled"; 120 121 122 124 127 public static final String IS_NARROW_KEY = "jgoodies.isNarrow"; 128 129 132 public static final String IS_ETCHED_KEY = "jgoodies.isEtched"; 133 134 137 public static final String HEADER_STYLE_KEY = "jgoodies.headerStyle"; 138 139 142 public static final String NO_ICONS_KEY = "jgoodies.noIcons"; 143 144 148 public static final String TREE_LINE_STYLE_KEY = 149 "JTree.lineStyle"; 150 151 155 public static final String TREE_LINE_STYLE_ANGLED_VALUE = 156 "Angled"; 157 158 162 public static final String TREE_LINE_STYLE_NONE_VALUE = 163 "None"; 164 165 171 public static final String NO_CONTENT_BORDER_KEY = 172 "jgoodies.noContentBorder"; 173 174 180 public static final String EMBEDDED_TABS_KEY = 181 "jgoodies.embeddedTabs"; 182 183 184 186 193 private static final Boolean TAB_ICONS_ENABLED_SYSTEM_VALUE = 194 LookUtils.getBooleanSystemProperty( 195 TAB_ICONS_ENABLED_KEY, "Icons in tabbed panes"); 196 197 198 211 private static final Boolean POPUP_DROP_SHADOW_ENABLED_SYSTEM_VALUE = 212 LookUtils.getBooleanSystemProperty( 213 POPUP_DROP_SHADOW_ENABLED_KEY, "Popup drop shadows"); 214 215 216 218 private static final Dimension DEFAULT_ICON_SIZE = 219 new Dimension (20, 20); 220 221 private Options() { 222 } 224 225 226 228 235 public static boolean getUseSystemFonts() { 236 return UIManager.get(USE_SYSTEM_FONTS_APP_KEY).equals(Boolean.TRUE); 237 } 238 239 246 public static void setUseSystemFonts(boolean useSystemFonts) { 247 UIManager.put(USE_SYSTEM_FONTS_APP_KEY, Boolean.valueOf(useSystemFonts)); 248 } 249 250 258 public static Dimension getDefaultIconSize() { 259 Dimension size = UIManager.getDimension(DEFAULT_ICON_SIZE_KEY); 260 return size == null ? DEFAULT_ICON_SIZE : size; 261 } 262 263 269 public static void setDefaultIconSize(Dimension defaultIconSize) { 270 UIManager.put(DEFAULT_ICON_SIZE_KEY, defaultIconSize); 271 } 272 273 280 public static FontSizeHints getGlobalFontSizeHints() { 281 Object value = UIManager.get(FONT_SIZE_HINTS_KEY); 282 if (value != null) 283 return (FontSizeHints) value; 284 285 String name = LookUtils.getSystemProperty(FONT_SIZE_HINTS_KEY, ""); 286 try { 287 return FontSizeHints.valueOf(name); 288 } catch (IllegalArgumentException e) { 289 return FontSizeHints.DEFAULT; 290 } 291 } 292 293 299 public static void setGlobalFontSizeHints(FontSizeHints hints) { 300 UIManager.put(FONT_SIZE_HINTS_KEY, hints); 301 } 302 303 317 public static boolean getUseNarrowButtons() { 318 return UIManager.getBoolean(USE_NARROW_BUTTONS_KEY); 319 } 320 321 327 public static void setUseNarrowButtons(boolean b) { 328 UIManager.put(USE_NARROW_BUTTONS_KEY, Boolean.valueOf(b)); 329 } 330 331 339 public static boolean isTabIconsEnabled() { 340 return TAB_ICONS_ENABLED_SYSTEM_VALUE == null 341 ? !Boolean.FALSE.equals(UIManager.get(TAB_ICONS_ENABLED_KEY)) 342 : TAB_ICONS_ENABLED_SYSTEM_VALUE.booleanValue(); 343 } 344 345 351 public static void setTabIconsEnabled(boolean b) { 352 UIManager.put(TAB_ICONS_ENABLED_KEY, Boolean.valueOf(b)); 353 } 354 355 356 375 public static boolean isPopupDropShadowActive() { 376 boolean toolkitUsesNativeDropShadows = 377 LookUtils.IS_OS_MAC; 378 379 return !toolkitUsesNativeDropShadows 380 && ShadowPopup.canSnapshot() 381 && isPopupDropShadowEnabled(); 382 } 383 384 393 public static boolean isPopupDropShadowEnabled() { 394 if (POPUP_DROP_SHADOW_ENABLED_SYSTEM_VALUE != null) 395 return POPUP_DROP_SHADOW_ENABLED_SYSTEM_VALUE.booleanValue(); 396 397 Object value = UIManager.get(POPUP_DROP_SHADOW_ENABLED_KEY); 398 return value == null 399 ? isPopupDropShadowEnabledDefault() 400 : Boolean.TRUE.equals(value); 401 } 402 403 416 public static void setPopupDropShadowEnabled(boolean b) { 417 UIManager.put(POPUP_DROP_SHADOW_ENABLED_KEY, Boolean.valueOf(b)); 418 } 419 420 434 private static boolean isPopupDropShadowEnabledDefault() { 435 return LookUtils.IS_OS_WINDOWS_MODERN; 436 } 437 438 439 441 450 public static void putLookAndFeelReplacement( 451 String original, 452 String replacement) { 453 LAF_REPLACEMENTS.put(original, replacement); 454 } 455 456 464 public static void removeLookAndFeelReplacement(String original) { 465 LAF_REPLACEMENTS.remove(original); 466 } 467 468 477 public static void initializeDefaultReplacements() { 478 putLookAndFeelReplacement( 479 "javax.swing.plaf.metal.MetalLookAndFeel", 480 PLASTIC3D_NAME); 481 putLookAndFeelReplacement( 482 "com.sun.java.swing.plaf.windows.WindowsLookAndFeel", 483 JGOODIES_WINDOWS_NAME); 484 } 485 486 496 public static String getReplacementClassNameFor(String className) { 497 String replacement = (String ) LAF_REPLACEMENTS.get(className); 498 return replacement == null ? className : replacement; 499 } 500 501 507 public static String getCrossPlatformLookAndFeelClassName() { 508 return PLASTIC3D_NAME; 509 } 510 511 517 public static String getSystemLookAndFeelClassName() { 518 String osName = System.getProperty("os.name"); 519 if (osName.startsWith("Windows")) 520 return Options.JGOODIES_WINDOWS_NAME; 521 else if (osName.startsWith("Mac")) 522 return UIManager.getSystemLookAndFeelClassName(); 523 else 524 return getCrossPlatformLookAndFeelClassName(); 525 } 526 527 } | Popular Tags |