Package org.fest.swing.listener
Class WeakEventListener
java.lang.Object
org.fest.swing.listener.WeakEventListener
- All Implemented Interfaces:
AWTEventListener,EventListener
Understands an event listener that wraps a given
AWTEventListener and:
- attaches itself to the default toolkit
- dispatches any given event to the wrapped listener
- removes itself from the default toolkit when the wrapped listener gets garbage-collected
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final WeakReference<AWTEventListener>private final Toolkit -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateWeakEventListener(Toolkit toolkit, AWTEventListener listener) -
Method Summary
Modifier and TypeMethodDescriptionstatic WeakEventListenerattachAsWeakEventListener(Toolkit toolkit, AWTEventListener listener, long eventMask) Creates a newand adds it to the givenWeakEventListenerusing the given event mask.Toolkitvoiddispose()Removes itself from thethis listener is attached to.ToolkitvoidDispatches the given event to the wrapped event listener.(package private) voidRemoves the wrapped listener from the(to simulate garbage collection).WeakReferenceReturns the underlying listener.
-
Field Details
-
listenerReference
-
toolkit
-
-
Constructor Details
-
WeakEventListener
-
-
Method Details
-
attachAsWeakEventListener
public static WeakEventListener attachAsWeakEventListener(Toolkit toolkit, AWTEventListener listener, long eventMask) Creates a newand adds it to the givenWeakEventListenerusing the given event mask. The createdToolkitsimply "decorates" the givenWeakEventListener. All events dispatched to theAWTEventListenerare re-routed to the underlyingWeakEventListener. When the underlyingAWTEventListeneris garbage-collected, theAWTEventListenerwill remove itself from the toolkit.WeakEventListener- Parameters:
toolkit- the given AWTToolkit.listener- the underlying listener to wrap.eventMask- the event mask to use to attach theWeakEventListenerto the toolkit.- Returns:
- the created
WeakEventListener.
-
underlyingListener
Returns the underlying listener.- Returns:
- the underlying listener.
-
eventDispatched
Dispatches the given event to the wrapped event listener. If the wrapped listener isnull(garbage-collected,) this listener will remove itself from the default toolkit.- Specified by:
eventDispatchedin interfaceAWTEventListener- Parameters:
e- the event dispatched in the AWT.
-
dispose
public void dispose()Removes itself from thethis listener is attached to.Toolkit -
simulateUnderlyingListenerIsGarbageCollected
void simulateUnderlyingListenerIsGarbageCollected()Removes the wrapped listener from the(to simulate garbage collection). This method should be used only for testing only.WeakReference
-