org.openide.util
Class WeakListener

java.lang.Object
  |
  +--org.openide.util.WeakListener
All Implemented Interfaces:
EventListener
Direct Known Subclasses:
WeakListener.Change, WeakListener.Document, WeakListener.FileChange, WeakListener.FileStatus, WeakListener.Focus, WeakListener.PropertyChange, WeakListener.Repository, WeakListener.VetoableChange

public abstract class WeakListener
extends Object
implements EventListener

Property change listener that delegates to another one change listener but hold only weak reference to that listener, so it does not prevent it to be finalized.


Inner Class Summary
static class WeakListener.Change
          Deprecated. use appropriate method instead
static class WeakListener.Document
          Deprecated. use appropriate method instead
static class WeakListener.FileChange
          Deprecated. use appropriate method instead
static class WeakListener.FileStatus
          Deprecated. use appropriate method instead
static class WeakListener.Focus
          Deprecated. use appropriate method instead
static class WeakListener.Node
          Deprecated. use appropriate method instead
static class WeakListener.PropertyChange
          Deprecated. use appropriate method instead
static class WeakListener.Repository
          Deprecated. use appropriate method instead
static class WeakListener.VetoableChange
          Deprecated. use appropriate method instead
 
Constructor Summary
protected WeakListener(Class listenerClass, EventListener l)
           
 
Method Summary
static ChangeListener change(ChangeListener l, Object source)
           
static EventListener create(Class lType, EventListener l, Object source)
           
static DocumentListener document(DocumentListener l, Object source)
           
static FileChangeListener fileChange(FileChangeListener l, Object source)
           
static FileStatusListener fileStatus(FileStatusListener l, Object source)
           
static FocusListener focus(FocusListener l, Object source)
           
protected  EventListener get(EventObject ev)
          Getter for the target listener.
static NodeListener node(NodeListener l, Object source)
          Creates a weak listener.
static OperationListener operation(OperationListener l, Object source)
           
static PropertyChangeListener propertyChange(PropertyChangeListener l, Object source)
           
protected abstract  String removeMethodName()
          Method name to use for removing the listener.
static RepositoryListener repository(RepositoryListener l, Object source)
           
protected  void setSource(Object source)
          Setter for the source field.
 String toString()
          To string.
static VetoableChangeListener vetoableChange(VetoableChangeListener l, Object source)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WeakListener

protected WeakListener(Class listenerClass,
                       EventListener l)
Parameters:
listenerClass - class of the listener
l - listener to delegate to
Method Detail

setSource

protected final void setSource(Object source)
Setter for the source field. If a WeakReference to an underlying listener is cleared and enqueued, that is, the original listener is garbage collected, then the source field is used for deregistration of this WeakListener, thus making it eligible for garbage collection if no more references exist. This method is particularly useful in cases where the underlying listener was garbage collected and the event source, on which this listener is listening on, is quiet, i.e. does not fire any events for long periods. In this case, this listener is not removed from the event source until an event is fired. If the source field is set however, WeakListeners that lost their underlying listeners are removed on a regular basis, which is currently 25s (see CLEANER_TIME constant).
Parameters:
source - is any Object or null, though only setting an object that has an appropriate remove*listenerClass*Listener method and on which this listener is listening on, is useful.

removeMethodName

protected abstract String removeMethodName()
Method name to use for removing the listener.
Returns:
name of method of the source object that should be used to remove the listener from listening on source of events

get

protected final EventListener get(EventObject ev)
Getter for the target listener.
Parameters:
event - the event the we want to distribute
Returns:
null if there is no listener because it has been finalized

toString

public String toString()
To string.
Overrides:
toString in class Object

node

public static NodeListener node(NodeListener l,
                                Object source)
Creates a weak listener. The sample usage code is
   AnySource source;
   AnyListener listener;
   
   AnyListener weak = WeakListener.any (listener, source);
   source.addAnyListener (weak);
 
Parameters:
l - the listener to delegate to
source - the source that the listener should detach from when listener l is no longer used, can be null

propertyChange

public static PropertyChangeListener propertyChange(PropertyChangeListener l,
                                                    Object source)

vetoableChange

public static VetoableChangeListener vetoableChange(VetoableChangeListener l,
                                                    Object source)

fileChange

public static FileChangeListener fileChange(FileChangeListener l,
                                            Object source)

fileStatus

public static FileStatusListener fileStatus(FileStatusListener l,
                                            Object source)

repository

public static RepositoryListener repository(RepositoryListener l,
                                            Object source)

document

public static DocumentListener document(DocumentListener l,
                                        Object source)

change

public static ChangeListener change(ChangeListener l,
                                    Object source)

focus

public static FocusListener focus(FocusListener l,
                                  Object source)

operation

public static OperationListener operation(OperationListener l,
                                          Object source)

create

public static EventListener create(Class lType,
                                   EventListener l,
                                   Object source)


Built on December 12 2001.  |  Portions Copyright 1997-2001 Sun Microsystems, Inc. All rights reserved.