Index: javax/swing/UIDefaults.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/UIDefaults.java,v retrieving revision 1.18 diff -u -r1.18 UIDefaults.java --- javax/swing/UIDefaults.java 6 Apr 2005 20:45:12 -0000 1.18 +++ javax/swing/UIDefaults.java 7 Apr 2005 12:25:57 -0000 @@ -64,8 +64,14 @@ */ public class UIDefaults extends Hashtable { + + /** Our ResourceBundles. */ private LinkedList bundles; + + /** The default locale. */ private Locale defaultLocale; + + /** We use this for firing PropertyChangeEvents. */ private PropertyChangeSupport propertyChangeSupport; public static interface ActiveValue @@ -208,8 +214,12 @@ } } + /** Our serialVersionUID for serialization. */ private static final long serialVersionUID = 7341222528856548117L; + /** + * Constructs a new empty UIDefaults instance. + */ public UIDefaults() { bundles = new LinkedList(); @@ -217,6 +227,14 @@ propertyChangeSupport = new PropertyChangeSupport(this); } + /** + * 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. + * + * @param entries the entries to initialize the UIDefaults instance with + */ public UIDefaults(Object[] entries) { this(); @@ -225,11 +243,24 @@ put(entries[2 * i], entries[2 * i + 1]); } + /** + * Returns the entry for the specified key in the default + * locale. + * + * @return the entry for the specified key + */ public Object get(Object key) { return this.get(key, getDefaultLocale()); } + /** + * Returns the entry for the specified key in the Locale + * loc. + * + * @param key the key for which we return the value + * @param loc the locale + */ public Object get(Object key, Locale loc) { Object obj = null; @@ -284,6 +315,21 @@ return obj; } + /** + * Puts a key and value into this UIDefaults object.
+ * In contrast to + * address@hidden java.util.Hashtable}s null-values are accepted + * here and treated like #remove(key). + *
+ * This fires a PropertyChangeEvent with key as name and the old and new + * values. + * + * @param key the key to put into the map + * @param value the value to put into the map + * + * @return the old value for key or null if key + * had no value assigned + */ public Object put(Object key, Object value) { Object old = checkAndPut(key, value); @@ -293,6 +339,20 @@ return old; } + /** + * 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. + * + * @param entries the entries to be put into the map + */ public void putDefaults(Object[] entries) { for (int i = 0; (2 * i + 1) < entries.length; ++i) @@ -324,112 +384,275 @@ return old; } + /** + * Returns a font entry for the default locale. + * + * @param key the key to the requested entry + * + * @return the font entry for key or null if no such entry + * exists + */ public Font getFont(Object key) { Object o = get(key); return o instanceof Font ? (Font) o : null; } + /** + * Returns a font entry for a specic locale. + * + * @param key the key to the requested entry + * @param locale the locale to the requested entry + * + * @return the font entry for key or null if no such entry + * exists + */ public Font getFont(Object key, Locale l) { Object o = get(key, l); return o instanceof Font ? (Font) o : null; } + /** + * Returns a color entry for the default locale. + * + * @param key the key to the requested entry + * + * @return the color entry for key or null if no such entry + * exists + */ public Color getColor(Object key) { Object o = get(key); return o instanceof Color ? (Color) o : null; } + /** + * Returns a color entry for a specic locale. + * + * @param key the key to the requested entry + * @param locale the locale to the requested entry + * + * @return the color entry for key or null if no such entry + * exists + */ public Color getColor(Object key, Locale l) { Object o = get(key, l); return o instanceof Color ? (Color) o : null; } + /** + * Returns an icon entry for the default locale. + * + * @param key the key to the requested entry + * + * @return the icon entry for key or null if no such entry + * exists + */ public Icon getIcon(Object key) { Object o = get(key); return o instanceof Icon ? (Icon) o : null; } + /** + * Returns an icon entry for a specic locale. + * + * @param key the key to the requested entry + * @param locale the locale to the requested entry + * + * @return the icon entry for key or null if no such entry + * exists + */ public Icon getIcon(Object key, Locale l) { Object o = get(key, l); return o instanceof Icon ? (Icon) o : null; } + /** + * Returns a border entry for the default locale. + * + * @param key the key to the requested entry + * + * @return the border entry for key or null if no such entry + * exists + */ public Border getBorder(Object key) { Object o = get(key); return o instanceof Border ? (Border) o : null; } + /** + * Returns a border entry for a specic locale. + * + * @param key the key to the requested entry + * @param locale the locale to the requested entry + * + * @return the border entry for key or null if no such entry + * exists + */ public Border getBorder(Object key, Locale l) { Object o = get(key, l); return o instanceof Border ? (Border) o : null; } + /** + * Returns a string entry for the default locale. + * + * @param key the key to the requested entry + * + * @return the string entry for key or null if no such entry + * exists + */ public String getString(Object key) { Object o = get(key); return o instanceof String ? (String) o : null; } + /** + * Returns a string entry for a specic locale. + * + * @param key the key to the requested entry + * @param locale the locale to the requested entry + * + * @return the string entry for key or null if no such entry + * exists + */ public String getString(Object key, Locale l) { Object o = get(key, l); return o instanceof String ? (String) o : null; } + /** + * Returns an integer entry for the default locale. + * + * @param key the key to the requested entry + * + * @return the integer entry for key or null if no such entry + * exists + */ public int getInt(Object key) { Object o = get(key); return o instanceof Integer ? ((Integer) o).intValue() : 0; } + /** + * Returns an integer entry for a specic locale. + * + * @param key the key to the requested entry + * @param locale the locale to the requested entry + * + * @return the integer entry for key or null if no such entry + * exists + */ public int getInt(Object key, Locale l) { Object o = get(key, l); return o instanceof Integer ? ((Integer) o).intValue() : 0; } + /** + * Returns a boolean entry for the default locale. + * + * @param key the key to the requested entry + * + * @return the boolean entry for key or null if no such entry + * exists + */ public boolean getBoolean(Object key) { return Boolean.TRUE.equals(get(key)); } + /** + * Returns a boolean entry for a specic locale. + * + * @param key the key to the requested entry + * @param locale the locale to the requested entry + * + * @return the boolean entry for key or null if no such entry + * exists + */ public boolean getBoolean(Object key, Locale l) { return Boolean.TRUE.equals(get(key, l)); } + /** + * Returns an insets entry for the default locale. + * + * @param key the key to the requested entry + * + * @return the insets entry for key or null if no such entry + * exists + */ public Insets getInsets(Object key) { Object o = get(key); return o instanceof Insets ? (Insets) o : null; } + /** + * Returns an insets entry for a specic locale. + * + * @param key the key to the requested entry + * @param locale the locale to the requested entry + * + * @return the boolean entry for key or null if no such entry + * exists + */ public Insets getInsets(Object key, Locale l) { Object o = get(key, l); return o instanceof Insets ? (Insets) o : null; } + /** + * Returns a dimension entry for the default locale. + * + * @param key the key to the requested entry + * + * @return the dimension entry for key or null if no such entry + * exists + */ public Dimension getDimension(Object key) { Object o = get(key); return o instanceof Dimension ? (Dimension) o : null; } + /** + * Returns a dimension entry for a specic locale. + * + * @param key the key to the requested entry + * @param locale the locale to the requested entry + * + * @return the boolean entry for key or null if no such entry + * exists + */ public Dimension getDimension(Object key, Locale l) { Object o = get(key, l); return o instanceof Dimension ? (Dimension) o : null; } + /** + * 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. + * + * @param id the ID of the UI class + * @param loader the ClassLoader to use + * + * @return the UI class for id + */ public Class getUIClass(String id, ClassLoader loader) { String className = (String) get (id); @@ -447,16 +670,38 @@ } } + /** + * 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. + * + * @param id the ID of the UI class + * + * @return the UI class for id + */ public Class getUIClass(String id) { return getUIClass (id, null); } + /** + * If a key is requested in #get(key) that has no value, this method + * is called before returning null. + * + * @param msg the error message + */ protected void getUIError(String msg) { System.err.println ("UIDefaults.getUIError: " + msg); } + /** + * Returns the address@hidden ComponentUI} for the specified address@hidden JComponent}. + * + * @param target the component for which the ComponentUI is requested + * + * @return the address@hidden ComponentUI} for the specified address@hidden JComponent} + */ public ComponentUI getUI(JComponent target) { String classId = target.getUIClassID (); @@ -496,42 +741,86 @@ } } + /** + * Adds a address@hidden PropertyChangeListener} to this UIDefaults map. + * Registered PropertyChangeListener are notified when values + * are beeing put into this UIDefaults map. + * + * @param listener the PropertyChangeListener to add + */ public void addPropertyChangeListener(PropertyChangeListener listener) { propertyChangeSupport.addPropertyChangeListener(listener); } + /** + * Removes a PropertyChangeListener from this UIDefaults map. + * + * @param listener the PropertyChangeListener to remove + */ public void removePropertyChangeListener(PropertyChangeListener listener) { propertyChangeSupport.removePropertyChangeListener(listener); } + /** + * Returns an array of all registered PropertyChangeListeners. + * + * @return all registered PropertyChangeListeners + */ public PropertyChangeListener[] getPropertyChangeListeners() { return propertyChangeSupport.getPropertyChangeListeners(); } + /** + * Fires a PropertyChangeEvent. + * + * @param property the property name + * @param oldValue the old value + * @param newValue the new value + */ protected void firePropertyChange(String property, Object oldValue, Object newValue) { propertyChangeSupport.firePropertyChange(property, oldValue, newValue); } + /** + * Adds a ResourceBundle for localized values. + * + * @param name the name of the ResourceBundle to add + */ public void addResourceBundle(String name) { bundles.addFirst(name); } + /** + * Removes a ResourceBundle. + * + * @param name the name of the ResourceBundle to remove + */ public void removeResourceBundle(String name) { bundles.remove(name); } + /** + * Sets the current locale to loc. + * + * @param loc the Locale to be set + */ public void setDefaultLocale(Locale loc) { defaultLocale = loc; } + /** + * Returns the current default locale. + * + * @return the current default locale + */ public Locale getDefaultLocale() { return defaultLocale;