Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JPopupMenu/6544309/bug6544309.java
41155 views
1
/*
2
* Copyright (c) 2011, 2016, 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
@test
25
@key headful
26
@bug 6544309
27
@summary Checks that 'Select Input Method' popup menu allows to select
28
items with keyboard.
29
@run main bug6544309
30
*/
31
import java.awt.Robot;
32
import java.awt.event.ActionEvent;
33
import java.awt.event.ActionListener;
34
import java.awt.event.KeyEvent;
35
36
import javax.swing.JDialog;
37
import javax.swing.JMenuItem;
38
import javax.swing.JPopupMenu;
39
import javax.swing.SwingUtilities;
40
41
public class bug6544309 {
42
private JDialog dialog;
43
private boolean passed;
44
private static Robot robot;
45
46
public static void main(String[] args) throws Exception {
47
robot = new Robot();
48
robot.setAutoDelay(100);
49
// move mouse outside menu to prevent auto selection
50
robot.mouseMove(100,100);
51
robot.waitForIdle();
52
53
final bug6544309 test = new bug6544309();
54
try {
55
SwingUtilities.invokeAndWait(new Runnable() {
56
public void run() {
57
test.setupUI();
58
}
59
});
60
robot.waitForIdle();
61
robot.delay(1000);
62
test.test();
63
System.out.println("Test passed");
64
} finally {
65
if (test.dialog != null) {
66
test.dialog.dispose();
67
}
68
}
69
}
70
71
private void setupUI() {
72
dialog = new JDialog();
73
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
74
dialog.setSize(200, 100);
75
dialog.setLocationRelativeTo(null);
76
dialog.setVisible(true);
77
78
JPopupMenu popup = new JPopupMenu();
79
popup.add(new JMenuItem("one"));
80
JMenuItem two = new JMenuItem("two");
81
two.addActionListener(new ActionListener() {
82
public void actionPerformed(ActionEvent e) {
83
passed = true;
84
}
85
});
86
popup.add(two);
87
popup.add(new JMenuItem("three"));
88
popup.show(dialog, 50, 50);
89
}
90
91
private void test() throws Exception {
92
testImpl();
93
checkResult();
94
}
95
96
97
private void testImpl() throws Exception {
98
robot.waitForIdle();
99
System.out.println("Pressing DOWN ARROW");
100
robot.keyPress(KeyEvent.VK_DOWN);
101
robot.keyRelease(KeyEvent.VK_DOWN);
102
robot.waitForIdle();
103
System.out.println("Pressing DOWN ARROW");
104
robot.keyPress(KeyEvent.VK_DOWN);
105
robot.keyRelease(KeyEvent.VK_DOWN);
106
robot.waitForIdle();
107
System.out.println("Pressing SPACE");
108
robot.keyPress(KeyEvent.VK_SPACE);
109
robot.keyRelease(KeyEvent.VK_SPACE);
110
}
111
112
private void checkResult() {
113
robot.waitForIdle();
114
if (!passed) {
115
throw new RuntimeException("If a JDialog is invoker for JPopupMenu, " +
116
"the menu cannot be handled by keyboard.");
117
}
118
}
119
}
120
121