org.lirc
Class EventListenerList

java.lang.Object
  |
  +--org.lirc.EventListenerList
All Implemented Interfaces:
java.io.Serializable

public class EventListenerList
extends java.lang.Object
implements java.io.Serializable

Simliar to javax.swing.EventListener, but easier to use. Usage:

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

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

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

 protected void fireFooXXX() {
     FooEvent e = null;
     EventListener[] ls = listenerList.getListeners(FooListener.class);
     for (int j = ls.length-1; j >= 0; j--) {
        FooListener l = (FooListener)ls[j];
        if (e == null) e = new FooEvent();
        l.fireFooXXX(e);
     }
 }

Version:
$Revision: 1.1 $
Author:
Bjorn Bringert (bjorn@mumblebee.com)
See Also:
Serialized Form

Constructor Summary
EventListenerList()
          Creates a new empty EventListenerList.
 
Method Summary
 void add(java.lang.Class t, java.util.EventListener l)
          Adds the listener as a listener of the specified type.
 int getListenerCount()
          Returns the total number of listeners for this listener list.
 int getListenerCount(java.lang.Class t)
          Returns the total number of listeners of the supplied type for this listener list.
 java.util.EventListener[] getListeners(java.lang.Class t)
          Return an array of all the listeners of the given type.
 void remove(java.lang.Class t, java.util.EventListener l)
          Removes the listener as a listener of the specified type.
 java.lang.String toString()
          Returns a string representation of the EventListenerList.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EventListenerList

public EventListenerList()
Creates a new empty EventListenerList.
Method Detail

getListenerCount

public int getListenerCount()
Returns the total number of listeners for this listener list.
Returns:
a non-negative integer

getListenerCount

public int getListenerCount(java.lang.Class t)
Returns the total number of listeners of the supplied type for this listener list.
Returns:
a non-negative integer

getListeners

public java.util.EventListener[] getListeners(java.lang.Class t)
Return an array of all the listeners of the given type.
Returns:
An array containing all of the listeners of the specified type. The component type of the returned array only guaranteed to be EventListener
Throws:
ClassCastException - if the supplied class is not assignable to EventListener

add

public void add(java.lang.Class t,
                java.util.EventListener l)
Adds the listener as a listener of the specified type.
Parameters:
t - the type of the listener to be added
l - the listener to be added
Throws:
java.lang.IllegalArgumentException - if l is not an instance of t

remove

public void remove(java.lang.Class t,
                   java.util.EventListener l)
Removes the listener as a listener of the specified type.
Parameters:
t - the type of the listener to be removed
l - the listener to be removed
Throws:
java.lang.IllegalArgumentException - if l is not an instance of t

toString

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