Class WeakListenerImpl

  extended by org.openide.util.WeakListenerImpl
All Implemented Interfaces:
Direct Known Subclasses:
WeakListenerImpl.Change, WeakListenerImpl.Document, WeakListenerImpl.Focus, WeakListenerImpl.PropertyChange, WeakListenerImpl.VetoableChange

abstract class WeakListenerImpl
extends java.lang.Object
implements java.util.EventListener

A listener wrapper that delegates to another listener but hold only weak reference to it, so it does not prevent it to be finalized.

Jaroslav Tulach

Nested Class Summary
(package private) static class WeakListenerImpl.Change
          Weak swing change listener.
(package private) static class WeakListenerImpl.Document
          Weak document modifications listener.
(package private) static class WeakListenerImpl.Focus
          Weak version of focus listener.
(package private) static class WeakListenerImpl.PropertyChange
          Weak property change listener
(package private) static class WeakListenerImpl.VetoableChange
          Weak vetoable change listener
Field Summary
(package private)  java.lang.Class listenerClass
          class of the listener
Constructor Summary
protected WeakListenerImpl(java.lang.Class listenerClass, java.util.EventListener l)
Method Summary
<T extends java.util.EventListener>
create(java.lang.Class<T> lType, java.lang.Class<? super T> apiType, T l, java.lang.Object source)
protected  java.util.EventListener get(java.util.EventObject ev)
          Getter for the target listener.
(package private)  java.lang.Object getImplementator()
protected abstract  java.lang.String removeMethodName()
          Method name to use for removing the listener.
protected  void setSource(java.lang.Object source)
          Setter for the source field.
 java.lang.String toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail


java.lang.Class listenerClass
class of the listener

Constructor Detail


protected WeakListenerImpl(java.lang.Class listenerClass,
                           java.util.EventListener l)
listenerClass - class/interface of the listener
l - listener to delegate to, l must be an instance of listenerClass
Method Detail


protected final void setSource(java.lang.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 WeakListenerImpl, 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, WeakListenerImpls that lost their underlying listeners are removed as soon as the ReferenceQueue notifies the WeakListenerImpl.

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.


protected abstract java.lang.String removeMethodName()
Method name to use for removing the listener.

name of method of the source object that should be used to remove the listener from listening on source of events


protected final java.util.EventListener get(java.util.EventObject ev)
Getter for the target listener.

ev - the event the we want to distribute
null if there is no listener because it has been finalized


java.lang.Object getImplementator()


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


public static <T extends java.util.EventListener> T create(java.lang.Class<T> lType,
                                                           java.lang.Class<? super T> apiType,
                                                           T l,
                                                           java.lang.Object source)