src/java.desktop/share/classes/java/awt/EventQueue.java

Print this page




 882             }
 883             if ((topQueue.dispatchThread != null) &&
 884                 (topQueue.dispatchThread.getEventQueue() == this))
 885             {
 886                 newEventQueue.dispatchThread = topQueue.dispatchThread;
 887                 topQueue.dispatchThread.setEventQueue(newEventQueue);
 888             }
 889 
 890             // Transfer all events forward to new EventQueue.
 891             while (topQueue.peekEvent() != null) {
 892                 try {
 893                     // Use getNextEventPrivate() as it doesn't call flushPendingEvents()
 894                     newEventQueue.postEventPrivate(topQueue.getNextEventPrivate());
 895                 } catch (InterruptedException ie) {
 896                     if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) {
 897                         getEventLog().fine("Interrupted push", ie);
 898                     }
 899                 }
 900             }
 901 

 902             // Wake up EDT waiting in getNextEvent(), so it can
 903             // pick up a new EventQueue. Post the waking event before
 904             // topQueue.nextQueue is assigned, otherwise the event would
 905             // go newEventQueue
 906             topQueue.postEventPrivate(new InvocationEvent(topQueue, dummyRunnable));

 907 
 908             newEventQueue.previousQueue = topQueue;
 909             topQueue.nextQueue = newEventQueue;
 910 
 911             if (appContext.get(AppContext.EVENT_QUEUE_KEY) == topQueue) {
 912                 appContext.put(AppContext.EVENT_QUEUE_KEY, newEventQueue);
 913             }
 914 
 915             pushPopCond.signalAll();
 916         } finally {
 917             pushPopLock.unlock();
 918         }
 919     }
 920 
 921     /**
 922      * Stops dispatching events using this <code>EventQueue</code>.
 923      * Any pending events are transferred to the previous
 924      * <code>EventQueue</code> for processing.
 925      * <p>
 926      * Warning: To avoid deadlock, do not declare this method




 882             }
 883             if ((topQueue.dispatchThread != null) &&
 884                 (topQueue.dispatchThread.getEventQueue() == this))
 885             {
 886                 newEventQueue.dispatchThread = topQueue.dispatchThread;
 887                 topQueue.dispatchThread.setEventQueue(newEventQueue);
 888             }
 889 
 890             // Transfer all events forward to new EventQueue.
 891             while (topQueue.peekEvent() != null) {
 892                 try {
 893                     // Use getNextEventPrivate() as it doesn't call flushPendingEvents()
 894                     newEventQueue.postEventPrivate(topQueue.getNextEventPrivate());
 895                 } catch (InterruptedException ie) {
 896                     if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) {
 897                         getEventLog().fine("Interrupted push", ie);
 898                     }
 899                 }
 900             }
 901 
 902             if (topQueue.dispatchThread != null) {
 903                 // Wake up EDT waiting in getNextEvent(), so it can
 904                 // pick up a new EventQueue. Post the waking event before
 905                 // topQueue.nextQueue is assigned, otherwise the event would
 906                 // go newEventQueue
 907                 topQueue.postEventPrivate(new InvocationEvent(topQueue, dummyRunnable));
 908             }
 909 
 910             newEventQueue.previousQueue = topQueue;
 911             topQueue.nextQueue = newEventQueue;
 912 
 913             if (appContext.get(AppContext.EVENT_QUEUE_KEY) == topQueue) {
 914                 appContext.put(AppContext.EVENT_QUEUE_KEY, newEventQueue);
 915             }
 916 
 917             pushPopCond.signalAll();
 918         } finally {
 919             pushPopLock.unlock();
 920         }
 921     }
 922 
 923     /**
 924      * Stops dispatching events using this <code>EventQueue</code>.
 925      * Any pending events are transferred to the previous
 926      * <code>EventQueue</code> for processing.
 927      * <p>
 928      * Warning: To avoid deadlock, do not declare this method