Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Modal/FileDialog/FileDialogFWDTest.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
import java.awt.*;
25
26
27
28
// FWD: Frame, Window, Dialog
29
30
public class FileDialogFWDTest {
31
32
private volatile FileDialog fileDialog;
33
private volatile CustomDialog dialog;
34
private volatile TestFrame frame;
35
private volatile TestWindow window;
36
37
private static final int delay = 500;
38
private final ExtendedRobot robot;
39
40
private volatile Dialog hiddenDialog;
41
private volatile Frame hiddenFrame;
42
43
public enum DialogOwner {
44
HIDDEN_DIALOG, NULL_DIALOG, HIDDEN_FRAME, NULL_FRAME, FRAME};
45
46
private DialogOwner owner;
47
boolean setModal;
48
49
Dialog.ModalityType modalityType;
50
51
private FileDialogFWDTest(Dialog.ModalityType modType,
52
boolean modal,
53
DialogOwner o) throws Exception {
54
modalityType = modType;
55
setModal = modal;
56
owner = o;
57
58
robot = new ExtendedRobot();
59
EventQueue.invokeLater(this::createGUI);
60
}
61
62
public FileDialogFWDTest(Dialog.ModalityType modalityType,
63
DialogOwner o) throws Exception {
64
this(modalityType, false, o);
65
}
66
67
public FileDialogFWDTest(DialogOwner o) throws Exception {
68
this(null, true, o);
69
}
70
71
private void createGUI() {
72
73
frame = new CustomFrame();
74
75
switch (owner) {
76
case HIDDEN_DIALOG:
77
hiddenDialog = new Dialog((Frame) null);
78
dialog = new CustomDialog(hiddenDialog);
79
break;
80
case NULL_DIALOG:
81
dialog = new CustomDialog((Dialog) null);
82
break;
83
case HIDDEN_FRAME:
84
hiddenFrame = new Frame();
85
dialog = new CustomDialog(hiddenFrame);
86
break;
87
case NULL_FRAME:
88
dialog = new CustomDialog((Frame) null);
89
break;
90
case FRAME:
91
dialog = new CustomDialog(frame);
92
break;
93
}
94
95
if (setModal) {
96
dialog.setModal(true);
97
modalityType = dialog.getModalityType();
98
} else if (modalityType != null) {
99
dialog.setModalityType(modalityType);
100
}
101
102
window = new CustomWindow(frame);
103
104
int x = Toolkit.getDefaultToolkit().getScreenSize().width -
105
frame.getWidth() - 50;
106
int y = 50;
107
frame.setLocation(x, y);
108
y += (frame.getHeight() + 50);
109
window.setLocation(x, y);
110
y += (window.getHeight() + 50);
111
dialog.setLocation(x, y);
112
113
frame.setVisible(true);
114
}
115
116
private void openAll() throws Exception {
117
robot.waitForIdle(delay);
118
frame.clickOpenButton(robot);
119
robot.waitForIdle(delay);
120
window.clickOpenButton(robot);
121
robot.waitForIdle(delay);
122
dialog.clickOpenButton(robot);
123
robot.waitForIdle(delay);
124
}
125
126
private void checkBlockedWindows() throws Exception {
127
128
String msg = "FileDialog should block this ";
129
frame.checkBlockedFrame(robot, msg + "Frame.");
130
robot.waitForIdle(delay);
131
window.checkBlockedWindow(robot, msg + "Window.");
132
robot.waitForIdle(delay);
133
dialog.checkBlockedDialog(robot, msg + "Dialog.");
134
robot.waitForIdle(delay);
135
}
136
137
private void checkUnblockedWindows() throws Exception {
138
139
String msg = "Blocking dialogs were closed.";
140
frame.checkUnblockedFrame(robot, msg + "Frame.");
141
robot.waitForIdle(delay);
142
window.checkUnblockedWindow(robot, msg + "Window.");
143
robot.waitForIdle(delay);
144
}
145
146
private void modalTest(String type) throws Exception {
147
148
checkBlockedWindows();
149
150
EventQueue.invokeAndWait(() -> { fileDialog.dispose(); });
151
robot.waitForIdle(delay);
152
153
String msg = "FileDialog was closed, " +
154
"but the " + type + " modal dialog should block this ";
155
156
frame.checkBlockedFrame(robot, msg + "Frame.");
157
robot.waitForIdle(delay);
158
159
window.checkBlockedWindow(robot, msg + "Window.");
160
robot.waitForIdle(delay);
161
162
dialog.checkUnblockedDialog(robot, "FileDialog was closed.");
163
robot.waitForIdle(delay);
164
165
dialog.clickCloseButton(robot);
166
robot.waitForIdle(delay);
167
168
checkUnblockedWindows();
169
}
170
171
private void docModalTest() throws Exception {
172
173
if (owner == DialogOwner.FRAME) {
174
175
checkBlockedWindows();
176
177
EventQueue.invokeAndWait(() -> { fileDialog.dispose(); });
178
robot.waitForIdle(delay);
179
180
String msg = "FileDialog was closed.";
181
182
dialog.checkUnblockedDialog(robot, msg);
183
robot.waitForIdle(delay);
184
185
msg += " But the blocking document modal dialog is still open.";
186
187
frame.checkBlockedFrame(robot, msg);
188
robot.waitForIdle(delay);
189
190
window.checkBlockedWindow(robot, msg);
191
robot.waitForIdle(delay);
192
193
dialog.clickCloseButton(robot);
194
robot.waitForIdle(delay);
195
196
checkUnblockedWindows();
197
198
} else {
199
nonModalTest();
200
}
201
}
202
203
private void nonModalTest() throws Exception {
204
205
checkBlockedWindows();
206
207
EventQueue.invokeAndWait(() -> { fileDialog.dispose(); });
208
robot.waitForIdle(delay);
209
210
dialog.checkUnblockedDialog(robot, "FileDialog was closed.");
211
robot.waitForIdle(delay);
212
213
checkUnblockedWindows();
214
}
215
216
public void doTest() throws Exception {
217
218
try {
219
openAll();
220
221
if (modalityType == null) {
222
nonModalTest();
223
return;
224
}
225
226
switch (modalityType) {
227
case APPLICATION_MODAL:
228
modalTest("application");
229
break;
230
case DOCUMENT_MODAL:
231
docModalTest();
232
break;
233
case TOOLKIT_MODAL:
234
modalTest("toolkit");
235
break;
236
case MODELESS:
237
nonModalTest();
238
break;
239
}
240
241
} finally {
242
EventQueue.invokeAndWait(this::closeAll);
243
}
244
}
245
246
private void closeAll() {
247
if (dialog != null) { dialog.dispose(); }
248
if (frame != null) { frame.dispose(); }
249
if (window != null) { window.dispose(); }
250
if (fileDialog != null) { fileDialog.dispose(); }
251
if (hiddenDialog != null) { hiddenDialog.dispose(); }
252
if (hiddenFrame != null) { hiddenFrame.dispose(); }
253
}
254
255
256
class CustomDialog extends TestDialog {
257
258
public CustomDialog(Dialog d) { super(d); }
259
public CustomDialog(Frame f) { super(f); }
260
261
@Override
262
public void doOpenAction() {
263
fileDialog = new FileDialog((Frame) null);
264
fileDialog.setLocation(50, 50);
265
fileDialog.setVisible(true);
266
}
267
268
@Override
269
public void doCloseAction() {
270
this.dispose();
271
}
272
}
273
274
class CustomFrame extends TestFrame {
275
276
@Override
277
public void doOpenAction() {
278
if (window != null) { window.setVisible(true); }
279
}
280
}
281
282
class CustomWindow extends TestWindow {
283
284
public CustomWindow(Frame f) { super(f); }
285
286
@Override
287
public void doOpenAction() {
288
if (dialog != null) { dialog.setVisible(true); }
289
}
290
}
291
}
292
293