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