javax.swing
Class UIDefaults

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<Object,Object>
          extended by javax.swing.UIDefaults
All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public class UIDefaults
extends Hashtable<Object,Object>

UIDefaults is a database where all settings and interface bindings are stored into. A PLAF implementation fills one of these (see for example plaf/basic/BasicLookAndFeel.java) with "ButtonUI" -> new BasicButtonUI().

See Also:
Serialized Form

Nested Class Summary
static interface UIDefaults.ActiveValue
          Used for lazy instantiation of UIDefaults values so that they are not all loaded when a Swing application starts up, but only the values that are really needed.
static class UIDefaults.LazyInputMap
           
static interface UIDefaults.LazyValue
          Used for lazy instantiation of UIDefaults values so that they are not all loaded when a Swing application starts up, but only the values that are really needed.
static class UIDefaults.ProxyLazyValue
           
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
UIDefaults()
          Constructs a new empty UIDefaults instance.
UIDefaults(Object[] entries)
          Constructs a new UIDefaults instance and loads the specified entries.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a PropertyChangeListener to this UIDefaults map.
 void addResourceBundle(String name)
          Adds a ResourceBundle for localized values.
protected  void firePropertyChange(String property, Object oldValue, Object newValue)
          Fires a PropertyChangeEvent.
 Object get(Object key)
          Returns the entry for the specified key in the default locale.
 Object get(Object key, Locale loc)
          Returns the entry for the specified key in the Locale loc.
 boolean getBoolean(Object key)
          Returns a boolean entry for the default locale.
 boolean getBoolean(Object key, Locale locale)
          Returns a boolean entry for a specic locale.
 Border getBorder(Object key)
          Returns a border entry for the default locale.
 Border getBorder(Object key, Locale locale)
          Returns a border entry for a specic locale.
 Color getColor(Object key)
          Returns a color entry for the default locale.
 Color getColor(Object key, Locale locale)
          Returns a color entry for a specic locale.
 Locale getDefaultLocale()
          Returns the current default locale.
 Dimension getDimension(Object key)
          Returns a dimension entry for the default locale.
 Dimension getDimension(Object key, Locale locale)
          Returns a dimension entry for a specic locale.
 Font getFont(Object key)
          Returns a font entry for the default locale.
 Font getFont(Object key, Locale locale)
          Returns a font entry for a specic locale.
 Icon getIcon(Object key)
          Returns an icon entry for the default locale.
 Icon getIcon(Object key, Locale locale)
          Returns an icon entry for a specic locale.
 Insets getInsets(Object key)
          Returns an insets entry for the default locale.
 Insets getInsets(Object key, Locale locale)
          Returns an insets entry for a specic locale.
 int getInt(Object key)
          Returns an integer entry for the default locale.
 int getInt(Object key, Locale locale)
          Returns an integer entry for a specic locale.
 PropertyChangeListener[] getPropertyChangeListeners()
          Returns an array of all registered PropertyChangeListeners.
 String getString(Object key)
          Returns a string entry for the default locale.
 String getString(Object key, Locale locale)
          Returns a string entry for a specic locale.
 ComponentUI getUI(JComponent target)
          Returns the ComponentUI for the specified JComponent.
 Class<? extends ComponentUI> getUIClass(String id)
          Returns the ComponentUI class that renders a component.
 Class<? extends ComponentUI> getUIClass(String id, ClassLoader loader)
          Returns the ComponentUI class that renders a component.
protected  void getUIError(String msg)
          If a key is requested in #get(key) that has no value, this method is called before returning null.
 Object put(Object key, Object value)
          Puts a key and value into this UIDefaults object.
 void putDefaults(Object[] entries)
          Puts a set of key-value pairs into the map.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a PropertyChangeListener from this UIDefaults map.
 void removeResourceBundle(String name)
          Removes a ResourceBundle.
 void setDefaultLocale(Locale loc)
          Sets the current locale to loc.
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, hashCode, isEmpty, keys, keySet, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UIDefaults

