com.sdm.quasar.client.swing.common.event
Class EventLoop

java.lang.Object
  extended bycom.sdm.quasar.client.swing.common.event.EventLoop

public final class EventLoop
extends java.lang.Object

A replacement for Swing's event loop. To install it globally call #install(). To make another non-global event loop (e.g. to process awt events while waiting for another thread) call #processEvents(EventFilter, EventFilter) or #processEvents(EventFilter, EventFilter, ExceptionHandler) to install a temporary event loop. The loop finishes, when the runCondition EventLoop.EventFilter does not accept an awt event.

Author:
Thomas Wolf

Nested Class Summary
static interface EventLoop.EventFilter
          An interface used to accept or deny events.
static interface EventLoop.ExceptionHandler
          An interface that should be used to handle exceptions occured at the system event queue.
 
Method Summary
 void addEventFilter(EventLoop.EventFilter event_filter)
          Adds the EventLoop.EventFilter used to filter dispatched events.
static EventLoop getCurrentEventLoop()
          Returns the current EventLoop instance.
 EventLoop.ExceptionHandler getExceptionHandler()
          Returns the EventLoop.ExceptionHandler used.
static EventLoop getGlobalEventLoop()
          Returns the global event loop.
 EventLoop getParentEventLoop()
          Returns the parent EventLoop of this one or null, if this EventLoop is the global EventLoop.
 EventLoop.EventFilter getRunCondition()
           
static void installGlobalEventLoop()
          Installs the global EventLoop.
 boolean isRunning()
          Returns true, while the event loop is running and processing AWT events.
static void processEvents(EventLoop.EventFilter runCondition, EventLoop.EventFilter eventFilter)
          This method does the event processing of the system event queue until the run condition does no more accept events.
static void processEvents(EventLoop.EventFilter runCondition, EventLoop.EventFilter eventFilter, EventLoop.ExceptionHandler exceptionHandler)
          This method does the event processing of the system event queue until the run condition does no more accept events.
 void removeEventFilter(EventLoop.EventFilter event_filter)
          Removes a previously added EventLoop.EventFilter from the EventLoop.
 void setExceptionHandler(EventLoop.ExceptionHandler exceptionHandler)
          Sets the EventLoop.ExceptionHandler used to handle uncatched exceptions.
 void setRunCondition(EventLoop.EventFilter runCondition)
          Sets the EventLoop.EventFilter which accepts events as long as the loop runs.
 java.lang.String toString()
           
static void uninstallGlobalEventLoop()
          Uninstalls the previously installed global EventLoop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getParentEventLoop

public EventLoop getParentEventLoop()
Returns the parent EventLoop of this one or null, if this EventLoop is the global EventLoop.


installGlobalEventLoop

public static void installGlobalEventLoop()
Installs the global EventLoop. The method will return immediately; the event loop will be installed, after the last event on the system event queue is processed by the awt event loop. Subsequent calls to #install() will need the same number of calls to #uninstall() in order to uninstall the global EventLoop properly.


uninstallGlobalEventLoop

public static void uninstallGlobalEventLoop()
Uninstalls the previously installed global EventLoop.

See Also:
#install()

getGlobalEventLoop

public static EventLoop getGlobalEventLoop()
Returns the global event loop. The global EventLoop will not run until someone calls uninstallGlobalEventLoop().

Returns:
the global EventLoop

processEvents

public static void processEvents(EventLoop.EventFilter runCondition,
                                 EventLoop.EventFilter eventFilter)
This method does the event processing of the system event queue until the run condition does no more accept events. This method can only be called within the awt event thread and blocks until the run condition accepts events. Exceptions occured on the event processing, that are not handled by the processing method will be handled by the exception handler of the global EventLoop.

Parameters:
runCondition - an EventLoop.EventFilter defining a condition that should be true as long as this method should run. The condition will be checked after the event was processed
eventFilter - an EventLoop.EventFilter, that filters events, so that only accepted events might be processed by clients

processEvents

public static void processEvents(EventLoop.EventFilter runCondition,
                                 EventLoop.EventFilter eventFilter,
                                 EventLoop.ExceptionHandler exceptionHandler)
This method does the event processing of the system event queue until the run condition does no more accept events. This method can only be called within the awt event thread and blocks until the run condition accepts events.

Parameters:
runCondition - an EventLoop.EventFilter defining a condition that should be true as long as this method should run. The condition will be checked after the event was processed
eventFilter - an EventLoop.EventFilter, that filters events, so that only accepted events might be processed by clients
exceptionHandler - an EventLoop.ExceptionHandler used for fatal clean up exceptions that are not be caught by clients. If null, the exception handler of the global EventLoop will be used.

getCurrentEventLoop

public static EventLoop getCurrentEventLoop()
Returns the current EventLoop instance. If not called by the event dispatch thread, this returns the last started EventLoop instance.


isRunning

public boolean isRunning()
Returns true, while the event loop is running and processing AWT events.

Returns:
true, while the event loop is running.

getExceptionHandler

public EventLoop.ExceptionHandler getExceptionHandler()
Returns the EventLoop.ExceptionHandler used. If this EventLoop has no own EventLoop.ExceptionHandler, it uses the one of the global event loop.


getRunCondition

public EventLoop.EventFilter getRunCondition()
Returns:
EventFilter

addEventFilter

public void addEventFilter(EventLoop.EventFilter event_filter)
Adds the EventLoop.EventFilter used to filter dispatched events.

Parameters:
event_filter - the EventLoop.EventFilter to add (not null)

removeEventFilter

public void removeEventFilter(EventLoop.EventFilter event_filter)
Removes a previously added EventLoop.EventFilter from the EventLoop.

Parameters:
event_filter - the EventLoop.EventFilter to remove (not null)

setExceptionHandler

public void setExceptionHandler(EventLoop.ExceptionHandler exceptionHandler)
Sets the EventLoop.ExceptionHandler used to handle uncatched exceptions.

Parameters:
exceptionHandler - the EventLoop.ExceptionHandler to set

setRunCondition

public void setRunCondition(EventLoop.EventFilter runCondition)
Sets the EventLoop.EventFilter which accepts events as long as the loop runs.

Parameters:
runCondition - the run condition EventLoop.EventFilter to set

toString

public java.lang.String toString()