com.sdm.quasar.client.core.common.event
Class EventDispatchThreadUtilities

java.lang.Object
  extended bycom.sdm.quasar.client.core.common.event.EventDispatchThreadUtilities

public final class EventDispatchThreadUtilities
extends java.lang.Object

A utilities class collection event-loop utilities.

Version:
1.0
Author:
Thomas Wolf

Method Summary
static EventDispatchThreadService getEventDispatchThreadService()
          Returns the global EventDispatchThreadService implementation to use.
static boolean isEventDispatchThread()
          Returns true if the current thread is an AWT event dispatching thread.
static java.lang.Object runInEventDispatchThread(ExceptionRunnable runnable)
          Runs the given ExceptionRunnable in the event dispatch thread.
static void runInEventDispatchThread(java.lang.Runnable runnable)
          Runs the given Runnable in the event dispatch thread.
static void runLaterInEventDispatchThread(java.lang.Runnable runnable)
          Causes runnable to have its run() method called in the event dispatch thread.
static void runLaterInEventDispatchThread(java.lang.Runnable runnable, long delay)
          Causes runnable to have its Runnable.run() method called in the dispatch thread of the EventQueue after delay milliseconds.
static void runLaterNotInEventDispatchThread(java.lang.Runnable runnable)
          Causes runnable to have its run() method called outside the event dispatch thread.
static java.lang.Object runNotInEventDispatchThread(ExceptionRunnable runnable)
          Runs the given ExceptionRunnable not in the event dispatch thread.
static void runNotInEventDispatchThread(java.lang.Runnable runnable)
          Runs the given Runnable not in the event dispatch thread.
static void runOrRunLaterInEventDispatchThread(java.lang.Runnable runnable)
          Causes runnable to have its run() method called in the dispatch thread of the EventQueue.
static void setEventDispatchThreadService(EventDispatchThreadService eventDispatchThreadService)
          Sets the global EventDispatchThreadService implementation to be used.
static void waitForCondition(Condition condition)
          Waits for the condition given without blocking event processing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setEventDispatchThreadService

public static void setEventDispatchThreadService(EventDispatchThreadService eventDispatchThreadService)
Sets the global EventDispatchThreadService implementation to be used.

Parameters:
eventDispatchThreadService - the EventDispatchThreadService to be used

getEventDispatchThreadService

public static EventDispatchThreadService getEventDispatchThreadService()
Returns the global EventDispatchThreadService implementation to use.

Note: if no EventDispatchThreadService was set before (see setEventDispatchThreadService(EventDispatchThreadService)) a default implementation is used.


isEventDispatchThread

public static boolean isEventDispatchThread()
Returns true if the current thread is an AWT event dispatching thread.


waitForCondition

public static void waitForCondition(Condition condition)
                             throws java.lang.InterruptedException
Waits for the condition given without blocking event processing.

Note: Implementation might wait on the object given.

Parameters:
condition - the Condition to wait for (until Condition.isFulfilled() returns true)
Throws:
java.lang.InterruptedException - if waiting was interrupted

runLaterInEventDispatchThread

public static void runLaterInEventDispatchThread(java.lang.Runnable runnable,
                                                 long delay)
Causes runnable to have its Runnable.run() method called in the dispatch thread of the EventQueue after delay milliseconds. This will happen after all pending events are processed.

Parameters:
runnable - the Runnable whose run() method should be executed synchronously on the EventQueue
delay - the delay in milliseconds, after that the runnable should be executed.

runLaterInEventDispatchThread

public static void runLaterInEventDispatchThread(java.lang.Runnable runnable)
Causes runnable to have its run() method called in the event dispatch thread. This will happen after all pending events are processed.

Parameters:
runnable - the Runnable whose run() method should be executed synchronously on the event queue

runLaterNotInEventDispatchThread

public static void runLaterNotInEventDispatchThread(java.lang.Runnable runnable)
Causes runnable to have its run() method called outside the event dispatch thread.

Parameters:
runnable - the Runnable whose run() method should be executed

runNotInEventDispatchThread

public static java.lang.Object runNotInEventDispatchThread(ExceptionRunnable runnable)
                                                    throws java.lang.Exception
Runs the given ExceptionRunnable not in the event dispatch thread.

Parameters:
runnable - the ExceptionRunnable to run
Returns:
the return value returned by ExceptionRunnable.run()
Throws:
java.lang.InterruptedException - if the executing thread was interrupted
java.lang.Exception - any exception thrown by the ExceptionRunnable

runNotInEventDispatchThread

public static void runNotInEventDispatchThread(java.lang.Runnable runnable)
Runs the given Runnable not in the event dispatch thread.

Parameters:
runnable - the Runnable to run

runInEventDispatchThread

public static java.lang.Object runInEventDispatchThread(ExceptionRunnable runnable)
                                                 throws java.lang.Exception
Runs the given ExceptionRunnable in the event dispatch thread.

Parameters:
runnable - the ExceptionRunnable to run
Returns:
the return value returned by ExceptionRunnable.run()
Throws:
java.lang.InterruptedException - if the executing thread was interrupted
java.lang.Exception - any exception thrown by the ExceptionRunnable

runInEventDispatchThread

public static void runInEventDispatchThread(java.lang.Runnable runnable)
Runs the given Runnable in the event dispatch thread.

Parameters:
runnable - the Runnable to run
Throws:
WrappedCheckedException - if a InterruptedException occured

runOrRunLaterInEventDispatchThread

public static void runOrRunLaterInEventDispatchThread(java.lang.Runnable runnable)
Causes runnable to have its run() method called in the dispatch thread of the EventQueue. This will happen eighter immediately on method execution (if called from the event dispatch thread) or after all pending events are processed (if called from another thread).

Note: This method may or may not return before the runnable gets executed within the EDT. In opposite to #invokeLater(Runnable) it calls the runnable faster (immediately), if called within the EDT.

Parameters:
runnable - the Runnable whose run() method should be executed synchronously on the EventQueue
See Also:
#invokeLater(Runnable)