Class UIManagerExt


  • public class UIManagerExt
    extends java.lang.Object
    A utility class for obtaining configuration properties from the UIDefaults. This class handles SwingX-specific L&F needs, such as the installation of painters and shapes. There are several categories of utility methods:
    • Support for the safe creation of UIResources.
    • Support for new UIResource types, such as PainterUIResource.
    • Support for the dynamic localization of UIDefaults.
    • Support for returning non-String localizations from ResourceBundles.

    Safe Methods

    The getSafeXXX methods are designed for use with LookAndFeelAddons. Any addon that attempts to obtain a property defined in the defaults (available from UIManager.get) to set a property that will be added to the defaults for the addon should use the "safe" methods. The methods ensure that a valid value is always returned and that value is a UIResource.

    Support for New Types

    UIManagerExt supports the retrieval of new UIResource types. There is a getXXX method for every UIResource subtype in the org.jdesktop.swingx.plaf package.

    Support for Dynamic Localization

    UIManagerExt enables dynamic localization by supporting ResourceBundles. The UIDefaults.addResourceBundle(String) allows resource bundles to be added to the UIDefaults. While there is support for this feature in core, there is a bug with the class loader that prevents user added bundles from working correctly when used via Web Start. Therefore, UIManagerExt defines methods to add and remove resource bundles. These are the only methods that SwingX classes should use when adding resource bundles to the defaults. Since UIManagerExt is maintaining the bundles, any localized Strings must be retrieved from the getString methods in this class.

    Support for Non-String Localization Values

    All methods work by first determining if the value is present UIDefaults. If the value is not present, then the installed ResourceBundles are queried. UIManagerExt will attempt to convert any returned value to the appropriate type. For instance, getInt uses Integer.decode to convert Strings returned from the bundle into ints.

    Author:
    Karl George Schaefer
    See Also:
    UIManager, UIDefaults
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addResourceBundle​(java.lang.String bundleName)
      Adds a resource bundle to the list of resource bundles that are searched for localized values.
      static boolean getBoolean​(java.lang.Object key)
      Returns an Boolean from the defaults.
      static boolean getBoolean​(java.lang.Object key, java.util.Locale l)
      Returns an Boolean from the defaults.
      static java.awt.Color getColor​(java.lang.Object key)
      Returns a color from the defaults.
      static java.awt.Color getColor​(java.lang.Object key, java.util.Locale l)
      Returns a color from the defaults.
      static int getInt​(java.lang.Object key)
      Returns an integer from the defaults.
      static int getInt​(java.lang.Object key, java.util.Locale l)
      Returns an integer from the defaults.
      static Painter<?> getPainter​(java.lang.Object key)
      Returns a painter from the defaults.
      static Painter<?> getPainter​(java.lang.Object key, java.util.Locale l)
      Returns a painter from the defaults that is appropriate for the given locale.
      static javax.swing.border.Border getSafeBorder​(java.lang.Object key, javax.swing.border.Border defaultBorder)
      Returns a border from the defaults.
      static java.awt.Color getSafeColor​(java.lang.Object key, java.awt.Color defaultColor)
      Returns a color from the defaults.
      static java.awt.Dimension getSafeDimension​(java.lang.Object key, java.awt.Dimension defaultDimension)
      Returns a dimension from the defaults.
      static java.awt.Font getSafeFont​(java.lang.Object key, java.awt.Font defaultFont)
      Returns a font from the defaults.
      static javax.swing.Icon getSafeIcon​(java.lang.Object key, javax.swing.Icon defaultIcon)
      Returns an icon from the defaults.
      static java.awt.Insets getSafeInsets​(java.lang.Object key, java.awt.Insets defaultInsets)
      Returns an insets from the defaults.
      static java.awt.Shape getShape​(java.lang.Object key)
      Returns a shape from the defaults.
      static java.awt.Shape getShape​(java.lang.Object key, java.util.Locale l)
      Returns a shape from the defaults that is appropriate for the given locale.
      static java.lang.String getString​(java.lang.Object key)
      Returns a string from the defaults.
      static java.lang.String getString​(java.lang.Object key, java.util.Locale l)
      Returns a string from the defaults.
      static void removeResourceBundle​(java.lang.String bundleName)
      Removes a resource bundle from the list of resource bundles that are searched for localized defaults.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • addResourceBundle

        public static void addResourceBundle​(java.lang.String bundleName)
        Adds a resource bundle to the list of resource bundles that are searched for localized values. Resource bundles are searched in the reverse order they were added. In other words, the most recently added bundle is searched first.
        Parameters:
        bundleName - the base name of the resource bundle to be added
        See Also:
        ResourceBundle, removeResourceBundle(java.lang.String)
      • removeResourceBundle

        public static void removeResourceBundle​(java.lang.String bundleName)
        Removes a resource bundle from the list of resource bundles that are searched for localized defaults.
        Parameters:
        bundleName - the base name of the resource bundle to be removed
        See Also:
        ResourceBundle, addResourceBundle(java.lang.String)
      • getString

        public static java.lang.String getString​(java.lang.Object key)
        Returns a string from the defaults. If the value for key is not a String, null is returned.
        Parameters:
        key - an Object specifying the string
        Returns:
        the String object
        Throws:
        java.lang.NullPointerException - if key is null
      • getString

        public static java.lang.String getString​(java.lang.Object key,
                                                 java.util.Locale l)
        Returns a string from the defaults. If the value for key is not a String, null is returned.
        Parameters:
        key - an Object specifying the string
        l - the Locale for which the painter is desired; refer to UIDefaults for details on how a null Locale is handled
        Returns:
        the String object
        Throws:
        java.lang.NullPointerException - if key is null
      • getInt

        public static int getInt​(java.lang.Object key)
        Returns an integer from the defaults. If the value for key is not an int, 0 is returned.
        Parameters:
        key - an Object specifying the integer
        Returns:
        the int
        Throws:
        java.lang.NullPointerException - if key is null
      • getInt

        public static int getInt​(java.lang.Object key,
                                 java.util.Locale l)
        Returns an integer from the defaults. If the value for key is not an int, 0 is returned.
        Parameters:
        key - an Object specifying the integer
        l - the Locale for which the integer is desired; refer to UIDefaults for details on how a null Locale is handled
        Returns:
        the int
        Throws:
        java.lang.NullPointerException - if key is null
      • getBoolean

        public static boolean getBoolean​(java.lang.Object key)
        Returns an Boolean from the defaults. If the value for key is not a boolean, false is returned.
        Parameters:
        key - an Object specifying the Boolean
        Returns:
        the boolean
        Throws:
        java.lang.NullPointerException - if key is null
      • getBoolean

        public static boolean getBoolean​(java.lang.Object key,
                                         java.util.Locale l)
        Returns an Boolean from the defaults. If the value for key is not a boolean, false is returned.
        Parameters:
        key - an Object specifying the Boolean
        l - the Locale for which the Boolean is desired; refer to UIDefaults for details on how a null Locale is handled
        Returns:
        the boolean
        Throws:
        java.lang.NullPointerException - if key is null
      • getColor

        public static java.awt.Color getColor​(java.lang.Object key)
        Returns a color from the defaults. If the value for key is not a Color, null is returned.
        Parameters:
        key - an Object specifying the color
        Returns:
        the Color object
        Throws:
        java.lang.NullPointerException - if key is null
      • getColor

        public static java.awt.Color getColor​(java.lang.Object key,
                                              java.util.Locale l)
        Returns a color from the defaults. If the value for key is not a Color, null is returned.
        Parameters:
        key - an Object specifying the color
        l - the Locale for which the color is desired; refer to UIDefaults for details on how a null Locale is handled
        Returns:
        the Color object
        Throws:
        java.lang.NullPointerException - if key is null
      • getShape

        public static java.awt.Shape getShape​(java.lang.Object key)
        Returns a shape from the defaults. If the value for key is not a Shape, null is returned.
        Parameters:
        key - an Object specifying the shape
        Returns:
        the Shape object
        Throws:
        java.lang.NullPointerException - if key is null
      • getShape

        public static java.awt.Shape getShape​(java.lang.Object key,
                                              java.util.Locale l)
        Returns a shape from the defaults that is appropriate for the given locale. If the value for key is not a Shape, null is returned.
        Parameters:
        key - an Object specifying the shape
        l - the Locale for which the shape is desired; refer to UIDefaults for details on how a null Locale is handled
        Returns:
        the Shape object
        Throws:
        java.lang.NullPointerException - if key is null
      • getPainter

        public static Painter<?> getPainter​(java.lang.Object key)
        Returns a painter from the defaults. If the value for key is not a Painter, null is returned.
        Parameters:
        key - an Object specifying the painter
        Returns:
        the Painter object
        Throws:
        java.lang.NullPointerException - if key is null
      • getPainter

        public static Painter<?> getPainter​(java.lang.Object key,
                                            java.util.Locale l)
        Returns a painter from the defaults that is appropriate for the given locale. If the value for key is not a Painter, null is returned.
        Parameters:
        key - an Object specifying the painter
        l - the Locale for which the painter is desired; refer to UIDefaults for details on how a null Locale is handled
        Returns:
        the Painter object
        Throws:
        java.lang.NullPointerException - if key is null
      • getSafeBorder

        public static javax.swing.border.Border getSafeBorder​(java.lang.Object key,
                                                              javax.swing.border.Border defaultBorder)
        Returns a border from the defaults. If the value for key is not a Border, defaultBorder is returned.
        Parameters:
        key - an Object specifying the border
        defaultBorder - the border to return if the border specified by key does not exist
        Returns:
        the Border object
        Throws:
        java.lang.NullPointerException - if key or defaultBorder is null
      • getSafeColor

        public static java.awt.Color getSafeColor​(java.lang.Object key,
                                                  java.awt.Color defaultColor)
        Returns a color from the defaults. If the value for key is not a Color, defaultColor is returned.
        Parameters:
        key - an Object specifying the color
        defaultColor - the color to return if the color specified by key does not exist
        Returns:
        the Color object
        Throws:
        java.lang.NullPointerException - if key or defaultColor is null
      • getSafeDimension

        public static java.awt.Dimension getSafeDimension​(java.lang.Object key,
                                                          java.awt.Dimension defaultDimension)
        Returns a dimension from the defaults. If the value for key is not a Dimension, defaultDimension is returned.
        Parameters:
        key - an Object specifying the dimension
        defaultDimension - the dimension to return if the dimension specified by key does not exist
        Returns:
        the Dimension object
        Throws:
        java.lang.NullPointerException - if key or defaultColor is null
      • getSafeFont

        public static java.awt.Font getSafeFont​(java.lang.Object key,
                                                java.awt.Font defaultFont)
        Returns a font from the defaults. If the value for key is not a Font, defaultFont is returned.
        Parameters:
        key - an Object specifying the font
        defaultFont - the font to return if the font specified by key does not exist
        Returns:
        the Font object
        Throws:
        java.lang.NullPointerException - if key or defaultFont is null
      • getSafeIcon

        public static javax.swing.Icon getSafeIcon​(java.lang.Object key,
                                                   javax.swing.Icon defaultIcon)
        Returns an icon from the defaults. If the value for key is not a Icon, defaultIcon is returned.
        Parameters:
        key - an Object specifying the icon
        defaultIcon - the icon to return if the icon specified by key does not exist
        Returns:
        the Icon object
        Throws:
        java.lang.NullPointerException - if key or defaultIcon is null
      • getSafeInsets

        public static java.awt.Insets getSafeInsets​(java.lang.Object key,
                                                    java.awt.Insets defaultInsets)
        Returns an insets from the defaults. If the value for key is not a Insets, defaultInsets is returned.
        Parameters:
        key - an Object specifying the insets
        defaultInsets - the insets to return if the insets specified by key does not exist
        Returns:
        the Insets object
        Throws:
        java.lang.NullPointerException - if key or defaultInsets is null