Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Focus/FocusSubRequestTest/FocusSubRequestTest.java
41152 views
1
/*
2
* Copyright (c) 2004, 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.
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
@key headful
27
@bug 5082319
28
@summary Tests that focus request for already focused component doesn't block key events.
29
@run main FocusSubRequestTest
30
*/
31
32
import java.awt.*;
33
import java.awt.event.*;
34
35
public class FocusSubRequestTest {
36
Frame frame = new Frame("Test Frame");
37
Button button = new Button("button");
38
boolean passed = false;
39
Robot robot;
40
41
public static void main(final String[] args) {
42
FocusSubRequestTest app = new FocusSubRequestTest();
43
app.init();
44
app.start();
45
}
46
47
public void init() {
48
frame.add(button);
49
button.addFocusListener(new FocusAdapter() {
50
public void focusGained(FocusEvent e) {
51
System.out.println("FocusSubRequestTest: focusGained for: " + e.getSource());
52
((Component)e.getSource()).requestFocus();
53
}
54
});
55
56
button.addKeyListener(new KeyAdapter() {
57
public void keyPressed(KeyEvent e) {
58
System.out.println("FocusSubRequestTest: keyPressed for: " + e.getSource());
59
passed = true;
60
}
61
});
62
63
try {
64
robot = new Robot();
65
robot.setAutoDelay(100);
66
} catch(Exception e) {
67
throw new RuntimeException("Error: unable to create robot", e);
68
}
69
}
70
71
public void start() {
72
frame.pack();
73
frame.setLocationRelativeTo(null);
74
frame.setVisible(true);
75
76
waitTillShown(button);
77
frame.toFront();
78
79
robot.delay(100);
80
robot.keyPress(KeyEvent.VK_K);
81
robot.keyRelease(KeyEvent.VK_K);
82
83
robot.waitForIdle();
84
85
if(passed) {
86
System.out.println("Test passed.");
87
} else {
88
throw new RuntimeException("Test failed.");
89
}
90
}
91
92
private void waitTillShown(Component component) {
93
Point p = null;
94
while (p == null) {
95
try {
96
p = component.getLocationOnScreen();
97
} catch (IllegalStateException e) {
98
try {
99
Thread.sleep(500);
100
} catch (InterruptedException ie) {
101
}
102
}
103
}
104
}
105
}
106
107