public class ListenerList
extends java.lang.Object
ListenerList
class provides a utility to maintain lists of
registered listeners. It is fairly lightweight and should not impose to
much memory overhead.
Use the getListeners()
method when notifying listeners. Note that
no garbage is created if no listeners are registered. The recommended code
sequence for notifying all registered listeners of say,
FooListener.eventHappened
, is:
Object[] listeners = myListenerList.getListeners(); for (int i = 0; i < listeners.length; ++i) { ((FooListener) listeners[i]).eventHappened(event); }
Constructor and Description |
---|
ListenerList()
Creates an instance of this listener list class.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addListener(java.lang.Object listener)
Adds a listener to the list of listeners if it is not yet registered in
the list.
|
void |
clear()
Clears the list of registered listeners.
|
java.lang.Object[] |
getListeners()
Returns the list of registered listeners.
|
java.lang.Object[] |
getListeners(java.lang.Class requestedType)
Returns the list of registered listeners in an array of the reqeusted
runtime type.
|
boolean |
removeListener(java.lang.Object listener)
Removes a listener from the list of listeners if it is contained.
|
int |
size()
Returns the number of currently registered listeners.
|
public ListenerList()
public boolean addListener(java.lang.Object listener)
listener
- The listener to add to the list. If null
nothing is done.true
if the listener has been added to the listpublic boolean removeListener(java.lang.Object listener)
listener
- The listener to remove from the list. If
null
nothing is done.true
if the listener has been added to the listpublic void clear()
public int size()
public java.lang.Object[] getListeners()
public java.lang.Object[] getListeners(java.lang.Class requestedType)
requestedType
- The runtime type of the components of the array to
return.java.lang.ArrayStoreException
- if the runtime type is not a supertype of
the runtime type of every element in this list."Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"