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