src/share/classes/java/awt/EventQueue.java
Print this page
@@ -35,20 +35,14 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.EmptyStackException;
+import sun.awt.*;
import sun.awt.dnd.SunDropTargetEvent;
import sun.util.logging.PlatformLogger;
-import sun.awt.AppContext;
-import sun.awt.AWTAutoShutdown;
-import sun.awt.PeerEvent;
-import sun.awt.SunToolkit;
-import sun.awt.EventQueueItem;
-import sun.awt.AWTAccessor;
-
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.atomic.AtomicInteger;
import java.security.AccessControlContext;
@@ -179,10 +173,12 @@
*/
private volatile int waitForID;
private final String name = "AWT-EventQueue-" + threadInitNumber.getAndIncrement();
+ private FwDispatcher fwDispatcher;
+
private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventQueue");
static {
AWTAccessor.setEventQueueAccessor(
new AWTAccessor.EventQueueAccessor() {
@@ -207,10 +203,14 @@
public void invokeAndWait(Object source, Runnable r)
throws InterruptedException, InvocationTargetException
{
EventQueue.invokeAndWait(source, r);
}
+ public void setFwDispatcher(EventQueue eventQueue,
+ FwDispatcher dispatcher) {
+ eventQueue.setFwDispatcher(dispatcher);
+ }
});
}
public EventQueue() {
for (int i = 0; i < NUM_PRIORITIES; i++) {
@@ -682,11 +682,20 @@
*/
protected void dispatchEvent(final AWTEvent event) {
final Object src = event.getSource();
final PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
public Void run() {
+ if (fwDispatcher == null) {
dispatchEventImpl(event, src);
+ } else {
+ fwDispatcher.scheduleDispatch(new Runnable() {
+ @Override
+ public void run() {
+ dispatchEventImpl(event, src);
+ }
+ });
+ }
return null;
}
};
final AccessControlContext stack = AccessController.getContext();
@@ -842,11 +851,13 @@
try {
EventQueue topQueue = this;
while (topQueue.nextQueue != null) {
topQueue = topQueue.nextQueue;
}
-
+ if (topQueue.fwDispatcher != null) {
+ throw new RuntimeException("push() to queue with fwDispatcher");
+ }
if ((topQueue.dispatchThread != null) &&
(topQueue.dispatchThread.getEventQueue() == this))
{
newEventQueue.dispatchThread = topQueue.dispatchThread;
topQueue.dispatchThread.setEventQueue(newEventQueue);
@@ -973,10 +984,13 @@
try {
if (nextQueue != null) {
// Forward the request to the top of EventQueue stack
return nextQueue.createSecondaryLoop(cond, filter, interval);
}
+ if (fwDispatcher != null) {
+ return fwDispatcher.createSecondaryLoop();
+ }
if (dispatchThread == null) {
initDispatchThread();
}
return new WaitDispatchSupport(dispatchThread, cond, filter, interval);
} finally {
@@ -1016,10 +1030,13 @@
EventQueue next = eq.nextQueue;
while (next != null) {
eq = next;
next = eq.nextQueue;
}
+ if (eq.fwDispatcher != null) {
+ return eq.fwDispatcher.isDispatchThread();
+ }
return (Thread.currentThread() == eq.dispatchThread);
} finally {
pushPopLock.unlock();
}
}
@@ -1301,10 +1318,19 @@
}
} finally {
pushPopLock.unlock();
}
}
+
+ // The method is used by AWTAccessor for javafx/AWT single threaded mode.
+ private void setFwDispatcher(FwDispatcher dispatcher) {
+ if (nextQueue != null) {
+ nextQueue.setFwDispatcher(dispatcher);
+ } else {
+ fwDispatcher = dispatcher;
+ }
+ }
}
/**
* The Queue object holds pointers to the beginning and end of one internal
* queue. An EventQueue object is composed of multiple internal Queues, one