author | mchung |
Tue, 06 Nov 2018 10:01:16 -0800 | |
changeset 52427 | 3c6aa484536c |
parent 47971 | 75686e8da573 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
47971
diff
changeset
|
2 |
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.awt; |
|
27 |
||
28 |
import java.awt.event.*; |
|
29 |
||
30 |
import java.awt.peer.ComponentPeer; |
|
31 |
||
32 |
import java.lang.ref.WeakReference; |
|
33 |
import java.lang.reflect.InvocationTargetException; |
|
34 |
||
35 |
import java.security.AccessController; |
|
36 |
import java.security.PrivilegedAction; |
|
37 |
||
38 |
import java.util.EmptyStackException; |
|
13541
5626307c2f86
7177144: [macosx] Drag and drop not working (regression in 7u6)
kizune
parents:
10583
diff
changeset
|
39 |
|
17899 | 40 |
import sun.awt.*; |
13541
5626307c2f86
7177144: [macosx] Drag and drop not working (regression in 7u6)
kizune
parents:
10583
diff
changeset
|
41 |
import sun.awt.dnd.SunDropTargetEvent; |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
42 |
import sun.util.logging.PlatformLogger; |
2 | 43 |
|
4365 | 44 |
import java.util.concurrent.locks.Condition; |
45 |
import java.util.concurrent.locks.Lock; |
|
10583
8bb208d39fb1
7081670: Disposing an AppContext can lead to a spinning EventDispatchThread
anthony
parents:
9035
diff
changeset
|
46 |
import java.util.concurrent.atomic.AtomicInteger; |
4365 | 47 |
|
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
48 |
import java.security.AccessControlContext; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
49 |
|
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
47971
diff
changeset
|
50 |
import jdk.internal.access.SharedSecrets; |
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
47971
diff
changeset
|
51 |
import jdk.internal.access.JavaSecurityAccess; |
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
52 |
|
2 | 53 |
/** |
35667 | 54 |
* {@code EventQueue} is a platform-independent class |
2 | 55 |
* that queues events, both from the underlying peer classes |
56 |
* and from trusted application classes. |
|
57 |
* <p> |
|
58 |
* It encapsulates asynchronous event dispatch machinery which |
|
59 |
* extracts events from the queue and dispatches them by calling |
|
60 |
* {@link #dispatchEvent(AWTEvent) dispatchEvent(AWTEvent)} method |
|
35667 | 61 |
* on this {@code EventQueue} with the event to be dispatched |
2 | 62 |
* as an argument. The particular behavior of this machinery is |
63 |
* implementation-dependent. The only requirements are that events |
|
64 |
* which were actually enqueued to this queue (note that events |
|
35667 | 65 |
* being posted to the {@code EventQueue} can be coalesced) |
2 | 66 |
* are dispatched: |
67 |
* <dl> |
|
68 |
* <dt> Sequentially. |
|
69 |
* <dd> That is, it is not permitted that several events from |
|
70 |
* this queue are dispatched simultaneously. |
|
71 |
* <dt> In the same order as they are enqueued. |
|
35667 | 72 |
* <dd> That is, if {@code AWTEvent} A is enqueued |
73 |
* to the {@code EventQueue} before |
|
74 |
* {@code AWTEvent} B then event B will not be |
|
2 | 75 |
* dispatched before event A. |
76 |
* </dl> |
|
77 |
* <p> |
|
78 |
* Some browsers partition applets in different code bases into |
|
79 |
* separate contexts, and establish walls between these contexts. |
|
35667 | 80 |
* In such a scenario, there will be one {@code EventQueue} |
2 | 81 |
* per context. Other browsers place all applets into the same |
82 |
* context, implying that there will be only a single, global |
|
35667 | 83 |
* {@code EventQueue} for all applets. This behavior is |
2 | 84 |
* implementation-dependent. Consult your browser's documentation |
85 |
* for more information. |
|
86 |
* <p> |
|
87 |
* For information on the threading issues of the event dispatch |
|
88 |
* machinery, see <a href="doc-files/AWTThreadIssues.html#Autoshutdown" |
|
89 |
* >AWT Threading Issues</a>. |
|
90 |
* |
|
91 |
* @author Thomas Ball |
|
92 |
* @author Fred Ecks |
|
93 |
* @author David Mendenhall |
|
94 |
* |
|
95 |
* @since 1.1 |
|
96 |
*/ |
|
97 |
public class EventQueue { |
|
10583
8bb208d39fb1
7081670: Disposing an AppContext can lead to a spinning EventDispatchThread
anthony
parents:
9035
diff
changeset
|
98 |
private static final AtomicInteger threadInitNumber = new AtomicInteger(0); |
2 | 99 |
|
100 |
private static final int LOW_PRIORITY = 0; |
|
101 |
private static final int NORM_PRIORITY = 1; |
|
102 |
private static final int HIGH_PRIORITY = 2; |
|
103 |
private static final int ULTIMATE_PRIORITY = 3; |
|
104 |
||
105 |
private static final int NUM_PRIORITIES = ULTIMATE_PRIORITY + 1; |
|
106 |
||
107 |
/* |
|
108 |
* We maintain one Queue for each priority that the EventQueue supports. |
|
109 |
* That is, the EventQueue object is actually implemented as |
|
110 |
* NUM_PRIORITIES queues and all Events on a particular internal Queue |
|
111 |
* have identical priority. Events are pulled off the EventQueue starting |
|
112 |
* with the Queue of highest priority. We progress in decreasing order |
|
113 |
* across all Queues. |
|
114 |
*/ |
|
115 |
private Queue[] queues = new Queue[NUM_PRIORITIES]; |
|
116 |
||
117 |
/* |
|
118 |
* The next EventQueue on the stack, or null if this EventQueue is |
|
119 |
* on the top of the stack. If nextQueue is non-null, requests to post |
|
120 |
* an event are forwarded to nextQueue. |
|
121 |
*/ |
|
122 |
private EventQueue nextQueue; |
|
123 |
||
124 |
/* |
|
125 |
* The previous EventQueue on the stack, or null if this is the |
|
126 |
* "base" EventQueue. |
|
127 |
*/ |
|
128 |
private EventQueue previousQueue; |
|
129 |
||
4365 | 130 |
/* |
131 |
* A single lock to synchronize the push()/pop() and related operations with |
|
132 |
* all the EventQueues from the AppContext. Synchronization on any particular |
|
133 |
* event queue(s) is not enough: we should lock the whole stack. |
|
134 |
*/ |
|
135 |
private final Lock pushPopLock; |
|
136 |
private final Condition pushPopCond; |
|
137 |
||
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
138 |
/* |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
139 |
* Dummy runnable to wake up EDT from getNextEvent() after |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
140 |
push/pop is performed |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
141 |
*/ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
32675
diff
changeset
|
142 |
private static final Runnable dummyRunnable = new Runnable() { |
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
143 |
public void run() { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
144 |
} |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
145 |
}; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
146 |
|
2 | 147 |
private EventDispatchThread dispatchThread; |
148 |
||
149 |
private final ThreadGroup threadGroup = |
|
150 |
Thread.currentThread().getThreadGroup(); |
|
151 |
private final ClassLoader classLoader = |
|
152 |
Thread.currentThread().getContextClassLoader(); |
|
153 |
||
154 |
/* |
|
155 |
* The time stamp of the last dispatched InputEvent or ActionEvent. |
|
156 |
*/ |
|
157 |
private long mostRecentEventTime = System.currentTimeMillis(); |
|
158 |
||
13652
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
159 |
/* |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
160 |
* The time stamp of the last KeyEvent . |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
161 |
*/ |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
162 |
private long mostRecentKeyEventTime = System.currentTimeMillis(); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
163 |
|
2 | 164 |
/** |
165 |
* The modifiers field of the current event, if the current event is an |
|
166 |
* InputEvent or ActionEvent. |
|
167 |
*/ |
|
15994
5c8a3d840366
8007295: Reduce number of warnings in awt classes
mcherkas
parents:
13775
diff
changeset
|
168 |
private WeakReference<AWTEvent> currentEvent; |
2 | 169 |
|
170 |
/* |
|
171 |
* Non-zero if a thread is waiting in getNextEvent(int) for an event of |
|
172 |
* a particular ID to be posted to the queue. |
|
173 |
*/ |
|
10583
8bb208d39fb1
7081670: Disposing an AppContext can lead to a spinning EventDispatchThread
anthony
parents:
9035
diff
changeset
|
174 |
private volatile int waitForID; |
2 | 175 |
|
18231
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16126
diff
changeset
|
176 |
/* |
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16126
diff
changeset
|
177 |
* AppContext corresponding to the queue. |
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16126
diff
changeset
|
178 |
*/ |
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16126
diff
changeset
|
179 |
private final AppContext appContext; |
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16126
diff
changeset
|
180 |
|
10583
8bb208d39fb1
7081670: Disposing an AppContext can lead to a spinning EventDispatchThread
anthony
parents:
9035
diff
changeset
|
181 |
private final String name = "AWT-EventQueue-" + threadInitNumber.getAndIncrement(); |
2 | 182 |
|
17899 | 183 |
private FwDispatcher fwDispatcher; |
184 |
||
28994
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
185 |
private static volatile PlatformLogger eventLog; |
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
186 |
|
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
187 |
private static final PlatformLogger getEventLog() { |
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
188 |
if(eventLog == null) { |
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
189 |
eventLog = PlatformLogger.getLogger("java.awt.event.EventQueue"); |
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
190 |
} |
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
191 |
return eventLog; |
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
192 |
} |
2 | 193 |
|
47229
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
194 |
private static boolean fxAppThreadIsDispatchThread; |
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
195 |
|
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
1247
diff
changeset
|
196 |
static { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
1247
diff
changeset
|
197 |
AWTAccessor.setEventQueueAccessor( |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
1247
diff
changeset
|
198 |
new AWTAccessor.EventQueueAccessor() { |
4365 | 199 |
public Thread getDispatchThread(EventQueue eventQueue) { |
200 |
return eventQueue.getDispatchThread(); |
|
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
1247
diff
changeset
|
201 |
} |
4365 | 202 |
public boolean isDispatchThreadImpl(EventQueue eventQueue) { |
203 |
return eventQueue.isDispatchThreadImpl(); |
|
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
1247
diff
changeset
|
204 |
} |
13604 | 205 |
public void removeSourceEvents(EventQueue eventQueue, |
206 |
Object source, |
|
16092 | 207 |
boolean removeAllEvents) |
208 |
{ |
|
13604 | 209 |
eventQueue.removeSourceEvents(source, removeAllEvents); |
210 |
} |
|
211 |
public boolean noEvents(EventQueue eventQueue) { |
|
212 |
return eventQueue.noEvents(); |
|
213 |
} |
|
214 |
public void wakeup(EventQueue eventQueue, boolean isShutdown) { |
|
215 |
eventQueue.wakeup(isShutdown); |
|
216 |
} |
|
16092 | 217 |
public void invokeAndWait(Object source, Runnable r) |
218 |
throws InterruptedException, InvocationTargetException |
|
219 |
{ |
|
220 |
EventQueue.invokeAndWait(source, r); |
|
221 |
} |
|
17899 | 222 |
public void setFwDispatcher(EventQueue eventQueue, |
223 |
FwDispatcher dispatcher) { |
|
224 |
eventQueue.setFwDispatcher(dispatcher); |
|
225 |
} |
|
25133
a327a33a1e0a
8041990: [macosx] Language specific keys does not work in applets when opened outside the browser
pchelko
parents:
23900
diff
changeset
|
226 |
|
a327a33a1e0a
8041990: [macosx] Language specific keys does not work in applets when opened outside the browser
pchelko
parents:
23900
diff
changeset
|
227 |
@Override |
a327a33a1e0a
8041990: [macosx] Language specific keys does not work in applets when opened outside the browser
pchelko
parents:
23900
diff
changeset
|
228 |
public long getMostRecentEventTime(EventQueue eventQueue) { |
a327a33a1e0a
8041990: [macosx] Language specific keys does not work in applets when opened outside the browser
pchelko
parents:
23900
diff
changeset
|
229 |
return eventQueue.getMostRecentEventTimeImpl(); |
a327a33a1e0a
8041990: [macosx] Language specific keys does not work in applets when opened outside the browser
pchelko
parents:
23900
diff
changeset
|
230 |
} |
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
1247
diff
changeset
|
231 |
}); |
47229
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
232 |
AccessController.doPrivileged(new PrivilegedAction<Object>() { |
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
233 |
public Object run() { |
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
234 |
fxAppThreadIsDispatchThread = |
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
235 |
"true".equals(System.getProperty("javafx.embed.singleThread")); |
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
236 |
return null; |
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
237 |
} |
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
238 |
}); |
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
1247
diff
changeset
|
239 |
} |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
1247
diff
changeset
|
240 |
|
25162 | 241 |
/** |
242 |
* Initializes a new instance of {@code EventQueue}. |
|
243 |
*/ |
|
2 | 244 |
public EventQueue() { |
245 |
for (int i = 0; i < NUM_PRIORITIES; i++) { |
|
246 |
queues[i] = new Queue(); |
|
247 |
} |
|
248 |
/* |
|
249 |
* NOTE: if you ever have to start the associated event dispatch |
|
250 |
* thread at this point, be aware of the following problem: |
|
251 |
* If this EventQueue instance is created in |
|
252 |
* SunToolkit.createNewAppContext() the started dispatch thread |
|
253 |
* may call AppContext.getAppContext() before createNewAppContext() |
|
254 |
* completes thus causing mess in thread group to appcontext mapping. |
|
255 |
*/ |
|
4365 | 256 |
|
18231
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16126
diff
changeset
|
257 |
appContext = AppContext.getAppContext(); |
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16126
diff
changeset
|
258 |
pushPopLock = (Lock)appContext.get(AppContext.EVENT_QUEUE_LOCK_KEY); |
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16126
diff
changeset
|
259 |
pushPopCond = (Condition)appContext.get(AppContext.EVENT_QUEUE_COND_KEY); |
2 | 260 |
} |
261 |
||
262 |
/** |
|
35667 | 263 |
* Posts a 1.1-style event to the {@code EventQueue}. |
2 | 264 |
* If there is an existing event on the queue with the same ID |
35667 | 265 |
* and event source, the source {@code Component}'s |
266 |
* {@code coalesceEvents} method will be called. |
|
2 | 267 |
* |
35667 | 268 |
* @param theEvent an instance of {@code java.awt.AWTEvent}, |
2 | 269 |
* or a subclass of it |
35667 | 270 |
* @throws NullPointerException if {@code theEvent} is {@code null} |
2 | 271 |
*/ |
272 |
public void postEvent(AWTEvent theEvent) { |
|
18231
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16126
diff
changeset
|
273 |
SunToolkit.flushPendingEvents(appContext); |
2 | 274 |
postEventPrivate(theEvent); |
275 |
} |
|
276 |
||
277 |
/** |
|
35667 | 278 |
* Posts a 1.1-style event to the {@code EventQueue}. |
2 | 279 |
* If there is an existing event on the queue with the same ID |
35667 | 280 |
* and event source, the source {@code Component}'s |
281 |
* {@code coalesceEvents} method will be called. |
|
2 | 282 |
* |
35667 | 283 |
* @param theEvent an instance of {@code java.awt.AWTEvent}, |
2 | 284 |
* or a subclass of it |
285 |
*/ |
|
47971
75686e8da573
8190228: Remove redundant modifiers in java.desktop module.
ssadetsky
parents:
47829
diff
changeset
|
286 |
private void postEventPrivate(AWTEvent theEvent) { |
2 | 287 |
theEvent.isPosted = true; |
4365 | 288 |
pushPopLock.lock(); |
289 |
try { |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
290 |
if (nextQueue != null) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
291 |
// Forward the event to the top of EventQueue stack |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
292 |
nextQueue.postEventPrivate(theEvent); |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
293 |
return; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
294 |
} |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
295 |
if (dispatchThread == null) { |
2 | 296 |
if (theEvent.getSource() == AWTAutoShutdown.getInstance()) { |
297 |
return; |
|
298 |
} else { |
|
299 |
initDispatchThread(); |
|
300 |
} |
|
301 |
} |
|
302 |
postEvent(theEvent, getPriority(theEvent)); |
|
4365 | 303 |
} finally { |
304 |
pushPopLock.unlock(); |
|
2 | 305 |
} |
306 |
} |
|
307 |
||
308 |
private static int getPriority(AWTEvent theEvent) { |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
309 |
if (theEvent instanceof PeerEvent) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
310 |
PeerEvent peerEvent = (PeerEvent)theEvent; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
311 |
if ((peerEvent.getFlags() & PeerEvent.ULTIMATE_PRIORITY_EVENT) != 0) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
312 |
return ULTIMATE_PRIORITY; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
313 |
} |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
314 |
if ((peerEvent.getFlags() & PeerEvent.PRIORITY_EVENT) != 0) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
315 |
return HIGH_PRIORITY; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
316 |
} |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
317 |
if ((peerEvent.getFlags() & PeerEvent.LOW_PRIORITY_EVENT) != 0) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
318 |
return LOW_PRIORITY; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
319 |
} |
2 | 320 |
} |
321 |
int id = theEvent.getID(); |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
322 |
if ((id >= PaintEvent.PAINT_FIRST) && (id <= PaintEvent.PAINT_LAST)) { |
2 | 323 |
return LOW_PRIORITY; |
324 |
} |
|
325 |
return NORM_PRIORITY; |
|
326 |
} |
|
327 |
||
328 |
/** |
|
329 |
* Posts the event to the internal Queue of specified priority, |
|
330 |
* coalescing as appropriate. |
|
331 |
* |
|
35667 | 332 |
* @param theEvent an instance of {@code java.awt.AWTEvent}, |
2 | 333 |
* or a subclass of it |
334 |
* @param priority the desired priority of the event |
|
335 |
*/ |
|
336 |
private void postEvent(AWTEvent theEvent, int priority) { |
|
337 |
if (coalesceEvent(theEvent, priority)) { |
|
338 |
return; |
|
339 |
} |
|
340 |
||
341 |
EventQueueItem newItem = new EventQueueItem(theEvent); |
|
342 |
||
343 |
cacheEQItem(newItem); |
|
344 |
||
345 |
boolean notifyID = (theEvent.getID() == this.waitForID); |
|
346 |
||
347 |
if (queues[priority].head == null) { |
|
348 |
boolean shouldNotify = noEvents(); |
|
349 |
queues[priority].head = queues[priority].tail = newItem; |
|
350 |
||
351 |
if (shouldNotify) { |
|
352 |
if (theEvent.getSource() != AWTAutoShutdown.getInstance()) { |
|
353 |
AWTAutoShutdown.getInstance().notifyThreadBusy(dispatchThread); |
|
354 |
} |
|
4365 | 355 |
pushPopCond.signalAll(); |
2 | 356 |
} else if (notifyID) { |
4365 | 357 |
pushPopCond.signalAll(); |
2 | 358 |
} |
359 |
} else { |
|
360 |
// The event was not coalesced or has non-Component source. |
|
361 |
// Insert it at the end of the appropriate Queue. |
|
362 |
queues[priority].tail.next = newItem; |
|
363 |
queues[priority].tail = newItem; |
|
364 |
if (notifyID) { |
|
4365 | 365 |
pushPopCond.signalAll(); |
2 | 366 |
} |
367 |
} |
|
368 |
} |
|
369 |
||
370 |
private boolean coalescePaintEvent(PaintEvent e) { |
|
371 |
ComponentPeer sourcePeer = ((Component)e.getSource()).peer; |
|
372 |
if (sourcePeer != null) { |
|
373 |
sourcePeer.coalescePaintEvent(e); |
|
374 |
} |
|
375 |
EventQueueItem[] cache = ((Component)e.getSource()).eventCache; |
|
376 |
if (cache == null) { |
|
377 |
return false; |
|
378 |
} |
|
379 |
int index = eventToCacheIndex(e); |
|
380 |
||
381 |
if (index != -1 && cache[index] != null) { |
|
382 |
PaintEvent merged = mergePaintEvents(e, (PaintEvent)cache[index].event); |
|
383 |
if (merged != null) { |
|
384 |
cache[index].event = merged; |
|
385 |
return true; |
|
386 |
} |
|
387 |
} |
|
388 |
return false; |
|
389 |
} |
|
390 |
||
391 |
private PaintEvent mergePaintEvents(PaintEvent a, PaintEvent b) { |
|
392 |
Rectangle aRect = a.getUpdateRect(); |
|
393 |
Rectangle bRect = b.getUpdateRect(); |
|
394 |
if (bRect.contains(aRect)) { |
|
395 |
return b; |
|
396 |
} |
|
397 |
if (aRect.contains(bRect)) { |
|
398 |
return a; |
|
399 |
} |
|
400 |
return null; |
|
401 |
} |
|
402 |
||
403 |
private boolean coalesceMouseEvent(MouseEvent e) { |
|
404 |
EventQueueItem[] cache = ((Component)e.getSource()).eventCache; |
|
405 |
if (cache == null) { |
|
406 |
return false; |
|
407 |
} |
|
408 |
int index = eventToCacheIndex(e); |
|
409 |
if (index != -1 && cache[index] != null) { |
|
410 |
cache[index].event = e; |
|
411 |
return true; |
|
412 |
} |
|
413 |
return false; |
|
414 |
} |
|
415 |
||
416 |
private boolean coalescePeerEvent(PeerEvent e) { |
|
417 |
EventQueueItem[] cache = ((Component)e.getSource()).eventCache; |
|
418 |
if (cache == null) { |
|
419 |
return false; |
|
420 |
} |
|
421 |
int index = eventToCacheIndex(e); |
|
422 |
if (index != -1 && cache[index] != null) { |
|
423 |
e = e.coalesceEvents((PeerEvent)cache[index].event); |
|
424 |
if (e != null) { |
|
425 |
cache[index].event = e; |
|
426 |
return true; |
|
427 |
} else { |
|
428 |
cache[index] = null; |
|
429 |
} |
|
430 |
} |
|
431 |
return false; |
|
432 |
} |
|
433 |
||
434 |
/* |
|
435 |
* Should avoid of calling this method by any means |
|
47020
2c55106dc37b
8186851: fix misspellings of "dependent" and "independent" in the JDK repo
smarks
parents:
45648
diff
changeset
|
436 |
* as it's working time is dependent on EQ length. |
26749 | 437 |
* In the worst case this method alone can slow down the entire application |
2 | 438 |
* 10 times by stalling the Event processing. |
439 |
* Only here by backward compatibility reasons. |
|
440 |
*/ |
|
441 |
private boolean coalesceOtherEvent(AWTEvent e, int priority) { |
|
442 |
int id = e.getID(); |
|
443 |
Component source = (Component)e.getSource(); |
|
444 |
for (EventQueueItem entry = queues[priority].head; |
|
445 |
entry != null; entry = entry.next) |
|
446 |
{ |
|
447 |
// Give Component.coalesceEvents a chance |
|
1181
c5971dbeaaaa
6693974: Unify EventQueue$EventQueueItem and SunToolkit.$EventQueueItem classes
dav
parents:
2
diff
changeset
|
448 |
if (entry.event.getSource() == source && entry.event.getID() == id) { |
2 | 449 |
AWTEvent coalescedEvent = source.coalesceEvents( |
450 |
entry.event, e); |
|
451 |
if (coalescedEvent != null) { |
|
452 |
entry.event = coalescedEvent; |
|
453 |
return true; |
|
454 |
} |
|
455 |
} |
|
456 |
} |
|
457 |
return false; |
|
458 |
} |
|
459 |
||
460 |
private boolean coalesceEvent(AWTEvent e, int priority) { |
|
461 |
if (!(e.getSource() instanceof Component)) { |
|
462 |
return false; |
|
463 |
} |
|
464 |
if (e instanceof PeerEvent) { |
|
465 |
return coalescePeerEvent((PeerEvent)e); |
|
466 |
} |
|
467 |
// The worst case |
|
468 |
if (((Component)e.getSource()).isCoalescingEnabled() |
|
469 |
&& coalesceOtherEvent(e, priority)) |
|
470 |
{ |
|
471 |
return true; |
|
472 |
} |
|
473 |
if (e instanceof PaintEvent) { |
|
474 |
return coalescePaintEvent((PaintEvent)e); |
|
475 |
} |
|
476 |
if (e instanceof MouseEvent) { |
|
477 |
return coalesceMouseEvent((MouseEvent)e); |
|
478 |
} |
|
479 |
return false; |
|
480 |
} |
|
481 |
||
482 |
private void cacheEQItem(EventQueueItem entry) { |
|
483 |
int index = eventToCacheIndex(entry.event); |
|
484 |
if (index != -1 && entry.event.getSource() instanceof Component) { |
|
485 |
Component source = (Component)entry.event.getSource(); |
|
486 |
if (source.eventCache == null) { |
|
487 |
source.eventCache = new EventQueueItem[CACHE_LENGTH]; |
|
488 |
} |
|
489 |
source.eventCache[index] = entry; |
|
490 |
} |
|
491 |
} |
|
492 |
||
493 |
private void uncacheEQItem(EventQueueItem entry) { |
|
494 |
int index = eventToCacheIndex(entry.event); |
|
495 |
if (index != -1 && entry.event.getSource() instanceof Component) { |
|
496 |
Component source = (Component)entry.event.getSource(); |
|
497 |
if (source.eventCache == null) { |
|
498 |
return; |
|
499 |
} |
|
500 |
source.eventCache[index] = null; |
|
501 |
} |
|
502 |
} |
|
503 |
||
504 |
private static final int PAINT = 0; |
|
505 |
private static final int UPDATE = 1; |
|
506 |
private static final int MOVE = 2; |
|
507 |
private static final int DRAG = 3; |
|
508 |
private static final int PEER = 4; |
|
509 |
private static final int CACHE_LENGTH = 5; |
|
510 |
||
511 |
private static int eventToCacheIndex(AWTEvent e) { |
|
512 |
switch(e.getID()) { |
|
513 |
case PaintEvent.PAINT: |
|
514 |
return PAINT; |
|
515 |
case PaintEvent.UPDATE: |
|
516 |
return UPDATE; |
|
517 |
case MouseEvent.MOUSE_MOVED: |
|
518 |
return MOVE; |
|
519 |
case MouseEvent.MOUSE_DRAGGED: |
|
13541
5626307c2f86
7177144: [macosx] Drag and drop not working (regression in 7u6)
kizune
parents:
10583
diff
changeset
|
520 |
// Return -1 for SunDropTargetEvent since they are usually synchronous |
5626307c2f86
7177144: [macosx] Drag and drop not working (regression in 7u6)
kizune
parents:
10583
diff
changeset
|
521 |
// and we don't want to skip them by coalescing with MouseEvent or other drag events |
5626307c2f86
7177144: [macosx] Drag and drop not working (regression in 7u6)
kizune
parents:
10583
diff
changeset
|
522 |
return e instanceof SunDropTargetEvent ? -1 : DRAG; |
2 | 523 |
default: |
524 |
return e instanceof PeerEvent ? PEER : -1; |
|
525 |
} |
|
526 |
} |
|
527 |
||
528 |
/** |
|
529 |
* Returns whether an event is pending on any of the separate |
|
530 |
* Queues. |
|
531 |
* @return whether an event is pending on any of the separate Queues |
|
532 |
*/ |
|
533 |
private boolean noEvents() { |
|
534 |
for (int i = 0; i < NUM_PRIORITIES; i++) { |
|
535 |
if (queues[i].head != null) { |
|
536 |
return false; |
|
537 |
} |
|
538 |
} |
|
539 |
||
540 |
return true; |
|
541 |
} |
|
542 |
||
543 |
/** |
|
35667 | 544 |
* Removes an event from the {@code EventQueue} and |
2 | 545 |
* returns it. This method will block until an event has |
546 |
* been posted by another thread. |
|
35667 | 547 |
* @return the next {@code AWTEvent} |
2 | 548 |
* @exception InterruptedException |
549 |
* if any thread has interrupted this thread |
|
550 |
*/ |
|
551 |
public AWTEvent getNextEvent() throws InterruptedException { |
|
552 |
do { |
|
553 |
/* |
|
554 |
* SunToolkit.flushPendingEvents must be called outside |
|
555 |
* of the synchronized block to avoid deadlock when |
|
556 |
* event queues are nested with push()/pop(). |
|
557 |
*/ |
|
18231
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16126
diff
changeset
|
558 |
SunToolkit.flushPendingEvents(appContext); |
4365 | 559 |
pushPopLock.lock(); |
560 |
try { |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
561 |
AWTEvent event = getNextEventPrivate(); |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
562 |
if (event != null) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
563 |
return event; |
2 | 564 |
} |
565 |
AWTAutoShutdown.getInstance().notifyThreadFree(dispatchThread); |
|
4365 | 566 |
pushPopCond.await(); |
567 |
} finally { |
|
568 |
pushPopLock.unlock(); |
|
2 | 569 |
} |
570 |
} while(true); |
|
571 |
} |
|
572 |
||
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
573 |
/* |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
574 |
* Must be called under the lock. Doesn't call flushPendingEvents() |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
575 |
*/ |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
576 |
AWTEvent getNextEventPrivate() throws InterruptedException { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
577 |
for (int i = NUM_PRIORITIES - 1; i >= 0; i--) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
578 |
if (queues[i].head != null) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
579 |
EventQueueItem entry = queues[i].head; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
580 |
queues[i].head = entry.next; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
581 |
if (entry.next == null) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
582 |
queues[i].tail = null; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
583 |
} |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
584 |
uncacheEQItem(entry); |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
585 |
return entry.event; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
586 |
} |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
587 |
} |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
588 |
return null; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
589 |
} |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
590 |
|
2 | 591 |
AWTEvent getNextEvent(int id) throws InterruptedException { |
592 |
do { |
|
593 |
/* |
|
594 |
* SunToolkit.flushPendingEvents must be called outside |
|
595 |
* of the synchronized block to avoid deadlock when |
|
596 |
* event queues are nested with push()/pop(). |
|
597 |
*/ |
|
18231
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16126
diff
changeset
|
598 |
SunToolkit.flushPendingEvents(appContext); |
4365 | 599 |
pushPopLock.lock(); |
600 |
try { |
|
2 | 601 |
for (int i = 0; i < NUM_PRIORITIES; i++) { |
602 |
for (EventQueueItem entry = queues[i].head, prev = null; |
|
603 |
entry != null; prev = entry, entry = entry.next) |
|
604 |
{ |
|
1181
c5971dbeaaaa
6693974: Unify EventQueue$EventQueueItem and SunToolkit.$EventQueueItem classes
dav
parents:
2
diff
changeset
|
605 |
if (entry.event.getID() == id) { |
2 | 606 |
if (prev == null) { |
607 |
queues[i].head = entry.next; |
|
608 |
} else { |
|
609 |
prev.next = entry.next; |
|
610 |
} |
|
611 |
if (queues[i].tail == entry) { |
|
612 |
queues[i].tail = prev; |
|
613 |
} |
|
614 |
uncacheEQItem(entry); |
|
615 |
return entry.event; |
|
616 |
} |
|
617 |
} |
|
618 |
} |
|
4365 | 619 |
waitForID = id; |
620 |
pushPopCond.await(); |
|
621 |
waitForID = 0; |
|
622 |
} finally { |
|
623 |
pushPopLock.unlock(); |
|
2 | 624 |
} |
625 |
} while(true); |
|
626 |
} |
|
627 |
||
628 |
/** |
|
35667 | 629 |
* Returns the first event on the {@code EventQueue} |
2 | 630 |
* without removing it. |
631 |
* @return the first event |
|
632 |
*/ |
|
4365 | 633 |
public AWTEvent peekEvent() { |
634 |
pushPopLock.lock(); |
|
635 |
try { |
|
636 |
for (int i = NUM_PRIORITIES - 1; i >= 0; i--) { |
|
637 |
if (queues[i].head != null) { |
|
638 |
return queues[i].head.event; |
|
639 |
} |
|
2 | 640 |
} |
4365 | 641 |
} finally { |
642 |
pushPopLock.unlock(); |
|
2 | 643 |
} |
644 |
||
645 |
return null; |
|
646 |
} |
|
647 |
||
648 |
/** |
|
649 |
* Returns the first event with the specified id, if any. |
|
650 |
* @param id the id of the type of event desired |
|
35667 | 651 |
* @return the first event of the specified id or {@code null} |
2 | 652 |
* if there is no such event |
653 |
*/ |
|
4365 | 654 |
public AWTEvent peekEvent(int id) { |
655 |
pushPopLock.lock(); |
|
656 |
try { |
|
657 |
for (int i = NUM_PRIORITIES - 1; i >= 0; i--) { |
|
658 |
EventQueueItem q = queues[i].head; |
|
659 |
for (; q != null; q = q.next) { |
|
660 |
if (q.event.getID() == id) { |
|
661 |
return q.event; |
|
662 |
} |
|
2 | 663 |
} |
664 |
} |
|
4365 | 665 |
} finally { |
666 |
pushPopLock.unlock(); |
|
2 | 667 |
} |
668 |
||
669 |
return null; |
|
670 |
} |
|
671 |
||
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
672 |
private static final JavaSecurityAccess javaSecurityAccess = |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
673 |
SharedSecrets.getJavaSecurityAccess(); |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
674 |
|
2 | 675 |
/** |
676 |
* Dispatches an event. The manner in which the event is |
|
677 |
* dispatched depends upon the type of the event and the |
|
678 |
* type of the event's source object: |
|
21957 | 679 |
* |
45648
87c997b74bb8
8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents:
35667
diff
changeset
|
680 |
* <table class="striped"> |
87c997b74bb8
8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents:
35667
diff
changeset
|
681 |
* <caption>Event types, source types, and dispatch methods</caption> |
87c997b74bb8
8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents:
35667
diff
changeset
|
682 |
* <thead> |
47498
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
683 |
* <tr> |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
684 |
* <th scope="col">Event Type |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
685 |
* <th scope="col">Source Type |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
686 |
* <th scope="col">Dispatched To |
45648
87c997b74bb8
8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents:
35667
diff
changeset
|
687 |
* </thead> |
87c997b74bb8
8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents:
35667
diff
changeset
|
688 |
* <tbody> |
47498
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
689 |
* <tr> |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
690 |
* <th scope="row">ActiveEvent |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
691 |
* <td>Any |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
692 |
* <td>event.dispatch() |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
693 |
* <tr> |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
694 |
* <th scope="row">Other |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
695 |
* <td>Component |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
696 |
* <td>source.dispatchEvent(AWTEvent) |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
697 |
* <tr> |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
698 |
* <th scope="row">Other |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
699 |
* <td>MenuComponent |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
700 |
* <td>source.dispatchEvent(AWTEvent) |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
701 |
* <tr> |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
702 |
* <th scope="row">Other |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
703 |
* <td>Other |
aa0344e6f39b
8184219: Fix accessibility of tables in the java.desktop module
serb
parents:
47229
diff
changeset
|
704 |
* <td>No action (ignored) |
45648
87c997b74bb8
8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents:
35667
diff
changeset
|
705 |
* </tbody> |
2 | 706 |
* </table> |
23717 | 707 |
* |
35667 | 708 |
* @param event an instance of {@code java.awt.AWTEvent}, |
2 | 709 |
* or a subclass of it |
35667 | 710 |
* @throws NullPointerException if {@code event} is {@code null} |
2 | 711 |
* @since 1.2 |
712 |
*/ |
|
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
713 |
protected void dispatchEvent(final AWTEvent event) { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
714 |
final Object src = event.getSource(); |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
715 |
final PrivilegedAction<Void> action = new PrivilegedAction<Void>() { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
716 |
public Void run() { |
20142
43a46d7366ab
8024839: [Unified Swing/Fx threading] don't schedule an event dispatching from the event dispatch thread
ant
parents:
18275
diff
changeset
|
717 |
// In case fwDispatcher is installed and we're already on the |
43a46d7366ab
8024839: [Unified Swing/Fx threading] don't schedule an event dispatching from the event dispatch thread
ant
parents:
18275
diff
changeset
|
718 |
// dispatch thread (e.g. performing DefaultKeyboardFocusManager.sendMessage), |
43a46d7366ab
8024839: [Unified Swing/Fx threading] don't schedule an event dispatching from the event dispatch thread
ant
parents:
18275
diff
changeset
|
719 |
// dispatch the event straight away. |
43a46d7366ab
8024839: [Unified Swing/Fx threading] don't schedule an event dispatching from the event dispatch thread
ant
parents:
18275
diff
changeset
|
720 |
if (fwDispatcher == null || isDispatchThreadImpl()) { |
17899 | 721 |
dispatchEventImpl(event, src); |
722 |
} else { |
|
723 |
fwDispatcher.scheduleDispatch(new Runnable() { |
|
724 |
@Override |
|
725 |
public void run() { |
|
47192
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
726 |
if (dispatchThread.filterAndCheckEvent(event)) { |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
727 |
dispatchEventImpl(event, src); |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
728 |
} |
17899 | 729 |
} |
730 |
}); |
|
731 |
} |
|
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
732 |
return null; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
733 |
} |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
734 |
}; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
735 |
|
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
736 |
final AccessControlContext stack = AccessController.getContext(); |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
737 |
final AccessControlContext srcAcc = getAccessControlContextFrom(src); |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
738 |
final AccessControlContext eventAcc = event.getAccessControlContext(); |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
739 |
if (srcAcc == null) { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
740 |
javaSecurityAccess.doIntersectionPrivilege(action, stack, eventAcc); |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
741 |
} else { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
742 |
javaSecurityAccess.doIntersectionPrivilege( |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
743 |
new PrivilegedAction<Void>() { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
744 |
public Void run() { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
745 |
javaSecurityAccess.doIntersectionPrivilege(action, eventAcc); |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
746 |
return null; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
747 |
} |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
748 |
}, stack, srcAcc); |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
749 |
} |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
750 |
} |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
751 |
|
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
752 |
private static AccessControlContext getAccessControlContextFrom(Object src) { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
753 |
return src instanceof Component ? |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
754 |
((Component)src).getAccessControlContext() : |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
755 |
src instanceof MenuComponent ? |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
756 |
((MenuComponent)src).getAccessControlContext() : |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
757 |
src instanceof TrayIcon ? |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
758 |
((TrayIcon)src).getAccessControlContext() : |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
759 |
null; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
760 |
} |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
761 |
|
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
762 |
/** |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
763 |
* Called from dispatchEvent() under a correct AccessControlContext |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
764 |
*/ |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7668
diff
changeset
|
765 |
private void dispatchEventImpl(final AWTEvent event, final Object src) { |
2 | 766 |
event.isPosted = true; |
767 |
if (event instanceof ActiveEvent) { |
|
768 |
// This could become the sole method of dispatching in time. |
|
769 |
setCurrentEventAndMostRecentTimeImpl(event); |
|
770 |
((ActiveEvent)event).dispatch(); |
|
771 |
} else if (src instanceof Component) { |
|
772 |
((Component)src).dispatchEvent(event); |
|
773 |
event.dispatched(); |
|
774 |
} else if (src instanceof MenuComponent) { |
|
775 |
((MenuComponent)src).dispatchEvent(event); |
|
776 |
} else if (src instanceof TrayIcon) { |
|
777 |
((TrayIcon)src).dispatchEvent(event); |
|
778 |
} else if (src instanceof AWTAutoShutdown) { |
|
779 |
if (noEvents()) { |
|
780 |
dispatchThread.stopDispatching(); |
|
781 |
} |
|
782 |
} else { |
|
28994
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
783 |
if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) { |
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
784 |
getEventLog().fine("Unable to dispatch event: " + event); |
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
785 |
} |
2 | 786 |
} |
787 |
} |
|
788 |
||
789 |
/** |
|
790 |
* Returns the timestamp of the most recent event that had a timestamp, and |
|
35667 | 791 |
* that was dispatched from the {@code EventQueue} associated with the |
2 | 792 |
* calling thread. If an event with a timestamp is currently being |
793 |
* dispatched, its timestamp will be returned. If no events have yet |
|
794 |
* been dispatched, the EventQueue's initialization time will be |
|
795 |
* returned instead.In the current version of |
|
35667 | 796 |
* the JDK, only {@code InputEvent}s, |
797 |
* {@code ActionEvent}s, and {@code InvocationEvent}s have |
|
2 | 798 |
* timestamps; however, future versions of the JDK may add timestamps to |
799 |
* additional event types. Note that this method should only be invoked |
|
800 |
* from an application's {@link #isDispatchThread event dispatching thread}. |
|
801 |
* If this method is |
|
802 |
* invoked from another thread, the current system time (as reported by |
|
35667 | 803 |
* {@code System.currentTimeMillis()}) will be returned instead. |
2 | 804 |
* |
35667 | 805 |
* @return the timestamp of the last {@code InputEvent}, |
806 |
* {@code ActionEvent}, or {@code InvocationEvent} to be |
|
807 |
* dispatched, or {@code System.currentTimeMillis()} if this |
|
2 | 808 |
* method is invoked on a thread other than an event dispatching |
809 |
* thread |
|
810 |
* @see java.awt.event.InputEvent#getWhen |
|
811 |
* @see java.awt.event.ActionEvent#getWhen |
|
812 |
* @see java.awt.event.InvocationEvent#getWhen |
|
813 |
* @see #isDispatchThread |
|
814 |
* |
|
815 |
* @since 1.4 |
|
816 |
*/ |
|
817 |
public static long getMostRecentEventTime() { |
|
818 |
return Toolkit.getEventQueue().getMostRecentEventTimeImpl(); |
|
819 |
} |
|
4365 | 820 |
private long getMostRecentEventTimeImpl() { |
821 |
pushPopLock.lock(); |
|
822 |
try { |
|
823 |
return (Thread.currentThread() == dispatchThread) |
|
824 |
? mostRecentEventTime |
|
825 |
: System.currentTimeMillis(); |
|
826 |
} finally { |
|
827 |
pushPopLock.unlock(); |
|
828 |
} |
|
2 | 829 |
} |
830 |
||
831 |
/** |
|
832 |
* @return most recent event time on all threads. |
|
833 |
*/ |
|
4365 | 834 |
long getMostRecentEventTimeEx() { |
835 |
pushPopLock.lock(); |
|
836 |
try { |
|
837 |
return mostRecentEventTime; |
|
838 |
} finally { |
|
839 |
pushPopLock.unlock(); |
|
840 |
} |
|
2 | 841 |
} |
842 |
||
843 |
/** |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
26749
diff
changeset
|
844 |
* Returns the event currently being dispatched by the |
35667 | 845 |
* {@code EventQueue} associated with the calling thread. This is |
2 | 846 |
* useful if a method needs access to the event, but was not designed to |
847 |
* receive a reference to it as an argument. Note that this method should |
|
848 |
* only be invoked from an application's event dispatching thread. If this |
|
849 |
* method is invoked from another thread, null will be returned. |
|
850 |
* |
|
851 |
* @return the event currently being dispatched, or null if this method is |
|
852 |
* invoked on a thread other than an event dispatching thread |
|
853 |
* @since 1.4 |
|
854 |
*/ |
|
855 |
public static AWTEvent getCurrentEvent() { |
|
856 |
return Toolkit.getEventQueue().getCurrentEventImpl(); |
|
857 |
} |
|
4365 | 858 |
private AWTEvent getCurrentEventImpl() { |
859 |
pushPopLock.lock(); |
|
860 |
try { |
|
47829
51010df5ecb1
8190456: sanity/client/SwingSet/src/ComboBoxDemoTest.java failed with NPE from java.awt.EventQueue.getCurrentEventImpl()
akolarkunnu
parents:
47498
diff
changeset
|
861 |
if (Thread.currentThread() == dispatchThread |
51010df5ecb1
8190456: sanity/client/SwingSet/src/ComboBoxDemoTest.java failed with NPE from java.awt.EventQueue.getCurrentEventImpl()
akolarkunnu
parents:
47498
diff
changeset
|
862 |
|| fxAppThreadIsDispatchThread) { |
47229
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
863 |
return (currentEvent != null) |
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
864 |
? currentEvent.get() |
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
865 |
: null; |
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
866 |
} |
47829
51010df5ecb1
8190456: sanity/client/SwingSet/src/ComboBoxDemoTest.java failed with NPE from java.awt.EventQueue.getCurrentEventImpl()
akolarkunnu
parents:
47498
diff
changeset
|
867 |
return null; |
4365 | 868 |
} finally { |
869 |
pushPopLock.unlock(); |
|
870 |
} |
|
2 | 871 |
} |
872 |
||
873 |
/** |
|
35667 | 874 |
* Replaces the existing {@code EventQueue} with the specified one. |
875 |
* Any pending events are transferred to the new {@code EventQueue} |
|
2 | 876 |
* for processing by it. |
877 |
* |
|
35667 | 878 |
* @param newEventQueue an {@code EventQueue} |
2 | 879 |
* (or subclass thereof) instance to be use |
880 |
* @see java.awt.EventQueue#pop |
|
35667 | 881 |
* @throws NullPointerException if {@code newEventQueue} is {@code null} |
2 | 882 |
* @since 1.2 |
883 |
*/ |
|
4365 | 884 |
public void push(EventQueue newEventQueue) { |
28994
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
885 |
if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) { |
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
886 |
getEventLog().fine("EventQueue.push(" + newEventQueue + ")"); |
2 | 887 |
} |
888 |
||
4365 | 889 |
pushPopLock.lock(); |
890 |
try { |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
891 |
EventQueue topQueue = this; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
892 |
while (topQueue.nextQueue != null) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
893 |
topQueue = topQueue.nextQueue; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
894 |
} |
17899 | 895 |
if (topQueue.fwDispatcher != null) { |
896 |
throw new RuntimeException("push() to queue with fwDispatcher"); |
|
897 |
} |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
898 |
if ((topQueue.dispatchThread != null) && |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
899 |
(topQueue.dispatchThread.getEventQueue() == this)) |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
900 |
{ |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
901 |
newEventQueue.dispatchThread = topQueue.dispatchThread; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
902 |
topQueue.dispatchThread.setEventQueue(newEventQueue); |
4365 | 903 |
} |
2 | 904 |
|
905 |
// Transfer all events forward to new EventQueue. |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
906 |
while (topQueue.peekEvent() != null) { |
2 | 907 |
try { |
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
908 |
// Use getNextEventPrivate() as it doesn't call flushPendingEvents() |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
909 |
newEventQueue.postEventPrivate(topQueue.getNextEventPrivate()); |
2 | 910 |
} catch (InterruptedException ie) { |
28994
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
911 |
if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) { |
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
912 |
getEventLog().fine("Interrupted push", ie); |
2 | 913 |
} |
914 |
} |
|
915 |
} |
|
916 |
||
32675
1b2f76f1053d
8081485: EDT auto shutdown is broken in case of new event queue usage
anashaty
parents:
28994
diff
changeset
|
917 |
if (topQueue.dispatchThread != null) { |
1b2f76f1053d
8081485: EDT auto shutdown is broken in case of new event queue usage
anashaty
parents:
28994
diff
changeset
|
918 |
// Wake up EDT waiting in getNextEvent(), so it can |
1b2f76f1053d
8081485: EDT auto shutdown is broken in case of new event queue usage
anashaty
parents:
28994
diff
changeset
|
919 |
// pick up a new EventQueue. Post the waking event before |
1b2f76f1053d
8081485: EDT auto shutdown is broken in case of new event queue usage
anashaty
parents:
28994
diff
changeset
|
920 |
// topQueue.nextQueue is assigned, otherwise the event would |
1b2f76f1053d
8081485: EDT auto shutdown is broken in case of new event queue usage
anashaty
parents:
28994
diff
changeset
|
921 |
// go newEventQueue |
1b2f76f1053d
8081485: EDT auto shutdown is broken in case of new event queue usage
anashaty
parents:
28994
diff
changeset
|
922 |
topQueue.postEventPrivate(new InvocationEvent(topQueue, dummyRunnable)); |
1b2f76f1053d
8081485: EDT auto shutdown is broken in case of new event queue usage
anashaty
parents:
28994
diff
changeset
|
923 |
} |
2 | 924 |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
925 |
newEventQueue.previousQueue = topQueue; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
926 |
topQueue.nextQueue = newEventQueue; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
927 |
|
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
928 |
if (appContext.get(AppContext.EVENT_QUEUE_KEY) == topQueue) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
929 |
appContext.put(AppContext.EVENT_QUEUE_KEY, newEventQueue); |
4365 | 930 |
} |
2 | 931 |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
932 |
pushPopCond.signalAll(); |
4365 | 933 |
} finally { |
934 |
pushPopLock.unlock(); |
|
2 | 935 |
} |
936 |
} |
|
937 |
||
938 |
/** |
|
35667 | 939 |
* Stops dispatching events using this {@code EventQueue}. |
2 | 940 |
* Any pending events are transferred to the previous |
35667 | 941 |
* {@code EventQueue} for processing. |
2 | 942 |
* <p> |
943 |
* Warning: To avoid deadlock, do not declare this method |
|
944 |
* synchronized in a subclass. |
|
945 |
* |
|
946 |
* @exception EmptyStackException if no previous push was made |
|
35667 | 947 |
* on this {@code EventQueue} |
2 | 948 |
* @see java.awt.EventQueue#push |
949 |
* @since 1.2 |
|
950 |
*/ |
|
951 |
protected void pop() throws EmptyStackException { |
|
28994
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
952 |
if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) { |
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
953 |
getEventLog().fine("EventQueue.pop(" + this + ")"); |
2 | 954 |
} |
955 |
||
4365 | 956 |
pushPopLock.lock(); |
957 |
try { |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
958 |
EventQueue topQueue = this; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
959 |
while (topQueue.nextQueue != null) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
960 |
topQueue = topQueue.nextQueue; |
2 | 961 |
} |
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
962 |
EventQueue prevQueue = topQueue.previousQueue; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
963 |
if (prevQueue == null) { |
2 | 964 |
throw new EmptyStackException(); |
965 |
} |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
966 |
|
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
967 |
topQueue.previousQueue = null; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
968 |
prevQueue.nextQueue = null; |
2 | 969 |
|
970 |
// Transfer all events back to previous EventQueue. |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
971 |
while (topQueue.peekEvent() != null) { |
2 | 972 |
try { |
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
973 |
prevQueue.postEventPrivate(topQueue.getNextEventPrivate()); |
2 | 974 |
} catch (InterruptedException ie) { |
28994
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
975 |
if (getEventLog().isLoggable(PlatformLogger.Level.FINE)) { |
9c28c226d526
8065709: Deadlock in awt/logging apparently introduced by 8019623
mcherkas
parents:
28059
diff
changeset
|
976 |
getEventLog().fine("Interrupted pop", ie); |
2 | 977 |
} |
978 |
} |
|
979 |
} |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
980 |
|
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
981 |
if ((topQueue.dispatchThread != null) && |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
982 |
(topQueue.dispatchThread.getEventQueue() == this)) |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
983 |
{ |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
984 |
prevQueue.dispatchThread = topQueue.dispatchThread; |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
985 |
topQueue.dispatchThread.setEventQueue(prevQueue); |
2 | 986 |
} |
987 |
||
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
988 |
if (appContext.get(AppContext.EVENT_QUEUE_KEY) == this) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
989 |
appContext.put(AppContext.EVENT_QUEUE_KEY, prevQueue); |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
990 |
} |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
991 |
|
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
992 |
// Wake up EDT waiting in getNextEvent(), so it can |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
993 |
// pick up a new EventQueue |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
994 |
topQueue.postEventPrivate(new InvocationEvent(topQueue, dummyRunnable)); |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
995 |
|
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
996 |
pushPopCond.signalAll(); |
4365 | 997 |
} finally { |
998 |
pushPopLock.unlock(); |
|
2 | 999 |
} |
1000 |
} |
|
1001 |
||
1002 |
/** |
|
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1003 |
* Creates a new {@code secondary loop} associated with this |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1004 |
* event queue. Use the {@link SecondaryLoop#enter} and |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1005 |
* {@link SecondaryLoop#exit} methods to start and stop the |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1006 |
* event loop and dispatch the events from this queue. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1007 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1008 |
* @return secondaryLoop A new secondary loop object, which can |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1009 |
* be used to launch a new nested event |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1010 |
* loop and dispatch events from this queue |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1011 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1012 |
* @see SecondaryLoop#enter |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1013 |
* @see SecondaryLoop#exit |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1014 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1015 |
* @since 1.7 |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1016 |
*/ |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1017 |
public SecondaryLoop createSecondaryLoop() { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1018 |
return createSecondaryLoop(null, null, 0); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1019 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1020 |
|
47192
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1021 |
private class FwSecondaryLoopWrapper implements SecondaryLoop { |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1022 |
final private SecondaryLoop loop; |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1023 |
final private EventFilter filter; |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1024 |
|
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1025 |
public FwSecondaryLoopWrapper(SecondaryLoop loop, EventFilter filter) { |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1026 |
this.loop = loop; |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1027 |
this.filter = filter; |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1028 |
} |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1029 |
|
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1030 |
@Override |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1031 |
public boolean enter() { |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1032 |
if (filter != null) { |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1033 |
dispatchThread.addEventFilter(filter); |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1034 |
} |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1035 |
return loop.enter(); |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1036 |
} |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1037 |
|
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1038 |
@Override |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1039 |
public boolean exit() { |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1040 |
if (filter != null) { |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1041 |
dispatchThread.removeEventFilter(filter); |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1042 |
} |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1043 |
return loop.exit(); |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1044 |
} |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1045 |
} |
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1046 |
|
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1047 |
SecondaryLoop createSecondaryLoop(Conditional cond, EventFilter filter, long interval) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1048 |
pushPopLock.lock(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1049 |
try { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1050 |
if (nextQueue != null) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1051 |
// Forward the request to the top of EventQueue stack |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1052 |
return nextQueue.createSecondaryLoop(cond, filter, interval); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1053 |
} |
17899 | 1054 |
if (fwDispatcher != null) { |
47192
d46b91465a81
8181786: Extra runLater causes impossible states to be possible using javafx.embed.singleThread=true
azvegint
parents:
47183
diff
changeset
|
1055 |
return new FwSecondaryLoopWrapper(fwDispatcher.createSecondaryLoop(), filter); |
17899 | 1056 |
} |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1057 |
if (dispatchThread == null) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1058 |
initDispatchThread(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1059 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1060 |
return new WaitDispatchSupport(dispatchThread, cond, filter, interval); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1061 |
} finally { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1062 |
pushPopLock.unlock(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1063 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1064 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1065 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
5942
diff
changeset
|
1066 |
/** |
2 | 1067 |
* Returns true if the calling thread is |
1068 |
* {@link Toolkit#getSystemEventQueue the current AWT EventQueue}'s |
|
1069 |
* dispatch thread. Use this method to ensure that a particular |
|
1070 |
* task is being executed (or not being) there. |
|
1071 |
* <p> |
|
1072 |
* Note: use the {@link #invokeLater} or {@link #invokeAndWait} |
|
1073 |
* methods to execute a task in |
|
1074 |
* {@link Toolkit#getSystemEventQueue the current AWT EventQueue}'s |
|
1075 |
* dispatch thread. |
|
1076 |
* |
|
1077 |
* @return true if running in |
|
1078 |
* {@link Toolkit#getSystemEventQueue the current AWT EventQueue}'s |
|
1079 |
* dispatch thread |
|
1080 |
* @see #invokeLater |
|
1081 |
* @see #invokeAndWait |
|
1082 |
* @see Toolkit#getSystemEventQueue |
|
1083 |
* @since 1.2 |
|
1084 |
*/ |
|
1085 |
public static boolean isDispatchThread() { |
|
1086 |
EventQueue eq = Toolkit.getEventQueue(); |
|
4365 | 1087 |
return eq.isDispatchThreadImpl(); |
1088 |
} |
|
1089 |
||
1090 |
final boolean isDispatchThreadImpl() { |
|
1091 |
EventQueue eq = this; |
|
1092 |
pushPopLock.lock(); |
|
1093 |
try { |
|
1094 |
EventQueue next = eq.nextQueue; |
|
1095 |
while (next != null) { |
|
1096 |
eq = next; |
|
1097 |
next = eq.nextQueue; |
|
1098 |
} |
|
17899 | 1099 |
if (eq.fwDispatcher != null) { |
1100 |
return eq.fwDispatcher.isDispatchThread(); |
|
1101 |
} |
|
4365 | 1102 |
return (Thread.currentThread() == eq.dispatchThread); |
1103 |
} finally { |
|
1104 |
pushPopLock.unlock(); |
|
2 | 1105 |
} |
1106 |
} |
|
1107 |
||
1108 |
final void initDispatchThread() { |
|
4365 | 1109 |
pushPopLock.lock(); |
1110 |
try { |
|
3969
6e77be3973ea
6878284: Sometimes test/javax/swing/system/6799345/TestShutdown.java "hangs"
dcherepanov
parents:
3084
diff
changeset
|
1111 |
if (dispatchThread == null && !threadGroup.isDestroyed() && !appContext.isDisposed()) { |
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
1112 |
dispatchThread = AccessController.doPrivileged( |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
1113 |
new PrivilegedAction<EventDispatchThread>() { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
1114 |
public EventDispatchThread run() { |
2 | 1115 |
EventDispatchThread t = |
1116 |
new EventDispatchThread(threadGroup, |
|
1117 |
name, |
|
1118 |
EventQueue.this); |
|
1119 |
t.setContextClassLoader(classLoader); |
|
1120 |
t.setPriority(Thread.NORM_PRIORITY + 1); |
|
1121 |
t.setDaemon(false); |
|
23900
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23717
diff
changeset
|
1122 |
AWTAutoShutdown.getInstance().notifyThreadBusy(t); |
2 | 1123 |
return t; |
1124 |
} |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
1125 |
} |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
1126 |
); |
2 | 1127 |
dispatchThread.start(); |
1128 |
} |
|
4365 | 1129 |
} finally { |
1130 |
pushPopLock.unlock(); |
|
2 | 1131 |
} |
1132 |
} |
|
1133 |
||
21263 | 1134 |
final void detachDispatchThread(EventDispatchThread edt) { |
4365 | 1135 |
/* |
13775
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
1136 |
* Minimize discard possibility for non-posted events |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
1137 |
*/ |
18231
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16126
diff
changeset
|
1138 |
SunToolkit.flushPendingEvents(appContext); |
13775
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
1139 |
/* |
4365 | 1140 |
* This synchronized block is to secure that the event dispatch |
1141 |
* thread won't die in the middle of posting a new event to the |
|
1142 |
* associated event queue. It is important because we notify |
|
1143 |
* that the event dispatch thread is busy after posting a new event |
|
1144 |
* to its queue, so the EventQueue.dispatchThread reference must |
|
1145 |
* be valid at that point. |
|
1146 |
*/ |
|
1147 |
pushPopLock.lock(); |
|
1148 |
try { |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
1149 |
if (edt == dispatchThread) { |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
1150 |
dispatchThread = null; |
4365 | 1151 |
} |
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
1152 |
AWTAutoShutdown.getInstance().notifyThreadFree(edt); |
23293
94f894482549
8031694: [macosx] TwentyThousandTest test intermittently hangs
bagiras
parents:
21957
diff
changeset
|
1153 |
/* |
94f894482549
8031694: [macosx] TwentyThousandTest test intermittently hangs
bagiras
parents:
21957
diff
changeset
|
1154 |
* Event was posted after EDT events pumping had stopped, so start |
94f894482549
8031694: [macosx] TwentyThousandTest test intermittently hangs
bagiras
parents:
21957
diff
changeset
|
1155 |
* another EDT to handle this event |
94f894482549
8031694: [macosx] TwentyThousandTest test intermittently hangs
bagiras
parents:
21957
diff
changeset
|
1156 |
*/ |
94f894482549
8031694: [macosx] TwentyThousandTest test intermittently hangs
bagiras
parents:
21957
diff
changeset
|
1157 |
if (peekEvent() != null) { |
94f894482549
8031694: [macosx] TwentyThousandTest test intermittently hangs
bagiras
parents:
21957
diff
changeset
|
1158 |
initDispatchThread(); |
94f894482549
8031694: [macosx] TwentyThousandTest test intermittently hangs
bagiras
parents:
21957
diff
changeset
|
1159 |
} |
4365 | 1160 |
} finally { |
1161 |
pushPopLock.unlock(); |
|
1162 |
} |
|
2 | 1163 |
} |
1164 |
||
1165 |
/* |
|
35667 | 1166 |
* Gets the {@code EventDispatchThread} for this |
1167 |
* {@code EventQueue}. |
|
2 | 1168 |
* @return the event dispatch thread associated with this event queue |
35667 | 1169 |
* or {@code null} if this event queue doesn't have a |
2 | 1170 |
* working thread associated with it |
1171 |
* @see java.awt.EventQueue#initDispatchThread |
|
1172 |
* @see java.awt.EventQueue#detachDispatchThread |
|
1173 |
*/ |
|
1174 |
final EventDispatchThread getDispatchThread() { |
|
4365 | 1175 |
pushPopLock.lock(); |
1176 |
try { |
|
1177 |
return dispatchThread; |
|
1178 |
} finally { |
|
1179 |
pushPopLock.unlock(); |
|
1180 |
} |
|
2 | 1181 |
} |
1182 |
||
1183 |
/* |
|
1184 |
* Removes any pending events for the specified source object. |
|
35667 | 1185 |
* If removeAllEvents parameter is {@code true} then all |
2 | 1186 |
* events for the specified source object are removed, if it |
35667 | 1187 |
* is {@code false} then {@code SequencedEvent}, {@code SentEvent}, |
1188 |
* {@code FocusEvent}, {@code WindowEvent}, {@code KeyEvent}, |
|
1189 |
* and {@code InputMethodEvent} are kept in the queue, but all other |
|
2 | 1190 |
* events are removed. |
1191 |
* |
|
1192 |
* This method is normally called by the source's |
|
35667 | 1193 |
* {@code removeNotify} method. |
2 | 1194 |
*/ |
1195 |
final void removeSourceEvents(Object source, boolean removeAllEvents) { |
|
18231
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16126
diff
changeset
|
1196 |
SunToolkit.flushPendingEvents(appContext); |
4365 | 1197 |
pushPopLock.lock(); |
1198 |
try { |
|
2 | 1199 |
for (int i = 0; i < NUM_PRIORITIES; i++) { |
1200 |
EventQueueItem entry = queues[i].head; |
|
1201 |
EventQueueItem prev = null; |
|
1202 |
while (entry != null) { |
|
1203 |
if ((entry.event.getSource() == source) |
|
1204 |
&& (removeAllEvents |
|
1205 |
|| ! (entry.event instanceof SequencedEvent |
|
1206 |
|| entry.event instanceof SentEvent |
|
1207 |
|| entry.event instanceof FocusEvent |
|
1208 |
|| entry.event instanceof WindowEvent |
|
1209 |
|| entry.event instanceof KeyEvent |
|
1210 |
|| entry.event instanceof InputMethodEvent))) |
|
1211 |
{ |
|
1212 |
if (entry.event instanceof SequencedEvent) { |
|
1213 |
((SequencedEvent)entry.event).dispose(); |
|
1214 |
} |
|
1215 |
if (entry.event instanceof SentEvent) { |
|
1216 |
((SentEvent)entry.event).dispose(); |
|
1217 |
} |
|
21246 | 1218 |
if (entry.event instanceof InvocationEvent) { |
1219 |
AWTAccessor.getInvocationEventAccessor() |
|
1220 |
.dispose((InvocationEvent)entry.event); |
|
1221 |
} |
|
47183
03c1b9f44ba2
8186263: The SunDropTargetEvent sometimes is not dispatched
serb
parents:
45648
diff
changeset
|
1222 |
if (entry.event instanceof SunDropTargetEvent) { |
03c1b9f44ba2
8186263: The SunDropTargetEvent sometimes is not dispatched
serb
parents:
45648
diff
changeset
|
1223 |
((SunDropTargetEvent)entry.event).dispose(); |
03c1b9f44ba2
8186263: The SunDropTargetEvent sometimes is not dispatched
serb
parents:
45648
diff
changeset
|
1224 |
} |
2 | 1225 |
if (prev == null) { |
1226 |
queues[i].head = entry.next; |
|
1227 |
} else { |
|
1228 |
prev.next = entry.next; |
|
1229 |
} |
|
1230 |
uncacheEQItem(entry); |
|
1231 |
} else { |
|
1232 |
prev = entry; |
|
1233 |
} |
|
1234 |
entry = entry.next; |
|
1235 |
} |
|
1236 |
queues[i].tail = prev; |
|
1237 |
} |
|
4365 | 1238 |
} finally { |
1239 |
pushPopLock.unlock(); |
|
2 | 1240 |
} |
1241 |
} |
|
1242 |
||
13652
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
1243 |
synchronized long getMostRecentKeyEventTime() { |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
1244 |
pushPopLock.lock(); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
1245 |
try { |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
1246 |
return mostRecentKeyEventTime; |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
1247 |
} finally { |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
1248 |
pushPopLock.unlock(); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
1249 |
} |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
1250 |
} |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
1251 |
|
2 | 1252 |
static void setCurrentEventAndMostRecentTime(AWTEvent e) { |
1253 |
Toolkit.getEventQueue().setCurrentEventAndMostRecentTimeImpl(e); |
|
1254 |
} |
|
4365 | 1255 |
private void setCurrentEventAndMostRecentTimeImpl(AWTEvent e) { |
1256 |
pushPopLock.lock(); |
|
1257 |
try { |
|
47229
7d4896d180e7
8156042: Modifiers of swing ActionEvent does not work when "-Djavafx.embed.singleThread=true"
psadhukhan
parents:
47216
diff
changeset
|
1258 |
if (!fxAppThreadIsDispatchThread && Thread.currentThread() != dispatchThread) { |
4365 | 1259 |
return; |
1260 |
} |
|
2 | 1261 |
|
15994
5c8a3d840366
8007295: Reduce number of warnings in awt classes
mcherkas
parents:
13775
diff
changeset
|
1262 |
currentEvent = new WeakReference<>(e); |
2 | 1263 |
|
4365 | 1264 |
// This series of 'instanceof' checks should be replaced with a |
1265 |
// polymorphic type (for example, an interface which declares a |
|
1266 |
// getWhen() method). However, this would require us to make such |
|
1267 |
// a type public, or to place it in sun.awt. Both of these approaches |
|
1268 |
// have been frowned upon. So for now, we hack. |
|
1269 |
// |
|
1270 |
// In tiger, we will probably give timestamps to all events, so this |
|
1271 |
// will no longer be an issue. |
|
1272 |
long mostRecentEventTime2 = Long.MIN_VALUE; |
|
1273 |
if (e instanceof InputEvent) { |
|
1274 |
InputEvent ie = (InputEvent)e; |
|
1275 |
mostRecentEventTime2 = ie.getWhen(); |
|
13652
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
1276 |
if (e instanceof KeyEvent) { |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
1277 |
mostRecentKeyEventTime = ie.getWhen(); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13541
diff
changeset
|
1278 |
} |
4365 | 1279 |
} else if (e instanceof InputMethodEvent) { |
1280 |
InputMethodEvent ime = (InputMethodEvent)e; |
|
1281 |
mostRecentEventTime2 = ime.getWhen(); |
|
1282 |
} else if (e instanceof ActionEvent) { |
|
1283 |
ActionEvent ae = (ActionEvent)e; |
|
1284 |
mostRecentEventTime2 = ae.getWhen(); |
|
1285 |
} else if (e instanceof InvocationEvent) { |
|
1286 |
InvocationEvent ie = (InvocationEvent)e; |
|
1287 |
mostRecentEventTime2 = ie.getWhen(); |
|
1288 |
} |
|
1289 |
mostRecentEventTime = Math.max(mostRecentEventTime, mostRecentEventTime2); |
|
1290 |
} finally { |
|
1291 |
pushPopLock.unlock(); |
|
2 | 1292 |
} |
1293 |
} |
|
1294 |
||
1295 |
/** |
|
35667 | 1296 |
* Causes {@code runnable} to have its {@code run} |
2 | 1297 |
* method called in the {@link #isDispatchThread dispatch thread} of |
1298 |
* {@link Toolkit#getSystemEventQueue the system EventQueue}. |
|
1299 |
* This will happen after all pending events are processed. |
|
1300 |
* |
|
35667 | 1301 |
* @param runnable the {@code Runnable} whose {@code run} |
2 | 1302 |
* method should be executed |
1303 |
* asynchronously in the |
|
1304 |
* {@link #isDispatchThread event dispatch thread} |
|
1305 |
* of {@link Toolkit#getSystemEventQueue the system EventQueue} |
|
1306 |
* @see #invokeAndWait |
|
1307 |
* @see Toolkit#getSystemEventQueue |
|
1308 |
* @see #isDispatchThread |
|
1309 |
* @since 1.2 |
|
1310 |
*/ |
|
1311 |
public static void invokeLater(Runnable runnable) { |
|
1312 |
Toolkit.getEventQueue().postEvent( |
|
1313 |
new InvocationEvent(Toolkit.getDefaultToolkit(), runnable)); |
|
1314 |
} |
|
1315 |
||
1316 |
/** |
|
35667 | 1317 |
* Causes {@code runnable} to have its {@code run} |
2 | 1318 |
* method called in the {@link #isDispatchThread dispatch thread} of |
1319 |
* {@link Toolkit#getSystemEventQueue the system EventQueue}. |
|
1320 |
* This will happen after all pending events are processed. |
|
1321 |
* The call blocks until this has happened. This method |
|
1322 |
* will throw an Error if called from the |
|
1323 |
* {@link #isDispatchThread event dispatcher thread}. |
|
1324 |
* |
|
35667 | 1325 |
* @param runnable the {@code Runnable} whose {@code run} |
2 | 1326 |
* method should be executed |
1327 |
* synchronously in the |
|
1328 |
* {@link #isDispatchThread event dispatch thread} |
|
1329 |
* of {@link Toolkit#getSystemEventQueue the system EventQueue} |
|
1330 |
* @exception InterruptedException if any thread has |
|
1331 |
* interrupted this thread |
|
1332 |
* @exception InvocationTargetException if an throwable is thrown |
|
35667 | 1333 |
* when running {@code runnable} |
2 | 1334 |
* @see #invokeLater |
1335 |
* @see Toolkit#getSystemEventQueue |
|
1336 |
* @see #isDispatchThread |
|
1337 |
* @since 1.2 |
|
1338 |
*/ |
|
1339 |
public static void invokeAndWait(Runnable runnable) |
|
16092 | 1340 |
throws InterruptedException, InvocationTargetException |
1341 |
{ |
|
1342 |
invokeAndWait(Toolkit.getDefaultToolkit(), runnable); |
|
1343 |
} |
|
2 | 1344 |
|
16092 | 1345 |
static void invokeAndWait(Object source, Runnable runnable) |
1346 |
throws InterruptedException, InvocationTargetException |
|
1347 |
{ |
|
2 | 1348 |
if (EventQueue.isDispatchThread()) { |
1349 |
throw new Error("Cannot call invokeAndWait from the event dispatcher thread"); |
|
1350 |
} |
|
1351 |
||
1352 |
class AWTInvocationLock {} |
|
1353 |
Object lock = new AWTInvocationLock(); |
|
1354 |
||
1355 |
InvocationEvent event = |
|
16092 | 1356 |
new InvocationEvent(source, runnable, lock, true); |
2 | 1357 |
|
1358 |
synchronized (lock) { |
|
1359 |
Toolkit.getEventQueue().postEvent(event); |
|
4264
40c232605c68
6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents:
3972
diff
changeset
|
1360 |
while (!event.isDispatched()) { |
40c232605c68
6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents:
3972
diff
changeset
|
1361 |
lock.wait(); |
40c232605c68
6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents:
3972
diff
changeset
|
1362 |
} |
2 | 1363 |
} |
1364 |
||
1365 |
Throwable eventThrowable = event.getThrowable(); |
|
1366 |
if (eventThrowable != null) { |
|
1367 |
throw new InvocationTargetException(eventThrowable); |
|
1368 |
} |
|
1369 |
} |
|
1370 |
||
1371 |
/* |
|
1372 |
* Called from PostEventQueue.postEvent to notify that a new event |
|
1373 |
* appeared. First it proceeds to the EventQueue on the top of the |
|
1374 |
* stack, then notifies the associated dispatch thread if it exists |
|
1375 |
* or starts a new one otherwise. |
|
1376 |
*/ |
|
1377 |
private void wakeup(boolean isShutdown) { |
|
4365 | 1378 |
pushPopLock.lock(); |
1379 |
try { |
|
2 | 1380 |
if (nextQueue != null) { |
1381 |
// Forward call to the top of EventQueue stack. |
|
1382 |
nextQueue.wakeup(isShutdown); |
|
1383 |
} else if (dispatchThread != null) { |
|
4365 | 1384 |
pushPopCond.signalAll(); |
2 | 1385 |
} else if (!isShutdown) { |
1386 |
initDispatchThread(); |
|
1387 |
} |
|
4365 | 1388 |
} finally { |
1389 |
pushPopLock.unlock(); |
|
2 | 1390 |
} |
1391 |
} |
|
17899 | 1392 |
|
1393 |
// The method is used by AWTAccessor for javafx/AWT single threaded mode. |
|
1394 |
private void setFwDispatcher(FwDispatcher dispatcher) { |
|
1395 |
if (nextQueue != null) { |
|
1396 |
nextQueue.setFwDispatcher(dispatcher); |
|
1397 |
} else { |
|
1398 |
fwDispatcher = dispatcher; |
|
1399 |
} |
|
1400 |
} |
|
2 | 1401 |
} |
1402 |
||
1403 |
/** |
|
1404 |
* The Queue object holds pointers to the beginning and end of one internal |
|
1405 |
* queue. An EventQueue object is composed of multiple internal Queues, one |
|
1406 |
* for each priority supported by the EventQueue. All Events on a particular |
|
1407 |
* internal Queue have identical priority. |
|
1408 |
*/ |
|
1409 |
class Queue { |
|
1410 |
EventQueueItem head; |
|
1411 |
EventQueueItem tail; |
|
1412 |
} |