net.wotonomy.foundation
Class NSRunLoop

java.lang.Object
  extended by java.awt.EventQueue
      extended by net.wotonomy.foundation.NSRunLoop

public class NSRunLoop
extends java.awt.EventQueue

NSRunLoop is provided specifically for EODelayedObserverQueue and EOEditingContext, which assume the existence of a prioritized event queue that Java does not provide.

This extends java.awt.EventQueue and does not conform to the NSRunLoop specifications. The only supported methods are NSRunLoop.currentRunLoop, performSelectorWithOrder, and cancelSelectorWithOrder. Note that in Swing there is only one AWT thread and one event queue; newly created threads will not get their own run loop as in OpenStep.

That said, this event queue is servicable as a replacement for the default event queue and will provide prioritized execution of selectors before and after normal AWT events.

Each run loop dispatches the lowest order event from the queue. When queued events have the same ordering, they are dispatched as first-in, first-out (FIFO). Because all AWT events have the same ordering (AWTEventsRunLoopOrdering), they are processed FIFO, just like the default event queue.

Note that because EventQueue is not well-factored for subclassing, pushing a new event queue onto the stack on top of this one will only copy the existing AWT events to the new queue. For this reason, pushing new event queues onto the stack is not supported and will throw an exception.

Version:
$Revision: 893 $
Author:
michael@mpowers.net, $Author: cgruber $

Field Summary
static int AWTEventsRunLoopOrdering
          This is the ordering at which the conventional AWT event queue will be executed.
protected static NSRunLoop instance
          The singleton instance.
 
Constructor Summary
protected NSRunLoop()
          Create a new instance of NSRunLoop.
 
Method Summary
 void cancelPerformSelectorWithOrder(NSSelector aSelector, java.lang.Object aTarget, java.lang.Object aParameter)
          Cancels the next scheduled invocation of the specified selector, target, and parameter.
static NSRunLoop currentRunLoop()
          Returns the singleton instance of NSRunLoop.
 void dispatchAllEvents()
          Useful method, but not in the spec.
 boolean dispatchNextEvent()
          Useful method, but not in the spec.
 java.awt.AWTEvent getNextEvent()
          Remove an event from the EventQueue and return it.
static void invokeLaterWithOrder(java.lang.Runnable aRunnable, int anOrdering)
          Causes runnable to have its run() method on the next event loop with the specified priority ordering.
 void performSelectorWithOrder(NSSelector aSelector, java.lang.Object aTarget, java.lang.Object aParameter, int anOrdering, java.util.List aModeList)
          Schedules the specified selector with the specified target and parameter to be invoked on the next event loop with the specified ordering.
protected  void pop()
          This implementation calls super and then throws an UnsupportedOperationException.
 void postEvent(java.awt.AWTEvent theEvent)
          Post a 1.1-style event to the EventQueue.
 void push(java.awt.EventQueue newEventQueue)
          This implementation calls super and then throws an UnsupportedOperationException.
 
Methods inherited from class java.awt.EventQueue
dispatchEvent, getCurrentEvent, getMostRecentEventTime, invokeAndWait, invokeLater, isDispatchThread, peekEvent, peekEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AWTEventsRunLoopOrdering

public static final int AWTEventsRunLoopOrdering
This is the ordering at which the conventional AWT event queue will be executed. Selectors with this ordering or less will be executed before AWT events, and selectors with ordering greater than this ordering will be be executed after AWT events.

See Also:
Constant Field Values

instance

protected static NSRunLoop instance
The singleton instance.

Constructor Detail

NSRunLoop

protected NSRunLoop()
Create a new instance of NSRunLoop.

Method Detail

currentRunLoop

public static NSRunLoop currentRunLoop()
Returns the singleton instance of NSRunLoop. This returns the same instance no matter what thread calls it, which is different from OpenStep. NSRunLoop is limited to a singleton instance because there is no way of obtaining the stack of event queues from EventQueue because it is private state.


postEvent

public void postEvent(java.awt.AWTEvent theEvent)
Post a 1.1-style event to the EventQueue. If there is an existing event on the queue with the same ID and event source, the source Component's coalesceEvents method will be called.

Overrides:
postEvent in class java.awt.EventQueue
Parameters:
theEvent - an instance of java.awt.AWTEvent, or a subclass of it.

dispatchNextEvent

public boolean dispatchNextEvent()
Useful method, but not in the spec. Dispatches the next AWT event in the queue. Returns whether a selector or an event was executed: if the event queue is empty, returns false.


dispatchAllEvents

public void dispatchAllEvents()
Useful method, but not in the spec. Dispatches all events in the queue before returning.


getNextEvent

public java.awt.AWTEvent getNextEvent()
                               throws java.lang.InterruptedException
Remove an event from the EventQueue and return it. This override will dispatch all selectors up to 5000, and then check if there are AWT events on the queue. If the queue is empty, all remaining selectors are dispatched. Then, this method calls the super class' implementation.

Overrides:
getNextEvent in class java.awt.EventQueue
Returns:
the next AWTEvent
Throws:
java.lang.InterruptedException - if another thread has interrupted this thread.

push

public void push(java.awt.EventQueue newEventQueue)
This implementation calls super and then throws an UnsupportedOperationException. Catch that exception and ignore it if you know what you are doing.

Overrides:
push in class java.awt.EventQueue

pop

protected void pop()
            throws java.util.EmptyStackException
This implementation calls super and then throws an UnsupportedOperationException. Catch that exception and ignore it if you know what you are doing.

Overrides:
pop in class java.awt.EventQueue
Throws:
java.util.EmptyStackException

performSelectorWithOrder

public void performSelectorWithOrder(NSSelector aSelector,
                                     java.lang.Object aTarget,
                                     java.lang.Object aParameter,
                                     int anOrdering,
                                     java.util.List aModeList)
Schedules the specified selector with the specified target and parameter to be invoked on the next event loop with the specified ordering. The selector must be able to be invoked on the target and the target method must accept the parameter. aModeList is currently ignored.


cancelPerformSelectorWithOrder

public void cancelPerformSelectorWithOrder(NSSelector aSelector,
                                           java.lang.Object aTarget,
                                           java.lang.Object aParameter)
Cancels the next scheduled invocation of the specified selector, target, and parameter. If no such invocation is scheduled, does nothing.


invokeLaterWithOrder

public static void invokeLaterWithOrder(java.lang.Runnable aRunnable,
                                        int anOrdering)
Causes runnable to have its run() method on the next event loop with the specified priority ordering.



Copyright © 2006 null. All Rights Reserved.