org.openide.util
Class WeakListenerImpl

java.lang.Object
  extended by org.openide.util.WeakListenerImpl
All Implemented Interfaces:
java.util.EventListener
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.

Author:
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
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)
           
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

listenerClass

java.lang.Class listenerClass
class of the listener

Constructor Detail

WeakListenerImpl

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

setSource

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.

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 java.lang.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 java.util.EventListener get(java.util.EventObject ev)
Getter for the target listener.

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

getImplementator

java.lang.Object getImplementator()

toString

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

create

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)