|
Foxtrot Version 2.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfoxtrot.utils.EventListenerProxy
public class EventListenerProxy
This class wraps an EventListener subclass (and thus any AWT/Swing event
listener such as ActionListener
s, MouseListener
s
and so on) making sure that if a wrapped listener is executing, another
wrapped listener (even of different type) it is not executed.
For example, if a user clicks very quickly on a button, it may trigger the
execution of the associated listener more than once. When the listener
contains Foxtrot code, the second click event is dequeued by Foxtrot and
processed again, invoking the listener again. Using this class to wrap the
listener avoids this problem: the second event will
be dequeued and processed by Foxtrot as before, but the wrapped listener will
not be called.
Example Usage:
final JButton apply = new JButton("Apply"); apply.addActionListener((ActionListener)EventListenerProxy .create(ActionListener.class, new ActionListener() { public void actionPerformed(ActionEvent e) { apply.setEnabled(false); Worker.post(new Job() { public Object run() { // Lenghty apply code } }); } })); JButton cancel = new JButton("Cancel"); cancel.addActionListener((ActionListener)EventListenerProxy .create(ActionListener.class, new ActionListener() { public void actionPerformed(ActionEvent e) { // For example, dispose a dialog } }));
button.addActionListener(new ActionListener() {...});to this:
button.addActionListener((ActionListener)EventListenerProxy .create(ActionListener.class, new ActionListener() {...}));
Constructor Summary | |
---|---|
protected |
EventListenerProxy(EventListener listener)
Creates an instance that wraps the given listener |
Method Summary | |
---|---|
static EventListener |
create(Class listenerInterface,
EventListener listener)
Creates a proxy for the given listener. |
Object |
invoke(Object proxy,
Method method,
Object[] args)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected EventListenerProxy(EventListener listener)
listener
- the listener to wrapMethod Detail |
---|
public static EventListener create(Class listenerInterface, EventListener listener)
listenerInterface
- The interface used to create the proxylistener
- The listener to proxy
NullPointerException
- When the interface or the listener is null
IllegalArgumentException
- When the listener does not implement the
interfacepublic Object invoke(Object proxy, Method method, Object[] args) throws Throwable
invoke
in interface InvocationHandler
Throwable
|
Foxtrot Version 2.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |