src/share/classes/sun/awt/SunToolkit.java

Print this page




2079         return AWTAccessor.getAWTEventAccessor().isSystemGenerated(e);
2080     }
2081 
2082 } // class SunToolkit
2083 
2084 
2085 /*
2086  * PostEventQueue is a Thread that runs in the same AppContext as the
2087  * Java EventQueue.  It is a queue of AWTEvents to be posted to the
2088  * Java EventQueue.  The toolkit Thread (AWT-Windows/AWT-Motif) posts
2089  * events to this queue, which then calls EventQueue.postEvent().
2090  *
2091  * We do this because EventQueue.postEvent() may be overridden by client
2092  * code, and we mustn't ever call client code from the toolkit thread.
2093  */
2094 class PostEventQueue {
2095     private EventQueueItem queueHead = null;
2096     private EventQueueItem queueTail = null;
2097     private final EventQueue eventQueue;
2098 



2099     PostEventQueue(EventQueue eq) {
2100         eventQueue = eq;
2101     }
2102 
2103     public synchronized boolean noEvents() {
2104         return queueHead == null;
2105     }
2106 
2107     /*
2108      * Continually post pending AWTEvents to the Java EventQueue. The method
2109      * is synchronized to ensure the flush is completed before a new event
2110      * can be posted to this queue.




2111      */
2112     public synchronized void flush() {
2113         EventQueueItem tempQueue = queueHead;


2114         queueHead = queueTail = null;


2115         while (tempQueue != null) {
2116             eventQueue.postEvent(tempQueue.event);
2117             tempQueue = tempQueue.next;
2118         }

2119     }
2120 
2121     /*
2122      * Enqueue an AWTEvent to be posted to the Java EventQueue.
2123      */
2124     void postEvent(AWTEvent event) {
2125         EventQueueItem item = new EventQueueItem(event);
2126 
2127         synchronized (this) {
2128             if (queueHead == null) {
2129                 queueHead = queueTail = item;
2130             } else {
2131                 queueTail.next = item;
2132                 queueTail = item;
2133             }
2134         }
2135         SunToolkit.wakeupEventQueue(eventQueue, event.getSource() == AWTAutoShutdown.getInstance());
2136     }
2137 } // class PostEventQueue


2079         return AWTAccessor.getAWTEventAccessor().isSystemGenerated(e);
2080     }
2081 
2082 } // class SunToolkit
2083 
2084 
2085 /*
2086  * PostEventQueue is a Thread that runs in the same AppContext as the
2087  * Java EventQueue.  It is a queue of AWTEvents to be posted to the
2088  * Java EventQueue.  The toolkit Thread (AWT-Windows/AWT-Motif) posts
2089  * events to this queue, which then calls EventQueue.postEvent().
2090  *
2091  * We do this because EventQueue.postEvent() may be overridden by client
2092  * code, and we mustn't ever call client code from the toolkit thread.
2093  */
2094 class PostEventQueue {
2095     private EventQueueItem queueHead = null;
2096     private EventQueueItem queueTail = null;
2097     private final EventQueue eventQueue;
2098 
2099     // For the case when queue is cleared but events are not posted
2100     private boolean isPending = false;
2101 
2102     PostEventQueue(EventQueue eq) {
2103         eventQueue = eq;
2104     }
2105 
2106     public synchronized boolean noEvents() {
2107         return queueHead == null && !isPending;
2108     }
2109 
2110     /*
2111      * Continually post pending AWTEvents to the Java EventQueue. The method
2112      * is synchronized to ensure the flush is completed before a new event
2113      * can be posted to this queue.
2114      *
2115      * 7177040: The method couldn't be wholly synchronized because of calls
2116      * of EventQueue.postEvent() that uses pushPopLock, otherwise it could
2117      * potentially lead to deadlock
2118      */
2119     public void flush() {
2120         EventQueueItem tempQueue;
2121         synchronized (this) {
2122             tempQueue = queueHead;
2123             queueHead = queueTail = null;
2124             isPending = true;
2125         }
2126         while (tempQueue != null) {
2127             eventQueue.postEvent(tempQueue.event);
2128             tempQueue = tempQueue.next;
2129         }
2130         isPending = false;
2131     }
2132 
2133     /*
2134      * Enqueue an AWTEvent to be posted to the Java EventQueue.
2135      */
2136     void postEvent(AWTEvent event) {
2137         EventQueueItem item = new EventQueueItem(event);
2138 
2139         synchronized (this) {
2140             if (queueHead == null) {
2141                 queueHead = queueTail = item;
2142             } else {
2143                 queueTail.next = item;
2144                 queueTail = item;
2145             }
2146         }
2147         SunToolkit.wakeupEventQueue(eventQueue, event.getSource() == AWTAutoShutdown.getInstance());
2148     }
2149 } // class PostEventQueue