Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java
41152 views
1
/*
2
* Copyright (c) 2007, 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
@key headful
27
@bug 6566434 8039467
28
@library ../../regtesthelpers
29
@build Util Sysout AbstractTest
30
@summary Choice in unfocusable window responds to keyboard
31
@author Andrei Dmitriev: area=awt-choice
32
@run main UnfocusableToplevel
33
*/
34
35
/**
36
* UnfocusableToplevel.java
37
*
38
* summary:
39
*/
40
41
import java.awt.AWTEvent;
42
import java.awt.Choice;
43
import java.awt.FlowLayout;
44
import java.awt.Frame;
45
import java.awt.Robot;
46
import java.awt.Window;
47
import java.awt.event.ItemEvent;
48
import java.awt.event.ItemListener;
49
import java.awt.event.KeyAdapter;
50
import java.awt.event.KeyEvent;
51
52
import test.java.awt.regtesthelpers.AbstractTest;
53
import test.java.awt.regtesthelpers.Util;
54
55
public class UnfocusableToplevel {
56
57
final static Robot robot = Util.createRobot();
58
final static int REASONABLE_PATH_TIME = 5000;
59
60
public static void main(String []s)
61
{
62
Frame f = new Frame();
63
Window w = new Window(f);
64
final Choice ch = new Choice();
65
66
ch.add("item 1");
67
ch.add("item 2");
68
ch.add("item 3");
69
ch.add("item 4");
70
ch.add("item 5");
71
w.add(ch);
72
w.setLayout(new FlowLayout());
73
w.setSize(200, 200);
74
75
// Note that Window w is non focusable. Key press events will not be
76
// consumed by w, but by any previously focused window & this can
77
// disturb the environment. So creating tempFrameToHoldFocus frame,
78
// to consume key press events.
79
Frame tempFrameToHoldFocus = new Frame();
80
tempFrameToHoldFocus.setSize(300, 300);
81
tempFrameToHoldFocus.setLocationRelativeTo(null);
82
tempFrameToHoldFocus.setVisible(true);
83
Util.waitForIdle(robot);
84
85
tempFrameToHoldFocus.requestFocus();
86
Util.clickOnComp(tempFrameToHoldFocus, robot);
87
Util.waitForIdle(robot);
88
89
ch.addKeyListener(new KeyAdapter(){
90
public void keyTyped(KeyEvent e){
91
traceEvent("keytyped", e);
92
}
93
public void keyPressed(KeyEvent e){
94
traceEvent("keypress", e);
95
}
96
public void keyReleased(KeyEvent e){
97
traceEvent("keyrelease", e);
98
}
99
});
100
101
ch.addItemListener(new ItemListener(){
102
public void itemStateChanged(ItemEvent ie){
103
traceEvent("stateChanged", ie);
104
}
105
});
106
w.setLocationRelativeTo(null);
107
w.setVisible(true);
108
109
Util.waitForIdle(robot);
110
111
Util.clickOnComp(ch, robot);
112
Util.waitForIdle(robot);
113
114
// will not test if the dropdown become opened as there is no reliable
115
// technique to accomplish that rather then checking color of dropdown
116
// Will suppose that the dropdown appears
117
118
testKeys();
119
Util.waitForIdle(robot);
120
121
tempFrameToHoldFocus.dispose();
122
w.dispose();
123
f.dispose();
124
}
125
126
private static void testKeys(){
127
typeKey(KeyEvent.VK_UP);
128
typeKey(KeyEvent.VK_DOWN);
129
typeKey(KeyEvent.VK_K);
130
typeKey(KeyEvent.VK_PAGE_UP);
131
typeKey(KeyEvent.VK_PAGE_DOWN);
132
}
133
134
private static void typeKey(int keyChar){
135
try {
136
robot.keyPress(keyChar);
137
robot.delay(5);
138
} finally {
139
robot.keyRelease(keyChar);
140
}
141
robot.delay(100);
142
}
143
144
private static void traceEvent(String message, AWTEvent e){
145
AbstractTest.fail(message + " " + e.toString());
146
}
147
}
148
149