|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecteu.webtoolkit.jwt.AbstractSignal
eu.webtoolkit.jwt.Signal2<A1,A2>
public class Signal2<A1,A2>
A signal that propagates events to listeners, and is capable of passing 2 argument.
A signal implements the Observer pattern, allowing one or more listeners to listen for events generated on the signal. The event may propagate 2 arguments to the listeners.
A usage example:
class MyWidget extends WContainerWidget
{
public MyWidget(WContainerWidget parent)
{
super(parent);
this.done = new Signal2
This widget could then be used form another class:
class GUIClass extends WContainerWidget
{
...
private void init() {
MyWidget widget = new MyWidget(this);
widget.done().addListener(this, new Signal2.Listener
| Nested Class Summary | |
|---|---|
static interface |
Signal2.Listener<A1,A2>
The listener interface. |
| Nested classes/interfaces inherited from class eu.webtoolkit.jwt.AbstractSignal |
|---|
AbstractSignal.Connection |
| Constructor Summary | |
|---|---|
Signal2()
Creates a new signal. |
|
| Method Summary | |
|---|---|
AbstractSignal.Connection |
addListener(WObject listenerOwner,
Signal.Listener listener)
Adds a listener for this signal. |
AbstractSignal.Connection |
addListener(WObject listenerOwner,
Signal2.Listener<A1,A2> listener)
Adds a listener for this signal. |
void |
removeListener(Signal.Listener listener)
Removes a listener. |
void |
removeListener(Signal2.Listener<A1,A2> listener)
Removes a listener. |
void |
trigger(A1 arg1,
A2 arg2)
Triggers the signal. |
| Methods inherited from class eu.webtoolkit.jwt.AbstractSignal |
|---|
getListenerCount, getListeners, isBlocked, isConnected, setBlocked |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Signal2()
| Method Detail |
|---|
public AbstractSignal.Connection addListener(WObject listenerOwner,
Signal2.Listener<A1,A2> listener)
Each listener will be triggered whenever the signal is triggered.
listenerOwner - the enclosing object for a listener implemented using an (anonymous) inner classlistener - the listener
AbstractSignal.addListener(WObject, eu.webtoolkit.jwt.Signal.Listener)public void removeListener(Signal2.Listener<A1,A2> listener)
listener - a listener that was previously added
public void trigger(A1 arg1,
A2 arg2)
The arguments are passed to the listeners.
arg1 - Argument 1.arg2 - Argument 2.
public AbstractSignal.Connection addListener(WObject listenerOwner,
Signal.Listener listener)
AbstractSignalEach listener will be notified when the signal is triggered.
An owner object may be passed when the listener is implemented using an (anonymous) inner class. In that case the owner object should be the enclosing object of the listener object, and this is used to bind the lifetime of the listener. To avoid the owner object from not being garbage collected when it is no longer used, only the owner object will add a reference to the listener, while the signal will use a weak reference.
This avoids the most common reason for memory leaks in Java
implementations of the Observer pattern: the owner object will not get
garbage collected because of the (anonymous) listener object having a
reference to it, even if the receiver object is no longer referenced from
anywhere. When the owner object is not null, the listener is
stored using a strong reference in the owner object, and using a weak
reference in the signal.
addListener in class AbstractSignallistenerOwner - if not null, the enclosing object for a
listener implemented using an inner classlistener - the listener
public void removeListener(Signal.Listener listener)
AbstractSignal
removeListener in class AbstractSignallistener - a listener that was previously added.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||