org.progeeks.graph
Class WeakGraphListener

java.lang.Object
  extended by org.progeeks.graph.WeakGraphListener
All Implemented Interfaces:
com.phoenixst.plexus.GraphListener, java.util.EventListener

public class WeakGraphListener
extends java.lang.Object
implements com.phoenixst.plexus.GraphListener

Graph listener that holds weak reference to a delegate GraphListener. If the weak reference becomes null (meaning the delegate has been GC'ed) then this listener will remove itself from any graphs that it receives events from. It isn't perfect, but it's a lot better than nothing... and presumably graphs that no longer send out events probably don't care if their listeners weren't properly cleaned up. Any other approach would require this class to keep track of every graph it had been added to. It's more convenient this way. Note: DON"T FORGET TO KEEP A REFERENCE TO YOUR DELEGATE. It is often tempting to do something like: l = new WeakGraphListener( new MyGraphListener() ); But since you aren't keeping a reference to the listener, it will be GCed and this weak listener will remove itself from wherever you've added it.

Version:
$Revision: 1.3 $
Author:
Paul Speed

Constructor Summary
WeakGraphListener(com.phoenixst.plexus.GraphListener delegate)
           
 
Method Summary
 void edgeAdded(com.phoenixst.plexus.GraphEvent event)
           
 void edgeRemoved(com.phoenixst.plexus.GraphEvent event)
           
 void nodeAdded(com.phoenixst.plexus.GraphEvent event)
           
 void nodeRemoved(com.phoenixst.plexus.GraphEvent event)
           
protected  void removeFromSource(com.phoenixst.plexus.GraphEvent event)
          Method that can be subclassed to provide additional remove support.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WeakGraphListener

public WeakGraphListener(com.phoenixst.plexus.GraphListener delegate)
Method Detail

removeFromSource

protected void removeFromSource(com.phoenixst.plexus.GraphEvent event)
Method that can be subclassed to provide additional remove support.


nodeAdded

public void nodeAdded(com.phoenixst.plexus.GraphEvent event)
Specified by:
nodeAdded in interface com.phoenixst.plexus.GraphListener

nodeRemoved

public void nodeRemoved(com.phoenixst.plexus.GraphEvent event)
Specified by:
nodeRemoved in interface com.phoenixst.plexus.GraphListener

edgeAdded

public void edgeAdded(com.phoenixst.plexus.GraphEvent event)
Specified by:
edgeAdded in interface com.phoenixst.plexus.GraphListener

edgeRemoved

public void edgeRemoved(com.phoenixst.plexus.GraphEvent event)
Specified by:
edgeRemoved in interface com.phoenixst.plexus.GraphListener


Copyright © 2002-2003 Paul Speed. All Rights Reserved.