java.awt
Class EventQueue

java.lang.Object
  |
  +--java.awt.EventQueue

public class EventQueue
extends Object

EventQueue is a platform-independent class that queues events, both from the underlying peer classes and from trusted application classes. There is only one EventQueue for each AppContext.


Field Summary
private static boolean debug
           
private  EventDispatchThread dispatchThread
           
private  EventQueueItem lastPriorityItem
           
private  EventQueue nextQueue
           
private  EventQueue previousQueue
           
private  EventQueueItem queue
           
private  EventQueueItem queueTail
           
private static int threadInitNumber
           
 
Constructor Summary
EventQueue()
           
 
Method Summary
(package private)  void changeKeyEventFocus(Object newSource)
           
protected  void dispatchEvent(AWTEvent event)
          Dispatch an event.
(package private)  EventDispatchThread getDispatchThread()
           
 AWTEvent getNextEvent()
          Remove an event from the queue and return it.
static void invokeAndWait(Runnable runnable)
          Causes runnable to have its run() method called in the dispatch thread of the EventQueue.
static void invokeLater(Runnable runnable)
          Causes runnable to have its run() method called in the dispatch thread of the EventQueue.
static boolean isDispatchThread()
          Returns true if the calling thread is the current AWT EventQueue's dispatch thread.
private static int nextThreadNum()
           
 AWTEvent peekEvent()
          Return the first event without removing it.
 AWTEvent peekEvent(int id)
          Return the first event with the specified id, if any.
protected  void pop()
          Stop dispatching events using this EventQueue instance.
 void postEvent(AWTEvent theEvent)
          Post a 1.1-style event to the EventQueue.
private  void postEvent(AWTEvent theEvent, boolean priorityEvent)
           
 void push(EventQueue newEventQueue)
          Replace the existing EventQueue with the specified one.
(package private)  void removeSourceEvents(Object source)
           
(package private)  void removeSourceEvents(Object source, int id)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

threadInitNumber

private static int threadInitNumber

queue

private EventQueueItem queue

queueTail

private EventQueueItem queueTail

lastPriorityItem

private EventQueueItem lastPriorityItem

nextQueue

private EventQueue nextQueue

previousQueue

private EventQueue previousQueue

dispatchThread

private EventDispatchThread dispatchThread

debug

private static final boolean debug
Constructor Detail

EventQueue

public EventQueue()
Method Detail

nextThreadNum

private static int nextThreadNum()

postEvent

public void postEvent(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.
Parameters:
theEvent - an instance of java.awt.AWTEvent, or a subclass of it.

postEvent

private void postEvent(AWTEvent theEvent,
                       boolean priorityEvent)

getNextEvent

public AWTEvent getNextEvent()
                      throws InterruptedException
Remove an event from the queue and return it. This method will block until an event has been posted by another thread.
Returns:
the next AWTEvent
Throws:
InterruptedException - if another thread has interrupted this thread.

peekEvent

public AWTEvent peekEvent()
Return the first event without removing it.
Returns:
the first event

peekEvent

public AWTEvent peekEvent(int id)
Return the first event with the specified id, if any.
Parameters:
id - the id of the type of event desired.
Returns:
the first event of the specified id

dispatchEvent

protected void dispatchEvent(AWTEvent event)
Dispatch an event. The manner in which the event is dispatched depends upon the type of the event and the type of the event's source object:

Event Type Source Type Dispatched To
ActiveEvent Any event.dispatch()
Other Component source.dispatchEvent(AWTEvent)
Other MenuComponent source.dispatchEvent(AWTEvent)
Other Other No action (ignored)

Parameters:
theEvent - an instance of java.awt.AWTEvent, or a subclass of it.

push

public void push(EventQueue newEventQueue)
Replace the existing EventQueue with the specified one. Any pending events are transferred to the new EventQueue for processing by it.
Parameters:
an - EventQueue (or subclass thereof) instance to be used.
See Also:
pop()

pop

protected void pop()
            throws EmptyStackException
Stop dispatching events using this EventQueue instance. Any pending events are transferred to the previous EventQueue for processing by it.
Throws:
if - no previous push was made on this EventQueue.
See Also:
push(java.awt.EventQueue)

isDispatchThread

public static boolean isDispatchThread()
Returns true if the calling thread is the current AWT EventQueue's dispatch thread. Use this call the ensure that a given task is being executed (or not being) on the current AWT EventDispatchThread.
Returns:
true if running on the current AWT EventQueue's dispatch thread.

getDispatchThread

final EventDispatchThread getDispatchThread()

changeKeyEventFocus

final void changeKeyEventFocus(Object newSource)

removeSourceEvents

final void removeSourceEvents(Object source)

removeSourceEvents

void removeSourceEvents(Object source,
                        int id)

invokeLater

public static void invokeLater(Runnable runnable)
Causes runnable to have its run() method called in the dispatch thread of the EventQueue. This will happen after all pending events are processed.
Parameters:
runnable - the Runnable whose run() method should be executed synchronously on the EventQueue
Since:
JDK1.2
See Also:
invokeAndWait(java.lang.Runnable)

invokeAndWait

public static void invokeAndWait(Runnable runnable)
                          throws InterruptedException,
                                 java.lang.reflect.InvocationTargetException
Causes runnable to have its run() method called in the dispatch thread of the EventQueue. This will happen after all pending events are processed. The call blocks until this has happened. This method will throw an Error if called from the event dispatcher thread.
Parameters:
runnable - the Runnable whose run() method should be executed synchronously on the EventQueue
Throws:
InterruptedException - if another thread has interrupted this thread
java.lang.reflect.InvocationTargetException - if an exception is thrown when running runnable
Since:
JDK1.2
See Also:
invokeLater(java.lang.Runnable)