0N/A/*
3261N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
3109N/A * @test
0N/A * @bug 7186371
0N/A * @summary [macosx] Main menu shortcuts not displayed
0N/A * @author vera.akulova@oracle.com
0N/A * @run main/manual ShortcutNotDisplayedTest
0N/A */
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport javax.swing.*;
0N/A
0N/Apublic class ShortcutNotDisplayedTest {
0N/A static volatile boolean done = false;
0N/A static volatile boolean pass = false;
0N/A static final String PASS_COMMAND = "pass";
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A if (sun.awt.OSInfo.getOSType() != sun.awt.OSInfo.OSType.MACOSX) {
0N/A System.out.println("This test is for MacOS only. Automatically passed on other platforms.");
0N/A return;
0N/A }
0N/A System.setProperty("apple.laf.useScreenMenuBar", "true");
0N/A SwingUtilities.invokeAndWait(new Runnable() {
0N/A public void run() {
0N/A createAndShowGUI();
0N/A }
0N/A });
0N/A
0N/A do { try { Thread.sleep(300); } catch (Exception e) {} } while (!done) ;
0N/A if (!pass) {
0N/A throw new Exception("Shortcuts not displayed as expected in the screen menu bar.");
46N/A }
46N/A }
46N/A
46N/A private static void createAndShowGUI() {
46N/A JMenuItem newItem = new JMenuItem("Exit");
46N/A newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, java.awt.event.InputEvent.META_MASK));
46N/A
46N/A JMenu menu = new JMenu("Test Frame Window Menu");
46N/A menu.setMnemonic(KeyEvent.VK_M);
46N/A menu.add(newItem);
46N/A
46N/A JMenuBar bar = new JMenuBar();
46N/A bar.add(menu);
46N/A JTextArea text = new JTextArea(
46N/A " Please follow instructions:\n" +
46N/A " 1. You should see \"Test Frame Window Menu\" menu on the screen menu bar.\n" +
46N/A " 2. Open \"Test Frame Window Menu\" menu. \n" +
46N/A " Check that menu item \"Exit\" has a shortcut with image for Command Key and symbol \"E\". \n" +
46N/A " If you see the shortcut press \"Passed\". Otherwise press \"Failed\".\n"
46N/A );
46N/A text.setEditable(false);
46N/A
46N/A JScrollPane sp = new JScrollPane(text);
3109N/A sp.setSize(300,200);
3109N/A
3109N/A JButton passBtn = new JButton("Pass");
3109N/A passBtn.setActionCommand(PASS_COMMAND);
3109N/A JButton failBtn = new JButton("Fail");
3109N/A ActionListener listener = new ActionListener() {
3109N/A public void actionPerformed(ActionEvent e) {
3109N/A if (e.getActionCommand().equals(PASS_COMMAND)) {
3109N/A pass = true;
3109N/A }
3109N/A done = true;
3109N/A }
3109N/A };
3109N/A
3109N/A JFrame testFrame = new JFrame("Test Frame Window");
46N/A testFrame.setLayout(new FlowLayout());
46N/A testFrame.setBounds(100, 100, 600, 180);
46N/A testFrame.setJMenuBar(bar);
46N/A testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
3109N/A passBtn.addActionListener(listener);
46N/A failBtn.addActionListener(listener);
46N/A testFrame.getContentPane().add(sp);
46N/A testFrame.getContentPane().add(passBtn);
46N/A testFrame.getContentPane().add(failBtn);
46N/A testFrame.setVisible(true);
46N/A }
46N/A}
46N/A