public class ListenerManager<T extends EventListener> extends Object
ListenerManager
helps you keep track of EventListener
lists. The
speciality of this manager is to store the listeners weakly, so you won't need to
remove the listeners before you destroy the receiver object.Constructor and Description |
---|
ListenerManager() |
Modifier and Type | Method and Description |
---|---|
void |
addListener(T listener)
Adds a listener to this manager.
|
Collection<T> |
getListeners()
Gets a
Collection of all current listeners. |
void |
removeAllListeners()
Removes all listeners from this manager.
|
void |
removeListener(T listener)
Removes the listener from this manager.
|
public ListenerManager()
public void addListener(T listener)
listener
- Listener to be addedpublic void removeListener(T listener)
listener
- Listener to be removedpublic Collection<T> getListeners()
Collection
of all current listeners. This collection is
for immediate use only and must not be stored. If a listener is
removed after this method was invoked, it will still be present in the result
collection. Also, storing the result collection will keep a reference to the
listeners and will render the weak reference mechanism useless.
Example for proper usage:
for (ActionListener listener : manager.getListeners()) { listener.actionPerformed(event); }
The listeners are returned in no special order.
Collection
of all current listeners.public void removeAllListeners()
Copyright © 2004–2016. All rights reserved.