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