|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.geotools.util.ListenerList
This class is used to maintain a list of listeners, and is used in the implementations of several classes within JFace which allow you to register listeners of various kinds. It is a fairly lightweight object, occupying minimal space when no listeners are registered.
Note that the add
method checks for and eliminates
duplicates based on identity (not equality). Likewise, the
remove
method compares based on identity.
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 a listener list with an initial capacity of 1. |
|
ListenerList(int capacity)
Creates a listener list with the given initial capacity. |
Method Summary | |
void |
add(java.lang.Object listener)
Adds the given listener to this list. |
void |
clear()
Removes all listeners from this list. |
java.lang.Object[] |
getListeners()
Returns an array containing all the registered listeners, in the order in which they were added. |
boolean |
isEmpty()
Returns whether this listener list is empty. |
void |
remove(java.lang.Object listener)
Removes the given listener from this list. |
int |
size()
Returns the number of registered listeners. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ListenerList()
public ListenerList(int capacity)
capacity
- the number of listeners which this list can initially accept
without growing its internal representation; must be at least 1Method Detail |
public void add(java.lang.Object listener)
listener
- the listenerpublic void clear()
public java.lang.Object[] getListeners()
The resulting array is unaffected by subsequent adds or removes. If there are no listeners registered, the result is an empty array singleton instance (no garbage is created). Use this method when notifying listeners, so that any modifications to the listener list during the notification will have no effect on the notification itself.
public boolean isEmpty()
true
if there are no registered listeners, and
false
otherwisepublic void remove(java.lang.Object listener)
listener
- the listenerpublic int size()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |