org.jhotdraw.beans
Class WeakPropertyChangeListener

java.lang.Object
  extended by org.jhotdraw.beans.WeakPropertyChangeListener
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener

public class WeakPropertyChangeListener
extends java.lang.Object
implements java.beans.PropertyChangeListener

Property change listener that holds weak reference to a target property change listener. If the weak reference becomes null (meaning the delegate has been GC'ed) then this listener will remove itself from any beans that it receives events from. It isn't perfect, but it's a lot better than nothing... and presumably beans that no longer send out events probably don't care if their listeners weren't properly cleaned up. Design pattern: Proxy.

Version:
$Id: WeakPropertyChangeListener.java 527 2009-06-07 14:28:19Z rawcoder $
Author:
Paul Speed

Field Summary
private  java.lang.ref.WeakReference<java.beans.PropertyChangeListener> weakRef
           
 
Constructor Summary
WeakPropertyChangeListener(java.beans.PropertyChangeListener target)
           
 
Method Summary
 java.beans.PropertyChangeListener getTarget()
          Returns the target of this proxy.
 void propertyChange(java.beans.PropertyChangeEvent event)
           
protected  void removeFromSource(java.beans.PropertyChangeEvent event)
          Method that can be subclassed to provide additional remove support.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

weakRef

private java.lang.ref.WeakReference<java.beans.PropertyChangeListener> weakRef
Constructor Detail

WeakPropertyChangeListener

public WeakPropertyChangeListener(java.beans.PropertyChangeListener target)
Method Detail

removeFromSource

protected void removeFromSource(java.beans.PropertyChangeEvent event)
Method that can be subclassed to provide additional remove support. Default implementation only supports StandardBeans.


propertyChange

public void propertyChange(java.beans.PropertyChangeEvent event)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener

getTarget

public java.beans.PropertyChangeListener getTarget()
Returns the target of this proxy. Returns null if the target has been garbage collected.

Returns:
The target or null.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object