Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Dialog/NestedDialogs/Modal/NestedModalDialogTest.java
41171 views
1
/*
2
* Copyright (c) 2011, 2020, 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
* @test
26
* @bug 8160266 8225790
27
* @key headful
28
* @summary See <rdar://problem/3429130>: Events: actionPerformed() method not
29
* called when it is button is clicked (system load related)
30
* @run main NestedModalDialogTest
31
*/
32
33
//////////////////////////////////////////////////////////////////////////////
34
// NestedModalDialogTest.java
35
// The test launches a parent frame. From this parent frame it launches a modal
36
// dialog. From the modal dialog it launches a second modal dialog with a text
37
// field in it and tries to write into the text field. The test succeeds if you
38
// are successfully able to write into this second Nested Modal Dialog
39
//////////////////////////////////////////////////////////////////////////////
40
// classes necessary for this test
41
42
import java.awt.Button;
43
import java.awt.Component;
44
import java.awt.Dialog;
45
import java.awt.Frame;
46
import java.awt.GridBagLayout;
47
import java.awt.Panel;
48
import java.awt.Point;
49
import java.awt.Rectangle;
50
import java.awt.Robot;
51
import java.awt.TextField;
52
import java.awt.event.ActionEvent;
53
import java.awt.event.InputEvent;
54
import java.awt.event.KeyEvent;
55
56
public class NestedModalDialogTest {
57
private static Frame frame;
58
private static IntermediateDialog interDiag;
59
private static TextDialog txtDiag;
60
61
// Global variables so the robot thread can locate things.
62
private static Button[] robot_button = new Button[2];
63
private static TextField robot_text = null;
64
private static Robot robot = null;
65
66
private static void blockTillDisplayed(Component comp) {
67
Point p = null;
68
while (p == null) {
69
try {
70
p = comp.getLocationOnScreen();
71
} catch (IllegalStateException e) {
72
try {
73
Thread.sleep(500);
74
} catch (InterruptedException ie) {
75
}
76
}
77
}
78
}
79
80
private static void clickOnComp(Component comp) {
81
Rectangle bounds = new Rectangle(comp.getLocationOnScreen(), comp.getSize());
82
robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
83
robot.waitForIdle();
84
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
85
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
86
robot.waitForIdle();
87
}
88
89
public void testModalDialogs() throws Exception {
90
try {
91
robot = new Robot();
92
robot.setAutoDelay(100);
93
94
// launch first frame with firstButton
95
frame = new StartFrame();
96
blockTillDisplayed(frame);
97
clickOnComp(robot_button[0]);
98
99
// Dialog must be created and onscreen before we proceed.
100
blockTillDisplayed(interDiag);
101
clickOnComp(robot_button[1]);
102
103
// Again, the Dialog must be created and onscreen before we proceed.
104
blockTillDisplayed(robot_text);
105
clickOnComp(robot_text);
106
107
robot.keyPress(KeyEvent.VK_SHIFT);
108
robot.keyPress(KeyEvent.VK_H);
109
robot.keyRelease(KeyEvent.VK_H);
110
robot.keyRelease(KeyEvent.VK_SHIFT);
111
robot.waitForIdle();
112
113
robot.keyPress(KeyEvent.VK_E);
114
robot.keyRelease(KeyEvent.VK_E);
115
robot.waitForIdle();
116
117
robot.keyPress(KeyEvent.VK_L);
118
robot.keyRelease(KeyEvent.VK_L);
119
robot.waitForIdle();
120
121
robot.keyPress(KeyEvent.VK_L);
122
robot.keyRelease(KeyEvent.VK_L);
123
robot.waitForIdle();
124
125
robot.keyPress(KeyEvent.VK_O);
126
robot.keyRelease(KeyEvent.VK_O);
127
robot.waitForIdle();
128
} finally {
129
if (frame != null) {
130
frame.dispose();
131
}
132
if (interDiag != null) {
133
interDiag.dispose();
134
}
135
if (txtDiag != null) {
136
txtDiag.dispose();
137
}
138
}
139
}
140
141
//////////////////// Start Frame ///////////////////
142
/**
143
* Launches the first frame with a button in it
144
*/
145
class StartFrame extends Frame {
146
147
/**
148
* Constructs a new instance.
149
*/
150
public StartFrame() {
151
super("First Frame");
152
setLayout(new GridBagLayout());
153
setLocation(375, 200);
154
setSize(271, 161);
155
Button but = new Button("Make Intermediate");
156
but.addActionListener(new java.awt.event.ActionListener() {
157
public void actionPerformed(ActionEvent e) {
158
interDiag = new IntermediateDialog(StartFrame.this);
159
interDiag.setSize(300, 200);
160
161
// may need listener to watch this move.
162
interDiag.setLocation(getLocationOnScreen());
163
interDiag.pack();
164
interDiag.setVisible(true);
165
}
166
});
167
Panel pan = new Panel();
168
pan.add(but);
169
add(pan);
170
setVisible(true);
171
robot_button[0] = but;
172
}
173
}
174
175
///////////////////////////// MODAL DIALOGS /////////////////////////////
176
/* A Dialog that launches a sub-dialog */
177
class IntermediateDialog extends Dialog {
178
179
Dialog m_parent;
180
181
public IntermediateDialog(Frame parent) {
182
super(parent, "Intermediate Modal", true /*Modal*/);
183
m_parent = this;
184
Button but = new Button("Make Text");
185
but.addActionListener(new java.awt.event.ActionListener() {
186
public void actionPerformed(ActionEvent e) {
187
txtDiag = new TextDialog(m_parent);
188
txtDiag.setSize(300, 100);
189
txtDiag.setVisible(true);
190
}
191
});
192
Panel pan = new Panel();
193
pan.add(but);
194
add(pan);
195
pack();
196
197
// The robot needs to know about us, so set global
198
robot_button[1] = but;
199
}
200
}
201
202
/* A Dialog that just holds a text field */
203
class TextDialog extends Dialog {
204
205
public TextDialog(Dialog parent) {
206
super(parent, "Modal Dialog", true /*Modal*/);
207
TextField txt = new TextField("", 10);
208
Panel pan = new Panel();
209
pan.add(txt);
210
add(pan);
211
pack();
212
213
// The robot needs to know about us, so set global
214
robot_text = txt;
215
}
216
}
217
218
public static void main(String[] args) throws RuntimeException, Exception {
219
try {
220
new NestedModalDialogTest().testModalDialogs();
221
} catch (Exception e) {
222
throw new RuntimeException("NestedModalDialogTest object creation "
223
+ "failed");
224
}
225
}
226
}
227
228