|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectilog.views.util.event.IlvAbstractEventListenerCollection
public abstract class IlvAbstractEventListenerCollection
IlvAbstractEventListenerCollection implements a thread-safe
collection of event listeners. Concrete subclasses can choose a specific
collection implementation based on the tradeoffs of event dispatch speed vs.
the speed of adding and removing listeners. Several general issues should be
weighed when choosing between using an IlvAbstractEventListenerCollection
subclass or a multicaster to manage the event dispatch system for a class:
IlvAbstractEventListenerCollection will
dispatch events through an iterative algorithm, while a multicaster
uses a recursive algorithm. For large numbers of event listeners, a
multicaster can cause a stack overflow exception to occur.Here is an example that shows how a class can use an
IlvAbstractEventListenerCollection concrete subclass for
registering event listeners and dispatching events to them:
public class MyClass {
IlvEventListenerCollection xyzListeners = new IlvEventListenerSet();
public void addXYZListener (XYZListener aListener) {
xyzListeners.addListener(aListener);
}
public void removeXYZListener (XYZListener aListener) {
xyzListeners.removeListener(aListener);
}
public void notifyXYZListeners () {
XYZEvent event = new XYZEvent(this);
for (Iterator i = xyzListeners.getListeners(); i.hasNext(); ) {
XYZListener xyzListener = (XYZListener) i.next();
xyzListener.xyzHappened(event);
}
}
}
| Constructor Summary | |
|---|---|
IlvAbstractEventListenerCollection()
Creates a new IlvAbstractEventListenerCollection. |
|
| Method Summary | |
|---|---|
void |
addListener(EventListener listener)
Adds the specified listener to this collection. |
protected abstract Collection |
cloneListeners()
Returns a copy of the collection of event listeners. |
boolean |
contains(EventListener listener)
Returns whether this collection contains the specified listener. |
Iterator |
getListeners()
Returns an iterator over the event listeners. |
protected abstract void |
initListeners()
Initializes the collection of event listeners. |
void |
removeListener(EventListener listener)
Removes the specified listener from this collection. |
void |
save(ObjectOutputStream s,
String k)
Serializes the collection of event listeners as a series of key-value pairs. |
int |
size()
Returns the number of listeners in this collection. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public IlvAbstractEventListenerCollection()
IlvAbstractEventListenerCollection.
| Method Detail |
|---|
protected abstract void initListeners()
protected abstract Collection cloneListeners()
public void addListener(EventListener listener)
addListener in interface IlvEventListenerCollectionlistener - The listener.public void removeListener(EventListener listener)
removeListener in interface IlvEventListenerCollectionlistener - The listener.public Iterator getListeners()
getListeners in interface IlvEventListenerCollectionpublic int size()
public boolean contains(EventListener listener)
contains in interface IlvEventListenerCollectionlistener - The listener.
true if this collection contains listener,
otherwise false.
public void save(ObjectOutputStream s,
String k)
throws IOException
save in interface IlvEventListenerCollections - The object output stream to write the event listeners.k - A key string that is written in front of
each listener to identify its type.
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||