Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/java/swing/plaf/windows/Test8173145.java
41162 views
1
/*
2
* Copyright (c) 2017, 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
/* @test
25
@key headful
26
@bug 8173145
27
@requires (os.family == "windows")
28
@summary Menu is activated after using mnemonic Alt/Key combination
29
@run main Test8173145
30
*/
31
32
import java.awt.AWTException;
33
import java.awt.Component;
34
import java.awt.KeyboardFocusManager;
35
import java.awt.Robot;
36
import java.awt.event.KeyEvent;
37
import java.lang.reflect.InvocationTargetException;
38
39
import javax.swing.JButton;
40
import javax.swing.JFrame;
41
import javax.swing.JMenu;
42
import javax.swing.JMenuBar;
43
import javax.swing.JMenuItem;
44
import javax.swing.JPanel;
45
import javax.swing.JTextField;
46
import javax.swing.SwingUtilities;
47
import javax.swing.UIManager;
48
49
public class Test8173145 {
50
51
private volatile static JButton btn;
52
private volatile static JFrame f;
53
private volatile static boolean uiCreated;
54
55
public static void main(String[] args) throws InvocationTargetException, InterruptedException, AWTException {
56
try {
57
SwingUtilities.invokeAndWait(new Runnable() {
58
@Override
59
public void run() {
60
try {
61
uiCreated = createGUI();
62
} catch (Exception e) {
63
throw new RuntimeException(e);
64
}
65
}
66
});
67
68
if (uiCreated) {
69
test();
70
} else {
71
//no windows l&f, skip the test
72
}
73
}finally {
74
SwingUtilities.invokeAndWait(() -> f.dispose());
75
}
76
}
77
78
private static void test() {
79
final Robot robot;
80
try {
81
robot = new Robot();
82
} catch (AWTException e) {
83
throw new RuntimeException(e);
84
}
85
robot.setAutoDelay(150);
86
robot.waitForIdle();
87
88
robot.keyPress(KeyEvent.VK_ALT);
89
robot.keyPress(KeyEvent.VK_M);
90
robot.keyRelease(KeyEvent.VK_M);
91
robot.keyRelease(KeyEvent.VK_ALT);
92
robot.waitForIdle();
93
94
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
95
96
if (focusOwner != btn) {
97
throw new RuntimeException("Wrong focus owner");
98
}
99
}
100
101
private static boolean createGUI() {
102
try {
103
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
104
} catch (Exception e) {
105
return false;
106
}
107
f = new JFrame();
108
109
JPanel panel = new JPanel();
110
btn = new JButton("Mmmmm");
111
btn.setMnemonic(KeyEvent.VK_M);
112
btn.setDisplayedMnemonicIndex(0);
113
panel.add(btn);
114
115
JTextField tf = new JTextField();
116
tf.setColumns(10);
117
panel.add(tf);
118
119
f.setJMenuBar(getMenuBar());
120
f.add(panel);
121
f.pack();
122
f.setVisible(true);
123
f.setLocationRelativeTo(null);
124
tf.requestFocus();
125
return true;
126
}
127
128
static JMenuBar getMenuBar() {
129
JMenuBar menuBar;
130
JMenu menu;
131
132
menuBar = new JMenuBar();
133
134
menu = new JMenu("Menu");
135
menuBar.add(menu);
136
137
JMenuItem mi = new JMenuItem("test");
138
menu.add(mi);
139
140
return menuBar;
141
}
142
}
143
144