Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JMenuItem/ShortcutNotDiplayed/ShortcutNotDisplayedTest.java
41152 views
1
/*
2
* Copyright (c) 2012, 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
* @bug 7186371
27
* @summary [macosx] Main menu shortcuts not displayed
28
* @author [email protected]
29
* @library /test/lib
30
* @build jdk.test.lib.Platform
31
* @run main/manual ShortcutNotDisplayedTest
32
*/
33
34
import jdk.test.lib.Platform;
35
36
import java.awt.*;
37
import java.awt.event.*;
38
import javax.swing.*;
39
40
public class ShortcutNotDisplayedTest {
41
static volatile boolean done = false;
42
static volatile boolean pass = false;
43
static final String PASS_COMMAND = "pass";
44
45
public static void main(String[] args) throws Exception {
46
if (!Platform.isOSX()) {
47
System.out.println("This test is for MacOS only. Automatically passed on other platforms.");
48
return;
49
}
50
System.setProperty("apple.laf.useScreenMenuBar", "true");
51
SwingUtilities.invokeAndWait(new Runnable() {
52
public void run() {
53
createAndShowGUI();
54
}
55
});
56
57
do { try { Thread.sleep(300); } catch (Exception e) {} } while (!done) ;
58
if (!pass) {
59
throw new Exception("Shortcuts not displayed as expected in the screen menu bar.");
60
}
61
}
62
63
private static void createAndShowGUI() {
64
JMenuItem newItem = new JMenuItem("Exit");
65
newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, java.awt.event.InputEvent.META_MASK));
66
67
JMenu menu = new JMenu("Test Frame Window Menu");
68
menu.setMnemonic(KeyEvent.VK_M);
69
menu.add(newItem);
70
71
JMenuBar bar = new JMenuBar();
72
bar.add(menu);
73
JTextArea text = new JTextArea(
74
" Please follow instructions:\n" +
75
" 1. You should see \"Test Frame Window Menu\" menu on the screen menu bar.\n" +
76
" 2. Open \"Test Frame Window Menu\" menu. \n" +
77
" Check that menu item \"Exit\" has a shortcut with image for Command Key and symbol \"E\". \n" +
78
" If you see the shortcut press \"Passed\". Otherwise press \"Failed\".\n"
79
);
80
text.setEditable(false);
81
82
JScrollPane sp = new JScrollPane(text);
83
sp.setSize(300,200);
84
85
JButton passBtn = new JButton("Pass");
86
passBtn.setActionCommand(PASS_COMMAND);
87
JButton failBtn = new JButton("Fail");
88
ActionListener listener = new ActionListener() {
89
public void actionPerformed(ActionEvent e) {
90
if (e.getActionCommand().equals(PASS_COMMAND)) {
91
pass = true;
92
}
93
done = true;
94
}
95
};
96
97
JFrame testFrame = new JFrame("Test Frame Window");
98
testFrame.setLayout(new FlowLayout());
99
testFrame.setBounds(100, 100, 600, 180);
100
testFrame.setJMenuBar(bar);
101
testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
102
passBtn.addActionListener(listener);
103
failBtn.addActionListener(listener);
104
testFrame.getContentPane().add(sp);
105
testFrame.getContentPane().add(passBtn);
106
testFrame.getContentPane().add(failBtn);
107
testFrame.setVisible(true);
108
}
109
}
110
111