Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Dialog/NestedDialogs/Modeless/NestedModelessDialogTest.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 NestedModelessDialogTest
31
*/
32
33
/////////////////////////////////////////////////////////////////////////////
34
// NestedModelessDialogTest.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 modeless 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 Nested Modeless 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 NestedModelessDialogTest {
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;
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
/**
90
* Get called by test harness
91
*
92
* @throws Exception
93
*/
94
public void testModelessDialogs() throws Exception {
95
try {
96
robot = new Robot();
97
robot.setAutoDelay(100);
98
99
// launch first frame with fistButton
100
frame = new StartFrame();
101
robot.waitForIdle();
102
blockTillDisplayed(frame);
103
clickOnComp(robot_button[0]);
104
105
// Dialog must be created and onscreen before we proceed.
106
blockTillDisplayed(interDiag);
107
clickOnComp(robot_button[1]);
108
109
// Again, the Dialog must be created and onscreen before we proceed.
110
blockTillDisplayed(robot_text);
111
clickOnComp(robot_text);
112
113
robot.keyPress(KeyEvent.VK_SHIFT);
114
robot.keyPress(KeyEvent.VK_H);
115
robot.keyRelease(KeyEvent.VK_H);
116
robot.keyRelease(KeyEvent.VK_SHIFT);
117
robot.waitForIdle();
118
119
robot.keyPress(KeyEvent.VK_E);
120
robot.keyRelease(KeyEvent.VK_E);
121
robot.waitForIdle();
122
123
robot.keyPress(KeyEvent.VK_L);
124
robot.keyRelease(KeyEvent.VK_L);
125
robot.waitForIdle();
126
127
robot.keyPress(KeyEvent.VK_L);
128
robot.keyRelease(KeyEvent.VK_L);
129
robot.waitForIdle();
130
131
robot.keyPress(KeyEvent.VK_O);
132
robot.keyRelease(KeyEvent.VK_O);
133
robot.waitForIdle();
134
} finally {
135
if (frame != null) {
136
frame.dispose();
137
}
138
if (interDiag != null) {
139
interDiag.dispose();
140
}
141
if (txtDiag != null) {
142
txtDiag.dispose();
143
}
144
}
145
}
146
147
//////////////////// Start Frame ///////////////////
148
/**
149
* Launches the first frame with a button in it
150
*/
151
class StartFrame extends Frame {
152
153
/**
154
* Constructs a new instance.
155
*/
156
public StartFrame() {
157
super("First Frame");
158
setLayout(new GridBagLayout());
159
setLocation(375, 200);
160
setSize(271, 161);
161
Button but = new Button("Make Intermediate");
162
but.addActionListener(new java.awt.event.ActionListener() {
163
public void actionPerformed(ActionEvent e) {
164
interDiag = new IntermediateDialog(StartFrame.this);
165
interDiag.setSize(300, 200);
166
167
// may need listener to watch this move.
168
interDiag.setLocation(getLocationOnScreen());
169
interDiag.pack();
170
interDiag.setVisible(true);
171
}
172
});
173
Panel pan = new Panel();
174
pan.add(but);
175
add(pan);
176
setVisible(true);
177
robot_button[0] = but;
178
}
179
}
180
181
///////////////////////////// VARIOUS DIALOGS //////////////////////////
182
/* A Dialog that launches a sub-dialog */
183
class IntermediateDialog extends Dialog {
184
185
Dialog m_parent;
186
187
public IntermediateDialog(Frame parent) {
188
super(parent, "Intermediate Modal", true /*Modal*/);
189
m_parent = this;
190
Button but = new Button("Make Text");
191
but.addActionListener(new java.awt.event.ActionListener() {
192
public void actionPerformed(ActionEvent e) {
193
txtDiag = new TextDialog(m_parent);
194
txtDiag.setSize(300, 100);
195
txtDiag.setVisible(true);
196
}
197
});
198
Panel pan = new Panel();
199
pan.add(but);
200
add(pan);
201
pack();
202
203
// The robot needs to know about us, so set global
204
robot_button[1] = but;
205
}
206
}
207
208
/* A Dialog that just holds a text field */
209
class TextDialog extends Dialog {
210
211
public TextDialog(Dialog parent) {
212
super(parent, "Modeless Dialog", false /*Modeless*/);
213
TextField txt = new TextField("", 10);
214
Panel pan = new Panel();
215
pan.add(txt);
216
add(pan);
217
pack();
218
219
// The robot needs to know about us, so set global
220
robot_text = txt;
221
}
222
}
223
224
public static void main(String[] args) throws RuntimeException {
225
try {
226
new NestedModelessDialogTest().testModelessDialogs();
227
} catch (Exception e) {
228
throw new RuntimeException("NestedModelessDialogTest object "
229
+ "creation failed");
230
}
231
}
232
}
233
234