author | alanb |
Mon, 05 Oct 2009 16:45:55 +0100 | |
changeset 3956 | 2586d23078e4 |
parent 3084 | 67ca55732362 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
2
diff
changeset
|
2 |
* Copyright 1995-2008 Sun Microsystems, Inc. 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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
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 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
package java.awt; |
|
26 |
||
27 |
import java.awt.peer.DialogPeer; |
|
28 |
import java.awt.event.*; |
|
29 |
import java.io.ObjectInputStream; |
|
30 |
import java.io.IOException; |
|
31 |
import java.util.Iterator; |
|
32 |
import java.util.concurrent.atomic.AtomicLong; |
|
33 |
import java.security.AccessController; |
|
34 |
import java.security.PrivilegedAction; |
|
35 |
import javax.accessibility.*; |
|
36 |
import sun.awt.AppContext; |
|
37 |
import sun.awt.SunToolkit; |
|
38 |
import sun.awt.PeerEvent; |
|
39 |
import sun.awt.util.IdentityArrayList; |
|
40 |
import sun.awt.util.IdentityLinkedList; |
|
41 |
import sun.security.util.SecurityConstants; |
|
42 |
||
43 |
/** |
|
44 |
* A Dialog is a top-level window with a title and a border |
|
45 |
* that is typically used to take some form of input from the user. |
|
46 |
* |
|
47 |
* The size of the dialog includes any area designated for the |
|
48 |
* border. The dimensions of the border area can be obtained |
|
49 |
* using the <code>getInsets</code> method, however, since |
|
50 |
* these dimensions are platform-dependent, a valid insets |
|
51 |
* value cannot be obtained until the dialog is made displayable |
|
52 |
* by either calling <code>pack</code> or <code>show</code>. |
|
53 |
* Since the border area is included in the overall size of the |
|
54 |
* dialog, the border effectively obscures a portion of the dialog, |
|
55 |
* constraining the area available for rendering and/or displaying |
|
56 |
* subcomponents to the rectangle which has an upper-left corner |
|
57 |
* location of <code>(insets.left, insets.top)</code>, and has a size of |
|
58 |
* <code>width - (insets.left + insets.right)</code> by |
|
59 |
* <code>height - (insets.top + insets.bottom)</code>. |
|
60 |
* <p> |
|
61 |
* The default layout for a dialog is <code>BorderLayout</code>. |
|
62 |
* <p> |
|
63 |
* A dialog may have its native decorations (i.e. Frame & Titlebar) turned off |
|
64 |
* with <code>setUndecorated</code>. This can only be done while the dialog |
|
65 |
* is not {@link Component#isDisplayable() displayable}. |
|
66 |
* <p> |
|
67 |
* A dialog may have another window as its owner when it's constructed. When |
|
68 |
* the owner window of a visible dialog is minimized, the dialog will |
|
69 |
* automatically be hidden from the user. When the owner window is subsequently |
|
70 |
* restored, the dialog is made visible to the user again. |
|
71 |
* <p> |
|
72 |
* In a multi-screen environment, you can create a <code>Dialog</code> |
|
73 |
* on a different screen device than its owner. See {@link java.awt.Frame} for |
|
74 |
* more information. |
|
75 |
* <p> |
|
76 |
* A dialog can be either modeless (the default) or modal. A modal |
|
77 |
* dialog is one which blocks input to some other top-level windows |
|
78 |
* in the application, except for any windows created with the dialog |
|
79 |
* as their owner. See <a href="doc-files/Modality.html">AWT Modality</a> |
|
80 |
* specification for details. |
|
81 |
* <p> |
|
82 |
* Dialogs are capable of generating the following |
|
83 |
* <code>WindowEvents</code>: |
|
84 |
* <code>WindowOpened</code>, <code>WindowClosing</code>, |
|
85 |
* <code>WindowClosed</code>, <code>WindowActivated</code>, |
|
86 |
* <code>WindowDeactivated</code>, <code>WindowGainedFocus</code>, |
|
87 |
* <code>WindowLostFocus</code>. |
|
88 |
* |
|
89 |
* @see WindowEvent |
|
90 |
* @see Window#addWindowListener |
|
91 |
* |
|
92 |
* @author Sami Shaio |
|
93 |
* @author Arthur van Hoff |
|
94 |
* @since JDK1.0 |
|
95 |
*/ |
|
96 |
public class Dialog extends Window { |
|
97 |
||
98 |
static { |
|
99 |
/* ensure that the necessary native libraries are loaded */ |
|
100 |
Toolkit.loadLibraries(); |
|
101 |
if (!GraphicsEnvironment.isHeadless()) { |
|
102 |
initIDs(); |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
/** |
|
107 |
* A dialog's resizable property. Will be true |
|
108 |
* if the Dialog is to be resizable, otherwise |
|
109 |
* it will be false. |
|
110 |
* |
|
111 |
* @serial |
|
112 |
* @see #setResizable(boolean) |
|
113 |
*/ |
|
114 |
boolean resizable = true; |
|
115 |
||
116 |
||
117 |
/** |
|
118 |
* This field indicates whether the dialog is undecorated. |
|
119 |
* This property can only be changed while the dialog is not displayable. |
|
120 |
* <code>undecorated</code> will be true if the dialog is |
|
121 |
* undecorated, otherwise it will be false. |
|
122 |
* |
|
123 |
* @serial |
|
124 |
* @see #setUndecorated(boolean) |
|
125 |
* @see #isUndecorated() |
|
126 |
* @see Component#isDisplayable() |
|
127 |
* @since 1.4 |
|
128 |
*/ |
|
129 |
boolean undecorated = false; |
|
130 |
||
131 |
/** |
|
132 |
* Modal dialogs block all input to some top-level windows. |
|
133 |
* Whether a particular window is blocked depends on dialog's type |
|
134 |
* of modality; this is called the "scope of blocking". The |
|
135 |
* <code>ModalityType</code> enum specifies modal types and their |
|
136 |
* associated scopes. |
|
137 |
* |
|
138 |
* @see Dialog#getModalityType |
|
139 |
* @see Dialog#setModalityType |
|
140 |
* @see Toolkit#isModalityTypeSupported |
|
141 |
* |
|
142 |
* @since 1.6 |
|
143 |
*/ |
|
144 |
public static enum ModalityType { |
|
145 |
/** |
|
146 |
* <code>MODELESS</code> dialog doesn't block any top-level windows. |
|
147 |
*/ |
|
148 |
MODELESS, |
|
149 |
/** |
|
150 |
* A <code>DOCUMENT_MODAL</code> dialog blocks input to all top-level windows |
|
151 |
* from the same document except those from its own child hierarchy. |
|
152 |
* A document is a top-level window without an owner. It may contain child |
|
153 |
* windows that, together with the top-level window are treated as a single |
|
154 |
* solid document. Since every top-level window must belong to some |
|
155 |
* document, its root can be found as the top-nearest window without an owner. |
|
156 |
*/ |
|
157 |
DOCUMENT_MODAL, |
|
158 |
/** |
|
159 |
* An <code>APPLICATION_MODAL</code> dialog blocks all top-level windows |
|
160 |
* from the same Java application except those from its own child hierarchy. |
|
161 |
* If there are several applets launched in a browser, they can be |
|
162 |
* treated either as separate applications or a single one. This behavior |
|
163 |
* is implementation-dependent. |
|
164 |
*/ |
|
165 |
APPLICATION_MODAL, |
|
166 |
/** |
|
167 |
* A <code>TOOLKIT_MODAL</code> dialog blocks all top-level windows run |
|
168 |
* from the same toolkit except those from its own child hierarchy. If there |
|
169 |
* are several applets launched in a browser, all of them run with the same |
|
170 |
* toolkit; thus, a toolkit-modal dialog displayed by an applet may affect |
|
171 |
* other applets and all windows of the browser instance which embeds the |
|
172 |
* Java runtime environment for this toolkit. |
|
173 |
* Special <code>AWTPermission</code> "toolkitModality" must be granted to use |
|
174 |
* toolkit-modal dialogs. If a <code>TOOLKIT_MODAL</code> dialog is being created |
|
175 |
* and this permission is not granted, a <code>SecurityException</code> will be |
|
176 |
* thrown, and no dialog will be created. If a modality type is being changed |
|
177 |
* to <code>TOOLKIT_MODAL</code> and this permission is not granted, a |
|
178 |
* <code>SecurityException</code> will be thrown, and the modality type will |
|
179 |
* be left unchanged. |
|
180 |
*/ |
|
181 |
TOOLKIT_MODAL |
|
182 |
}; |
|
183 |
||
184 |
/** |
|
185 |
* Default modality type for modal dialogs. The default modality type is |
|
186 |
* <code>APPLICATION_MODAL</code>. Calling the oldstyle <code>setModal(true)</code> |
|
187 |
* is equal to <code>setModalityType(DEFAULT_MODALITY_TYPE)</code>. |
|
188 |
* |
|
189 |
* @see java.awt.Dialog.ModalityType |
|
190 |
* @see java.awt.Dialog#setModal |
|
191 |
* |
|
192 |
* @since 1.6 |
|
193 |
*/ |
|
194 |
public final static ModalityType DEFAULT_MODALITY_TYPE = ModalityType.APPLICATION_MODAL; |
|
195 |
||
196 |
/** |
|
197 |
* True if this dialog is modal, false is the dialog is modeless. |
|
198 |
* A modal dialog blocks user input to some application top-level |
|
199 |
* windows. This field is kept only for backwards compatibility. Use the |
|
200 |
* {@link Dialog.ModalityType ModalityType} enum instead. |
|
201 |
* |
|
202 |
* @serial |
|
203 |
* |
|
204 |
* @see #isModal |
|
205 |
* @see #setModal |
|
206 |
* @see #getModalityType |
|
207 |
* @see #setModalityType |
|
208 |
* @see ModalityType |
|
209 |
* @see ModalityType#MODELESS |
|
210 |
* @see #DEFAULT_MODALITY_TYPE |
|
211 |
*/ |
|
212 |
boolean modal; |
|
213 |
||
214 |
/** |
|
215 |
* Modality type of this dialog. If the dialog's modality type is not |
|
216 |
* {@link Dialog.ModalityType#MODELESS ModalityType.MODELESS}, it blocks all |
|
217 |
* user input to some application top-level windows. |
|
218 |
* |
|
219 |
* @serial |
|
220 |
* |
|
221 |
* @see ModalityType |
|
222 |
* @see #getModalityType |
|
223 |
* @see #setModalityType |
|
224 |
* |
|
225 |
* @since 1.6 |
|
226 |
*/ |
|
227 |
ModalityType modalityType; |
|
228 |
||
229 |
/** |
|
230 |
* Any top-level window can be marked not to be blocked by modal |
|
231 |
* dialogs. This is called "modal exclusion". This enum specifies |
|
232 |
* the possible modal exclusion types. |
|
233 |
* |
|
234 |
* @see Window#getModalExclusionType |
|
235 |
* @see Window#setModalExclusionType |
|
236 |
* @see Toolkit#isModalExclusionTypeSupported |
|
237 |
* |
|
238 |
* @since 1.6 |
|
239 |
*/ |
|
240 |
public static enum ModalExclusionType { |
|
241 |
/** |
|
242 |
* No modal exclusion. |
|
243 |
*/ |
|
244 |
NO_EXCLUDE, |
|
245 |
/** |
|
246 |
* <code>APPLICATION_EXCLUDE</code> indicates that a top-level window |
|
247 |
* won't be blocked by any application-modal dialogs. Also, it isn't |
|
248 |
* blocked by document-modal dialogs from outside of its child hierarchy. |
|
249 |
*/ |
|
250 |
APPLICATION_EXCLUDE, |
|
251 |
/** |
|
252 |
* <code>TOOLKIT_EXCLUDE</code> indicates that a top-level window |
|
253 |
* won't be blocked by application-modal or toolkit-modal dialogs. Also, |
|
254 |
* it isn't blocked by document-modal dialogs from outside of its |
|
255 |
* child hierarchy. |
|
256 |
* The "toolkitModality" <code>AWTPermission</code> must be granted |
|
257 |
* for this exclusion. If an exclusion property is being changed to |
|
258 |
* <code>TOOLKIT_EXCLUDE</code> and this permission is not granted, a |
|
259 |
* <code>SecurityEcxeption</code> will be thrown, and the exclusion |
|
260 |
* property will be left unchanged. |
|
261 |
*/ |
|
262 |
TOOLKIT_EXCLUDE |
|
263 |
}; |
|
264 |
||
265 |
/* operations with this list should be synchronized on tree lock*/ |
|
266 |
transient static IdentityArrayList<Dialog> modalDialogs = new IdentityArrayList<Dialog>(); |
|
267 |
||
268 |
transient IdentityArrayList<Window> blockedWindows = new IdentityArrayList<Window>(); |
|
269 |
||
270 |
/** |
|
271 |
* Specifies the title of the Dialog. |
|
272 |
* This field can be null. |
|
273 |
* |
|
274 |
* @serial |
|
275 |
* @see #getTitle() |
|
276 |
* @see #setTitle(String) |
|
277 |
*/ |
|
278 |
String title; |
|
279 |
||
280 |
private transient volatile boolean keepBlockingEDT = false; |
|
281 |
private transient volatile boolean keepBlockingCT = false; |
|
282 |
||
283 |
private transient ModalEventFilter modalFilter; |
|
284 |
||
285 |
/* |
|
286 |
* Indicates that this dialog is being hidden. This flag is set to true at |
|
287 |
* the beginning of hide() and to false at the end of hide(). |
|
288 |
* |
|
289 |
* @see #hide() |
|
290 |
* @see #hideAndDisposePreHandler() |
|
291 |
* @see #hideAndDisposeHandler() |
|
292 |
* @see #shouldBlock() |
|
293 |
*/ |
|
294 |
transient volatile boolean isInHide = false; |
|
295 |
||
296 |
/* |
|
297 |
* Indicates that this dialog is being disposed. This flag is set to true at |
|
298 |
* the beginning of doDispose() and to false at the end of doDispose(). |
|
299 |
* |
|
300 |
* @see #hide() |
|
301 |
* @see #hideAndDisposePreHandler() |
|
302 |
* @see #hideAndDisposeHandler() |
|
303 |
* @see #doDispose() |
|
304 |
*/ |
|
305 |
transient volatile boolean isInDispose = false; |
|
306 |
||
307 |
private static final String base = "dialog"; |
|
308 |
private static int nameCounter = 0; |
|
309 |
||
310 |
/* |
|
311 |
* JDK 1.1 serialVersionUID |
|
312 |
*/ |
|
313 |
private static final long serialVersionUID = 5920926903803293709L; |
|
314 |
||
315 |
/** |
|
316 |
* Constructs an initially invisible, modeless <code>Dialog</code> with |
|
317 |
* the specified owner <code>Frame</code> and an empty title. |
|
318 |
* |
|
319 |
* @param owner the owner of the dialog or <code>null</code> if |
|
320 |
* this dialog has no owner |
|
321 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s |
|
322 |
* <code>GraphicsConfiguration</code> is not from a screen device |
|
323 |
* @exception HeadlessException when |
|
324 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
325 |
* |
|
326 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
327 |
* @see Component#setSize |
|
328 |
* @see Component#setVisible |
|
329 |
*/ |
|
330 |
public Dialog(Frame owner) { |
|
331 |
this(owner, "", false); |
|
332 |
} |
|
333 |
||
334 |
/** |
|
335 |
* Constructs an initially invisible <code>Dialog</code> with the specified |
|
336 |
* owner <code>Frame</code> and modality and an empty title. |
|
337 |
* |
|
338 |
* @param owner the owner of the dialog or <code>null</code> if |
|
339 |
* this dialog has no owner |
|
340 |
* @param modal specifes whether dialog blocks user input to other top-level |
|
341 |
* windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>; |
|
342 |
* if <code>true</code>, the modality type property is set to |
|
343 |
* <code>DEFAULT_MODALITY_TYPE</code> |
|
344 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s |
|
345 |
* <code>GraphicsConfiguration</code> is not from a screen device |
|
346 |
* @exception HeadlessException when |
|
347 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
348 |
* |
|
349 |
* @see java.awt.Dialog.ModalityType |
|
350 |
* @see java.awt.Dialog.ModalityType#MODELESS |
|
351 |
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE |
|
352 |
* @see java.awt.Dialog#setModal |
|
353 |
* @see java.awt.Dialog#setModalityType |
|
354 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
355 |
*/ |
|
356 |
public Dialog(Frame owner, boolean modal) { |
|
357 |
this(owner, "", modal); |
|
358 |
} |
|
359 |
||
360 |
/** |
|
361 |
* Constructs an initially invisible, modeless <code>Dialog</code> with |
|
362 |
* the specified owner <code>Frame</code> and title. |
|
363 |
* |
|
364 |
* @param owner the owner of the dialog or <code>null</code> if |
|
365 |
* this dialog has no owner |
|
366 |
* @param title the title of the dialog or <code>null</code> if this dialog |
|
367 |
* has no title |
|
368 |
* @exception IllegalArgumentException if the <code>owner</code>'s |
|
369 |
* <code>GraphicsConfiguration</code> is not from a screen device |
|
370 |
* @exception HeadlessException when |
|
371 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
372 |
* |
|
373 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
374 |
* @see Component#setSize |
|
375 |
* @see Component#setVisible |
|
376 |
*/ |
|
377 |
public Dialog(Frame owner, String title) { |
|
378 |
this(owner, title, false); |
|
379 |
} |
|
380 |
||
381 |
/** |
|
382 |
* Constructs an initially invisible <code>Dialog</code> with the |
|
383 |
* specified owner <code>Frame</code>, title and modality. |
|
384 |
* |
|
385 |
* @param owner the owner of the dialog or <code>null</code> if |
|
386 |
* this dialog has no owner |
|
387 |
* @param title the title of the dialog or <code>null</code> if this dialog |
|
388 |
* has no title |
|
389 |
* @param modal specifes whether dialog blocks user input to other top-level |
|
390 |
* windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>; |
|
391 |
* if <code>true</code>, the modality type property is set to |
|
392 |
* <code>DEFAULT_MODALITY_TYPE</code> |
|
393 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s |
|
394 |
* <code>GraphicsConfiguration</code> is not from a screen device |
|
395 |
* @exception HeadlessException when |
|
396 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
397 |
* |
|
398 |
* @see java.awt.Dialog.ModalityType |
|
399 |
* @see java.awt.Dialog.ModalityType#MODELESS |
|
400 |
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE |
|
401 |
* @see java.awt.Dialog#setModal |
|
402 |
* @see java.awt.Dialog#setModalityType |
|
403 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
404 |
* @see Component#setSize |
|
405 |
* @see Component#setVisible |
|
406 |
*/ |
|
407 |
public Dialog(Frame owner, String title, boolean modal) { |
|
408 |
this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS); |
|
409 |
} |
|
410 |
||
411 |
/** |
|
412 |
* Constructs an initially invisible <code>Dialog</code> with the specified owner |
|
413 |
* <code>Frame</code>, title, modality, and <code>GraphicsConfiguration</code>. |
|
414 |
* @param owner the owner of the dialog or <code>null</code> if this dialog |
|
415 |
* has no owner |
|
416 |
* @param title the title of the dialog or <code>null</code> if this dialog |
|
417 |
* has no title |
|
418 |
* @param modal specifes whether dialog blocks user input to other top-level |
|
419 |
* windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>; |
|
420 |
* if <code>true</code>, the modality type property is set to |
|
421 |
* <code>DEFAULT_MODALITY_TYPE</code> |
|
422 |
* @param gc the <code>GraphicsConfiguration</code> of the target screen device; |
|
423 |
* if <code>null</code>, the default system <code>GraphicsConfiguration</code> |
|
424 |
* is assumed |
|
425 |
* @exception java.lang.IllegalArgumentException if <code>gc</code> |
|
426 |
* is not from a screen device |
|
427 |
* @exception HeadlessException when |
|
428 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
429 |
* |
|
430 |
* @see java.awt.Dialog.ModalityType |
|
431 |
* @see java.awt.Dialog.ModalityType#MODELESS |
|
432 |
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE |
|
433 |
* @see java.awt.Dialog#setModal |
|
434 |
* @see java.awt.Dialog#setModalityType |
|
435 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
436 |
* @see Component#setSize |
|
437 |
* @see Component#setVisible |
|
438 |
* @since 1.4 |
|
439 |
*/ |
|
440 |
public Dialog(Frame owner, String title, boolean modal, |
|
441 |
GraphicsConfiguration gc) { |
|
442 |
this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc); |
|
443 |
} |
|
444 |
||
445 |
/** |
|
446 |
* Constructs an initially invisible, modeless <code>Dialog</code> with |
|
447 |
* the specified owner <code>Dialog</code> and an empty title. |
|
448 |
* |
|
449 |
* @param owner the owner of the dialog or <code>null</code> if this |
|
450 |
* dialog has no owner |
|
451 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s |
|
452 |
* <code>GraphicsConfiguration</code> is not from a screen device |
|
453 |
* @exception HeadlessException when |
|
454 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
455 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
456 |
* @since 1.2 |
|
457 |
*/ |
|
458 |
public Dialog(Dialog owner) { |
|
459 |
this(owner, "", false); |
|
460 |
} |
|
461 |
||
462 |
/** |
|
463 |
* Constructs an initially invisible, modeless <code>Dialog</code> |
|
464 |
* with the specified owner <code>Dialog</code> and title. |
|
465 |
* |
|
466 |
* @param owner the owner of the dialog or <code>null</code> if this |
|
467 |
* has no owner |
|
468 |
* @param title the title of the dialog or <code>null</code> if this dialog |
|
469 |
* has no title |
|
470 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s |
|
471 |
* <code>GraphicsConfiguration</code> is not from a screen device |
|
472 |
* @exception HeadlessException when |
|
473 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
474 |
* |
|
475 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
476 |
* @since 1.2 |
|
477 |
*/ |
|
478 |
public Dialog(Dialog owner, String title) { |
|
479 |
this(owner, title, false); |
|
480 |
} |
|
481 |
||
482 |
/** |
|
483 |
* Constructs an initially invisible <code>Dialog</code> with the |
|
484 |
* specified owner <code>Dialog</code>, title, and modality. |
|
485 |
* |
|
486 |
* @param owner the owner of the dialog or <code>null</code> if this |
|
487 |
* dialog has no owner |
|
488 |
* @param title the title of the dialog or <code>null</code> if this |
|
489 |
* dialog has no title |
|
490 |
* @param modal specifes whether dialog blocks user input to other top-level |
|
491 |
* windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>; |
|
492 |
* if <code>true</code>, the modality type property is set to |
|
493 |
* <code>DEFAULT_MODALITY_TYPE</code> |
|
494 |
* @exception IllegalArgumentException if the <code>owner</code>'s |
|
495 |
* <code>GraphicsConfiguration</code> is not from a screen device |
|
496 |
* @exception HeadlessException when |
|
497 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
498 |
* |
|
499 |
* @see java.awt.Dialog.ModalityType |
|
500 |
* @see java.awt.Dialog.ModalityType#MODELESS |
|
501 |
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE |
|
502 |
* @see java.awt.Dialog#setModal |
|
503 |
* @see java.awt.Dialog#setModalityType |
|
504 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
505 |
* |
|
506 |
* @since 1.2 |
|
507 |
*/ |
|
508 |
public Dialog(Dialog owner, String title, boolean modal) { |
|
509 |
this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS); |
|
510 |
} |
|
511 |
||
512 |
/** |
|
513 |
* Constructs an initially invisible <code>Dialog</code> with the |
|
514 |
* specified owner <code>Dialog</code>, title, modality and |
|
515 |
* <code>GraphicsConfiguration</code>. |
|
516 |
* |
|
517 |
* @param owner the owner of the dialog or <code>null</code> if this |
|
518 |
* dialog has no owner |
|
519 |
* @param title the title of the dialog or <code>null</code> if this |
|
520 |
* dialog has no title |
|
521 |
* @param modal specifes whether dialog blocks user input to other top-level |
|
522 |
* windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>; |
|
523 |
* if <code>true</code>, the modality type property is set to |
|
524 |
* <code>DEFAULT_MODALITY_TYPE</code> |
|
525 |
* @param gc the <code>GraphicsConfiguration</code> of the target screen device; |
|
526 |
* if <code>null</code>, the default system <code>GraphicsConfiguration</code> |
|
527 |
* is assumed |
|
528 |
* @exception java.lang.IllegalArgumentException if <code>gc</code> |
|
529 |
* is not from a screen device |
|
530 |
* @exception HeadlessException when |
|
531 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
532 |
* |
|
533 |
* @see java.awt.Dialog.ModalityType |
|
534 |
* @see java.awt.Dialog.ModalityType#MODELESS |
|
535 |
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE |
|
536 |
* @see java.awt.Dialog#setModal |
|
537 |
* @see java.awt.Dialog#setModalityType |
|
538 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
539 |
* @see Component#setSize |
|
540 |
* @see Component#setVisible |
|
541 |
* |
|
542 |
* @since 1.4 |
|
543 |
*/ |
|
544 |
public Dialog(Dialog owner, String title, boolean modal, |
|
545 |
GraphicsConfiguration gc) { |
|
546 |
this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc); |
|
547 |
} |
|
548 |
||
549 |
/** |
|
550 |
* Constructs an initially invisible, modeless <code>Dialog</code> with the |
|
551 |
* specified owner <code>Window</code> and an empty title. |
|
552 |
* |
|
553 |
* @param owner the owner of the dialog. The owner must be an instance of |
|
554 |
* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any |
|
555 |
* of their descendents or <code>null</code> |
|
556 |
* |
|
557 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code> |
|
558 |
* is not an instance of {@link java.awt.Dialog Dialog} or {@link |
|
559 |
* java.awt.Frame Frame} |
|
560 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s |
|
561 |
* <code>GraphicsConfiguration</code> is not from a screen device |
|
562 |
* @exception HeadlessException when |
|
563 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
564 |
* |
|
565 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
566 |
* |
|
567 |
* @since 1.6 |
|
568 |
*/ |
|
569 |
public Dialog(Window owner) { |
|
570 |
this(owner, null, ModalityType.MODELESS); |
|
571 |
} |
|
572 |
||
573 |
/** |
|
574 |
* Constructs an initially invisible, modeless <code>Dialog</code> with |
|
575 |
* the specified owner <code>Window</code> and title. |
|
576 |
* |
|
577 |
* @param owner the owner of the dialog. The owner must be an instance of |
|
578 |
* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any |
|
579 |
* of their descendents or <code>null</code> |
|
580 |
* @param title the title of the dialog or <code>null</code> if this dialog |
|
581 |
* has no title |
|
582 |
* |
|
583 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code> |
|
584 |
* is not an instance of {@link java.awt.Dialog Dialog} or {@link |
|
585 |
* java.awt.Frame Frame} |
|
586 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s |
|
587 |
* <code>GraphicsConfiguration</code> is not from a screen device |
|
588 |
* @exception HeadlessException when |
|
589 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
590 |
* |
|
591 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
592 |
* |
|
593 |
* @since 1.6 |
|
594 |
*/ |
|
595 |
public Dialog(Window owner, String title) { |
|
596 |
this(owner, title, ModalityType.MODELESS); |
|
597 |
} |
|
598 |
||
599 |
/** |
|
600 |
* Constructs an initially invisible <code>Dialog</code> with the |
|
601 |
* specified owner <code>Window</code> and modality and an empty title. |
|
602 |
* |
|
603 |
* @param owner the owner of the dialog. The owner must be an instance of |
|
604 |
* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any |
|
605 |
* of their descendents or <code>null</code> |
|
606 |
* @param modalityType specifies whether dialog blocks input to other |
|
607 |
* windows when shown. <code>null</code> value and unsupported modality |
|
608 |
* types are equivalent to <code>MODELESS</code> |
|
609 |
* |
|
610 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code> |
|
611 |
* is not an instance of {@link java.awt.Dialog Dialog} or {@link |
|
612 |
* java.awt.Frame Frame} |
|
613 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s |
|
614 |
* <code>GraphicsConfiguration</code> is not from a screen device |
|
615 |
* @exception HeadlessException when |
|
616 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
617 |
* @exception SecurityException if the calling thread does not have permission |
|
618 |
* to create modal dialogs with the given <code>modalityType</code> |
|
619 |
* |
|
620 |
* @see java.awt.Dialog.ModalityType |
|
621 |
* @see java.awt.Dialog#setModal |
|
622 |
* @see java.awt.Dialog#setModalityType |
|
623 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
624 |
* @see java.awt.Toolkit#isModalityTypeSupported |
|
625 |
* |
|
626 |
* @since 1.6 |
|
627 |
*/ |
|
628 |
public Dialog(Window owner, ModalityType modalityType) { |
|
629 |
this(owner, null, modalityType); |
|
630 |
} |
|
631 |
||
632 |
/** |
|
633 |
* Constructs an initially invisible <code>Dialog</code> with the |
|
634 |
* specified owner <code>Window</code>, title and modality. |
|
635 |
* |
|
636 |
* @param owner the owner of the dialog. The owner must be an instance of |
|
637 |
* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any |
|
638 |
* of their descendents or <code>null</code> |
|
639 |
* @param title the title of the dialog or <code>null</code> if this dialog |
|
640 |
* has no title |
|
641 |
* @param modalityType specifies whether dialog blocks input to other |
|
642 |
* windows when shown. <code>null</code> value and unsupported modality |
|
643 |
* types are equivalent to <code>MODELESS</code> |
|
644 |
* |
|
645 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code> |
|
646 |
* is not an instance of {@link java.awt.Dialog Dialog} or {@link |
|
647 |
* java.awt.Frame Frame} |
|
648 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s |
|
649 |
* <code>GraphicsConfiguration</code> is not from a screen device |
|
650 |
* @exception HeadlessException when |
|
651 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
652 |
* @exception SecurityException if the calling thread does not have permission |
|
653 |
* to create modal dialogs with the given <code>modalityType</code> |
|
654 |
* |
|
655 |
* @see java.awt.Dialog.ModalityType |
|
656 |
* @see java.awt.Dialog#setModal |
|
657 |
* @see java.awt.Dialog#setModalityType |
|
658 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
659 |
* @see java.awt.Toolkit#isModalityTypeSupported |
|
660 |
* |
|
661 |
* @since 1.6 |
|
662 |
*/ |
|
663 |
public Dialog(Window owner, String title, ModalityType modalityType) { |
|
664 |
super(owner); |
|
665 |
||
666 |
if ((owner != null) && |
|
667 |
!(owner instanceof Frame) && |
|
668 |
!(owner instanceof Dialog)) |
|
669 |
{ |
|
670 |
throw new IllegalArgumentException("Wrong parent window"); |
|
671 |
} |
|
672 |
||
673 |
this.title = title; |
|
674 |
setModalityType(modalityType); |
|
675 |
SunToolkit.checkAndSetPolicy(this, false); |
|
676 |
} |
|
677 |
||
678 |
/** |
|
679 |
* Constructs an initially invisible <code>Dialog</code> with the |
|
680 |
* specified owner <code>Window</code>, title, modality and |
|
681 |
* <code>GraphicsConfiguration</code>. |
|
682 |
* |
|
683 |
* @param owner the owner of the dialog. The owner must be an instance of |
|
684 |
* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any |
|
685 |
* of their descendents or <code>null</code> |
|
686 |
* @param title the title of the dialog or <code>null</code> if this dialog |
|
687 |
* has no title |
|
688 |
* @param modalityType specifies whether dialog blocks input to other |
|
689 |
* windows when shown. <code>null</code> value and unsupported modality |
|
690 |
* types are equivalent to <code>MODELESS</code> |
|
691 |
* @param gc the <code>GraphicsConfiguration</code> of the target screen device; |
|
692 |
* if <code>null</code>, the default system <code>GraphicsConfiguration</code> |
|
693 |
* is assumed |
|
694 |
* |
|
695 |
* @exception java.lang.IllegalArgumentException if the <code>owner</code> |
|
696 |
* is not an instance of {@link java.awt.Dialog Dialog} or {@link |
|
697 |
* java.awt.Frame Frame} |
|
698 |
* @exception java.lang.IllegalArgumentException if <code>gc</code> |
|
699 |
* is not from a screen device |
|
700 |
* @exception HeadlessException when |
|
701 |
* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code> |
|
702 |
* @exception SecurityException if the calling thread does not have permission |
|
703 |
* to create modal dialogs with the given <code>modalityType</code> |
|
704 |
* |
|
705 |
* @see java.awt.Dialog.ModalityType |
|
706 |
* @see java.awt.Dialog#setModal |
|
707 |
* @see java.awt.Dialog#setModalityType |
|
708 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
709 |
* @see java.awt.Toolkit#isModalityTypeSupported |
|
710 |
* |
|
711 |
* @since 1.6 |
|
712 |
*/ |
|
713 |
public Dialog(Window owner, String title, ModalityType modalityType, |
|
714 |
GraphicsConfiguration gc) { |
|
715 |
super(owner, gc); |
|
716 |
||
717 |
if ((owner != null) && |
|
718 |
!(owner instanceof Frame) && |
|
719 |
!(owner instanceof Dialog)) |
|
720 |
{ |
|
721 |
throw new IllegalArgumentException("wrong owner window"); |
|
722 |
} |
|
723 |
||
724 |
this.title = title; |
|
725 |
setModalityType(modalityType); |
|
726 |
SunToolkit.checkAndSetPolicy(this, false); |
|
727 |
} |
|
728 |
||
729 |
/** |
|
730 |
* Construct a name for this component. Called by getName() when the |
|
731 |
* name is null. |
|
732 |
*/ |
|
733 |
String constructComponentName() { |
|
734 |
synchronized (Dialog.class) { |
|
735 |
return base + nameCounter++; |
|
736 |
} |
|
737 |
} |
|
738 |
||
739 |
/** |
|
740 |
* Makes this Dialog displayable by connecting it to |
|
741 |
* a native screen resource. Making a dialog displayable will |
|
742 |
* cause any of its children to be made displayable. |
|
743 |
* This method is called internally by the toolkit and should |
|
744 |
* not be called directly by programs. |
|
745 |
* @see Component#isDisplayable |
|
746 |
* @see #removeNotify |
|
747 |
*/ |
|
748 |
public void addNotify() { |
|
749 |
synchronized (getTreeLock()) { |
|
750 |
if (parent != null && parent.getPeer() == null) { |
|
751 |
parent.addNotify(); |
|
752 |
} |
|
753 |
||
754 |
if (peer == null) { |
|
755 |
peer = getToolkit().createDialog(this); |
|
756 |
} |
|
757 |
super.addNotify(); |
|
758 |
} |
|
759 |
} |
|
760 |
||
761 |
/** |
|
762 |
* Indicates whether the dialog is modal. |
|
763 |
* <p> |
|
764 |
* This method is obsolete and is kept for backwards compatiblity only. |
|
765 |
* Use {@link #getModalityType getModalityType()} instead. |
|
766 |
* |
|
767 |
* @return <code>true</code> if this dialog window is modal; |
|
768 |
* <code>false</code> otherwise |
|
769 |
* |
|
770 |
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE |
|
771 |
* @see java.awt.Dialog.ModalityType#MODELESS |
|
772 |
* @see java.awt.Dialog#setModal |
|
773 |
* @see java.awt.Dialog#getModalityType |
|
774 |
* @see java.awt.Dialog#setModalityType |
|
775 |
*/ |
|
776 |
public boolean isModal() { |
|
777 |
return isModal_NoClientCode(); |
|
778 |
} |
|
779 |
final boolean isModal_NoClientCode() { |
|
780 |
return modalityType != ModalityType.MODELESS; |
|
781 |
} |
|
782 |
||
783 |
/** |
|
784 |
* Specifies whether this dialog should be modal. |
|
785 |
* <p> |
|
786 |
* This method is obsolete and is kept for backwards compatibility only. |
|
787 |
* Use {@link #setModalityType setModalityType()} instead. |
|
788 |
* <p> |
|
789 |
* Note: changing modality of the visible dialog may have no effect |
|
790 |
* until it is hidden and then shown again. |
|
791 |
* |
|
792 |
* @param modal specifies whether dialog blocks input to other windows |
|
793 |
* when shown; calling to <code>setModal(true)</code> is equivalent to |
|
794 |
* <code>setModalityType(Dialog.DEFAULT_MODALITY_TYPE)</code>, and |
|
795 |
* calling to <code>setModal(false)</code> is equvivalent to |
|
796 |
* <code>setModalityType(Dialog.ModalityType.MODELESS)</code> |
|
797 |
* |
|
798 |
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE |
|
799 |
* @see java.awt.Dialog.ModalityType#MODELESS |
|
800 |
* @see java.awt.Dialog#isModal |
|
801 |
* @see java.awt.Dialog#getModalityType |
|
802 |
* @see java.awt.Dialog#setModalityType |
|
803 |
* |
|
804 |
* @since 1.1 |
|
805 |
*/ |
|
806 |
public void setModal(boolean modal) { |
|
807 |
this.modal = modal; |
|
808 |
setModalityType(modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS); |
|
809 |
} |
|
810 |
||
811 |
/** |
|
812 |
* Returns the modality type of this dialog. |
|
813 |
* |
|
814 |
* @return modality type of this dialog |
|
815 |
* |
|
816 |
* @see java.awt.Dialog#setModalityType |
|
817 |
* |
|
818 |
* @since 1.6 |
|
819 |
*/ |
|
820 |
public ModalityType getModalityType() { |
|
821 |
return modalityType; |
|
822 |
} |
|
823 |
||
824 |
/** |
|
825 |
* Sets the modality type for this dialog. See {@link |
|
826 |
* java.awt.Dialog.ModalityType ModalityType} for possible modality types. |
|
827 |
* <p> |
|
828 |
* If the given modality type is not supported, <code>MODELESS</code> |
|
829 |
* is used. You may want to call <code>getModalityType()</code> after calling |
|
830 |
* this method to ensure that the modality type has been set. |
|
831 |
* <p> |
|
832 |
* Note: changing modality of the visible dialog may have no effect |
|
833 |
* until it is hidden and then shown again. |
|
834 |
* |
|
835 |
* @param type specifies whether dialog blocks input to other |
|
836 |
* windows when shown. <code>null</code> value and unsupported modality |
|
837 |
* types are equivalent to <code>MODELESS</code> |
|
838 |
* @exception SecurityException if the calling thread does not have permission |
|
839 |
* to create modal dialogs with the given <code>modalityType</code> |
|
840 |
* |
|
841 |
* @see java.awt.Dialog#getModalityType |
|
842 |
* @see java.awt.Toolkit#isModalityTypeSupported |
|
843 |
* |
|
844 |
* @since 1.6 |
|
845 |
*/ |
|
846 |
public void setModalityType(ModalityType type) { |
|
847 |
if (type == null) { |
|
848 |
type = Dialog.ModalityType.MODELESS; |
|
849 |
} |
|
850 |
if (!Toolkit.getDefaultToolkit().isModalityTypeSupported(type)) { |
|
851 |
type = Dialog.ModalityType.MODELESS; |
|
852 |
} |
|
853 |
if (modalityType == type) { |
|
854 |
return; |
|
855 |
} |
|
856 |
if (type == ModalityType.TOOLKIT_MODAL) { |
|
857 |
SecurityManager sm = System.getSecurityManager(); |
|
858 |
if (sm != null) { |
|
3956
2586d23078e4
6854954: Eliminate static dependency on java.awt.AWTPermission
alanb
parents:
3084
diff
changeset
|
859 |
sm.checkPermission(SecurityConstants.AWT.TOOLKIT_MODALITY_PERMISSION); |
2 | 860 |
} |
861 |
} |
|
862 |
modalityType = type; |
|
863 |
modal = (modalityType != ModalityType.MODELESS); |
|
864 |
} |
|
865 |
||
866 |
/** |
|
867 |
* Gets the title of the dialog. The title is displayed in the |
|
868 |
* dialog's border. |
|
869 |
* @return the title of this dialog window. The title may be |
|
870 |
* <code>null</code>. |
|
871 |
* @see java.awt.Dialog#setTitle |
|
872 |
*/ |
|
873 |
public String getTitle() { |
|
874 |
return title; |
|
875 |
} |
|
876 |
||
877 |
/** |
|
878 |
* Sets the title of the Dialog. |
|
879 |
* @param title the title displayed in the dialog's border; |
|
880 |
* a null value results in an empty title |
|
881 |
* @see #getTitle |
|
882 |
*/ |
|
883 |
public void setTitle(String title) { |
|
884 |
String oldTitle = this.title; |
|
885 |
||
886 |
synchronized(this) { |
|
887 |
this.title = title; |
|
888 |
DialogPeer peer = (DialogPeer)this.peer; |
|
889 |
if (peer != null) { |
|
890 |
peer.setTitle(title); |
|
891 |
} |
|
892 |
} |
|
893 |
firePropertyChange("title", oldTitle, title); |
|
894 |
} |
|
895 |
||
896 |
/** |
|
897 |
* @return true if we actually showed, false if we just called toFront() |
|
898 |
*/ |
|
899 |
private boolean conditionalShow(Component toFocus, AtomicLong time) { |
|
900 |
boolean retval; |
|
901 |
||
902 |
closeSplashScreen(); |
|
903 |
||
904 |
synchronized (getTreeLock()) { |
|
905 |
if (peer == null) { |
|
906 |
addNotify(); |
|
907 |
} |
|
908 |
validate(); |
|
909 |
if (visible) { |
|
910 |
toFront(); |
|
911 |
retval = false; |
|
912 |
} else { |
|
913 |
visible = retval = true; |
|
914 |
||
915 |
// check if this dialog should be modal blocked BEFORE calling peer.show(), |
|
916 |
// otherwise, a pair of FOCUS_GAINED and FOCUS_LOST may be mistakenly |
|
917 |
// generated for the dialog |
|
918 |
if (!isModal()) { |
|
919 |
checkShouldBeBlocked(this); |
|
920 |
} else { |
|
921 |
modalDialogs.add(this); |
|
922 |
modalShow(); |
|
923 |
} |
|
924 |
||
925 |
if (toFocus != null && time != null && isFocusable() && |
|
926 |
isEnabled() && !isModalBlocked()) { |
|
927 |
// keep the KeyEvents from being dispatched |
|
928 |
// until the focus has been transfered |
|
929 |
time.set(Toolkit.getEventQueue().getMostRecentEventTimeEx()); |
|
930 |
KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
931 |
enqueueKeyEvents(time.get(), toFocus); |
|
932 |
} |
|
933 |
||
934 |
// This call is required as the show() method of the Dialog class |
|
935 |
// does not invoke the super.show(). So wried... :( |
|
936 |
mixOnShowing(); |
|
937 |
||
1964 | 938 |
peer.setVisible(true); // now guaranteed never to block |
2 | 939 |
if (isModalBlocked()) { |
940 |
modalBlocker.toFront(); |
|
941 |
} |
|
942 |
||
943 |
setLocationByPlatform(false); |
|
944 |
for (int i = 0; i < ownedWindowList.size(); i++) { |
|
945 |
Window child = ownedWindowList.elementAt(i).get(); |
|
946 |
if ((child != null) && child.showWithParent) { |
|
947 |
child.show(); |
|
948 |
child.showWithParent = false; |
|
949 |
} // endif |
|
950 |
} // endfor |
|
951 |
Window.updateChildFocusableWindowState(this); |
|
952 |
||
953 |
createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, |
|
954 |
this, parent, |
|
955 |
HierarchyEvent.SHOWING_CHANGED, |
|
956 |
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)); |
|
957 |
if (componentListener != null || |
|
958 |
(eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 || |
|
959 |
Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) { |
|
960 |
ComponentEvent e = |
|
961 |
new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN); |
|
962 |
Toolkit.getEventQueue().postEvent(e); |
|
963 |
} |
|
964 |
} |
|
965 |
} |
|
966 |
||
967 |
if (retval && (state & OPENED) == 0) { |
|
968 |
postWindowEvent(WindowEvent.WINDOW_OPENED); |
|
969 |
state |= OPENED; |
|
970 |
} |
|
971 |
||
972 |
return retval; |
|
973 |
} |
|
974 |
||
975 |
/** |
|
976 |
* Shows or hides this {@code Dialog} depending on the value of parameter |
|
977 |
* {@code b}. |
|
978 |
* @param b if {@code true}, makes the {@code Dialog} visible, |
|
979 |
* otherwise hides the {@code Dialog}. |
|
980 |
* If the dialog and/or its owner |
|
981 |
* are not yet displayable, both are made displayable. The |
|
982 |
* dialog will be validated prior to being made visible. |
|
983 |
* If {@code false}, hides the {@code Dialog} and then causes {@code setVisible(true)} |
|
984 |
* to return if it is currently blocked. |
|
985 |
* <p> |
|
986 |
* <b>Notes for modal dialogs</b>. |
|
987 |
* <ul> |
|
988 |
* <li>{@code setVisible(true)}: If the dialog is not already |
|
989 |
* visible, this call will not return until the dialog is |
|
990 |
* hidden by calling {@code setVisible(false)} or |
|
991 |
* {@code dispose}. |
|
992 |
* <li>{@code setVisible(false)}: Hides the dialog and then |
|
993 |
* returns on {@code setVisible(true)} if it is currently blocked. |
|
994 |
* <li>It is OK to call this method from the event dispatching |
|
995 |
* thread because the toolkit ensures that other events are |
|
996 |
* not blocked while this method is blocked. |
|
997 |
* </ul> |
|
998 |
* @see java.awt.Window#setVisible |
|
999 |
* @see java.awt.Window#dispose |
|
1000 |
* @see java.awt.Component#isDisplayable |
|
1001 |
* @see java.awt.Component#validate |
|
1002 |
* @see java.awt.Dialog#isModal |
|
1003 |
*/ |
|
1004 |
public void setVisible(boolean b) { |
|
1005 |
super.setVisible(b); |
|
1006 |
} |
|
1007 |
||
1008 |
/** |
|
1009 |
* Stores the app context on which event dispatch thread the dialog |
|
1010 |
* is being shown. Initialized in show(), used in hideAndDisposeHandler() |
|
1011 |
*/ |
|
1012 |
transient private AppContext showAppContext; |
|
1013 |
||
1014 |
/** |
|
1015 |
* Makes the {@code Dialog} visible. If the dialog and/or its owner |
|
1016 |
* are not yet displayable, both are made displayable. The |
|
1017 |
* dialog will be validated prior to being made visible. |
|
1018 |
* If the dialog is already visible, this will bring the dialog |
|
1019 |
* to the front. |
|
1020 |
* <p> |
|
1021 |
* If the dialog is modal and is not already visible, this call |
|
1022 |
* will not return until the dialog is hidden by calling hide or |
|
1023 |
* dispose. It is permissible to show modal dialogs from the event |
|
1024 |
* dispatching thread because the toolkit will ensure that another |
|
1025 |
* event pump runs while the one which invoked this method is blocked. |
|
1026 |
* @see Component#hide |
|
1027 |
* @see Component#isDisplayable |
|
1028 |
* @see Component#validate |
|
1029 |
* @see #isModal |
|
1030 |
* @see Window#setVisible(boolean) |
|
1031 |
* @deprecated As of JDK version 1.5, replaced by |
|
1032 |
* {@link #setVisible(boolean) setVisible(boolean)}. |
|
1033 |
*/ |
|
1034 |
@Deprecated |
|
1035 |
public void show() { |
|
1036 |
beforeFirstShow = false; |
|
1037 |
if (!isModal()) { |
|
1038 |
conditionalShow(null, null); |
|
1039 |
} else { |
|
1040 |
// Set this variable before calling conditionalShow(). That |
|
1041 |
// way, if the Dialog is hidden right after being shown, we |
|
1042 |
// won't mistakenly block this thread. |
|
1043 |
keepBlockingEDT = true; |
|
1044 |
keepBlockingCT = true; |
|
1045 |
||
1046 |
// Store the app context on which this dialog is being shown. |
|
1047 |
// Event dispatch thread of this app context will be sleeping until |
|
1048 |
// we wake it by any event from hideAndDisposeHandler(). |
|
1049 |
showAppContext = AppContext.getAppContext(); |
|
1050 |
||
1051 |
AtomicLong time = new AtomicLong(); |
|
1052 |
Component predictedFocusOwner = null; |
|
1053 |
try { |
|
1054 |
predictedFocusOwner = getMostRecentFocusOwner(); |
|
1055 |
if (conditionalShow(predictedFocusOwner, time)) { |
|
1056 |
// We have two mechanisms for blocking: 1. If we're on the |
|
1057 |
// EventDispatchThread, start a new event pump. 2. If we're |
|
1058 |
// on any other thread, call wait() on the treelock. |
|
1059 |
||
1060 |
modalFilter = ModalEventFilter.createFilterForDialog(this); |
|
1061 |
||
1062 |
final Runnable pumpEventsForFilter = new Runnable() { |
|
1063 |
public void run() { |
|
1064 |
EventDispatchThread dispatchThread = |
|
1065 |
(EventDispatchThread)Thread.currentThread(); |
|
1066 |
dispatchThread.pumpEventsForFilter(new Conditional() { |
|
1067 |
public boolean evaluate() { |
|
1068 |
synchronized (getTreeLock()) { |
|
1069 |
return keepBlockingEDT && windowClosingException == null; |
|
1070 |
} |
|
1071 |
} |
|
1072 |
}, modalFilter); |
|
1073 |
} |
|
1074 |
}; |
|
1075 |
||
1076 |
// if this dialog is toolkit-modal, the filter should be added |
|
1077 |
// to all EDTs (for all AppContexts) |
|
1078 |
if (modalityType == ModalityType.TOOLKIT_MODAL) { |
|
1079 |
Iterator it = AppContext.getAppContexts().iterator(); |
|
1080 |
while (it.hasNext()) { |
|
1081 |
AppContext appContext = (AppContext)it.next(); |
|
1082 |
if (appContext == showAppContext) { |
|
1083 |
continue; |
|
1084 |
} |
|
1085 |
EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY); |
|
1086 |
// it may occur that EDT for appContext hasn't been started yet, so |
|
1087 |
// we post an empty invocation event to trigger EDT initialization |
|
1088 |
Runnable createEDT = new Runnable() { |
|
1089 |
public void run() {}; |
|
1090 |
}; |
|
1091 |
eventQueue.postEvent(new InvocationEvent(this, createEDT)); |
|
1092 |
EventDispatchThread edt = eventQueue.getDispatchThread(); |
|
1093 |
edt.addEventFilter(modalFilter); |
|
1094 |
} |
|
1095 |
} |
|
1096 |
||
1097 |
modalityPushed(); |
|
1098 |
try { |
|
1099 |
if (EventQueue.isDispatchThread()) { |
|
1100 |
/* |
|
1101 |
* dispose SequencedEvent we are dispatching on current |
|
1102 |
* AppContext, to prevent us from hang. |
|
1103 |
* |
|
1104 |
*/ |
|
1105 |
// BugId 4531693 (son@sparc.spb.su) |
|
1106 |
SequencedEvent currentSequencedEvent = KeyboardFocusManager. |
|
1107 |
getCurrentKeyboardFocusManager().getCurrentSequencedEvent(); |
|
1108 |
if (currentSequencedEvent != null) { |
|
1109 |
currentSequencedEvent.dispose(); |
|
1110 |
} |
|
1111 |
||
1112 |
/* |
|
1113 |
* Event processing is done inside doPrivileged block so that |
|
1114 |
* it wouldn't matter even if user code is on the stack |
|
1115 |
* Fix for BugId 6300270 |
|
1116 |
*/ |
|
1117 |
||
1118 |
AccessController.doPrivileged(new PrivilegedAction() { |
|
1119 |
public Object run() { |
|
1120 |
pumpEventsForFilter.run(); |
|
1121 |
return null; |
|
1122 |
} |
|
1123 |
}); |
|
1124 |
} else { |
|
1125 |
synchronized (getTreeLock()) { |
|
1126 |
Toolkit.getEventQueue().postEvent(new PeerEvent(this, |
|
1127 |
pumpEventsForFilter, |
|
1128 |
PeerEvent.PRIORITY_EVENT)); |
|
1129 |
while (keepBlockingCT && windowClosingException == null) { |
|
1130 |
try { |
|
1131 |
getTreeLock().wait(); |
|
1132 |
} catch (InterruptedException e) { |
|
1133 |
break; |
|
1134 |
} |
|
1135 |
} |
|
1136 |
} |
|
1137 |
} |
|
1138 |
} finally { |
|
1139 |
modalityPopped(); |
|
1140 |
} |
|
1141 |
||
1142 |
// if this dialog is toolkit-modal, its filter must be removed |
|
1143 |
// from all EDTs (for all AppContexts) |
|
1144 |
if (modalityType == ModalityType.TOOLKIT_MODAL) { |
|
1145 |
Iterator it = AppContext.getAppContexts().iterator(); |
|
1146 |
while (it.hasNext()) { |
|
1147 |
AppContext appContext = (AppContext)it.next(); |
|
1148 |
if (appContext == showAppContext) { |
|
1149 |
continue; |
|
1150 |
} |
|
1151 |
EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY); |
|
1152 |
EventDispatchThread edt = eventQueue.getDispatchThread(); |
|
1153 |
edt.removeEventFilter(modalFilter); |
|
1154 |
} |
|
1155 |
} |
|
1156 |
||
1157 |
if (windowClosingException != null) { |
|
1158 |
windowClosingException.fillInStackTrace(); |
|
1159 |
throw windowClosingException; |
|
1160 |
} |
|
1161 |
} |
|
1162 |
} finally { |
|
1163 |
if (predictedFocusOwner != null) { |
|
1164 |
// Restore normal key event dispatching |
|
1165 |
KeyboardFocusManager.getCurrentKeyboardFocusManager(). |
|
1166 |
dequeueKeyEvents(time.get(), predictedFocusOwner); |
|
1167 |
} |
|
1168 |
} |
|
1169 |
} |
|
1170 |
} |
|
1171 |
||
1172 |
final void modalityPushed() { |
|
1173 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
|
1174 |
if (tk instanceof SunToolkit) { |
|
1175 |
SunToolkit stk = (SunToolkit)tk; |
|
1176 |
stk.notifyModalityPushed(this); |
|
1177 |
} |
|
1178 |
} |
|
1179 |
||
1180 |
final void modalityPopped() { |
|
1181 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
|
1182 |
if (tk instanceof SunToolkit) { |
|
1183 |
SunToolkit stk = (SunToolkit)tk; |
|
1184 |
stk.notifyModalityPopped(this); |
|
1185 |
} |
|
1186 |
} |
|
1187 |
||
1188 |
void interruptBlocking() { |
|
1189 |
if (isModal()) { |
|
1190 |
disposeImpl(); |
|
1191 |
} else if (windowClosingException != null) { |
|
1192 |
windowClosingException.fillInStackTrace(); |
|
1193 |
windowClosingException.printStackTrace(); |
|
1194 |
windowClosingException = null; |
|
1195 |
} |
|
1196 |
} |
|
1197 |
final class WakingRunnable implements Runnable { |
|
1198 |
public void run() { |
|
1199 |
synchronized (getTreeLock()) { |
|
1200 |
keepBlockingCT = false; |
|
1201 |
getTreeLock().notifyAll(); |
|
1202 |
} |
|
1203 |
} |
|
1204 |
} |
|
1205 |
private void hideAndDisposePreHandler() { |
|
1206 |
isInHide = true; |
|
1207 |
synchronized (getTreeLock()) { |
|
1208 |
if (keepBlockingEDT) { |
|
1209 |
modalHide(); |
|
1210 |
// dialog can be shown and then disposed before its |
|
1211 |
// modal filter is created |
|
1212 |
if (modalFilter != null) { |
|
1213 |
modalFilter.disable(); |
|
1214 |
} |
|
1215 |
modalDialogs.remove(this); |
|
1216 |
} |
|
1217 |
} |
|
1218 |
} |
|
1219 |
private void hideAndDisposeHandler() { |
|
1220 |
synchronized (getTreeLock()) { |
|
1221 |
if (keepBlockingEDT) { |
|
1222 |
keepBlockingEDT = false; |
|
2470
45c5e082f53d
6809233: Modal dialog blocks calling thread after it is hidden and disposed
rkennke
parents:
1964
diff
changeset
|
1223 |
PeerEvent wakingEvent = new PeerEvent(getToolkit(), new WakingRunnable(), PeerEvent.PRIORITY_EVENT); |
2 | 1224 |
AppContext curAppContext = AppContext.getAppContext(); |
1225 |
if (showAppContext != curAppContext) { |
|
1226 |
// Wake up event dispatch thread on which the dialog was |
|
1227 |
// initially shown |
|
1228 |
SunToolkit.postEvent(showAppContext, wakingEvent); |
|
1229 |
showAppContext = null; |
|
1230 |
} else { |
|
1231 |
Toolkit.getEventQueue().postEvent(wakingEvent); |
|
1232 |
} |
|
1233 |
} |
|
1234 |
} |
|
1235 |
isInHide = false; |
|
1236 |
} |
|
1237 |
||
1238 |
/** |
|
1239 |
* Hides the Dialog and then causes {@code show} to return if it is currently |
|
1240 |
* blocked. |
|
1241 |
* @see Window#show |
|
1242 |
* @see Window#dispose |
|
1243 |
* @see Window#setVisible(boolean) |
|
1244 |
* @deprecated As of JDK version 1.5, replaced by |
|
1245 |
* {@link #setVisible(boolean) setVisible(boolean)}. |
|
1246 |
*/ |
|
1247 |
@Deprecated |
|
1248 |
public void hide() { |
|
1249 |
hideAndDisposePreHandler(); |
|
1250 |
super.hide(); |
|
1251 |
// fix for 5048370: if hide() is called from super.doDispose(), then |
|
1252 |
// hideAndDisposeHandler() should not be called here as it will be called |
|
1253 |
// at the end of doDispose() |
|
1254 |
if (!isInDispose) { |
|
1255 |
hideAndDisposeHandler(); |
|
1256 |
} |
|
1257 |
} |
|
1258 |
||
1259 |
/** |
|
1260 |
* Disposes the Dialog and then causes show() to return if it is currently |
|
1261 |
* blocked. |
|
1262 |
*/ |
|
1263 |
void doDispose() { |
|
1264 |
// fix for 5048370: set isInDispose flag to true to prevent calling |
|
1265 |
// to hideAndDisposeHandler() from hide() |
|
1266 |
isInDispose = true; |
|
1267 |
super.doDispose(); |
|
1268 |
hideAndDisposeHandler(); |
|
1269 |
isInDispose = false; |
|
1270 |
} |
|
1271 |
||
1272 |
/** |
|
1273 |
* {@inheritDoc} |
|
1274 |
* <p> |
|
1275 |
* If this dialog is modal and blocks some windows, then all of them are |
|
1276 |
* also sent to the back to keep them below the blocking dialog. |
|
1277 |
* |
|
1278 |
* @see java.awt.Window#toBack |
|
1279 |
*/ |
|
1280 |
public void toBack() { |
|
1281 |
super.toBack(); |
|
1282 |
if (visible) { |
|
1283 |
synchronized (getTreeLock()) { |
|
1284 |
for (Window w : blockedWindows) { |
|
1285 |
w.toBack_NoClientCode(); |
|
1286 |
} |
|
1287 |
} |
|
1288 |
} |
|
1289 |
} |
|
1290 |
||
1291 |
/** |
|
1292 |
* Indicates whether this dialog is resizable by the user. |
|
1293 |
* By default, all dialogs are initially resizable. |
|
1294 |
* @return <code>true</code> if the user can resize the dialog; |
|
1295 |
* <code>false</code> otherwise. |
|
1296 |
* @see java.awt.Dialog#setResizable |
|
1297 |
*/ |
|
1298 |
public boolean isResizable() { |
|
1299 |
return resizable; |
|
1300 |
} |
|
1301 |
||
1302 |
/** |
|
1303 |
* Sets whether this dialog is resizable by the user. |
|
1304 |
* @param resizable <code>true</code> if the user can |
|
1305 |
* resize this dialog; <code>false</code> otherwise. |
|
1306 |
* @see java.awt.Dialog#isResizable |
|
1307 |
*/ |
|
1308 |
public void setResizable(boolean resizable) { |
|
1309 |
boolean testvalid = false; |
|
1310 |
||
1311 |
synchronized (this) { |
|
1312 |
this.resizable = resizable; |
|
1313 |
DialogPeer peer = (DialogPeer)this.peer; |
|
1314 |
if (peer != null) { |
|
1315 |
peer.setResizable(resizable); |
|
1316 |
testvalid = true; |
|
1317 |
} |
|
1318 |
} |
|
1319 |
||
1320 |
// On some platforms, changing the resizable state affects |
|
1321 |
// the insets of the Dialog. If we could, we'd call invalidate() |
|
1322 |
// from the peer, but we need to guarantee that we're not holding |
|
1323 |
// the Dialog lock when we call invalidate(). |
|
1183
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
2
diff
changeset
|
1324 |
if (testvalid) { |
80d6aafba03a
6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents:
2
diff
changeset
|
1325 |
invalidateIfValid(); |
2 | 1326 |
} |
1327 |
} |
|
1328 |
||
1329 |
||
1330 |
/** |
|
1331 |
* Disables or enables decorations for this dialog. |
|
1332 |
* This method can only be called while the dialog is not displayable. |
|
1333 |
* @param undecorated <code>true</code> if no dialog decorations are |
|
1334 |
* to be enabled; |
|
1335 |
* <code>false</code> if dialog decorations are to be enabled. |
|
1336 |
* @throws <code>IllegalComponentStateException</code> if the dialog |
|
1337 |
* is displayable. |
|
1338 |
* @see #isUndecorated |
|
1339 |
* @see Component#isDisplayable |
|
1340 |
* @since 1.4 |
|
1341 |
*/ |
|
1342 |
public void setUndecorated(boolean undecorated) { |
|
1343 |
/* Make sure we don't run in the middle of peer creation.*/ |
|
1344 |
synchronized (getTreeLock()) { |
|
1345 |
if (isDisplayable()) { |
|
1346 |
throw new IllegalComponentStateException("The dialog is displayable."); |
|
1347 |
} |
|
1348 |
this.undecorated = undecorated; |
|
1349 |
} |
|
1350 |
} |
|
1351 |
||
1352 |
/** |
|
1353 |
* Indicates whether this dialog is undecorated. |
|
1354 |
* By default, all dialogs are initially decorated. |
|
1355 |
* @return <code>true</code> if dialog is undecorated; |
|
1356 |
* <code>false</code> otherwise. |
|
1357 |
* @see java.awt.Dialog#setUndecorated |
|
1358 |
* @since 1.4 |
|
1359 |
*/ |
|
1360 |
public boolean isUndecorated() { |
|
1361 |
return undecorated; |
|
1362 |
} |
|
1363 |
||
1364 |
/** |
|
1365 |
* Returns a string representing the state of this dialog. This |
|
1366 |
* method is intended to be used only for debugging purposes, and the |
|
1367 |
* content and format of the returned string may vary between |
|
1368 |
* implementations. The returned string may be empty but may not be |
|
1369 |
* <code>null</code>. |
|
1370 |
* |
|
1371 |
* @return the parameter string of this dialog window. |
|
1372 |
*/ |
|
1373 |
protected String paramString() { |
|
1374 |
String str = super.paramString() + "," + modalityType; |
|
1375 |
if (title != null) { |
|
1376 |
str += ",title=" + title; |
|
1377 |
} |
|
1378 |
return str; |
|
1379 |
} |
|
1380 |
||
1381 |
/** |
|
1382 |
* Initialize JNI field and method IDs |
|
1383 |
*/ |
|
1384 |
private static native void initIDs(); |
|
1385 |
||
1386 |
/* |
|
1387 |
* --- Modality support --- |
|
1388 |
* |
|
1389 |
*/ |
|
1390 |
||
1391 |
/* |
|
1392 |
* This method is called only for modal dialogs. |
|
1393 |
* |
|
1394 |
* Goes through the list of all visible top-level windows and |
|
1395 |
* divide them into three distinct groups: blockers of this dialog, |
|
1396 |
* blocked by this dialog and all others. Then blocks this dialog |
|
1397 |
* by first met dialog from the first group (if any) and blocks all |
|
1398 |
* the windows from the second group. |
|
1399 |
*/ |
|
1400 |
void modalShow() { |
|
1401 |
// find all the dialogs that block this one |
|
1402 |
IdentityArrayList<Dialog> blockers = new IdentityArrayList<Dialog>(); |
|
1403 |
for (Dialog d : modalDialogs) { |
|
1404 |
if (d.shouldBlock(this)) { |
|
1405 |
Window w = d; |
|
1406 |
while ((w != null) && (w != this)) { |
|
1407 |
w = (Window)(w.getOwner_NoClientCode()); |
|
1408 |
} |
|
1409 |
if ((w == this) || !shouldBlock(d) || (modalityType.compareTo(d.getModalityType()) < 0)) { |
|
1410 |
blockers.add(d); |
|
1411 |
} |
|
1412 |
} |
|
1413 |
} |
|
1414 |
||
1415 |
// add all blockers' blockers to blockers :) |
|
1416 |
for (int i = 0; i < blockers.size(); i++) { |
|
1417 |
Dialog blocker = blockers.get(i); |
|
1418 |
if (blocker.isModalBlocked()) { |
|
1419 |
Dialog blockerBlocker = blocker.getModalBlocker(); |
|
1420 |
if (!blockers.contains(blockerBlocker)) { |
|
1421 |
blockers.add(i + 1, blockerBlocker); |
|
1422 |
} |
|
1423 |
} |
|
1424 |
} |
|
1425 |
||
1426 |
if (blockers.size() > 0) { |
|
1427 |
blockers.get(0).blockWindow(this); |
|
1428 |
} |
|
1429 |
||
1430 |
// find all windows from blockers' hierarchies |
|
1431 |
IdentityArrayList<Window> blockersHierarchies = new IdentityArrayList<Window>(blockers); |
|
1432 |
int k = 0; |
|
1433 |
while (k < blockersHierarchies.size()) { |
|
1434 |
Window w = blockersHierarchies.get(k); |
|
1435 |
Window[] ownedWindows = w.getOwnedWindows_NoClientCode(); |
|
1436 |
for (Window win : ownedWindows) { |
|
1437 |
blockersHierarchies.add(win); |
|
1438 |
} |
|
1439 |
k++; |
|
1440 |
} |
|
1441 |
||
1442 |
java.util.List<Window> toBlock = new IdentityLinkedList<Window>(); |
|
1443 |
// block all windows from scope of blocking except from blockers' hierarchies |
|
1444 |
IdentityArrayList<Window> unblockedWindows = Window.getAllUnblockedWindows(); |
|
1445 |
for (Window w : unblockedWindows) { |
|
1446 |
if (shouldBlock(w) && !blockersHierarchies.contains(w)) { |
|
1447 |
if ((w instanceof Dialog) && ((Dialog)w).isModal_NoClientCode()) { |
|
1448 |
Dialog wd = (Dialog)w; |
|
1449 |
if (wd.shouldBlock(this) && (modalDialogs.indexOf(wd) > modalDialogs.indexOf(this))) { |
|
1450 |
continue; |
|
1451 |
} |
|
1452 |
} |
|
1453 |
toBlock.add(w); |
|
1454 |
} |
|
1455 |
} |
|
1456 |
blockWindows(toBlock); |
|
1457 |
||
1458 |
if (!isModalBlocked()) { |
|
1459 |
updateChildrenBlocking(); |
|
1460 |
} |
|
1461 |
} |
|
1462 |
||
1463 |
/* |
|
1464 |
* This method is called only for modal dialogs. |
|
1465 |
* |
|
1466 |
* Unblocks all the windows blocked by this modal dialog. After |
|
1467 |
* each of them has been unblocked, it is checked to be blocked by |
|
1468 |
* any other modal dialogs. |
|
1469 |
*/ |
|
1470 |
void modalHide() { |
|
1471 |
// we should unblock all the windows first... |
|
1472 |
IdentityArrayList<Window> save = new IdentityArrayList<Window>(); |
|
1473 |
int blockedWindowsCount = blockedWindows.size(); |
|
1474 |
for (int i = 0; i < blockedWindowsCount; i++) { |
|
1475 |
Window w = blockedWindows.get(0); |
|
1476 |
save.add(w); |
|
1477 |
unblockWindow(w); // also removes w from blockedWindows |
|
1478 |
} |
|
1479 |
// ... and only after that check if they should be blocked |
|
1480 |
// by another dialogs |
|
1481 |
for (int i = 0; i < blockedWindowsCount; i++) { |
|
1482 |
Window w = save.get(i); |
|
1483 |
if ((w instanceof Dialog) && ((Dialog)w).isModal_NoClientCode()) { |
|
1484 |
Dialog d = (Dialog)w; |
|
1485 |
d.modalShow(); |
|
1486 |
} else { |
|
1487 |
checkShouldBeBlocked(w); |
|
1488 |
} |
|
1489 |
} |
|
1490 |
} |
|
1491 |
||
1492 |
/* |
|
1493 |
* Returns whether the given top-level window should be blocked by |
|
1494 |
* this dialog. Note, that the given window can be also a modal dialog |
|
1495 |
* and it should block this dialog, but this method do not take such |
|
1496 |
* situations into consideration (such checks are performed in the |
|
1497 |
* modalShow() and modalHide() methods). |
|
1498 |
* |
|
1499 |
* This method should be called on the getTreeLock() lock. |
|
1500 |
*/ |
|
1501 |
boolean shouldBlock(Window w) { |
|
1502 |
if (!isVisible_NoClientCode() || |
|
1503 |
(!w.isVisible_NoClientCode() && !w.isInShow) || |
|
1504 |
isInHide || |
|
1505 |
(w == this) || |
|
1506 |
!isModal_NoClientCode()) |
|
1507 |
{ |
|
1508 |
return false; |
|
1509 |
} |
|
1510 |
if ((w instanceof Dialog) && ((Dialog)w).isInHide) { |
|
1511 |
return false; |
|
1512 |
} |
|
1513 |
// check if w is from children hierarchy |
|
1514 |
// fix for 6271546: we should also take into consideration child hierarchies |
|
1515 |
// of this dialog's blockers |
|
1516 |
Window blockerToCheck = this; |
|
1517 |
while (blockerToCheck != null) { |
|
1518 |
Component c = w; |
|
1519 |
while ((c != null) && (c != blockerToCheck)) { |
|
1520 |
c = c.getParent_NoClientCode(); |
|
1521 |
} |
|
1522 |
if (c == blockerToCheck) { |
|
1523 |
return false; |
|
1524 |
} |
|
1525 |
blockerToCheck = blockerToCheck.getModalBlocker(); |
|
1526 |
} |
|
1527 |
switch (modalityType) { |
|
1528 |
case MODELESS: |
|
1529 |
return false; |
|
1530 |
case DOCUMENT_MODAL: |
|
1531 |
if (w.isModalExcluded(ModalExclusionType.APPLICATION_EXCLUDE)) { |
|
1532 |
// application- and toolkit-excluded windows are not blocked by |
|
1533 |
// document-modal dialogs from outside their children hierarchy |
|
1534 |
Component c = this; |
|
1535 |
while ((c != null) && (c != w)) { |
|
1536 |
c = c.getParent_NoClientCode(); |
|
1537 |
} |
|
1538 |
return c == w; |
|
1539 |
} else { |
|
1540 |
return getDocumentRoot() == w.getDocumentRoot(); |
|
1541 |
} |
|
1542 |
case APPLICATION_MODAL: |
|
1543 |
return !w.isModalExcluded(ModalExclusionType.APPLICATION_EXCLUDE) && |
|
1544 |
(appContext == w.appContext); |
|
1545 |
case TOOLKIT_MODAL: |
|
1546 |
return !w.isModalExcluded(ModalExclusionType.TOOLKIT_EXCLUDE); |
|
1547 |
} |
|
1548 |
||
1549 |
return false; |
|
1550 |
} |
|
1551 |
||
1552 |
/* |
|
1553 |
* Adds the given top-level window to the list of blocked |
|
1554 |
* windows for this dialog and marks it as modal blocked. |
|
1555 |
* If the window is already blocked by some modal dialog, |
|
1556 |
* does nothing. |
|
1557 |
*/ |
|
1558 |
void blockWindow(Window w) { |
|
1559 |
if (!w.isModalBlocked()) { |
|
1560 |
w.setModalBlocked(this, true, true); |
|
1561 |
blockedWindows.add(w); |
|
1562 |
} |
|
1563 |
} |
|
1564 |
||
1565 |
void blockWindows(java.util.List<Window> toBlock) { |
|
1566 |
DialogPeer dpeer = (DialogPeer)peer; |
|
1567 |
if (dpeer == null) { |
|
1568 |
return; |
|
1569 |
} |
|
1570 |
Iterator<Window> it = toBlock.iterator(); |
|
1571 |
while (it.hasNext()) { |
|
1572 |
Window w = it.next(); |
|
1573 |
if (!w.isModalBlocked()) { |
|
1574 |
w.setModalBlocked(this, true, false); |
|
1575 |
} else { |
|
1576 |
it.remove(); |
|
1577 |
} |
|
1578 |
} |
|
1579 |
dpeer.blockWindows(toBlock); |
|
1580 |
blockedWindows.addAll(toBlock); |
|
1581 |
} |
|
1582 |
||
1583 |
/* |
|
1584 |
* Removes the given top-level window from the list of blocked |
|
1585 |
* windows for this dialog and marks it as unblocked. If the |
|
1586 |
* window is not modal blocked, does nothing. |
|
1587 |
*/ |
|
1588 |
void unblockWindow(Window w) { |
|
1589 |
if (w.isModalBlocked() && blockedWindows.contains(w)) { |
|
1590 |
blockedWindows.remove(w); |
|
1591 |
w.setModalBlocked(this, false, true); |
|
1592 |
} |
|
1593 |
} |
|
1594 |
||
1595 |
/* |
|
1596 |
* Checks if any other modal dialog D blocks the given window. |
|
1597 |
* If such D exists, mark the window as blocked by D. |
|
1598 |
*/ |
|
1599 |
static void checkShouldBeBlocked(Window w) { |
|
1600 |
synchronized (w.getTreeLock()) { |
|
1601 |
for (int i = 0; i < modalDialogs.size(); i++) { |
|
1602 |
Dialog modalDialog = modalDialogs.get(i); |
|
1603 |
if (modalDialog.shouldBlock(w)) { |
|
1604 |
modalDialog.blockWindow(w); |
|
1605 |
break; |
|
1606 |
} |
|
1607 |
} |
|
1608 |
} |
|
1609 |
} |
|
1610 |
||
1611 |
private void readObject(ObjectInputStream s) |
|
1612 |
throws ClassNotFoundException, IOException, HeadlessException |
|
1613 |
{ |
|
1614 |
GraphicsEnvironment.checkHeadless(); |
|
1615 |
s.defaultReadObject(); |
|
1616 |
||
1617 |
// in 1.5 or earlier modalityType was absent, so use "modal" instead |
|
1618 |
if (modalityType == null) { |
|
1619 |
setModal(modal); |
|
1620 |
} |
|
1621 |
||
1622 |
blockedWindows = new IdentityArrayList(); |
|
1623 |
} |
|
1624 |
||
1625 |
/* |
|
1626 |
* --- Accessibility Support --- |
|
1627 |
* |
|
1628 |
*/ |
|
1629 |
||
1630 |
/** |
|
1631 |
* Gets the AccessibleContext associated with this Dialog. |
|
1632 |
* For dialogs, the AccessibleContext takes the form of an |
|
1633 |
* AccessibleAWTDialog. |
|
1634 |
* A new AccessibleAWTDialog instance is created if necessary. |
|
1635 |
* |
|
1636 |
* @return an AccessibleAWTDialog that serves as the |
|
1637 |
* AccessibleContext of this Dialog |
|
1638 |
* @since 1.3 |
|
1639 |
*/ |
|
1640 |
public AccessibleContext getAccessibleContext() { |
|
1641 |
if (accessibleContext == null) { |
|
1642 |
accessibleContext = new AccessibleAWTDialog(); |
|
1643 |
} |
|
1644 |
return accessibleContext; |
|
1645 |
} |
|
1646 |
||
1647 |
/** |
|
1648 |
* This class implements accessibility support for the |
|
1649 |
* <code>Dialog</code> class. It provides an implementation of the |
|
1650 |
* Java Accessibility API appropriate to dialog user-interface elements. |
|
1651 |
* @since 1.3 |
|
1652 |
*/ |
|
1653 |
protected class AccessibleAWTDialog extends AccessibleAWTWindow |
|
1654 |
{ |
|
1655 |
/* |
|
1656 |
* JDK 1.3 serialVersionUID |
|
1657 |
*/ |
|
1658 |
private static final long serialVersionUID = 4837230331833941201L; |
|
1659 |
||
1660 |
/** |
|
1661 |
* Get the role of this object. |
|
1662 |
* |
|
1663 |
* @return an instance of AccessibleRole describing the role of the |
|
1664 |
* object |
|
1665 |
* @see AccessibleRole |
|
1666 |
*/ |
|
1667 |
public AccessibleRole getAccessibleRole() { |
|
1668 |
return AccessibleRole.DIALOG; |
|
1669 |
} |
|
1670 |
||
1671 |
/** |
|
1672 |
* Get the state of this object. |
|
1673 |
* |
|
1674 |
* @return an instance of AccessibleStateSet containing the current |
|
1675 |
* state set of the object |
|
1676 |
* @see AccessibleState |
|
1677 |
*/ |
|
1678 |
public AccessibleStateSet getAccessibleStateSet() { |
|
1679 |
AccessibleStateSet states = super.getAccessibleStateSet(); |
|
1680 |
if (getFocusOwner() != null) { |
|
1681 |
states.add(AccessibleState.ACTIVE); |
|
1682 |
} |
|
1683 |
if (isModal()) { |
|
1684 |
states.add(AccessibleState.MODAL); |
|
1685 |
} |
|
1686 |
if (isResizable()) { |
|
1687 |
states.add(AccessibleState.RESIZABLE); |
|
1688 |
} |
|
1689 |
return states; |
|
1690 |
} |
|
1691 |
||
1692 |
} // inner class AccessibleAWTDialog |
|
1693 |
} |