Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Modal/FileDialog/FileDialogDWDTest.java
41152 views
1
/*
2
* Copyright (c) 2007, 2014, 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
25
import java.awt.*;
26
27
28
// DWD: Dialog, Window, Dialog
29
30
public class FileDialogDWDTest {
31
32
private volatile FileDialog fileDialog;
33
private volatile ParentDialog parent;
34
private volatile CustomDialog dialog;
35
private volatile TestWindow window;
36
37
private static final int delay = 500;
38
private final ExtendedRobot robot;
39
40
boolean setModal;
41
42
Dialog.ModalityType modalityType;
43
44
private FileDialogDWDTest(Dialog.ModalityType modType,
45
boolean modal) throws Exception {
46
modalityType = modType;
47
setModal = modal;
48
49
robot = new ExtendedRobot();
50
EventQueue.invokeLater(this::createGUI);
51
}
52
53
public FileDialogDWDTest(Dialog.ModalityType modalityType) throws Exception {
54
this(modalityType, false);
55
}
56
57
public FileDialogDWDTest() throws Exception {
58
this(null, true);
59
}
60
61
private void createGUI() {
62
63
parent = new ParentDialog();
64
dialog = new CustomDialog(parent);
65
66
if (setModal) {
67
dialog.setModal(true);
68
modalityType = dialog.getModalityType();
69
} else if (modalityType != null) {
70
dialog.setModalityType(modalityType);
71
}
72
73
window = new CustomWindow(parent);
74
75
int x = Toolkit.getDefaultToolkit().getScreenSize().width -
76
parent.getWidth() - 50;
77
int y = 50;
78
parent.setLocation(x, y);
79
y += (parent.getHeight() + 50);
80
window.setLocation(x, y);
81
y += (window.getHeight() + 50);
82
dialog.setLocation(x, y);
83
84
parent.setVisible(true);
85
}
86
87
private void openAll() throws Exception {
88
robot.waitForIdle(delay);
89
parent.clickOpenButton(robot);
90
robot.waitForIdle(delay);
91
window.clickOpenButton(robot);
92
robot.waitForIdle(delay);
93
dialog.clickOpenButton(robot);
94
robot.waitForIdle(delay);
95
}
96
97
private void checkBlockedWindows() throws Exception {
98
99
String msg = "FileDialog should block this ";
100
parent.checkBlockedDialog(robot, msg + "Dialog.");
101
robot.waitForIdle(delay);
102
window.checkBlockedWindow(robot, msg + "Window.");
103
robot.waitForIdle(delay);
104
dialog.checkBlockedDialog(robot, msg + "Dialog.");
105
robot.waitForIdle(delay);
106
}
107
108
private void checkUnblockedWindows() throws Exception {
109
110
String msg = "Blocking dialogs were closed.";
111
parent.checkUnblockedDialog(robot, msg + "Frame.");
112
robot.waitForIdle(delay);
113
window.checkUnblockedWindow(robot, msg + "Window.");
114
robot.waitForIdle(delay);
115
}
116
117
118
private void modalTest(String type) throws Exception {
119
120
checkBlockedWindows();
121
122
EventQueue.invokeAndWait(() -> { fileDialog.dispose(); });
123
robot.waitForIdle(delay);
124
125
String msg = "FileDialog was closed, " +
126
"but the " + type + " modal dialog should block this ";
127
128
parent.checkBlockedDialog(robot, msg + "Dialog.");
129
robot.waitForIdle(delay);
130
131
window.checkBlockedWindow(robot, msg + "Window.");
132
robot.waitForIdle(delay);
133
134
dialog.checkUnblockedDialog(robot, "FileDialog was closed.");
135
robot.waitForIdle(delay);
136
137
dialog.clickCloseButton(robot);
138
robot.waitForIdle(delay);
139
140
checkUnblockedWindows();
141
}
142
143
private void nonModalTest() throws Exception {
144
145
checkBlockedWindows();
146
147
EventQueue.invokeAndWait(() -> { fileDialog.dispose(); });
148
robot.waitForIdle(delay);
149
150
dialog.checkUnblockedDialog(robot, "FileDialog was closed.");
151
robot.waitForIdle(delay);
152
153
checkUnblockedWindows();
154
}
155
156
public void doTest() throws Exception {
157
158
try {
159
160
openAll();
161
162
if (modalityType == null) {
163
nonModalTest();
164
return;
165
}
166
167
switch (modalityType) {
168
case APPLICATION_MODAL:
169
modalTest("application");
170
break;
171
case DOCUMENT_MODAL:
172
modalTest("document");
173
break;
174
case TOOLKIT_MODAL:
175
modalTest("toolkit");
176
break;
177
case MODELESS:
178
nonModalTest();
179
break;
180
}
181
182
} finally {
183
EventQueue.invokeAndWait(this::closeAll);
184
}
185
}
186
187
private void closeAll() {
188
if (parent != null) { parent.dispose(); }
189
if (dialog != null) { dialog.dispose(); }
190
if (window != null) { window.dispose(); }
191
if (fileDialog != null) { fileDialog.dispose(); }
192
193
}
194
195
class ParentDialog extends TestDialog {
196
197
public ParentDialog() { super((Frame) null); }
198
199
@Override
200
public void doOpenAction() {
201
if (window != null) { window.setVisible(true); }
202
}
203
204
}
205
206
207
class CustomDialog extends TestDialog {
208
209
public CustomDialog(Dialog d) { super(d); }
210
211
@Override
212
public void doOpenAction() {
213
fileDialog = new FileDialog((Frame) null);
214
fileDialog.setLocation(50, 50);
215
fileDialog.setVisible(true);
216
}
217
218
@Override
219
public void doCloseAction() {
220
this.dispose();
221
}
222
}
223
224
class CustomWindow extends TestWindow {
225
226
public CustomWindow(Dialog d) { super(d); }
227
228
@Override
229
public void doOpenAction() {
230
if (dialog != null) { dialog.setVisible(true); }
231
}
232
}
233
}
234
235