001: /*
002: * Copyright (c) 2001-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.looks;
032:
033: import java.awt.Dimension;
034: import java.util.HashMap;
035: import java.util.Map;
036:
037: import javax.swing.UIManager;
038:
039: import com.jgoodies.looks.common.ShadowPopup;
040: import com.jgoodies.looks.plastic.PlasticLookAndFeel;
041: import com.jgoodies.looks.windows.WindowsLookAndFeel;
042: import com.sun.java.swing.plaf.windows.WindowsComboBoxUI;
043:
044: /**
045: * Provides access to optional features of the JGoodies L&Fs
046: * via a key to the system properties, via a key for the <code>UIDefaults</code>
047: * table, via a method, or all of them.<p>
048: *
049: * API users can use this class' constants or their values to configure
050: * the JGoodies L&amP;f. Using the constants requires the Looks library
051: * classes in the class path of the using application/applet, where using
052: * the String values doesn't require having this class in the class path.
053: *
054: * @author Karsten Lentzsch
055: * @version $Revision: 1.16 $
056: */
057: public final class Options {
058:
059: // Look & Feel Names ******************************************************
060:
061: /**
062: * The class name of the JGoodies Plastic L&f.
063: */
064: public static final String PLASTIC_NAME = "com.jgoodies.looks.plastic.PlasticLookAndFeel";
065:
066: /**
067: * The class name of the JGoodies Plastic3D L&f.
068: */
069: public static final String PLASTIC3D_NAME = "com.jgoodies.looks.plastic.Plastic3DLookAndFeel";
070:
071: /**
072: * The class name of the JGoodies PlasticXP L&f.
073: */
074: public static final String PLASTICXP_NAME = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel";
075:
076: /**
077: * The class name of the JGoodies Windows L&f.
078: */
079: public static final String JGOODIES_WINDOWS_NAME = "com.jgoodies.looks.windows.WindowsLookAndFeel";
080:
081: /**
082: * The class name of the default JGoodies L&f, PlasticXP.
083: */
084: public static final String DEFAULT_LOOK_NAME = PLASTICXP_NAME;
085:
086: /**
087: * Holds a Map that enables the look&feel replacement
088: * mechanism to replace one look by another.
089: * Maps the original class names to their replacement class names.
090: *
091: * @see #getReplacementClassNameFor(String)
092: * @see #putLookAndFeelReplacement(String, String)
093: * @see #removeLookAndFeelReplacement(String)
094: */
095: private static final Map LAF_REPLACEMENTS;
096: static {
097: LAF_REPLACEMENTS = new HashMap();
098: initializeDefaultReplacements();
099: }
100:
101: // Keys for Overriding Font Settings **************************************
102:
103: /**
104: * A key for setting a custom FontPolicy for the Plastic L&fs.
105: * Used for both the system properties and the UIDefaults table.
106: *
107: * @see PlasticLookAndFeel#getFontPolicy()
108: * @see PlasticLookAndFeel#setFontPolicy(FontPolicy)
109: */
110: public static final String PLASTIC_FONT_POLICY_KEY = "Plastic.fontPolicy";
111:
112: /**
113: * A key for setting the default control font in Plastic L&fs.
114: * Used for both the system properties and the UIDefaults table.
115: *
116: * @see FontPolicies#customSettingsPolicy(FontPolicy)
117: */
118: public static final String PLASTIC_CONTROL_FONT_KEY = "Plastic.controlFont";
119:
120: /**
121: * A key for setting the default menu font in Plastic L&fs.
122: * Used for both the system properties and the UIDefaults table.
123: *
124: * @see FontPolicies#customSettingsPolicy(FontPolicy)
125: */
126: public static final String PLASTIC_MENU_FONT_KEY = "Plastic.menuFont";
127:
128: /**
129: * A key for setting a custom FontPolicy for the Windows L&fs.
130: * Used for both the system properties and the UIDefaults table.
131: *
132: * @see WindowsLookAndFeel#getFontPolicy()
133: * @see WindowsLookAndFeel#setFontPolicy(FontPolicy)
134: */
135: public static final String WINDOWS_FONT_POLICY_KEY = "Windows.fontPolicy";
136:
137: /**
138: * A key for setting the default control font in the Windows L&f.
139: * Used for both the system properties and the UIDefaults table.
140: *
141: * @see FontPolicies#customSettingsPolicy(FontPolicy)
142: */
143: public static final String WINDOWS_CONTROL_FONT_KEY = "Windows.controlFont";
144:
145: /**
146: * A key for setting the default menu font in the Windows L&f.
147: * Used for both the system properties and the UIDefaults table.
148: *
149: * @see FontPolicies#customSettingsPolicy(FontPolicy)
150: */
151: public static final String WINDOWS_MENU_FONT_KEY = "Windows.menuFont";
152:
153: /**
154: * A convenience constant for the standard Swing system property key
155: * that configures the use of system fonts.
156: *
157: * @see #getUseSystemFonts()
158: * @see #setUseSystemFonts(boolean)
159: */
160: public static final String USE_SYSTEM_FONTS_KEY = "swing.useSystemFontSettings";
161:
162: /**
163: * A convenience constant for the standard Swing UIDefaults key
164: * that configures the use of system fonts.
165: *
166: * @see #getUseSystemFonts()
167: * @see #setUseSystemFonts(boolean)
168: */
169: public static final String USE_SYSTEM_FONTS_APP_KEY = "Application.useSystemFontSettings";
170:
171: // Keys for Micro Layout Policies *****************************************
172:
173: /**
174: * A UIManager key for setting a custom MicroLayoutPolicy
175: * for the Plastic L&fs.
176: *
177: * @see PlasticLookAndFeel#getMicroLayoutPolicy()
178: * @see PlasticLookAndFeel#setMicroLayoutPolicy(MicroLayout)
179: */
180: public static final String PLASTIC_MICRO_LAYOUT_POLICY_KEY = "Plastic.MicroLayoutPolicy";
181:
182: /**
183: * A UIManager key for setting a custom MicroLayoutPolicy
184: * for the Windows L&f.
185: *
186: * @see WindowsLookAndFeel#getMicroLayoutPolicy()
187: * @see WindowsLookAndFeel#setMicroLayoutPolicy(MicroLayout)
188: */
189: public static final String WINDOWS_MICRO_LAYOUT_POLICY_KEY = "Windows.MicroLayoutPolicy";
190:
191: // Optional Global User Properties ****************************************
192:
193: public static final String DEFAULT_ICON_SIZE_KEY = "jgoodies.defaultIconSize";
194:
195: public static final String USE_NARROW_BUTTONS_KEY = "jgoodies.useNarrowButtons";
196:
197: public static final String TAB_ICONS_ENABLED_KEY = "jgoodies.tabIconsEnabled";
198:
199: /**
200: * A UIDefaults key for the popup drop shadow enablement.
201: *
202: * @see #isPopupDropShadowEnabled()
203: * @see #setPopupDropShadowEnabled(boolean)
204: */
205: public static final String POPUP_DROP_SHADOW_ENABLED_KEY = "jgoodies.popupDropShadowEnabled";
206:
207: /**
208: * A UIDefaults key for enabling/disabling the new high-resolution
209: * gray filter.
210: *
211: * @since 2.1
212: */
213: public static final String HI_RES_GRAY_FILTER_ENABLED_KEY = "HiResGrayFilterEnabled";
214:
215: // Optional Client Properties *********************************************
216:
217: /**
218: * A JScrollPane client property key for a hint
219: * that the scroll pane border should be etched.
220: */
221: public static final String IS_ETCHED_KEY = "jgoodies.isEtched";
222:
223: /**
224: * A client property key for JMenuBar and JToolBar style hints.
225: * Available styles are: <code>HeaderStyle.Single</code> and
226: * <code>HeaderStyle.Both</code>.
227: *
228: * @see HeaderStyle
229: * @see BorderStyle
230: */
231: public static final String HEADER_STYLE_KEY = "jgoodies.headerStyle";
232:
233: /**
234: * A JMenu client property key for a hint
235: * that the menu items in the menu have no icons.
236: */
237: public static final String NO_ICONS_KEY = "jgoodies.noIcons";
238:
239: /**
240: * A JPopupMenu client property key for a hint that the border
241: * shall have no extra margin. This is useful if the popup menu
242: * contains only a single component, for example a scrollpane.
243: */
244: public static final String NO_MARGIN_KEY = "JPopupMenu.noMargin";
245:
246: /**
247: * A JTree client property key for a tree line style hint.
248: *
249: * @see #TREE_LINE_STYLE_ANGLED_VALUE
250: * @see #TREE_LINE_STYLE_NONE_VALUE
251: */
252: public static final String TREE_LINE_STYLE_KEY = "JTree.lineStyle";
253:
254: /**
255: * A JTree client property value that indicates that lines shall be drawn.
256: *
257: * @see #TREE_LINE_STYLE_KEY
258: */
259: public static final String TREE_LINE_STYLE_ANGLED_VALUE = "Angled";
260:
261: /**
262: * A JTree client property value that indicates that lines shall be hidden.
263: *
264: * @see #TREE_LINE_STYLE_KEY
265: */
266: public static final String TREE_LINE_STYLE_NONE_VALUE = "None";
267:
268: /**
269: * A JTabbedPane client property key that indicates
270: * that no content border shall be painted.
271: * Supported by the JGoodies Windows L&f and the
272: * JGoodies Plastic look&feel family.
273: * This effect will be achieved also if the EMBEDDED property is true.
274: */
275: public static final String NO_CONTENT_BORDER_KEY = "jgoodies.noContentBorder";
276:
277: /**
278: * A JTabbedPane client property key that indicates
279: * that tabs are painted with a special embedded appearance.
280: * Supported by the JGoodies Windows L&f and the
281: * JGoodies Plastic look&feel family.
282: * As a side effect of the embedded appearance,
283: * supporting L&fs won't paint the content border.
284: */
285: public static final String EMBEDDED_TABS_KEY = "jgoodies.embeddedTabs";
286:
287: /**
288: * A JComboBox client property key for the combo's
289: * popup menu prototype display value. If this key is set,
290: * the value will be used to compute the combo popup width.
291: * This optional feature is supported by the JGoodies Windows L&f
292: * as well as the JGoodies Plastic L&fs.
293: */
294: public static final String COMBO_POPUP_PROTOTYPE_DISPLAY_VALUE_KEY = "ComboBox.popupPrototypeDisplayValue";
295:
296: /**
297: * A client property key for combo box renderer components.
298: * The Boolean value indicates whether the component's border
299: * can be temporarily removed when painting the current value or not.
300: * This is useful for custom renderers used with Windows combo boxes.
301: *
302: * @see WindowsComboBoxUI#paintCurrentValue(java.awt.Graphics, java.awt.Rectangle, boolean)
303: * @since 2.1
304: */
305: public static final String COMBO_RENDERER_IS_BORDER_REMOVABLE = "isBorderRemovable";
306:
307: /**
308: * A client property key for components with a disabled icon
309: * such as buttons, labels, and tabbed panes. Specifies whether
310: * the new high resolution gray filter shall be used to compute
311: * a disabled icon - if none is available.
312: *
313: * @since 2.1
314: */
315: public static final String HI_RES_DISABLED_ICON_CLIENT_KEY = "generateHiResDisabledIcon";
316:
317: // System Settings ********************************************************
318:
319: /**
320: * Holds the Boolean system property value for the use of system fonts,
321: * or null, if it has not been set. If this property has been
322: * set, we log a message about the choosen value.
323: *
324: * @see #getUseSystemFonts()
325: */
326: private static final Boolean USE_SYSTEM_FONTS_SYSTEM_VALUE = LookUtils
327: .getBooleanSystemProperty(USE_SYSTEM_FONTS_KEY,
328: "Use system fonts");
329:
330: /**
331: * Holds the Boolean system property value for the use of narrow buttons
332: * or null, if it has not been set. If this property has been
333: * set, we log a message about the choosen value.
334: *
335: * @see #getUseNarrowButtons()
336: */
337: private static final Boolean USE_NARROW_BUTTONS_SYSTEM_VALUE = LookUtils
338: .getBooleanSystemProperty(USE_NARROW_BUTTONS_KEY,
339: "Use narrow buttons");
340:
341: /**
342: * Holds the Boolean system property value for the tab icon enablement,
343: * or null, if it has not been set. If this property has been
344: * set, we log a message about the choosen value.
345: *
346: * @see #isTabIconsEnabled()
347: */
348: private static final Boolean TAB_ICONS_ENABLED_SYSTEM_VALUE = LookUtils
349: .getBooleanSystemProperty(TAB_ICONS_ENABLED_KEY,
350: "Icons in tabbed panes");
351:
352: /**
353: * Holds the Boolean system property value for the popup drop shadow
354: * enablement, or null, if it has not been set. If this property has been
355: * set, we log a message about the choosen value.<p>
356: *
357: * This property just set the feature's enablement, not its actual
358: * activation. For example, drop shadows are always inactive on
359: * the Mac OS X, because this platform already provides shadows.
360: * The activation is requested in <code>#isPopupDropShadowActive</code>.
361: *
362: * @see #isPopupDropShadowEnabled()
363: * @see #isPopupDropShadowActive()
364: */
365: private static final Boolean POPUP_DROP_SHADOW_ENABLED_SYSTEM_VALUE = LookUtils
366: .getBooleanSystemProperty(POPUP_DROP_SHADOW_ENABLED_KEY,
367: "Popup drop shadows");
368:
369: // Private ****************************************************************
370:
371: private static final Dimension DEFAULT_ICON_SIZE = new Dimension(
372: 20, 20);
373:
374: private Options() {
375: // Override default constructor; prevents instantiation.
376: }
377:
378: // Accessing Options ******************************************************
379:
380: /**
381: * Returns whether native system fonts shall be used, <code>true</code>
382: * by default unless disabled in the system properties or UIManager.
383: *
384: * @return true unless disabled in the system properties or UIManager
385: *
386: * @see #setUseSystemFonts(boolean)
387: * @see #USE_SYSTEM_FONTS_KEY
388: * @see #USE_SYSTEM_FONTS_APP_KEY
389: */
390: public static boolean getUseSystemFonts() {
391: return USE_SYSTEM_FONTS_SYSTEM_VALUE != null ? USE_SYSTEM_FONTS_SYSTEM_VALUE
392: .booleanValue()
393: : !Boolean.FALSE.equals(UIManager
394: .get(USE_SYSTEM_FONTS_APP_KEY));
395: }
396:
397: /**
398: * Sets a value in the UIManager to indicate,
399: * that a look&feel may use the native system fonts.
400: *
401: * @param useSystemFonts true to enable system fonts in the UIManager
402: *
403: * @see #getUseSystemFonts()
404: * @see #USE_SYSTEM_FONTS_KEY
405: * @see #USE_SYSTEM_FONTS_APP_KEY
406: */
407: public static void setUseSystemFonts(boolean useSystemFonts) {
408: UIManager.put(USE_SYSTEM_FONTS_APP_KEY, Boolean
409: .valueOf(useSystemFonts));
410: }
411:
412: /**
413: * Returns the default icon size that is used in menus, menu items and
414: * toolbars. Menu items that have no icon set are aligned using the default
415: * icon dimensions.
416: *
417: * @return the dimension of the default icon
418: *
419: * @see #setDefaultIconSize(Dimension)
420: */
421: public static Dimension getDefaultIconSize() {
422: Dimension size = UIManager.getDimension(DEFAULT_ICON_SIZE_KEY);
423: return size == null ? DEFAULT_ICON_SIZE : size;
424: }
425:
426: /**
427: * Sets the default icon size.
428: *
429: * @param defaultIconSize the default icon size to set
430: *
431: * @see #getDefaultIconSize()
432: */
433: public static void setDefaultIconSize(Dimension defaultIconSize) {
434: UIManager.put(DEFAULT_ICON_SIZE_KEY, defaultIconSize);
435: }
436:
437: /**
438: * Checks and answers if we shall use narrow button margins of 4 pixels.
439: * As of the Looks version 1.4 the default value is <code>true</code>
440: * (narrow) for the JGoodies Windows L&F and the JGoodies Plastic
441: * L&F family. The native Windows L&F uses narrow margins too.
442: * The default can be disabled in the system properties or UIManager.<p>
443: *
444: * <strong>Note:</strong> Using narrow button margins can potentially cause
445: * compatibility issues, if you don't take care that command buttons with
446: * short labels (OK) get a reasonable minimum width. Therefore you can
447: * get back to wide button margins using <code>#setUseNarrowButtons</code>.
448: * Sun's L&F implementations use a wider button margin of 14 pixels.<p>
449: *
450: * Narrow button margins make it easier to give buttons in a button bar
451: * the same width, even if some button labels are long. And narrow margins
452: * are useful for embedded command buttons that just have an icon,
453: * or an ellipsis (...). Many style guides recommend to use a minimum
454: * button width in command button bars, for example 50 dialog units on
455: * Windows. Such a minimum width makes it easier to click a button,
456: * just because the button area has a reasonable minimum size.
457: * To ensure a reasonable button minimum width, you may configure a
458: * LayoutManager, use a special panel for command button bars, or
459: * a factory that vends command button bars.<p>
460: *
461: * The JGoodies FormLayout can layout button bars that comply with both the
462: * MS Windows Layout Guidelines and the Mac Aqua Human Interface Guidelines.
463: * The JGoodies Forms contains a ButtonBarBuilder to build command button
464: * bars, and a ButtonBarFactory that vends frequently used button bars.
465: *
466: * @return <code>true</code> (default) if all buttons shall use narrow
467: * margins, <code>false</code> for wider margins
468: *
469: * @see #setUseNarrowButtons(boolean)
470: * @see #USE_NARROW_BUTTONS_KEY
471: */
472: public static boolean getUseNarrowButtons() {
473: return USE_NARROW_BUTTONS_SYSTEM_VALUE != null ? USE_NARROW_BUTTONS_SYSTEM_VALUE
474: .booleanValue()
475: : !Boolean.FALSE.equals(UIManager
476: .get(USE_NARROW_BUTTONS_KEY));
477: }
478:
479: /**
480: * Globally sets the use narrow or standard button margins.<p>
481: *
482: * In previous versions of the JGoodies Looks this setting was supported
483: * also for individual buttons - primarily to offer visual backward
484: * compatibility with Sun L&Fs.
485: *
486: * @param b true to use narrow button margins globally
487: *
488: * @see #getUseNarrowButtons()
489: * @see #USE_NARROW_BUTTONS_KEY
490: */
491: public static void setUseNarrowButtons(boolean b) {
492: UIManager.put(USE_NARROW_BUTTONS_KEY, Boolean.valueOf(b));
493: }
494:
495: /**
496: * Checks and answers if we shall use icons in JTabbedPanes.
497: * By default, tab icons are enabled. If the user has set a system property,
498: * we log a message about the choosen style.
499: *
500: * @return true if icons in tabbed panes are enabled, false if disabled
501: * @see #setTabIconsEnabled(boolean)
502: */
503: public static boolean isTabIconsEnabled() {
504: return TAB_ICONS_ENABLED_SYSTEM_VALUE != null ? TAB_ICONS_ENABLED_SYSTEM_VALUE
505: .booleanValue()
506: : !Boolean.FALSE.equals(UIManager
507: .get(TAB_ICONS_ENABLED_KEY));
508: }
509:
510: /**
511: * Enables or disables the use of icons in JTabbedPanes.
512: *
513: * @param b true to enable icons in tabbed panes, false to disable them
514: *
515: * @see #isTabIconsEnabled()
516: */
517: public static void setTabIconsEnabled(boolean b) {
518: UIManager.put(TAB_ICONS_ENABLED_KEY, Boolean.valueOf(b));
519: }
520:
521: /**
522: * Checks and answers whether popup drop shadows are active.
523: * This feature shall be inactive with toolkits that use
524: * native drop shadows, such as Aqua on the Mac OS X.
525: * It is also inactive if the ShadowPopup cannot snapshot
526: * the desktop background (due to security and AWT exceptions).
527: * Otherwise the feature's enablement state is returned.<p>
528: *
529: * Currently only the Mac OS X is detected as platform where
530: * the toolkit uses native drop shadows.
531: *
532: * @return true if drop shadows are active, false if inactive
533: *
534: * @see #isPopupDropShadowEnabled()
535: * @see #setPopupDropShadowEnabled(boolean)
536: */
537: public static boolean isPopupDropShadowActive() {
538: return !LookUtils.getToolkitUsesNativeDropShadows()
539: && ShadowPopup.canSnapshot()
540: && isPopupDropShadowEnabled();
541: }
542:
543: /**
544: * Checks and answers whether the optional drop shadows for
545: * PopupMenus are enabled or disabled.
546: *
547: * @return true if drop shadows are enabled, false if disabled
548: *
549: * @see #isPopupDropShadowActive()
550: * @see #setPopupDropShadowEnabled(boolean)
551: * @see #POPUP_DROP_SHADOW_ENABLED_KEY
552: */
553: public static boolean isPopupDropShadowEnabled() {
554: if (POPUP_DROP_SHADOW_ENABLED_SYSTEM_VALUE != null)
555: return POPUP_DROP_SHADOW_ENABLED_SYSTEM_VALUE
556: .booleanValue();
557:
558: Object value = UIManager.get(POPUP_DROP_SHADOW_ENABLED_KEY);
559: return value == null ? isPopupDropShadowEnabledDefault()
560: : Boolean.TRUE.equals(value);
561: }
562:
563: /**
564: * Enables or disables drop shadows in PopupMenus.
565: * Note that drop shadows are always inactive on platforms
566: * that provide native drop shadows such as the Mac OS X.<p>
567: *
568: * It is recommended to enable this feature only on platforms that
569: * accelerate translucency and snapshots with the hardware.
570: *
571: * @param b true to enable drop shadows, false to disable them
572: *
573: * @see #isPopupDropShadowActive()
574: * @see #isPopupDropShadowEnabled()
575: */
576: public static void setPopupDropShadowEnabled(boolean b) {
577: UIManager
578: .put(POPUP_DROP_SHADOW_ENABLED_KEY, Boolean.valueOf(b));
579: }
580:
581: /**
582: * Checks and answers whether popup drop shadows are enabled
583: * or disabled by default. True for modern Windows platforms:
584: * Windows 98/ME/2000/XP.<p>
585: *
586: * TODO: Consider enabling popup drop shadows on Linux by default.<p>
587: *
588: * TODO: Consider moving the default to the individual L&F's
589: * component defaults initialization. For example Plastic and Plastic3D
590: * may disable this feature by default, while PlasticXP enables it
591: * by default.
592: *
593: * @return false
594: */
595: private static boolean isPopupDropShadowEnabledDefault() {
596: return LookUtils.IS_OS_WINDOWS_MODERN;
597: }
598:
599: /**
600: * Checks and answers whether the new high-resolution gray filter
601: * is enabled or disabled. It is enabled by default.
602: *
603: * @return true if the high-resolution gray filter is enabled, false if disabled
604: *
605: * @see #setHiResGrayFilterEnabled(boolean)
606: * @see #HI_RES_GRAY_FILTER_ENABLED_KEY
607: * @see #HI_RES_DISABLED_ICON_CLIENT_KEY
608: *
609: * @since 2.1
610: */
611: public static boolean isHiResGrayFilterEnabled() {
612: return !Boolean.FALSE.equals(UIManager
613: .get(HI_RES_GRAY_FILTER_ENABLED_KEY));
614: }
615:
616: /**
617: * Enables or disables the new high-resolution gray filter globally.
618: * This gray filter can be disabled for individual components using the
619: * client property key <code>HI_RES_DISABLED_ICON_CLIENT_KEY</code>.
620: *
621: * @param b true to enable the high-resolution gray filter,
622: * false to disable them
623: *
624: * @see #isHiResGrayFilterEnabled()
625: *
626: * @since 2.1
627: */
628: public static void setHiResGrayFilterEnabled(boolean b) {
629: UIManager.put(HI_RES_GRAY_FILTER_ENABLED_KEY, Boolean
630: .valueOf(b));
631: }
632:
633: // Look And Feel Replacements *********************************************
634:
635: /**
636: * Puts a replacement name for a given <code>LookAndFeel</code>
637: * class name in the list of all look and feel replacements.
638: *
639: * @param original the name of the look-and-feel to replace
640: * @param replacement the name of the replacement look-and-feel
641: * @see #removeLookAndFeelReplacement(String)
642: * @see #getReplacementClassNameFor(String)
643: */
644: public static void putLookAndFeelReplacement(String original,
645: String replacement) {
646: LAF_REPLACEMENTS.put(original, replacement);
647: }
648:
649: /**
650: * Removes a replacement name for a given <code>LookAndFeel</code>
651: * class name from the list of all look and feel replacements.
652: *
653: * @param original the name of the look-and-feel that has been replaced
654: * @see #putLookAndFeelReplacement(String, String)
655: * @see #getReplacementClassNameFor(String)
656: */
657: public static void removeLookAndFeelReplacement(String original) {
658: LAF_REPLACEMENTS.remove(original);
659: }
660:
661: /**
662: * A replacement used to replace a given L&f with nothing,
663: * that indicates that it should not be used. For example,
664: * by default we mark the WindowsClass L&f this way,
665: * to remove it from L&f lists that replace the Sun Windows L&f
666: * with the JGoodies Windows L&f.
667: *
668: * @since 2.1.3
669: */
670: public static final String NO_REPLACEMENT = "none";
671:
672: /**
673: * Initializes some default class name replacements, that replace
674: * Sun's Java look and feel, and Sun's Windows look and feel by
675: * the appropriate JGoodies replacements.
676: *
677: * @see #putLookAndFeelReplacement(String, String)
678: * @see #removeLookAndFeelReplacement(String)
679: * @see #getReplacementClassNameFor(String)
680: */
681: private static void initializeDefaultReplacements() {
682: putLookAndFeelReplacement(
683: "javax.swing.plaf.metal.MetalLookAndFeel",
684: PLASTIC3D_NAME);
685: putLookAndFeelReplacement(
686: "com.sun.java.swing.plaf.windows.WindowsLookAndFeel",
687: JGOODIES_WINDOWS_NAME);
688: putLookAndFeelReplacement(
689: "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel",
690: NO_REPLACEMENT);
691: }
692:
693: /**
694: * Returns the class name that can be used to replace the specified
695: * <code>LookAndFeel</code> class name.
696: *
697: * @param className the name of the look-and-feel class
698: * @return the name of the suggested replacement class
699: *
700: * @see #putLookAndFeelReplacement(String, String)
701: * @see #removeLookAndFeelReplacement(String)
702: */
703: public static String getReplacementClassNameFor(String className) {
704: String replacement = (String) LAF_REPLACEMENTS.get(className);
705: if (replacement == null) {
706: return className;
707: } else if (replacement.equals(NO_REPLACEMENT)) {
708: return null;
709: } else {
710: return replacement;
711: }
712: }
713:
714: /**
715: * Returns the class name for a cross-platform <code>LookAndFeel</code>.
716: *
717: * @return the name of a cross platform look-and-feel class
718: * @see #getSystemLookAndFeelClassName()
719: */
720: public static String getCrossPlatformLookAndFeelClassName() {
721: return PLASTICXP_NAME;
722: }
723:
724: /**
725: * Returns the class name for a system specific <code>LookAndFeel</code>.
726: *
727: * @return the name of the system look-and-feel class
728: * @see #getCrossPlatformLookAndFeelClassName()
729: */
730: public static String getSystemLookAndFeelClassName() {
731: if (LookUtils.IS_OS_WINDOWS)
732: return Options.JGOODIES_WINDOWS_NAME;
733: else if (LookUtils.IS_OS_MAC)
734: return UIManager.getSystemLookAndFeelClassName();
735: else
736: return getCrossPlatformLookAndFeelClassName();
737: }
738:
739: }
|