Methods Summary |
---|
public synchronized void | addPropertyChangeListener(java.beans.PropertyChangeListener listener)Adds a PropertyChangeListener to the listener list.
The listener is registered for all properties.
A PropertyChangeEvent will get fired whenever a default
is changed.
if (changeSupport == null) {
changeSupport = new SwingPropertyChangeSupport(this);
}
changeSupport.addPropertyChangeListener(listener);
|
public synchronized 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.
if( bundleName == null ) {
return;
}
if( resourceBundles == null ) {
resourceBundles = new Vector(5);
}
if (!resourceBundles.contains(bundleName)) {
resourceBundles.add( bundleName );
resourceCache.clear();
}
|
protected void | firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)Support for reporting bound property changes. If oldValue and
newValue are not equal and the PropertyChangeEvent x
listener list isn't empty, then fire a
PropertyChange event to each listener.
if (changeSupport != null) {
changeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
|
public java.lang.Object | get(java.lang.Object key)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.
Object value = getFromHashtable( key );
return (value != null) ? value : getFromResourceBundle(key, null);
|
public java.lang.Object | get(java.lang.Object key, java.util.Locale 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.
Object value = getFromHashtable( key );
return (value != null) ? value : getFromResourceBundle(key, l);
|
public boolean | getBoolean(java.lang.Object key)If the value of key is boolean, return the
boolean value, otherwise return false.
Object value = get(key);
return (value instanceof Boolean) ? ((Boolean)value).booleanValue() : false;
|
public boolean | getBoolean(java.lang.Object key, java.util.Locale l)If the value of key for the given Locale
is boolean, return the boolean value, otherwise return false.
Object value = get(key,l);
return (value instanceof Boolean) ? ((Boolean)value).booleanValue() : false;
|
public javax.swing.border.Border | getBorder(java.lang.Object key)If the value of key is a Border return it,
otherwise return null .
Object value = get(key);
return (value instanceof Border) ? (Border)value : null;
|
public javax.swing.border.Border | getBorder(java.lang.Object key, java.util.Locale l)If the value of key for the given Locale
is a Border return it, otherwise return null .
Object value = get(key,l);
return (value instanceof Border) ? (Border)value : null;
|
public java.awt.Color | getColor(java.lang.Object key)If the value of key is a Color return it,
otherwise return null .
Object value = get(key);
return (value instanceof Color) ? (Color)value : null;
|
public java.awt.Color | getColor(java.lang.Object key, java.util.Locale l)If the value of key for the given Locale
is a Color return it, otherwise return null .
Object value = get(key,l);
return (value instanceof Color) ? (Color)value : null;
|
public java.util.Locale | getDefaultLocale()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.
return defaultLocale;
|
public java.awt.Dimension | getDimension(java.lang.Object key)If the value of key is a Dimension return it,
otherwise return null .
Object value = get(key);
return (value instanceof Dimension) ? (Dimension)value : null;
|
public java.awt.Dimension | getDimension(java.lang.Object key, java.util.Locale l)If the value of key for the given Locale
is a Dimension return it, otherwise return null .
Object value = get(key,l);
return (value instanceof Dimension) ? (Dimension)value : null;
|
public java.awt.Font | getFont(java.lang.Object key)If the value of key is a Font return it,
otherwise return null .
Object value = get(key);
return (value instanceof Font) ? (Font)value : null;
|
public java.awt.Font | getFont(java.lang.Object key, java.util.Locale l)If the value of key for the given Locale
is a Font return it, otherwise return null .
Object value = get(key,l);
return (value instanceof Font) ? (Font)value : null;
|
private java.lang.Object | getFromHashtable(java.lang.Object key)Looks up up the given key in our Hashtable and resolves LazyValues
or ActiveValues.
/* Quickly handle the common case, without grabbing
* a lock.
*/
Object value = super.get(key);
if ((value != PENDING) &&
!(value instanceof ActiveValue) &&
!(value instanceof LazyValue)) {
return value;
}
/* If the LazyValue for key is being constructed by another
* thread then wait and then return the new value, otherwise drop
* the lock and construct the ActiveValue or the LazyValue.
* We use the special value PENDING to mark LazyValues that
* are being constructed.
*/
synchronized(this) {
value = super.get(key);
if (value == PENDING) {
do {
try {
this.wait();
}
catch (InterruptedException e) {
}
value = super.get(key);
}
while(value == PENDING);
return value;
}
else if (value instanceof LazyValue) {
super.put(key, PENDING);
}
else if (!(value instanceof ActiveValue)) {
return value;
}
}
/* At this point we know that the value of key was
* a LazyValue or an ActiveValue.
*/
if (value instanceof LazyValue) {
try {
/* If an exception is thrown we'll just put the LazyValue
* back in the table.
*/
value = ((LazyValue)value).createValue(this);
}
finally {
synchronized(this) {
if (value == null) {
super.remove(key);
}
else {
super.put(key, value);
}
this.notifyAll();
}
}
}
else {
value = ((ActiveValue)value).createValue(this);
}
return value;
|
private java.lang.Object | getFromResourceBundle(java.lang.Object key, java.util.Locale l)Looks up given key in our resource bundles.
if( resourceBundles == null ||
resourceBundles.isEmpty() ||
!(key instanceof String) ) {
return null;
}
// A null locale means use the default locale.
if( l == null ) {
if( defaultLocale == null )
return null;
else
l = (Locale)defaultLocale;
}
synchronized(this) {
return getResourceCache(l).get((String)key);
}
|
public javax.swing.Icon | getIcon(java.lang.Object key)If the value of key is an Icon return it,
otherwise return null .
Object value = get(key);
return (value instanceof Icon) ? (Icon)value : null;
|
public javax.swing.Icon | getIcon(java.lang.Object key, java.util.Locale l)If the value of key for the given Locale
is an Icon return it, otherwise return null .
Object value = get(key,l);
return (value instanceof Icon) ? (Icon)value : null;
|
public java.awt.Insets | getInsets(java.lang.Object key)If the value of key is an Insets return it,
otherwise return null .
Object value = get(key);
return (value instanceof Insets) ? (Insets)value : null;
|
public java.awt.Insets | getInsets(java.lang.Object key, java.util.Locale l)If the value of key for the given Locale
is an Insets return it, otherwise return null .
Object value = get(key,l);
return (value instanceof Insets) ? (Insets)value : null;
|
public int | getInt(java.lang.Object key)If the value of key is an Integer return its
integer value, otherwise return 0.
Object value = get(key);
return (value instanceof Integer) ? ((Integer)value).intValue() : 0;
|
public int | getInt(java.lang.Object key, java.util.Locale l)If the value of key for the given Locale
is an Integer return its integer value, otherwise return 0.
Object value = get(key,l);
return (value instanceof Integer) ? ((Integer)value).intValue() : 0;
|
public synchronized java.beans.PropertyChangeListener[] | getPropertyChangeListeners()Returns an array of all the PropertyChangeListener s added
to this UIDefaults with addPropertyChangeListener().
if (changeSupport == null) {
return new PropertyChangeListener[0];
}
return changeSupport.getPropertyChangeListeners();
|
private java.util.Map | getResourceCache(java.util.Locale l)Returns a Map of the known resources for the given locale.
Map values = (Map)resourceCache.get(l);
if (values == null) {
values = new HashMap();
for (int i=resourceBundles.size()-1; i >= 0; i--) {
String bundleName = (String)resourceBundles.get(i);
try {
ResourceBundle b = ResourceBundle.getBundle(bundleName, l);
Enumeration keys = b.getKeys();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
if (values.get(key) == null) {
Object value = b.getObject(key);
values.put(key, value);
}
}
} catch( MissingResourceException mre ) {
// Keep looking
}
}
resourceCache.put(l, values);
}
return values;
|
public java.lang.String | getString(java.lang.Object key)If the value of key is a String return it,
otherwise return null .
Object value = get(key);
return (value instanceof String) ? (String)value : null;
|
public java.lang.String | getString(java.lang.Object key, java.util.Locale l)If the value of key for the given Locale
is a String return it, otherwise return null .
Object value = get(key,l);
return (value instanceof String) ? (String)value : null;
|
public javax.swing.plaf.ComponentUI | getUI(javax.swing.JComponent target)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.
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;
|
public java.lang.Class | getUIClass(java.lang.String uiClassID, java.lang.ClassLoader uiClassLoader)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.
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;
|
public java.lang.Class | getUIClass(java.lang.String uiClassID)Returns the L&F class that renders this component.
return getUIClass(uiClassID, null);
|
protected void | getUIError(java.lang.String msg)If getUI() fails for any reason,
it calls this method before returning null .
Subclasses may choose to do more or less here.
System.err.println("UIDefaults.getUI() failed: " + msg);
try {
throw new Error();
}
catch (Throwable e) {
e.printStackTrace();
}
|
public java.lang.Object | put(java.lang.Object key, java.lang.Object value)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.
Object oldValue = (value == null) ? super.remove(key) : super.put(key, value);
if (key instanceof String) {
firePropertyChange((String)key, oldValue, value);
}
return oldValue;
|
public void | putDefaults(java.lang.Object[] keyValueList)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.
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);
|
public synchronized void | removePropertyChangeListener(java.beans.PropertyChangeListener listener)Removes a PropertyChangeListener from the listener list.
This removes a PropertyChangeListener that was registered
for all properties.
if (changeSupport != null) {
changeSupport.removePropertyChangeListener(listener);
}
|
public synchronized void | removeResourceBundle(java.lang.String bundleName)Removes a resource bundle from the list of resource bundles that are
searched for localized defaults.
if( resourceBundles != null ) {
resourceBundles.remove( bundleName );
}
resourceCache.clear();
|
public void | setDefaultLocale(java.util.Locale 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.
defaultLocale = l;
|