A table of defaults for Swing components. Applications can set/get
default values via the
.
| Method from javax.swing.UIDefaults Detail: |
public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
if (changeSupport == null) {
changeSupport = new SwingPropertyChangeSupport(this);
}
changeSupport.addPropertyChangeListener(listener);
}
|
public synchronized void addResourceBundle(String bundleName) {
if( bundleName == null ) {
return;
}
if( resourceBundles == null ) {
resourceBundles = new Vector(5);
}
if (!resourceBundles.contains(bundleName)) {
resourceBundles.add( bundleName );
resourceCache.clear();
}
}
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. |
protected void firePropertyChange(String propertyName,
Object oldValue,
Object newValue) {
if (changeSupport != null) {
changeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
}
Support for reporting bound property changes. If oldValue and
newValue are not equal and the PropertyChangeEventx
listener list isn't empty, then fire a
PropertyChange event to each listener. |
public Object get(Object key) {
Object value = getFromHashtable( key );
return (value != null) ? value : getFromResourceBundle(key, null);
}
Returns the value for key. If the value is a
UIDefaults.LazyValue then the real
value is computed with LazyValue.createValue(),
the table entry is replaced, and the real value is returned.
If the value is an UIDefaults.ActiveValue
the table entry is not replaced - the value is computed
with ActiveValue.createValue() for each
get() call.
If the key is not found in the table then it is searched for in the list
of resource bundles maintained by this object. The resource bundles are
searched most recently added first using the locale returned by
getDefaultLocale. LazyValues and
ActiveValues are not supported in the resource bundles. |
public Object get(Object key,
Locale l) {
Object value = getFromHashtable( key );
return (value != null) ? value : getFromResourceBundle(key, l);
}
Returns the value for key associated with the given locale.
If the value is a UIDefaults.LazyValue then the real
value is computed with LazyValue.createValue(),
the table entry is replaced, and the real value is returned.
If the value is an UIDefaults.ActiveValue
the table entry is not replaced - the value is computed
with ActiveValue.createValue() for each
get() call.
If the key is not found in the table then it is searched for in the list
of resource bundles maintained by this object. The resource bundles are
searched most recently added first using the given locale.
LazyValues and ActiveValues are not supported
in the resource bundles. |
public boolean getBoolean(Object key) {
Object value = get(key);
return (value instanceof Boolean) ? ((Boolean)value).booleanValue() : false;
}
If the value of key is boolean, return the
boolean value, otherwise return false. |
public boolean getBoolean(Object key,
Locale l) {
Object value = get(key,l);
return (value instanceof Boolean) ? ((Boolean)value).booleanValue() : false;
}
If the value of key for the given Locale
is boolean, return the boolean value, otherwise return false. |
public Border getBorder(Object key) {
Object value = get(key);
return (value instanceof Border) ? (Border)value : null;
}
If the value of key is a Border return it,
otherwise return null. |
public Border getBorder(Object key,
Locale l) {
Object value = get(key,l);
return (value instanceof Border) ? (Border)value : null;
}
If the value of key for the given Locale
is a Border return it, otherwise return null. |
public Color getColor(Object key) {
Object value = get(key);
return (value instanceof Color) ? (Color)value : null;
}
If the value of key is a Color return it,
otherwise return null. |
public Color getColor(Object key,
Locale l) {
Object value = get(key,l);
return (value instanceof Color) ? (Color)value : null;
}
If the value of key for the given Locale
is a Color return it, otherwise return null. |
public Locale getDefaultLocale() {
return defaultLocale;
}
Returns the default locale. The default locale is used in retrieving
localized values via get methods that do not take a
locale argument. As of release 1.4, Swing UI objects should retrieve
localized values using the locale of their component rather than the
default locale. The default locale exists to provide compatibility with
pre 1.4 behaviour. |
public Dimension getDimension(Object key) {
Object value = get(key);
return (value instanceof Dimension) ? (Dimension)value : null;
}
If the value of key is a Dimension return it,
otherwise return null. |
public Dimension getDimension(Object key,
Locale l) {
Object value = get(key,l);
return (value instanceof Dimension) ? (Dimension)value : null;
}
If the value of key for the given Locale
is a Dimension return it, otherwise return null. |
public Font getFont(Object key) {
Object value = get(key);
return (value instanceof Font) ? (Font)value : null;
}
If the value of key is a Font return it,
otherwise return null. |
public Font getFont(Object key,
Locale l) {
Object value = get(key,l);
return (value instanceof Font) ? (Font)value : null;
}
If the value of key for the given Locale
is a Font return it, otherwise return null. |
public Icon getIcon(Object key) {
Object value = get(key);
return (value instanceof Icon) ? (Icon)value : null;
}
If the value of key is an Icon return it,
otherwise return null. |
public Icon getIcon(Object key,
Locale l) {
Object value = get(key,l);
return (value instanceof Icon) ? (Icon)value : null;
}
If the value of key for the given Locale
is an Icon return it, otherwise return null. |
public Insets getInsets(Object key) {
Object value = get(key);
return (value instanceof Insets) ? (Insets)value : null;
}
If the value of key is an Insets return it,
otherwise return null. |
public Insets getInsets(Object key,
Locale l) {
Object value = get(key,l);
return (value instanceof Insets) ? (Insets)value : null;
}
If the value of key for the given Locale
is an Insets return it, otherwise return null. |
public int getInt(Object key) {
Object value = get(key);
return (value instanceof Integer) ? ((Integer)value).intValue() : 0;
}
If the value of key is an Integer return its
integer value, otherwise return 0. |
public int getInt(Object key,
Locale l) {
Object value = get(key,l);
return (value instanceof Integer) ? ((Integer)value).intValue() : 0;
}
If the value of key for the given Locale
is an Integer return its integer value, otherwise return 0. |
public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
if (changeSupport == null) {
return new PropertyChangeListener[0];
}
return changeSupport.getPropertyChangeListeners();
}
Returns an array of all the PropertyChangeListeners added
to this UIDefaults with addPropertyChangeListener(). |
public String getString(Object key) {
Object value = get(key);
return (value instanceof String) ? (String)value : null;
}
If the value of key is a String return it,
otherwise return null. |
public String getString(Object key,
Locale l) {
Object value = get(key,l);
return (value instanceof String) ? (String)value : null;
}
If the value of key for the given Locale
is a String return it, otherwise return null. |
public ComponentUI getUI(JComponent target) {
Object cl = get("ClassLoader");
ClassLoader uiClassLoader =
(cl != null) ? (ClassLoader)cl : target.getClass().getClassLoader();
Class uiClass = getUIClass(target.getUIClassID(), uiClassLoader);
Object uiObject = null;
if (uiClass == null) {
getUIError("no ComponentUI class for: " + target);
}
else {
try {
Method m = (Method)get(uiClass);
if (m == null) {
Class acClass = javax.swing.JComponent.class;
m = uiClass.getMethod("createUI", new Class[]{acClass});
put(uiClass, m);
}
uiObject = MethodUtil.invoke(m, null, new Object[]{target});
}
catch (NoSuchMethodException e) {
getUIError("static createUI() method not found in " + uiClass);
}
catch (Exception e) {
getUIError("createUI() failed for " + target + " " + e);
}
}
return (ComponentUI)uiObject;
}
Creates an ComponentUI implementation for the
specified component. In other words create the look
and feel specific delegate object for target.
This is done in two steps:
- Look up the name of the
ComponentUI implementation
class under the value returned by target.getUIClassID().
- Use the implementation classes static
createUI()
method to construct a look and feel delegate.
|
public Class getUIClass(String uiClassID) {
return getUIClass(uiClassID, null);
}
Returns the L&F class that renders this component. |
public Class getUIClass(String uiClassID,
ClassLoader uiClassLoader) {
try {
String className = (String)get(uiClassID);
if (className != null) {
Class cls = (Class)get(className);
if (cls == null) {
if (uiClassLoader == null) {
cls = SwingUtilities.loadSystemClass(className);
}
else {
cls = uiClassLoader.loadClass(className);
}
if (cls != null) {
// Save lookup for future use, as forName is slow.
put(className, cls);
}
}
return cls;
}
}
catch (ClassNotFoundException e) {
return null;
}
catch (ClassCastException e) {
return null;
}
return null;
}
The value of get(uidClassID) must be the
String name of a
class that implements the corresponding ComponentUI
class. If the class hasn't been loaded before, this method looks
up the class with uiClassLoader.loadClass() if a non
null
class loader is provided, classForName() otherwise.
If a mapping for uiClassID exists or if the specified
class can't be found, return null.
This method is used by getUI, it's usually
not necessary to call it directly. |
protected void getUIError(String msg) {
System.err.println("UIDefaults.getUI() failed: " + msg);
try {
throw new Error();
}
catch (Throwable e) {
e.printStackTrace();
}
}
If getUI() fails for any reason,
it calls this method before returning null.
Subclasses may choose to do more or less here. |
public Object put(Object key,
Object value) {
Object oldValue = (value == null) ? super.remove(key) : super.put(key, value);
if (key instanceof String) {
firePropertyChange((String)key, oldValue, value);
}
return oldValue;
}
Sets the value of key to value for all locales.
If key is a string and the new value isn't
equal to the old one, fire a PropertyChangeEvent.
If value is null, the key is removed from the table. |
public void putDefaults(Object[] keyValueList) {
for(int i = 0, max = keyValueList.length; i < max; i += 2) {
Object value = keyValueList[i + 1];
if (value == null) {
super.remove(keyValueList[i]);
}
else {
super.put(keyValueList[i], value);
}
}
firePropertyChange("UIDefaults", null, null);
}
Puts all of the key/value pairs in the database and
unconditionally generates one PropertyChangeEvent.
The events oldValue and newValue will be null and its
propertyName will be "UIDefaults". The key/value pairs are
added for all locales. |
public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
if (changeSupport != null) {
changeSupport.removePropertyChangeListener(listener);
}
}
Removes a PropertyChangeListener from the listener list.
This removes a PropertyChangeListener that was registered
for all properties. |
public synchronized void removeResourceBundle(String bundleName) {
if( resourceBundles != null ) {
resourceBundles.remove( bundleName );
}
resourceCache.clear();
}
Removes a resource bundle from the list of resource bundles that are
searched for localized defaults. |
public void setDefaultLocale(Locale l) {
defaultLocale = l;
}
Sets the default locale. The default locale is used in retrieving
localized values via get methods that do not take a
locale argument. As of release 1.4, Swing UI objects should retrieve
localized values using the locale of their component rather than the
default locale. The default locale exists to provide compatibility with
pre 1.4 behaviour. |