danger.app
Class Dispatcher

java.lang.Object
  extended by danger.app.Dispatcher
All Implemented Interfaces:
Runnable


public class Dispatcher
extends Object
implements Runnable


Constructor Summary
Dispatcher()
           
 
Method Summary
 void abort()
           
static boolean anyActiveDispatchers()
           
 boolean childRun()
          Recursively invokes this Dispatcher's event pump.
 boolean childRunDone()
          Unwinds a recursive invocation of this Dispatcher's event pump.
 Event event()
          Return an event initialized with the given parameters.
 Event event(Event orig)
          Return an event initialized with the given parameters.
 Event event(int type)
          Return an event initialized with the given parameters.
 Event event(int type, int what)
          Return an event initialized with the given parameters.
 Event event(int type, int what, int data)
          Return an event initialized with the given parameters.
 Event event(int type, int what, int data, Object argument)
          Return an event initialized with the given parameters.
 Event event(Listener target, int type)
          Return an event initialized with the given parameters.
 Event event(Listener target, int type, int what)
          Return an event initialized with the given parameters.
 Event event(Listener target, int type, int what, int data)
          Return an event initialized with the given parameters.
 Event event(Listener target, int type, int what, int data, int modifiers)
          Return an event initialized with the given parameters.
 Event event(Listener target, int type, int what, int data, int modifiers, int timestamp, Object argument)
          Return an event initialized with the given parameters.
 Event event(Listener target, int type, int what, int data, Object argument)
          Return an event initialized with the given parameters.
 boolean eventProblem(Event event, Throwable ex)
          Handle an exception caused by event processing.
 boolean isDispatchingThread()
          Returns whether the current thread is the Dispatcher thread.
 void run()
           
 void sendEvent(Event e)
           
 void sendEvent(int type)
          Construct and send an event.
 void sendEvent(int type, int what)
          Construct and send an event.
 void sendEvent(int type, int what, int data)
          Construct and send an event.
 void sendEvent(int type, int what, int data, Object arg)
          Construct and send an event.
 void sendLowPriorityEvent(Event e)
           
 void setDefaultListener(Listener l)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dispatcher

public Dispatcher()
Method Detail

setDefaultListener

public void setDefaultListener(Listener l)

abort

public void abort()

sendEvent

public final void sendEvent(int type,
                            int what,
                            int data,
                            Object arg)
Construct and send an event. This initializes an Event using the given arguments (recycling a used event if possible), targetting the default listener of this instance, and then queues it up by calling sendEvent(Event).

Parameters:
type - the type of the event
what - the sub-type of the event
data - additional data for the event
arg - null-ok; an object related to the event

sendEvent

public final void sendEvent(int type,
                            int what,
                            int data)
Construct and send an event. This initializes an Event using the given arguments (recycling a used event if possible), targetting the default listener of this instance, and then queues it up by calling sendEvent(Event).

Parameters:
type - the type of the event
what - the sub-type of the event
data - additional data for the event

sendEvent

public final void sendEvent(int type,
                            int what)
Construct and send an event. This initializes an Event using the given arguments (recycling a used event if possible), targetting the default listener of this instance, and then queues it up by calling sendEvent(Event).

Parameters:
type - the type of the event
what - the sub-type of the event

sendEvent

public final void sendEvent(int type)
Construct and send an event. This initializes an Event using the given arguments (recycling a used event if possible), targetting the default listener of this instance, and then queues it up by calling sendEvent(Event).

Parameters:
type - the type of the event

sendEvent

public final void sendEvent(Event e)

sendLowPriorityEvent

public final void sendLowPriorityEvent(Event e)

eventProblem

public final boolean eventProblem(Event event,
                                  Throwable ex)
Handle an exception caused by event processing. This method is called by the default implementation of Listener.eventProblem(danger.app.Event, java.lang.Throwable), which is itself called by an instance of this class on its default listener when it catches any exception (in the generic sense, that is any Throwable). This is also called directly by an instance when there's an event dispatch problem if the instance has no default listener.

This implementation prints out an informative message (including the event and the exception stack trace) and returns true, for all exceptions other than ThreadDeath (which are not printed and for which this method returns false).

Parameters:
event - non-null; the event whose processing caused the exception
ex - non-null; the exception that was thrown
Returns:
whether (true) or not (false) to continue running the dispatcher loop

childRun

public boolean childRun()
Recursively invokes this Dispatcher's event pump. This method is useful if code executing on the Dispatcher thread--such as the code in an event handler--needs to block waiting for some state to change elsewhere in the Application. Clients should never call Object.wait() on the Dispatcher thread, as it will block any user input from reaching the Application. Use this method instead.

This method should only be called from the Dispatcher thread. Calling this method from any other thread has no effect.

Returns:
true if the calling thread was the Dispatcher thread and this method recursively invoked the event pump; false if this method did nothing
See Also:
childRunDone()

childRunDone

public boolean childRunDone()
Unwinds a recursive invocation of this Dispatcher's event pump. At the end of the current event handler, control will resume at the statement following the call to childRun().

This method should only be called from the Dispatcher thread, and must be proceeded by a call to childRun(). Calling this method under other circumstances has no effect.

Returns:
true if an event pump recursion was unwound; false if this method did nothing
See Also:
childRun()

isDispatchingThread

public boolean isDispatchingThread()
Returns whether the current thread is the Dispatcher thread.

Returns:
true if the current thread is the Dispatcher thread; false otherwise

run

public void run()
Specified by:
run in interface Runnable

anyActiveDispatchers

public static boolean anyActiveDispatchers()

event

public Event event(Listener target,
                   int type,
                   int what,
                   int data,
                   int modifiers,
                   int timestamp,
                   Object argument)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(Listener target,
                   int type,
                   int what,
                   int data,
                   Object argument)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(Listener target,
                   int type,
                   int what,
                   int data,
                   int modifiers)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(int type,
                   int what,
                   int data,
                   Object argument)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(int type,
                   int what,
                   int data)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(int type,
                   int what)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(int type)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event()
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(Listener target,
                   int type,
                   int what,
                   int data)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(Listener target,
                   int type,
                   int what)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(Listener target,
                   int type)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(Event orig)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.