public UIDefaults()
Constructs a new empty UIDefaults instance.


UIDefaults

public UIDefaults(Object[] entries)
Constructs a new UIDefaults instance and loads the specified entries. The entries are expected to come in pairs, that means entries[0] is a key, entries[1] is a value, entries[2] a key and so forth.

Parameters:
entries - the entries to initialize the UIDefaults instance with
Method Detail

get

public Object get(Object key)
Returns the entry for the specified key in the default locale.

Specified by:
get in interface Map<Object,Object>
Overrides:
get in class Hashtable<Object,Object>
Parameters:
key - the key for which to fetch an associated value
Returns:
the entry for the specified key
See Also:
Hashtable.put(Object, Object), Hashtable.containsKey(Object)

get

public Object get(Object key,
                  Locale loc)
Returns the entry for the specified key in the Locale loc.

Parameters:
key - the key for which we return the value
loc - the locale

put

public Object put(Object key,
                  Object value)
Puts a key and value into this UIDefaults object.
In contrast to Hashtables null-values are accepted here and treated like #remove(key).
This fires a PropertyChangeEvent with key as name and the old and new values.

Specified by:
put in interface Map<Object,Object>
Overrides:
put in class Hashtable<Object,Object>
Parameters:
key - the key to put into the map
value - the value to put into the map
Returns:
the old value for key or null if key had no value assigned
See Also:
Hashtable.get(Object), Object.equals(Object)

putDefaults

public void putDefaults(Object[] entries)
Puts a set of key-value pairs into the map. The entries are expected to come in pairs, that means entries[0] is a key, entries[1] is a value, entries[2] a key and so forth.
If a value is null it is treated like #remove(key).
This unconditionally fires a PropertyChangeEvent with 'UIDefaults' as name and null for old and new value.

Parameters:
entries - the entries to be put into the map

getFont

public Font getFont(Object key)
Returns a font entry for the default locale.

Parameters:
key - the key to the requested entry
Returns:
the font entry for key or null if no such entry exists

getFont

public Font getFont(Object key,
                    Locale locale)
Returns a font entry for a specic locale.

Parameters:
key - the key to the requested entry
locale - the locale to the requested entry
Returns:
the font entry for key or null if no such entry exists

getColor

public Color getColor(Object key)
Returns a color entry for the default locale.

Parameters:
key - the key to the requested entry
Returns:
the color entry for key or null if no such entry exists

getColor

public Color getColor(Object key,
                      Locale locale)
Returns a color entry for a specic locale.

Parameters:
key - the key to the requested entry
locale - the locale to the requested entry
Returns:
the color entry for key or null if no such entry exists

getIcon

public Icon getIcon(Object key)
Returns an icon entry for the default locale.

Parameters:
key - the key to the requested entry
Returns:
the icon entry for key or null if no such entry exists

getIcon

public Icon getIcon(Object key,
                    Locale locale)
Returns an icon entry for a specic locale.

Parameters:
key - the key to the requested entry
locale - the locale to the requested entry
Returns:
the icon entry for key or null if no such entry exists

getBorder

public Border getBorder(Object key)
Returns a border entry for the default locale.

Parameters:
key - the key to the requested entry
Returns:
the border entry for key or null if no such entry exists

getBorder

public Border getBorder(Object key,
                        Locale locale)
Returns a border entry for a specic locale.

Parameters:
key - the key to the requested entry
locale - the locale to the requested entry
Returns:
the border entry for key or null if no such entry exists

getString

public String getString(Object key)
Returns a string entry for the default locale.

Parameters:
key - the key to the requested entry
Returns:
the string entry for key or null if no such entry exists

getString

public String getString(Object key,
                        Locale locale)
Returns a string entry for a specic locale.

Parameters:
key - the key to the requested entry
locale - the locale to the requested entry
Returns:
the string entry for key or null if no such entry exists

