public class EventListenerList extends Object
A class for managing event listeners for an event source.
This class allows registering an arbitrary number of event listeners for
specific event types. Event types are specified using the EventType
class. Due to the type parameters in method signatures, it is guaranteed that
registered listeners are compatible with the event types they are interested
in.
There are also methods for firing events. Here all registered listeners are determined - based on the event type specified at registration time - which should receive the event to be fired. So basically, the event type at listener registration serves as a filter criterion. Because of the hierarchical nature of event types it can be determined in a fine-grained way which events are propagated to which listeners. It is also possible to register a listener multiple times for different event types.
Implementation note: This class is thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
EventListenerList.EventListenerIterator<T extends Event>
A special
Iterator implementation used by the
getEventListenerIterator() method. |
Constructor and Description |
---|
EventListenerList()
Creates a new instance of
EventListenerList . |
Modifier and Type | Method and Description |
---|---|
void |
addAll(EventListenerList c)
Adds all event listener registrations stored in the specified
EventListenerList to this list. |
<T extends Event> |
addEventListener(EventListenerRegistrationData<T> regData)
Adds the specified listener registration data object to the internal list
of event listeners.
|
<T extends Event> |
addEventListener(EventType<T> type,
EventListener<? super T> listener)
Adds an event listener for the specified event type.
|
void |
clear()
Removes all event listeners registered at this object.
|
void |
fire(Event event)
Fires an event to all registered listeners matching the event type.
|
<T extends Event> |
getEventListenerIterator(EventType<T> eventType)
Returns a specialized iterator for obtaining all event listeners stored
in this list which are compatible with the specified event type.
|
<T extends Event> |
getEventListeners(EventType<T> eventType)
Returns an
Iterable allowing access to all event listeners stored
in this list which are compatible with the specified event type. |
List<EventListenerRegistrationData<?>> |
getRegistrations()
Returns an (unmodifiable) list with registration information about all
event listeners registered at this object.
|
<T extends Event> |
getRegistrationsForSuperType(EventType<T> eventType)
Returns a list with
EventListenerRegistrationData objects for all
event listener registrations of the specified event type or an event type
having this type as super type (directly or indirectly). |
<T extends Event> |
removeEventListener(EventListenerRegistrationData<T> regData)
Removes the event listener registration defined by the passed in data
object.
|
<T extends Event> |
removeEventListener(EventType<T> eventType,
EventListener<? super T> listener)
Removes the event listener registration for the given event type and
listener.
|
public EventListenerList()
EventListenerList
.public <T extends Event> void addEventListener(EventType<T> type, EventListener<? super T> listener)
T
- the type of events processed by this listenertype
- the event type (must not be null)listener
- the listener to be registered (must not be null)IllegalArgumentException
- if a required parameter is nullpublic <T extends Event> void addEventListener(EventListenerRegistrationData<T> regData)
T
- the type of events processed by this listenerregData
- the registration data object (must not be null)IllegalArgumentException
- if the registration data object is
nullpublic <T extends Event> boolean removeEventListener(EventType<T> eventType, EventListener<? super T> listener)
T
- the type of events processed by this listenereventType
- the event typelistener
- the event listener to be removedpublic <T extends Event> boolean removeEventListener(EventListenerRegistrationData<T> regData)
T
- the type of events processed by this listenerregData
- the registration data objectremoveEventListener(EventType, EventListener)
public void fire(Event event)
event
- the event to be fired (must not be null)IllegalArgumentException
- if the event is nullpublic <T extends Event> Iterable<EventListener<? super T>> getEventListeners(EventType<T> eventType)
Iterable
allowing access to all event listeners stored
in this list which are compatible with the specified event type.T
- the event typeeventType
- the event type objectIterable
with the selected event listenerspublic <T extends Event> EventListenerList.EventListenerIterator<T> getEventListenerIterator(EventType<T> eventType)
T
- the event typeeventType
- the event type objectIterator
with the selected event listenerspublic List<EventListenerRegistrationData<?>> getRegistrations()
public <T extends Event> List<EventListenerRegistrationData<? extends T>> getRegistrationsForSuperType(EventType<T> eventType)
EventListenerRegistrationData
objects for all
event listener registrations of the specified event type or an event type
having this type as super type (directly or indirectly). Note that this
is the opposite direction than querying event types for firing events: in
this case event listener registrations are searched which are super event
types from a given type. This method in contrast returns event listener
registrations for listeners that extend a given super type.T
- the event typeeventType
- the event type objectpublic void clear()
public void addAll(EventListenerList c)
EventListenerList
to this list.c
- the list to be copied (must not be null)IllegalArgumentException
- if the list to be copied is nullCopyright © 2001–2020 The Apache Software Foundation. All rights reserved.