javax.swing

Class UIDefaults

Implemented Interfaces:
Cloneable, Map<K,V>, Serializable

public class UIDefaults
extends Hashtable<K,V>

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

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.
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
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.
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.
In contrast to Hashtables null-values are accepted here and treated like #remove(key).
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<K,V>

V>> entrySet, clear, clone, contains, containsKey, containsValue, elements, equals, get, hashCode, isEmpty, keySet, keys, put, putAll, rehash, remove, size, toString, values

Methods inherited from class java.util.Dictionary<K,V>

elements, get, isEmpty, keys, put, remove, size

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

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 Details

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

addResourceBundle

public void addResourceBundle(String name)
Adds a ResourceBundle for localized values.
Parameters:
name - the name of the ResourceBundle to add

extends ComponentUI> getUIClass

public Classextends 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

extends ComponentUI> getUIClass

public Classextends 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

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

get

public Object get(Object key)
Returns the entry for the specified key in the default locale.
Specified by:
get in interface Map<K,V>
Overrides:
get in interface Hashtable<K,V>
Returns:
the entry for the specified key

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

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

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

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

getDefaultLocale

public Locale getDefaultLocale()
Returns the current default locale.
Returns:
the current default locale

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

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

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

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

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

getPropertyChangeListeners

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

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

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

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

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.
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

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

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from this UIDefaults map.
Parameters:
listener - the PropertyChangeListener to remove

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

UIDefaults.java -- database for all settings and interface bindings. Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.