|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.miginfocom.util.ListenerSet
public class ListenerSet
An listener set that supports both WeakReferences and normal references. Doesn't create the
actual list until it's needed.
Good for having listeners weakly referenced, so they do not hider garbage collection. If the listener is not wrapped
in a weak listener it has do be explicitly cleared when the object goes out of scope or there may be a memory leak.
Using this class to store listeners make sure that there will be no memory leak.
| Field Summary | |
|---|---|
protected static com.miginfocom.util.ListenerSet.EmptyIterator |
EMPTY_ITERATOR
|
| Constructor Summary | |
|---|---|
ListenerSet()
Constructor for no runtime check of the listener classes. |
|
ListenerSet(java.lang.Class listenerClass)
Constructor for a runtime checked listener classes. |
|
| Method Summary | |
|---|---|
void |
add(java.util.EventListener listener,
boolean asWeakRef)
Adds the listener, if it isn't already in the list |
protected void |
assertListenerType(java.lang.Object l)
Throws a IllegalArgumentException if listener class isn't a subclass of the specified listener class and a NullPointerException if l is null. |
int |
findListener(java.util.EventListener listener)
Returns the listener index. |
boolean |
fireEvent(java.util.EventObject e)
Handles the fire marshalling based on the type of e. |
boolean |
fireVetoableEvent(java.util.EventObject e)
Handles the fire marshalling based on the type of e. |
java.util.EventListener |
getListener(int ix)
Returns the eventlistener for the index. |
java.util.List |
getListeners()
Returns the listeners as a new list. |
boolean |
isIgnoreEvents()
Returns if events are currently ignored. |
boolean |
isWeakReference(int ix)
Returns if listener at index ix is stored in a weak reference or normal reference. |
java.util.Iterator |
iterator()
Returns an iterator that iterates of the contained listeners. |
void |
remove(java.util.EventListener listener)
Removes the listener, if it is in the list. |
void |
removeAll()
Removes all listeners. |
boolean |
setIgnoreEvents(boolean b)
Sets if events should be ignored, and thus not fired. |
int |
size()
Returns the size of the listener list. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final com.miginfocom.util.ListenerSet.EmptyIterator EMPTY_ITERATOR
| Constructor Detail |
|---|
public ListenerSet()
public ListenerSet(java.lang.Class listenerClass)
listenerClass - The class to always check for.| Method Detail |
|---|
public void add(java.util.EventListener listener,
boolean asWeakRef)
listener - The listener. Not null. If the listener implements Comparable the list will be sorted so that
when later notifications will be conducted the liste will be notified in the sorted order. For instance MouseInteractionListener
is Comparable.asWeakRef - If the listener should be added wrapped in a WeakReference. This defers memory leak problems since
the garbage collector can collect the listener if it is only referenced from this list.public void remove(java.util.EventListener listener)
listener - The listener to remove, not null.public void removeAll()
public int size()
public boolean setIgnoreEvents(boolean b)
b - true turns off events
public boolean isIgnoreEvents()
setIgnoreEvents(boolean)public boolean isWeakReference(int ix)
listener at index ix is stored in a weak reference or normal reference.
ix - The index to check. Must be < size.
Boolean.TRUE if a weak reference, Boolean.FALSE if normal. null if not in the list.
java.lang.IndexOutOfBoundsExceptionpublic int findListener(java.util.EventListener listener)
listener - The listener to look for
-1 if not present.public java.util.EventListener getListener(int ix)
ix - The index into the list. Myst be < size.
null.
java.lang.IndexOutOfBoundsExceptionpublic java.util.Iterator iterator()
ListenerSet in the notification method without
it affecting the original list.
If ignore events is true the list will always be empty.
null.setIgnoreEvents(boolean)public java.util.List getListeners()
null.public boolean fireEvent(java.util.EventObject e)
e. Listener class type will be checked for
match at runtime.true no listeners will be notified.
e - The event to fire.
setIgnoreEvents(boolean)
public boolean fireVetoableEvent(java.util.EventObject e)
throws java.beans.PropertyVetoException
e. Listener class type will be checked for
match at runtime.true no listeners will be notified.
e - The event to fire.
java.beans.PropertyVetoExceptionsetIgnoreEvents(boolean)protected void assertListenerType(java.lang.Object l)
l is null.
l - The listener to test.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||