author | henryjen |
Tue, 10 Jun 2014 16:18:54 -0700 | |
changeset 24865 | 09b1d992ca72 |
parent 23010 | 6dadb192ad81 |
permissions | -rw-r--r-- |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21957
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
4 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
10 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
15 |
* accompanied this code). |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
16 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
20 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
23 |
* questions. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
24 |
*/ |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
25 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
26 |
package java.awt; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
27 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
28 |
import java.util.Timer; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
29 |
import java.util.TimerTask; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
30 |
import java.util.concurrent.atomic.AtomicBoolean; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
31 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
32 |
import java.security.PrivilegedAction; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
33 |
import java.security.AccessController; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
34 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
35 |
import sun.awt.PeerEvent; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
36 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
37 |
import sun.util.logging.PlatformLogger; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
38 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
39 |
/** |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
40 |
* This utility class is used to suspend execution on a thread |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
41 |
* while still allowing {@code EventDispatchThread} to dispatch events. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
42 |
* The API methods of the class are thread-safe. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
43 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
44 |
* @author Anton Tarasov, Artem Ananiev |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
45 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
46 |
* @since 1.7 |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
47 |
*/ |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
48 |
class WaitDispatchSupport implements SecondaryLoop { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
49 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
50 |
private final static PlatformLogger log = |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
51 |
PlatformLogger.getLogger("java.awt.event.WaitDispatchSupport"); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
52 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
53 |
private EventDispatchThread dispatchThread; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
54 |
private EventFilter filter; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
55 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
56 |
private volatile Conditional extCondition; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
57 |
private volatile Conditional condition; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
58 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
59 |
private long interval; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
60 |
// Use a shared daemon timer to serve all the WaitDispatchSupports |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
61 |
private static Timer timer; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
62 |
// When this WDS expires, we cancel the timer task leaving the |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
63 |
// shared timer up and running |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
64 |
private TimerTask timerTask; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
65 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
66 |
private AtomicBoolean keepBlockingEDT = new AtomicBoolean(false); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
67 |
private AtomicBoolean keepBlockingCT = new AtomicBoolean(false); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
68 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
69 |
private static synchronized void initializeTimer() { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
70 |
if (timer == null) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
71 |
timer = new Timer("AWT-WaitDispatchSupport-Timer", true); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
72 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
73 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
74 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
75 |
/** |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
76 |
* Creates a {@code WaitDispatchSupport} instance to |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
77 |
* serve the given event dispatch thread. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
78 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
79 |
* @param dispatchThread An event dispatch thread that |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
80 |
* should not stop dispatching events while waiting |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
81 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
82 |
* @since 1.7 |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
83 |
*/ |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
84 |
public WaitDispatchSupport(EventDispatchThread dispatchThread) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
85 |
this(dispatchThread, null); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
86 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
87 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
88 |
/** |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
89 |
* Creates a {@code WaitDispatchSupport} instance to |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
90 |
* serve the given event dispatch thread. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
91 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
92 |
* @param dispatchThread An event dispatch thread that |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
93 |
* should not stop dispatching events while waiting |
21957 | 94 |
* @param extCond A conditional object used to determine |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
95 |
* if the loop should be terminated |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
96 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
97 |
* @since 1.7 |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
98 |
*/ |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
99 |
public WaitDispatchSupport(EventDispatchThread dispatchThread, |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
100 |
Conditional extCond) |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
101 |
{ |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
102 |
if (dispatchThread == null) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
103 |
throw new IllegalArgumentException("The dispatchThread can not be null"); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
104 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
105 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
106 |
this.dispatchThread = dispatchThread; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
107 |
this.extCondition = extCond; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
108 |
this.condition = new Conditional() { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
109 |
@Override |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
110 |
public boolean evaluate() { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
111 |
if (log.isLoggable(PlatformLogger.Level.FINEST)) { |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
112 |
log.finest("evaluate(): blockingEDT=" + keepBlockingEDT.get() + |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
113 |
", blockingCT=" + keepBlockingCT.get()); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
114 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
115 |
boolean extEvaluate = |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
116 |
(extCondition != null) ? extCondition.evaluate() : true; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
117 |
if (!keepBlockingEDT.get() || !extEvaluate) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
118 |
if (timerTask != null) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
119 |
timerTask.cancel(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
120 |
timerTask = null; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
121 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
122 |
return false; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
123 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
124 |
return true; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
125 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
126 |
}; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
127 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
128 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
129 |
/** |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
130 |
* Creates a {@code WaitDispatchSupport} instance to |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
131 |
* serve the given event dispatch thread. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
132 |
* <p> |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
133 |
* The {@link EventFilter} is set on the {@code dispatchThread} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
134 |
* while waiting. The filter is removed on completion of the |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
135 |
* waiting process. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
136 |
* <p> |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
137 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
138 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
139 |
* @param dispatchThread An event dispatch thread that |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
140 |
* should not stop dispatching events while waiting |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
141 |
* @param filter {@code EventFilter} to be set |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
142 |
* @param interval A time interval to wait for. Note that |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
143 |
* when the waiting process takes place on EDT |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
144 |
* there is no guarantee to stop it in the given time |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
145 |
* |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
146 |
* @since 1.7 |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
147 |
*/ |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
148 |
public WaitDispatchSupport(EventDispatchThread dispatchThread, |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
149 |
Conditional extCondition, |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
150 |
EventFilter filter, long interval) |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
151 |
{ |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
152 |
this(dispatchThread, extCondition); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
153 |
this.filter = filter; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
154 |
if (interval < 0) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
155 |
throw new IllegalArgumentException("The interval value must be >= 0"); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
156 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
157 |
this.interval = interval; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
158 |
if (interval != 0) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
159 |
initializeTimer(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
160 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
161 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
162 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
163 |
/** |
21957 | 164 |
* {@inheritDoc} |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
165 |
*/ |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
166 |
@Override |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
167 |
public boolean enter() { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
168 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
169 |
log.fine("enter(): blockingEDT=" + keepBlockingEDT.get() + |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
170 |
", blockingCT=" + keepBlockingCT.get()); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
171 |
} |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
172 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
173 |
if (!keepBlockingEDT.compareAndSet(false, true)) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
174 |
log.fine("The secondary loop is already running, aborting"); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
175 |
return false; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
176 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
177 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
178 |
final Runnable run = new Runnable() { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
179 |
public void run() { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
180 |
log.fine("Starting a new event pump"); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
181 |
if (filter == null) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
182 |
dispatchThread.pumpEvents(condition); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
183 |
} else { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
184 |
dispatchThread.pumpEventsForFilter(condition, filter); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
185 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
186 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
187 |
}; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
188 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
189 |
// We have two mechanisms for blocking: if we're on the |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
190 |
// dispatch thread, start a new event pump; if we're |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
191 |
// on any other thread, call wait() on the treelock |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
192 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
193 |
Thread currentThread = Thread.currentThread(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
194 |
if (currentThread == dispatchThread) { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
195 |
if (log.isLoggable(PlatformLogger.Level.FINEST)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
196 |
log.finest("On dispatch thread: " + dispatchThread); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
197 |
} |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
198 |
if (interval != 0) { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
199 |
if (log.isLoggable(PlatformLogger.Level.FINEST)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
200 |
log.finest("scheduling the timer for " + interval + " ms"); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
201 |
} |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
202 |
timer.schedule(timerTask = new TimerTask() { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
203 |
@Override |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
204 |
public void run() { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
205 |
if (keepBlockingEDT.compareAndSet(true, false)) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
206 |
wakeupEDT(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
207 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
208 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
209 |
}, interval); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
210 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
211 |
// Dispose SequencedEvent we are dispatching on the the current |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
212 |
// AppContext, to prevent us from hang - see 4531693 for details |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
213 |
SequencedEvent currentSE = KeyboardFocusManager. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
214 |
getCurrentKeyboardFocusManager().getCurrentSequencedEvent(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
215 |
if (currentSE != null) { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
216 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
217 |
log.fine("Dispose current SequencedEvent: " + currentSE); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
218 |
} |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
219 |
currentSE.dispose(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
220 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
221 |
// In case the exit() method is called before starting |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
222 |
// new event pump it will post the waking event to EDT. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
223 |
// The event will be handled after the the new event pump |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
224 |
// starts. Thus, the enter() method will not hang. |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
225 |
// |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
226 |
// Event pump should be privileged. See 6300270. |
20107
18e644411f0b
8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents:
18178
diff
changeset
|
227 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
18e644411f0b
8022184: Fix static , Raw warnings in classes belonging to java.awt
art
parents:
18178
diff
changeset
|
228 |
public Void run() { |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
229 |
run.run(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
230 |
return null; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
231 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
232 |
}); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
233 |
} else { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
234 |
if (log.isLoggable(PlatformLogger.Level.FINEST)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
235 |
log.finest("On non-dispatch thread: " + currentThread); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
236 |
} |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
237 |
synchronized (getTreeLock()) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
238 |
if (filter != null) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
239 |
dispatchThread.addEventFilter(filter); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
240 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
241 |
try { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
242 |
EventQueue eq = dispatchThread.getEventQueue(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
243 |
eq.postEvent(new PeerEvent(this, run, PeerEvent.PRIORITY_EVENT)); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
244 |
keepBlockingCT.set(true); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
245 |
if (interval > 0) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
246 |
long currTime = System.currentTimeMillis(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
247 |
while (keepBlockingCT.get() && |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
248 |
((extCondition != null) ? extCondition.evaluate() : true) && |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
249 |
(currTime + interval > System.currentTimeMillis())) |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
250 |
{ |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
251 |
getTreeLock().wait(interval); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
252 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
253 |
} else { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
254 |
while (keepBlockingCT.get() && |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
255 |
((extCondition != null) ? extCondition.evaluate() : true)) |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
256 |
{ |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
257 |
getTreeLock().wait(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
258 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
259 |
} |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
260 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
261 |
log.fine("waitDone " + keepBlockingEDT.get() + " " + keepBlockingCT.get()); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
262 |
} |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
263 |
} catch (InterruptedException e) { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
264 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
265 |
log.fine("Exception caught while waiting: " + e); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
266 |
} |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
267 |
} finally { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
268 |
if (filter != null) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
269 |
dispatchThread.removeEventFilter(filter); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
270 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
271 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
272 |
// If the waiting process has been stopped because of the |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
273 |
// time interval passed or an exception occurred, the state |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
274 |
// should be changed |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
275 |
keepBlockingEDT.set(false); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
276 |
keepBlockingCT.set(false); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
277 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
278 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
279 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
280 |
return true; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
281 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
282 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
283 |
/** |
21957 | 284 |
* {@inheritDoc} |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
285 |
*/ |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
286 |
public boolean exit() { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
287 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
288 |
log.fine("exit(): blockingEDT=" + keepBlockingEDT.get() + |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
289 |
", blockingCT=" + keepBlockingCT.get()); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
290 |
} |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
291 |
if (keepBlockingEDT.compareAndSet(true, false)) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
292 |
wakeupEDT(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
293 |
return true; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
294 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
295 |
return false; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
296 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
297 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
298 |
private final static Object getTreeLock() { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
299 |
return Component.LOCK; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
300 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
301 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
302 |
private final Runnable wakingRunnable = new Runnable() { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
303 |
public void run() { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
304 |
log.fine("Wake up EDT"); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
305 |
synchronized (getTreeLock()) { |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
306 |
keepBlockingCT.set(false); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
307 |
getTreeLock().notifyAll(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
308 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
309 |
log.fine("Wake up EDT done"); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
310 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
311 |
}; |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
312 |
|
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
313 |
private void wakeupEDT() { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
314 |
if (log.isLoggable(PlatformLogger.Level.FINEST)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
315 |
log.finest("wakeupEDT(): EDT == " + dispatchThread); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
6484
diff
changeset
|
316 |
} |
6484
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
317 |
EventQueue eq = dispatchThread.getEventQueue(); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
318 |
eq.postEvent(new PeerEvent(this, wakingRunnable, PeerEvent.PRIORITY_EVENT)); |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
319 |
} |
f5dbd940a640
6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents:
diff
changeset
|
320 |
} |