getInt

public int getInt(Object key)
Returns an integer entry for the default locale.

Parameters:
key - the key to the requested entry
Returns:
the integer entry for key or null if no such entry exists

getInt

public int getInt(Object key,
                  Locale locale)
Returns an integer entry for a specic locale.

Parameters:
key - the key to the requested entry
locale - the locale to the requested entry
Returns:
the integer entry for key or null if no such entry exists

getBoolean

public boolean getBoolean(Object key)
Returns a boolean entry for the default locale.

Parameters:
key - the key to the requested entry
Returns:
The boolean entry for key or false if no such entry exists.

getBoolean

public boolean getBoolean(Object key,
                          Locale locale)
Returns a boolean entry for a specic locale.

Parameters:
key - the key to the requested entry
locale - the locale to the requested entry
Returns:
the boolean entry for key or null if no such entry exists

getInsets

public Insets getInsets(Object key)
Returns an insets entry for the default locale.

Parameters:
key - the key to the requested entry
Returns:
the insets entry for key or null if no such entry exists

getInsets

public Insets getInsets(Object key,
                        Locale locale)
Returns an insets entry for a specic locale.

Parameters:
key - the key to the requested entry
locale - the locale to the requested entry
Returns:
the boolean entry for key or null if no such entry exists

getDimension

public Dimension getDimension(Object key)
Returns a dimension entry for the default locale.

Parameters:
key - the key to the requested entry
Returns:
the dimension entry for key or null if no such entry exists

getDimension

public Dimension getDimension(Object key,
                              Locale locale)
Returns a dimension entry for a specic locale.

Parameters:
key - the key to the requested entry
locale - the locale to the requested entry
Returns:
the boolean entry for key or null if no such entry exists

getUIClass

public Class<? extends ComponentUI> getUIClass(String id,
                                               ClassLoader loader)
Returns the ComponentUI class that renders a component. id is the ID for which the String value of the classname is stored in this UIDefaults map.

Parameters:
id - the ID of the UI class
loader - the ClassLoader to use
Returns:
the UI class for id

getUIClass

public Class<? extends ComponentUI> getUIClass(String id)
Returns the ComponentUI class that renders a component. id is the ID for which the String value of the classname is stored in this UIDefaults map.

Parameters:
id - the ID of the UI class
Returns:
the UI class for id

getUIError

protected void getUIError(String msg)
If a key is requested in #get(key) that has no value, this method is called before returning null.

Parameters:
msg - the error message

getUI

public ComponentUI getUI(JComponent target)
Returns the ComponentUI for the specified JComponent.

Parameters:
target - the component for which the ComponentUI is requested
Returns:
the ComponentUI for the specified JComponent

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to this UIDefaults map. Registered PropertyChangeListener are notified when values are beeing put into this UIDefaults map.

Parameters:
listener - the PropertyChangeListener to add

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from this UIDefaults map.

Parameters:
listener - the PropertyChangeListener to remove

getPropertyChangeListeners

public PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all registered PropertyChangeListeners.

Returns:
all registered PropertyChangeListeners

firePropertyChange

protected void firePropertyChange(String property,
                                  Object oldValue,
                                  Object newValue)
Fires a PropertyChangeEvent.

Parameters:
property - the property name
oldValue - the old value
newValue - the new value

addResourceBundle

public void addResourceBundle(String name)
Adds a ResourceBundle for localized values.

Parameters:
name - the name of the ResourceBundle to add

removeResourceBundle

public void removeResourceBundle(String name)
Removes a ResourceBundle.

Parameters:
name - the name of the ResourceBundle to remove

setDefaultLocale

public void setDefaultLocale(Locale loc)
Sets the current locale to loc.

Parameters:
loc - the Locale to be set

getDefaultLocale

public Locale getDefaultLocale()
Returns the current default locale.

Returns:
the current default locale