|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.EventQueue
EventQueue
is a platform-independent class
that queues events, both from the underlying peer classes
and from trusted application classes.
It encapsulates asynchronous event dispatch machinery which
extracts events from the queue and dispatches them by calling
dispatchEvent(AWTEvent)
method
on this EventQueue
with the event to be dispatched
as an argument. The particular behavior of this machinery is
implementation-dependent. The only requirements are that events
which were actually enqueued to this queue (note that events
being posted to the EventQueue
can be coalesced)
are dispatched:
AWTEvent
A is enqueued
to the EventQueue
before
AWTEvent
B then event B will not be
dispatched before event A.
Some browsers partition applets in different code bases into
separate contexts, and establish walls between these contexts.
In such a scenario, there will be one EventQueue
per context. Other browsers place all applets into the same
context, implying that there will be only a single, global
EventQueue
for all applets. This behavior is
implementation-dependent. Consult your browser's documentation
for more information.
For information on the threading issues of the event dispatch machinery, see AWT Threading Issues.
Field Summary | |
private ClassLoader |
classLoader
|
private WeakReference |
currentEvent
The modifiers field of the current event, if the current event is an InputEvent or ActionEvent. |
private static sun.awt.DebugHelper |
dbg
|
private static boolean |
debug
|
private EventDispatchThread |
dispatchThread
|
private static int |
HIGH_PRIORITY
|
private static int |
LOW_PRIORITY
|
private long |
mostRecentEventTime
|
private String |
name
|
private EventQueue |
nextQueue
|
private static int |
NORM_PRIORITY
|
private static int |
NUM_PRIORITIES
|
private EventQueue |
previousQueue
|
private Queue[] |
queues
|
private ThreadGroup |
threadGroup
|
private static int |
threadInitNumber
|
private int |
waitForID
|
Constructor Summary | |
EventQueue()
|
Method Summary | |
(package private) void |
detachDispatchThread()
|
protected void |
dispatchEvent(AWTEvent event)
Dispatches an event. |
static AWTEvent |
getCurrentEvent()
Returns the the event currently being dispatched by the EventQueue associated with the calling thread. |
private AWTEvent |
getCurrentEventImpl()
|
(package private) EventDispatchThread |
getDispatchThread()
|
static long |
getMostRecentEventTime()
Returns the timestamp of the most recent event that had a timestamp, and that was dispatched from the EventQueue associated with the
calling thread. |
private long |
getMostRecentEventTimeImpl()
|
AWTEvent |
getNextEvent()
Removes an event from the EventQueue and
returns it. |
(package private) AWTEvent |
getNextEvent(int id)
|
(package private) void |
initDispatchThread()
|
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()
|
private boolean |
noEvents()
Returns whether an event is pending on any of the separate Queues. |
AWTEvent |
peekEvent()
Returns the first event on the EventQueue
without removing it. |
AWTEvent |
peekEvent(int id)
Returns the first event with the specified id, if any. |
protected void |
pop()
Stops dispatching events using this EventQueue .
|
void |
postEvent(AWTEvent theEvent)
Posts a 1.1-style event to the EventQueue .
|
private void |
postEvent(AWTEvent theEvent,
int priority)
Posts the event to the internal Queue of specified priority, coalescing as appropriate. |
(package private) void |
postEventPrivate(AWTEvent theEvent)
Posts a 1.1-style event to the EventQueue .
|
void |
push(EventQueue newEventQueue)
Replaces the existing EventQueue with the specified one.
|
(package private) void |
removeSourceEvents(Object source,
boolean removeAllEvents)
|
(package private) static void |
setCurrentEventAndMostRecentTime(AWTEvent e)
|
private void |
setCurrentEventAndMostRecentTimeImpl(AWTEvent e)
|
private void |
wakeup(boolean isShutdown)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final sun.awt.DebugHelper dbg
private static int threadInitNumber
private static final int LOW_PRIORITY
private static final int NORM_PRIORITY
private static final int HIGH_PRIORITY
private static final int NUM_PRIORITIES
private Queue[] queues
private EventQueue nextQueue
private EventQueue previousQueue
private EventDispatchThread dispatchThread
private final ThreadGroup threadGroup
private final ClassLoader classLoader
private static final boolean debug
private long mostRecentEventTime
private WeakReference currentEvent
private int waitForID
private final String name
Constructor Detail |
public EventQueue()
Method Detail |
private static int nextThreadNum()
public void postEvent(AWTEvent theEvent)
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.
theEvent
- an instance of java.awt.AWTEvent
,
or a subclass of it
NullPointerException
- if theEvent
is null
final void postEventPrivate(AWTEvent theEvent)
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.
theEvent
- an instance of java.awt.AWTEvent
,
or a subclass of itprivate void postEvent(AWTEvent theEvent, int priority)
theEvent
- an instance of java.awt.AWTEvent
,
or a subclass of itpriority
- the desired priority of the eventprivate boolean noEvents()
public AWTEvent getNextEvent() throws InterruptedException
EventQueue
and
returns it. This method will block until an event has
been posted by another thread.
AWTEvent
InterruptedException
- if another thread has interrupted this threadAWTEvent getNextEvent(int id) throws InterruptedException
InterruptedException
public AWTEvent peekEvent()
EventQueue
without removing it.
public AWTEvent peekEvent(int id)
id
- the id of the type of event desired
null
if there is no such eventprotected void dispatchEvent(AWTEvent event)
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) |
event
- an instance of java.awt.AWTEvent
,
or a subclass of it
NullPointerException
- if event
is null
public static long getMostRecentEventTime()
EventQueue
associated with the
calling thread. If an event with a timestamp is currently being
dispatched, its timestamp will be returned. If no events have yet
been dispatched, the EventQueue's initialization time will be
returned instead.In the current version of
the Java platform SDK, only InputEvent
s,
ActionEvent
s, and InvocationEvent
s have
timestamps; however, future versions of the SDK may add timestamps to
additional event types. Note that this method should only be invoked
from an application's event dispatching thread. If this method is
invoked from another thread, the current system time (as reported by
System.currentTimeMillis()
) will be returned instead.
InputEvent
,
ActionEvent
, or InvocationEvent
to be
dispatched, or System.currentTimeMillis()
if this
method is invoked on a thread other than an event dispatching
threadInputEvent.getWhen()
,
ActionEvent.getWhen()
,
InvocationEvent.getWhen()
private long getMostRecentEventTimeImpl()
public static AWTEvent getCurrentEvent()
EventQueue
associated with the calling thread. This is
useful if a method needs access to the event, but was not designed to
receive a reference to it as an argument. Note that this method should
only be invoked from an application's event dispatching thread. If this
method is invoked from another thread, null will be returned.
private AWTEvent getCurrentEventImpl()
public void push(EventQueue newEventQueue)
EventQueue
with the specified one.
Any pending events are transferred to the new EventQueue
for processing by it.
newEventQueue
- an EventQueue
(or subclass thereof) instance to be use
NullPointerException
- if newEventQueue
is null
pop()
protected void pop() throws EmptyStackException
EventQueue
.
Any pending events are transferred to the previous
EventQueue
for processing.
Warning: To avoid deadlock, do not declare this method synchronized in a subclass.
EmptyStackException
- if no previous push was made
on this EventQueue
push(java.awt.EventQueue)
public static boolean isDispatchThread()
EventQueue
's dispatch thread. Use this
call the ensure that a given
task is being executed (or not being) on the current AWT
EventDispatchThread
.
EventQueue
's dispatch threadfinal void initDispatchThread()
final void detachDispatchThread()
final EventDispatchThread getDispatchThread()
final void removeSourceEvents(Object source, boolean removeAllEvents)
static void setCurrentEventAndMostRecentTime(AWTEvent e)
private void setCurrentEventAndMostRecentTimeImpl(AWTEvent e)
public static void invokeLater(Runnable runnable)
runnable
to have its run
method called in the dispatch thread of the EventQueue
.
This will happen after all pending events are processed.
runnable
- the Runnable
whose run
method should be executed
synchronously on the EventQueue
invokeAndWait(java.lang.Runnable)
public static void invokeAndWait(Runnable runnable) throws InterruptedException, InvocationTargetException
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.
runnable
- the Runnable
whose run
method should be executed
synchronously on the EventQueue
InterruptedException
- if another thread has
interrupted this thread
InvocationTargetException
- if an exception is thrown
when running runnable
invokeLater(java.lang.Runnable)
private void wakeup(boolean isShutdown)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |