Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JPopupMenu/6827786/bug6827786.java
41153 views
1
/*
2
* Copyright (c) 2007, 2018, 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 6827786
28
* @summary Tests duplicate mnemonics
29
* @author Peter Zhelezniakov
30
* @library ../../regtesthelpers
31
* @library /test/lib
32
* @modules java.desktop/sun.awt
33
* @build jdk.test.lib.Platform
34
* @build Util
35
* @run main bug6827786
36
*/
37
38
import jdk.test.lib.Platform;
39
import java.awt.*;
40
import java.awt.event.KeyEvent;
41
import javax.swing.*;
42
43
public class bug6827786 {
44
45
private static JMenu menu;
46
private static Component focusable;
47
private static JFrame frame;
48
49
public static void main(String[] args) throws Exception {
50
try {
51
Robot robot = new Robot();
52
robot.setAutoDelay(100);
53
// move mouse outside menu to prevent auto selection
54
robot.mouseMove(100,100);
55
robot.waitForIdle();
56
57
SwingUtilities.invokeAndWait(new Runnable() {
58
59
public void run() {
60
createAndShowGUI();
61
}
62
});
63
64
robot.waitForIdle();
65
robot.delay(1000);
66
67
SwingUtilities.invokeAndWait(new Runnable() {
68
69
public void run() {
70
focusable.requestFocus();
71
}
72
});
73
74
robot.waitForIdle();
75
checkfocus();
76
77
// select menu
78
if (Platform.isOSX()) {
79
Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_F);
80
} else {
81
Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_F);
82
}
83
// select submenu
84
Util.hitKeys(robot, KeyEvent.VK_S);
85
robot.waitForIdle();
86
// verify submenu is selected
87
verify(1);
88
89
Util.hitKeys(robot, KeyEvent.VK_S);
90
robot.waitForIdle();
91
// verify last item is selected
92
verify(2);
93
94
Util.hitKeys(robot, KeyEvent.VK_S);
95
robot.waitForIdle();
96
// selection should wrap to first item
97
verify(0);
98
99
System.out.println("PASSED");
100
} finally {
101
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
102
}
103
}
104
105
private static void checkfocus() throws Exception {
106
SwingUtilities.invokeAndWait(new Runnable() {
107
108
public void run() {
109
if (!focusable.isFocusOwner()) {
110
throw new RuntimeException("Button is not the focus owner.");
111
}
112
}
113
});
114
}
115
116
private static void verify(final int index) throws Exception {
117
SwingUtilities.invokeAndWait(new Runnable() {
118
119
@Override
120
public void run() {
121
MenuElement[] path =
122
MenuSelectionManager.defaultManager().getSelectedPath();
123
MenuElement item = path[3];
124
if (item != menu.getMenuComponent(index)) {
125
System.err.println("Selected: " + item);
126
System.err.println("Should be: "
127
+ menu.getMenuComponent(index));
128
throw new RuntimeException("Test Failed");
129
}
130
}
131
});
132
}
133
134
private static JMenuBar createMenuBar() {
135
menu = new JMenu("File");
136
menu.setMnemonic('F');
137
138
menu.add(new JMenuItem("Save", 'S'));
139
140
JMenu sub = new JMenu("Submenu");
141
sub.setMnemonic('S');
142
sub.add(new JMenuItem("Sub Item"));
143
menu.add(sub);
144
145
menu.add(new JMenuItem("Special", 'S'));
146
147
JMenuBar bar = new JMenuBar();
148
bar.add(menu);
149
return bar;
150
}
151
152
private static void createAndShowGUI() {
153
frame = new JFrame("bug6827786");
154
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
155
frame.setJMenuBar(createMenuBar());
156
focusable = new JButton("Set Focus Here");
157
frame.add(focusable);
158
frame.pack();
159
frame.setLocationRelativeTo(null);
160
frame.setVisible(true);
161
}
162
}
163
164