Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/KeyboardFocusmanager/TypeAhead/SubMenuShowTest/SubMenuShowTest.java
42819 views
1
/*
2
* Copyright (c) 2006, 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 6380743 8158380 8198624
28
@summary Submenu should be shown by mnemonic key press.
29
@author anton.tarasov@...: area=awt.focus
30
@library ../../../regtesthelpers
31
@library /test/lib
32
@build Util
33
@build jdk.test.lib.Platform
34
@run main SubMenuShowTest
35
*/
36
37
import java.awt.Robot;
38
import java.awt.BorderLayout;
39
import java.awt.event.KeyEvent;
40
import java.awt.event.ActionListener;
41
import java.awt.event.ActionEvent;
42
import javax.swing.SwingUtilities;
43
import javax.swing.JFrame;
44
import javax.swing.JMenuBar;
45
import javax.swing.JMenu;
46
import javax.swing.JMenuItem;
47
import java.util.concurrent.atomic.AtomicBoolean;
48
import jdk.test.lib.Platform;
49
import test.java.awt.regtesthelpers.Util;
50
51
public class SubMenuShowTest {
52
private static Robot robot;
53
private static JFrame frame;
54
private static JMenuBar bar;
55
private static JMenu menu;
56
private static JMenu submenu;
57
private static JMenuItem item;
58
private static AtomicBoolean activated = new AtomicBoolean(false);
59
60
public static void main(String[] args) throws Exception {
61
SwingUtilities.invokeAndWait(SubMenuShowTest::createAndShowGUI);
62
63
try {
64
robot = new Robot();
65
robot.setAutoDelay(100);
66
robot.setAutoWaitForIdle(true);
67
68
doTest();
69
} catch (Exception ex) {
70
throw new RuntimeException("Test failed: Exception thrown:"+ex);
71
} finally {
72
dispose();
73
}
74
75
System.out.println("Test passed.");
76
}
77
78
public static void dispose() throws Exception {
79
if(frame != null) {
80
SwingUtilities.invokeAndWait(() -> {
81
frame.dispose();
82
});
83
}
84
}
85
86
public static void createAndShowGUI() {
87
// Create instructions for the user here, as well as set up
88
// the environment -- set the layout manager, add buttons,
89
// etc.
90
frame = new JFrame("Test Frame");
91
bar = new JMenuBar();
92
menu = new JMenu("Menu");
93
submenu = new JMenu("More");
94
item = new JMenuItem("item");
95
96
frame.setLayout (new BorderLayout ());
97
menu.setMnemonic('f');
98
submenu.setMnemonic('m');
99
menu.add(submenu);
100
submenu.add(item);
101
bar.add(menu);
102
frame.setJMenuBar(bar);
103
frame.pack();
104
105
item.addActionListener(new ActionListener() {
106
public void actionPerformed(ActionEvent e) {
107
System.out.println(e.toString());
108
synchronized (activated) {
109
activated.set(true);
110
activated.notifyAll();
111
}
112
}
113
});
114
115
frame.setVisible(true);
116
}
117
118
public static void doTest() {
119
boolean isMacOSX = Platform.isOSX();
120
if (isMacOSX) {
121
robot.keyPress(KeyEvent.VK_CONTROL);
122
}
123
robot.keyPress(KeyEvent.VK_ALT);
124
robot.keyPress(KeyEvent.VK_F);
125
robot.keyRelease(KeyEvent.VK_F);
126
robot.keyRelease(KeyEvent.VK_ALT);
127
128
if (isMacOSX) {
129
robot.keyRelease(KeyEvent.VK_CONTROL);
130
}
131
132
robot.keyPress(KeyEvent.VK_M);
133
robot.keyRelease(KeyEvent.VK_M);
134
robot.keyPress(KeyEvent.VK_SPACE);
135
robot.keyRelease(KeyEvent.VK_SPACE);
136
137
if (!Util.waitForCondition(activated, 1500)) {
138
throw new TestFailedException("A submenu wasn't activated by mnemonic key press");
139
}
140
}
141
}
142
143
class TestFailedException extends RuntimeException {
144
TestFailedException(String msg) {
145
super("Test failed: " + msg);
146
}
147
}
148
149