< prev index next >

test/jdk/java/awt/KeyboardFocusmanager/TypeAhead/SubMenuShowTest/SubMenuShowTest.java

Print this page
rev 51542 : 8210039: move OSInfo to top level testlibrary
Reviewed-by: duke


  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 import test.java.awt.regtesthelpers.Util;
  39 import jdk.testlibrary.OSInfo;
  40 
  41 public class SubMenuShowTest extends Applet {
  42     Robot robot;
  43     JFrame frame = new JFrame("Test Frame");
  44     JMenuBar bar = new JMenuBar();
  45     JMenu menu = new JMenu("Menu");
  46     JMenu submenu = new JMenu("More");
  47     JMenuItem item = new JMenuItem("item");
  48     AtomicBoolean activated = new AtomicBoolean(false);
  49 
  50     public static void main(String[] args) {
  51         SubMenuShowTest app = new SubMenuShowTest();
  52         app.init();
  53         app.start();
  54     }
  55 
  56     public void init() {
  57         robot = Util.createRobot();
  58         robot.setAutoDelay(200);
  59         robot.setAutoWaitForIdle(true);


  68         menu.setMnemonic('f');
  69         submenu.setMnemonic('m');
  70         menu.add(submenu);
  71         submenu.add(item);
  72         bar.add(menu);
  73         frame.setJMenuBar(bar);
  74         frame.pack();
  75 
  76         item.addActionListener(new ActionListener() {
  77                 public void actionPerformed(ActionEvent e) {
  78                     System.out.println(e.toString());
  79                     synchronized (activated) {
  80                         activated.set(true);
  81                         activated.notifyAll();
  82                     }
  83                 }
  84             });
  85 
  86         frame.setVisible(true);
  87 
  88         boolean isMacOSX = (OSInfo.getOSType() == OSInfo.OSType.MACOSX);
  89         if (isMacOSX) {
  90             robot.keyPress(KeyEvent.VK_CONTROL);
  91         }
  92         robot.keyPress(KeyEvent.VK_ALT);
  93         robot.keyPress(KeyEvent.VK_F);
  94         robot.keyRelease(KeyEvent.VK_F);
  95         robot.keyRelease(KeyEvent.VK_ALT);
  96 
  97         if (isMacOSX) {
  98             robot.keyRelease(KeyEvent.VK_CONTROL);
  99         }
 100 
 101         robot.keyPress(KeyEvent.VK_M);
 102         robot.keyRelease(KeyEvent.VK_M);
 103         robot.keyPress(KeyEvent.VK_SPACE);
 104         robot.keyRelease(KeyEvent.VK_SPACE);
 105 
 106         if (!Util.waitForCondition(activated, 2000)) {
 107             throw new TestFailedException("a submenu wasn't activated by mnemonic key press");
 108         }


  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);


  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 
 107         if (!Util.waitForCondition(activated, 2000)) {
 108             throw new TestFailedException("a submenu wasn't activated by mnemonic key press");
 109         }
< prev index next >