FileDocCategorySizeDatePackage
ActionPropertyChangeListener.javaAPI DocJava SE 6 API4449Tue Jun 10 00:26:34 BST 2008javax.swing

ActionPropertyChangeListener

public abstract class ActionPropertyChangeListener extends Object implements Serializable, PropertyChangeListener
A package-private PropertyChangeListener which listens for property changes on an Action and updates the properties of an ActionEvent source.

Subclasses must override the actionPropertyChanged method, which is invoked from the propertyChange method as long as the target is still valid.

WARNING WARNING WARNING WARNING WARNING WARNING:
Do NOT create an annonymous inner class that extends this! If you do a strong reference will be held to the containing class, which in most cases defeats the purpose of this class.

param
T the type of JComponent the underlying Action is attached to
version
1.15 02/09/06
author
Georges Saab
see
AbstractButton

Fields Summary
private static ReferenceQueue
queue
private transient OwnedWeakReference
target
private Action
action
Constructors Summary
public ActionPropertyChangeListener(T c, Action a)

	super();
	setTarget(c);
	this.action = a;
    
Methods Summary
protected abstract voidactionPropertyChanged(T target, javax.swing.Action action, java.beans.PropertyChangeEvent e)
Invoked when a property changes on the Action and the target still exists.

public javax.swing.ActiongetAction()

	  return action;
    
private static java.lang.ref.ReferenceQueuegetQueue()

        synchronized(ActionPropertyChangeListener.class) {
            if (queue == null) {
                queue = new ReferenceQueue<JComponent>();
            }
        }
        return queue;
    
public TgetTarget()

        if (target == null) {
            // Will only happen if serialized and real target was null
            return null;
        }
        return this.target.get();
    
public final voidpropertyChange(java.beans.PropertyChangeEvent e)
PropertyChangeListener method. If the target has been gc'ed this will remove the PropertyChangeListener from the Action, otherwise this will invoke actionPropertyChanged.

        T target = getTarget();
        if (target == null) {
            getAction().removePropertyChangeListener(this);
        } else {
            actionPropertyChanged(target, getAction(), e);
        }
    
private voidreadObject(java.io.ObjectInputStream s)

        s.defaultReadObject();
        T target = (T)s.readObject();
        if (target != null) {
            setTarget(target);
        }
    
private voidsetTarget(T c)

        ReferenceQueue<JComponent> queue = getQueue();
	// Check to see whether any old buttons have
	// been enqueued for GC.  If so, look up their
	// PCL instance and remove it from its Action.
	OwnedWeakReference r;
        while ((r = (OwnedWeakReference)queue.poll()) != null) {
            ActionPropertyChangeListener oldPCL = r.getOwner();
	    Action oldAction = oldPCL.getAction();
	    if (oldAction!=null) {
	        oldAction.removePropertyChangeListener(oldPCL);
	    }
	}
        this.target = new OwnedWeakReference<T>(c, queue, this);
    
private voidwriteObject(java.io.ObjectOutputStream s)

        s.defaultWriteObject();
        s.writeObject(getTarget());