|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.day.util.ListenerList
public class ListenerList
The 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 Summary | |
|---|---|
ListenerList()
Creates an instance of this listener list class. |
|
| Method Summary | |
|---|---|
boolean |
addListener(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. |
Object[] |
getListeners()
Returns the list of registered listeners. |
Object[] |
getListeners(Class requestedType)
Returns the list of registered listeners in an array of the reqeusted runtime type. |
boolean |
removeListener(Object listener)
Removes a listener from the list of listeners if it is contained. |
int |
size()
Returns the number of currently registered listeners. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ListenerList()
| Method Detail |
|---|
public boolean addListener(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(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 Object[] getListeners()
public Object[] getListeners(Class requestedType)
requestedType - The runtime type of the components of the array to
return.
ArrayStoreException - if the runtime type is not a supertype of
the runtime type of every element in this list.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||