org.argouml.model.uml
Class EventListenerList

java.lang.Object
  extended byorg.argouml.model.uml.EventListenerList

class EventListenerList
extends Object

A wrapped object array that contains triples of eventtype, eventname, interested listener. I used an Object array for this purpose since it performs fast. Copied a lot of the code from javax.swing.EventListenerList.


Field Summary
private  Object[] listenerList
          The list of EventKey - Listener pairs.
private static Logger LOG
           
private static Object[] NULL_ARRAY
          A null array to be shared by all empty listener lists.
 
Constructor Summary
(package private) EventListenerList()
           
 
Method Summary
 void add(EventKey key, ru.novosoft.uml.MElementListener listener)
          Registers the given listeners for the event typed by EventKey.
 boolean contains(EventKey key, ru.novosoft.uml.MElementListener listener)
           
 int getListenerCount()
          Returns the total number of listeners for this listener list.
 int getListenerCount(EventKey key)
          Returns the total number of listeners of the supplied type for this listener list.
private  int getListenerCount(Object[] list, EventKey key)
          Returns the number of listeners that are interested in the given key and exist in the given object array.
(package private)  Object[] getListenerList()
           
 ru.novosoft.uml.MElementListener[] getListeners(EventKey key)
          Returns an array of listeners that are interested in an event that is typed by the given EventKey.
 void remove(EventKey key, ru.novosoft.uml.MElementListener listener)
          Removes a listener from the list.
private  void removeElement(int index)
          Does the actual removal of an element at the given index in the list.
(package private)  void setListenerList(Object[] ll)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final Logger LOG

NULL_ARRAY

private static final Object[] NULL_ARRAY
A null array to be shared by all empty listener lists.


listenerList

private Object[] listenerList
The list of EventKey - Listener pairs. It's visibility is default since it's used in AbstractUmlModelFactory in a performant but quite awkward way from an encapsulation point of view.

Constructor Detail

EventListenerList

EventListenerList()
Method Detail

getListeners

public ru.novosoft.uml.MElementListener[] getListeners(EventKey key)
Returns an array of listeners that are interested in an event that is typed by the given EventKey. If the name is null of the EventKey, all listeners are returned that have the corresponding name filled or null. Same is true for the type.

Parameters:
key -
Returns:
An array of listeners that are interested in the event typed by the given EventKey

add

public void add(EventKey key,
                ru.novosoft.uml.MElementListener listener)
Registers the given listeners for the event typed by EventKey. If the name is null (of the EventKey), the listener is registred for all events that have a type corresponding to the type in the given key, no matter what the name of the event is. Vice versa for the type.

A listener that has been added twice will get the events for which it registred twice. Be careful with registring listeners!

Parameters:
key -
listener -

contains

public boolean contains(EventKey key,
                        ru.novosoft.uml.MElementListener listener)

remove

public void remove(EventKey key,
                   ru.novosoft.uml.MElementListener listener)
Removes a listener from the list.

Parameters:
key -
listener -

removeElement

private void removeElement(int index)
Does the actual removal of an element at the given index in the list.

Parameters:
index -

getListenerCount

private int getListenerCount(Object[] list,
                             EventKey key)
Returns the number of listeners that are interested in the given key and exist in the given object array.

Parameters:
list -
key -
Returns:
the count of listeners.

getListenerCount

public int getListenerCount(EventKey key)
Returns the total number of listeners of the supplied type for this listener list.

Parameters:
key - The type.
Returns:
The number of listeners.

getListenerCount

public int getListenerCount()
Returns the total number of listeners for this listener list.

Returns:
The number of listeners.

setListenerList

void setListenerList(Object[] ll)
Parameters:
ll - The listenerList to set.

getListenerList

Object[] getListenerList()
Returns:
Returns the listenerList.


ArgoUML © 1996-2004 (20050222)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook