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 6380743 8158380 27 @summary Submenu should be shown by mnemonic key press. 28 @author anton.tarasov@...: area=awt.focus 29 @run applet SubMenuShowTest.html 30 */ 31 32 import java.awt.*; 33 import java.awt.event.*; 34 import javax.swing.*; 35 import java.applet.Applet; 36 import java.util.concurrent.atomic.AtomicBoolean; 37 import java.lang.reflect.InvocationTargetException; 38 39 import jdk.test.lib.Platform; 40 import test.java.awt.regtesthelpers.Util; 41 42 public class SubMenuShowTest extends Applet { 43 Robot robot; 44 JFrame frame = new JFrame("Test Frame"); 45 JMenuBar bar = new JMenuBar(); 46 JMenu menu = new JMenu("Menu"); 47 JMenu submenu = new JMenu("More"); 48 JMenuItem item = new JMenuItem("item"); 49 AtomicBoolean activated = new AtomicBoolean(false); 50 51 public static void main(String[] args) { 52 SubMenuShowTest app = new SubMenuShowTest(); 53 app.init(); 54 app.start(); 55 } 56 57 public void init() { 58 robot = Util.createRobot(); 59 robot.setAutoDelay(200); 60 robot.setAutoWaitForIdle(true); 61 62 // Create instructions for the user here, as well as set up 63 // the environment -- set the layout manager, add buttons, 64 // etc. 65 this.setLayout (new BorderLayout ()); 66 } 67 68 public void start() { 69 menu.setMnemonic('f'); 70 submenu.setMnemonic('m'); 71 menu.add(submenu); 72 submenu.add(item); 73 bar.add(menu); 74 frame.setJMenuBar(bar); 75 frame.pack(); 76 77 item.addActionListener(new ActionListener() { 78 public void actionPerformed(ActionEvent e) { 79 System.out.println(e.toString()); 80 synchronized (activated) { 81 activated.set(true); 82 activated.notifyAll(); 83 } 84 } 85 }); 86 87 frame.setVisible(true); 88 89 boolean isMacOSX = Platform.isOSX(); 90 if (isMacOSX) { 91 robot.keyPress(KeyEvent.VK_CONTROL); 92 } 93 robot.keyPress(KeyEvent.VK_ALT); 94 robot.keyPress(KeyEvent.VK_F); 95 robot.keyRelease(KeyEvent.VK_F); 96 robot.keyRelease(KeyEvent.VK_ALT); 97 98 if (isMacOSX) { 99 robot.keyRelease(KeyEvent.VK_CONTROL); 100 } 101 102 robot.keyPress(KeyEvent.VK_M); 103 robot.keyRelease(KeyEvent.VK_M); 104 robot.keyPress(KeyEvent.VK_SPACE); 105 robot.keyRelease(KeyEvent.VK_SPACE); 106 | 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 28 @summary Submenu should be shown by mnemonic key press. 29 @library ../../../regtesthelpers 30 @library /test/lib 31 @build Util 32 @build jdk.test.lib.Platform 33 @run main SubMenuShowTest 34 */ 35 36 import java.awt.*; 37 import java.awt.event.*; 38 import javax.swing.*; 39 import java.util.concurrent.atomic.AtomicBoolean; 40 41 import jdk.test.lib.Platform; 42 import test.java.awt.regtesthelpers.Util; 43 44 public class SubMenuShowTest { 45 Robot robot; 46 JFrame frame = new JFrame("Test Frame"); 47 JMenuBar bar = new JMenuBar(); 48 JMenu menu = new JMenu("Menu"); 49 JMenu submenu = new JMenu("More"); 50 JMenuItem item = new JMenuItem("item"); 51 AtomicBoolean activated = new AtomicBoolean(false); 52 53 public static void main(String[] args) { 54 SubMenuShowTest app = new SubMenuShowTest(); 55 app.init(); 56 app.start(); 57 } 58 59 public void init() { 60 robot = Util.createRobot(); 61 robot.setAutoDelay(200); 62 robot.setAutoWaitForIdle(true); 63 } 64 65 public void start() { 66 menu.setMnemonic('f'); 67 submenu.setMnemonic('m'); 68 menu.add(submenu); 69 submenu.add(item); 70 bar.add(menu); 71 frame.setJMenuBar(bar); 72 frame.pack(); 73 74 item.addActionListener(new ActionListener() { 75 public void actionPerformed(ActionEvent e) { 76 System.out.println(e.toString()); 77 synchronized (activated) { 78 activated.set(true); 79 activated.notifyAll(); 80 } 81 } 82 }); 83 frame.setLocationRelativeTo(null); 84 frame.setVisible(true); 85 86 boolean isMacOSX = Platform.isOSX(); 87 if (isMacOSX) { 88 robot.keyPress(KeyEvent.VK_CONTROL); 89 } 90 robot.keyPress(KeyEvent.VK_ALT); 91 robot.keyPress(KeyEvent.VK_F); 92 robot.keyRelease(KeyEvent.VK_F); 93 robot.keyRelease(KeyEvent.VK_ALT); 94 95 if (isMacOSX) { 96 robot.keyRelease(KeyEvent.VK_CONTROL); 97 } 98 99 robot.keyPress(KeyEvent.VK_M); 100 robot.keyRelease(KeyEvent.VK_M); 101 robot.keyPress(KeyEvent.VK_SPACE); 102 robot.keyRelease(KeyEvent.VK_SPACE); 103 |