FileDocCategorySizeDatePackage
DesktopProperty.javaAPI DocJava SE 6 API8568Tue Jun 10 00:21:58 BST 2008com.sun.java.swing.plaf.windows

DesktopProperty

public class DesktopProperty extends Object implements UIDefaults$ActiveValue
Wrapper for a value from the desktop. The value is lazily looked up, and can be accessed using the UIManager.ActiveValue method createValue. If the underlying desktop property changes this will force the UIs to update all known Frames. You can invoke invalidate to force the value to be fetched again.
version
@(#)DesktopProperty.java 1.10 05/11/17

Fields Summary
private static boolean
updatePending
Indicates if an updateUI call is pending.
private static ReferenceQueue
queue
ReferenceQueue of unreferenced WeakPCLs.
private WeakPCL
pcl
PropertyChangeListener attached to the Toolkit.
private String
key
Key used to lookup value from desktop.
private Object
value
Value to return.
private Object
fallback
Fallback value in case we get null from desktop.
private Toolkit
toolkit
Toolkit.
Constructors Summary
public DesktopProperty(String key, Object fallback, Toolkit toolkit)
Creates a DesktopProperty.

param
key Key used in looking up desktop value.
param
fallback Value used if desktop property is null.
param
toolkit Toolkit used to fetch property from, can be null in which default will be used.

        this.key = key;
        this.fallback = fallback;
        this.toolkit = toolkit;
        // The only sure fire way to clear our references is to create a
        // Thread and wait for a reference to be added to the queue.
        // Because it is so rare that you will actually change the look
        // and feel, this stepped is forgoed and a middle ground of
        // flushing references from the constructor is instead done.
        // The implication is that once one DesktopProperty is created
        // there will most likely be n (number of DesktopProperties created
        // by the LookAndFeel) WeakPCLs around, but this number will not
        // grow past n.
        flushUnreferencedProperties();
    
Methods Summary
protected java.lang.ObjectconfigureValue(java.lang.Object value)
Configures the value as appropriate for a defaults property in the UIDefaults table.

        if (value != null) {
            if (value instanceof Color) {
                return new ColorUIResource((Color)value);
            }
            else if (value instanceof Font) {
                return new FontUIResource((Font)value);
            }
            else if (value instanceof UIDefaults.LazyValue) {
                value = ((UIDefaults.LazyValue)value).createValue(null);
            }
            else if (value instanceof UIDefaults.ActiveValue) {
                value = ((UIDefaults.ActiveValue)value).createValue(null);
            }
        }
        return value;
    
public java.lang.ObjectcreateValue(javax.swing.UIDefaults table)
UIManager.LazyValue method, returns the value from the desktop or the fallback value if the desktop value is null.

        if (value == null) {
            value = configureValue(getValueFromDesktop());
            if (value == null) {
                value = configureValue(getDefaultValue());
            }
        }
        return value;
    
static voidflushUnreferencedProperties()
Cleans up any lingering state held by unrefeernced DesktopProperties.

        queue = new ReferenceQueue();
    
        WeakPCL pcl;

        while ((pcl = (WeakPCL)queue.poll()) != null) {
            pcl.dispose();
        }
    
protected java.lang.ObjectgetDefaultValue()
Returns the value to use if the desktop property is null.

        return fallback;
    
protected java.lang.StringgetKey()
Returns the key used to lookup the desktop properties value.

        return key;
    
protected java.lang.ObjectgetValueFromDesktop()
Returns the value from the desktop.

        if (this.toolkit == null) {
            this.toolkit = Toolkit.getDefaultToolkit();
        }
        Object value = toolkit.getDesktopProperty(getKey());
        pcl = new WeakPCL(this, toolkit, getKey(), UIManager.getLookAndFeel());
        toolkit.addPropertyChangeListener(getKey(), pcl);
        return value;
    
public voidinvalidate(javax.swing.LookAndFeel laf)
Invalidates the current value.

param
laf the LookAndFeel this DesktopProperty was created with

        invalidate();
    
public voidinvalidate()
Invalides the current value so that the next invocation of createValue will ask for the property again.

        if (pcl != null) {
            toolkit.removePropertyChangeListener(getKey(), pcl);
            toolkit = null;
            pcl = null;
            value = null;
        }
    
private static synchronized booleanisUpdatePending()
Returns true if a UI update is pending.

	return updatePending;
    
private static synchronized voidsetUpdatePending(boolean update)
Sets whether or not an updateUI call is pending.

	updatePending = update;
    
private static voidupdateAllUIs()
Updates the UIs of all the known Frames.

	// Check if the current UI is WindowsLookAndfeel and flush the XP style map.
	// Note: Change the package test if this class is moved to a different package.
	Class uiClass = UIManager.getLookAndFeel().getClass();
 	if (uiClass.getPackage().equals(DesktopProperty.class.getPackage())) {
	    XPStyle.invalidateStyle();
 	}
        Frame appFrames[] = Frame.getFrames();
	for (int j=0; j < appFrames.length; j++) {
	    updateWindowUI(appFrames[j]);			    
	}
    
protected voidupdateUI()
Requests that all components in the GUI hierarchy be updated to reflect dynamic changes in this look&feel. This update occurs by uninstalling and re-installing the UI objects. Requests are batched and collapsed into a single update pass because often many desktop properties will change at once.

	if (!isUpdatePending()) {
            setUpdatePending(true);
            Runnable uiUpdater = new Runnable() {
                public void run() {
                    updateAllUIs();
		    setUpdatePending(false);
                }
            };
            SwingUtilities.invokeLater(uiUpdater);
	}
    
private static voidupdateWindowUI(java.awt.Window window)
Updates the UI of the passed in window and all its children.

        SwingUtilities.updateComponentTreeUI(window);
	Window ownedWins[] = window.getOwnedWindows();
	for (int i=0; i < ownedWins.length; i++) {
	    updateWindowUI(ownedWins[i]);
	}