com.glaivestone.javax.util
Class EventListenerList

java.lang.Object
  |
  +--com.glaivestone.javax.util.EventListenerList

public class EventListenerList
extends java.lang.Object

An EventListenerList holds a homogeneous list of event listeners. The implementation is efficient when there are no listeners and is thread-safe for list editing operations.

It is the responsibility of the list owner to provide type-safe services for accessing the listener list and ensuring that listeners in the list are of the correct type. A listener list owner will typically implement an addFooListener and optionally a removeFooListener service for managing the listener list for the Foo event listener interface.

The list owner typically also implements a fireXXX service for each event notification in the listener interface, within which the EventListener entries in the listener list are notified of the event by invoking the appropriate function in the listener interface.

When an event listener list has been configured for a specific listener type, the enerically typed EventListener[] listeners array obtained from getListeners can be cast directly to a correctly typed FooEventListener[] array. If the list has not been configured to hold a specific listener interface type, the owner must individually cast each entry in the listener list to the actual listener interface type when working with listeners in a listener list processing loop.

The owner of the listener list is is responsible for specifying the listener notification order when an event is fired. Listeners are appended to the list in registration order by the standard add operation.

Implementation Notes

This is a simplified version of the Swing EventListenerList. The Swing listener list provides a storage mechanism for multiple event types. This is a simpler mechanism which manages a single type of listeners. The EventManager provides a base class for event source objects which support multiple event types.

Author:
Deb Lewis
See Also:
EventListenerList, EventManager

Field Summary
static java.lang.Class GENERIC_LISTENER_TYPE
           
static int NOT_FOUND_INDEX
           
 
Constructor Summary
EventListenerList()
          Create a new event listener list.
EventListenerList(java.lang.Class listenerType)
          Create a new event listener list which holds listeners of the specified type.
 
Method Summary
 void add(java.util.EventListener aListener)
          Add the listener to the end of the list.
 void addFirst(java.util.EventListener aListener)
          Add the listener to the start of the list.
static java.util.EventListener[] getEmptyListenersArray(java.lang.Class listenerType)
          Answer an empty array of listeners of the specified type.
 java.util.EventListener[] getListeners()
          Answer the list of listeners.
static java.util.EventListener[] newListenersArray(java.lang.Class listenerType, int size)
          Answer a new array of listeners of the specified type with the given size.
 void remove(java.util.EventListener aListener)
          Remove the listener from the list.
 void removeAll()
          Remove all listeners from the list.
 int size()
          Answer the size of the listener list.
 java.lang.String toString()
          Answer a string representation of the receiver.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NOT_FOUND_INDEX

public static final int NOT_FOUND_INDEX
See Also:
Constant Field Values

GENERIC_LISTENER_TYPE

public static final java.lang.Class GENERIC_LISTENER_TYPE
Constructor Detail

EventListenerList

public EventListenerList()
Create a new event listener list.


EventListenerList

public EventListenerList(java.lang.Class listenerType)
Create a new event listener list which holds listeners of the specified type.

Method Detail

getEmptyListenersArray

public static java.util.EventListener[] getEmptyListenersArray(java.lang.Class listenerType)
Answer an empty array of listeners of the specified type.


newListenersArray

public static java.util.EventListener[] newListenersArray(java.lang.Class listenerType,
                                                          int size)
Answer a new array of listeners of the specified type with the given size.


add

public void add(java.util.EventListener aListener)
Add the listener to the end of the list.

Parameters:
aListener - the listener to be added

addFirst

public void addFirst(java.util.EventListener aListener)
Add the listener to the start of the list.

Parameters:
aListener - the listener to be added

getListeners

public java.util.EventListener[] getListeners()
Answer the list of listeners. Returns an empty array if there are none.

The listeners can be cast directly to FooEventListener[] if the listener list has been configured to manage a specific event type.

Clients must not modify the contents of the list; this should be treated as read-only. The actual storage list is returned directly for performance reasons.


remove

public void remove(java.util.EventListener aListener)
Remove the listener from the list.

Parameters:
aListener - the listener to be removed

removeAll

public void removeAll()
Remove all listeners from the list.


size

public int size()
Answer the size of the listener list.


toString

public java.lang.String toString()
Answer a string representation of the receiver.

Overrides:
toString in class java.lang.Object

GFL 1.1 API