se.lth.cs.realtime.event
Class RTEventListenerList

java.lang.Object
  |
  +--se.lth.cs.realtime.event.RTEventListenerList

public class RTEventListenerList
extends java.lang.Object

A class which holds a list of RTEventListeners. The list is sorted according to a priority value, specified when adding a listener. A single instance can be used to hold all listeners (of all types) for the instance using the list. It is the responsiblity of the class using the EventListenerList to provide type-safe API (preferably conforming to the JavaBeans spec) and methods which dispatch event notification methods to appropriate Event Listeners on the list. Usage example: Say one is defining a class which sends out FooEvents, and wants to allow users of the class to register FooListeners and receive notification when FooEvents occur. The following should be added to the class definition:

RTEventListenerList listenerList = new RTEventListenerList();
FooEvent fooEvent = null;

public void addFooListener(FooListener l, int priority) {
listenerList.add(FooListener.class, l, priority);
}

public void removeFooListener(FooListener l) {
listenerList.remove(FooListener.class, l);
}


// Notify all listeners that have registered interest for
// notification on this event type.  The event instance 
// is lazily created using the parameters passed into 
// the fire method.

protected void firefooXXX() {
// Guaranteed to return a non-null array
TaggedListener[] listeners = listenerList.getListenerList();
// Process the listeners, notifying
// those that are interested in this event
for (int i = 0; i
 foo should be changed to the appropriate name, and Method to the
 appropriate method name (one fire method should exist for each
 notification method in the FooListener interface).

See Also:
javax.swing.event.EventListenerList

Inner Class Summary
 class RTEventListenerList.TaggedListener
          The element actually stored in the list of listeners.
 
Constructor Summary
RTEventListenerList()
          Instantiates a new RTEventListenerList.
 
Method Summary
 void add(java.lang.Class t, java.util.EventListener l, int p)
          Add the listener as a listener of the specified type, with the specified priority.
 int getListenerCount()
          Return the total number of listeners for this listenerList
 RTEventListenerList.TaggedListener[] getListenerList()
          Passes back the event listener list as an array of TaggedListeners.
 void remove(java.lang.Class t, java.util.EventListener l)
          Remove the listener as a listener of the specified type.
 java.lang.String toString()
          Return a string representation of the RTEventListenerList.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RTEventListenerList

public RTEventListenerList()
Instantiates a new RTEventListenerList.
Method Detail

getListenerList

public RTEventListenerList.TaggedListener[] getListenerList()
Passes back the event listener list as an array of TaggedListeners. Note that for performance reasons, this implementation passes back the actual data structure in which the listener data is stored internally! This method is guaranteed to pass back a non-null array, so that no null-checking is required in fire methods. A zero-length array of Object is returned if there are currently no listeners.

WARNING!!! Absolutely NO modification of the data contained in this array should be made -- if any such manipulation is necessary, it should be done on a copy of the array returned rather than the array itself.


getListenerCount

public int getListenerCount()
Return the total number of listeners for this listenerList

add

public void add(java.lang.Class t,
                java.util.EventListener l,
                int p)
Add the listener as a listener of the specified type, with the specified priority.
Parameters:
t - the type of the listener to be added
l - the listener to be added
p - the priority of this listener
Throws:
java.lang.IllegalArgumentException - if the arguments are null or incompatible.

remove

public void remove(java.lang.Class t,
                   java.util.EventListener l)
Remove the listener as a listener of the specified type. If multiple copies of the same listener are present, the one with the highest priority is removed.
Parameters:
t - the type of the listener to be removed
l - the listener to be removed
Throws:
java.lang.IllegalArgumentException - if the arguments are null or incompatible.

toString

public java.lang.String toString()
Return a string representation of the RTEventListenerList.
Overrides:
toString in class java.lang.Object