< prev index next >

jdk/test/java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java

Print this page




  46 public class UnfocusableToplevel {
  47 
  48     final static Robot robot = Util.createRobot();
  49     final static int REASONABLE_PATH_TIME = 5000;
  50 
  51     public static void main(String []s)
  52     {
  53         Frame f = new Frame();
  54         Window w = new Window(f);
  55         final Choice ch = new Choice();
  56 
  57         ch.add("item 1");
  58         ch.add("item 2");
  59         ch.add("item 3");
  60         ch.add("item 4");
  61         ch.add("item 5");
  62         w.add(ch);
  63         w.setLayout(new FlowLayout());
  64         w.setSize(200, 200);
  65 








  66         ch.addKeyListener(new KeyAdapter(){
  67                 public void keyTyped(KeyEvent e){
  68                     traceEvent("keytyped", e);
  69                 }
  70                 public void keyPressed(KeyEvent e){
  71                     traceEvent("keypress", e);
  72                 }
  73                 public void keyReleased(KeyEvent e){
  74                     traceEvent("keyrelease", e);
  75                 }
  76         });
  77 
  78         ch.addItemListener(new ItemListener(){
  79                 public void itemStateChanged(ItemEvent ie){
  80                     traceEvent("stateChanged", ie);
  81                 }
  82             });
  83 
  84         w.setVisible(true);
  85 
  86         Util.waitForIdle(robot);
  87 
  88         Util.clickOnComp(ch, robot);
  89         Util.waitForIdle(robot);
  90 
  91         // will not test if the dropdown become opened as there is no reliable
  92         // technique to accomplish that rather then checking color of dropdown
  93         // Will suppose that the dropdown appears
  94 
  95         testKeys();
  96         Util.waitForIdle(robot);




  97     }
  98 
  99     private static void testKeys(){
 100         typeKey(KeyEvent.VK_UP);
 101         typeKey(KeyEvent.VK_DOWN);
 102         typeKey(KeyEvent.VK_K);
 103         typeKey(KeyEvent.VK_PAGE_UP);
 104         typeKey(KeyEvent.VK_PAGE_DOWN);
 105     }
 106 
 107     private static void typeKey(int keyChar){
 108         try {
 109             robot.keyPress(keyChar);
 110             robot.delay(5);
 111         } finally {
 112             robot.keyRelease(keyChar);
 113         }
 114         robot.delay(100);
 115     }
 116 


  46 public class UnfocusableToplevel {
  47 
  48     final static Robot robot = Util.createRobot();
  49     final static int REASONABLE_PATH_TIME = 5000;
  50 
  51     public static void main(String []s)
  52     {
  53         Frame f = new Frame();
  54         Window w = new Window(f);
  55         final Choice ch = new Choice();
  56 
  57         ch.add("item 1");
  58         ch.add("item 2");
  59         ch.add("item 3");
  60         ch.add("item 4");
  61         ch.add("item 5");
  62         w.add(ch);
  63         w.setLayout(new FlowLayout());
  64         w.setSize(200, 200);
  65 
  66         // fix for 8039467 : [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java -
  67         // - lefts keystrokes in a keyboard buffer on Windows
  68         // FIX: As Window w is non focusable, key press events will not be consumed by w.
  69         // So creating tempFrameToHoldFocus frame, to consume key press events
  70         Frame tempFrameToHoldFocus = new Frame();
  71         tempFrameToHoldFocus.setVisible(true);
  72         tempFrameToHoldFocus.requestFocus();
  73 
  74         ch.addKeyListener(new KeyAdapter(){
  75                 public void keyTyped(KeyEvent e){
  76                     traceEvent("keytyped", e);
  77                 }
  78                 public void keyPressed(KeyEvent e){
  79                     traceEvent("keypress", e);
  80                 }
  81                 public void keyReleased(KeyEvent e){
  82                     traceEvent("keyrelease", e);
  83                 }
  84         });
  85 
  86         ch.addItemListener(new ItemListener(){
  87                 public void itemStateChanged(ItemEvent ie){
  88                     traceEvent("stateChanged", ie);
  89                 }
  90             });
  91 
  92         w.setVisible(true);
  93 
  94         Util.waitForIdle(robot);
  95 
  96         Util.clickOnComp(ch, robot);
  97         Util.waitForIdle(robot);
  98 
  99         // will not test if the dropdown become opened as there is no reliable
 100         // technique to accomplish that rather then checking color of dropdown
 101         // Will suppose that the dropdown appears
 102 
 103         testKeys();
 104         Util.waitForIdle(robot);
 105 
 106         tempFrameToHoldFocus.dispose();
 107         w.dispose();
 108         f.dispose();
 109     }
 110 
 111     private static void testKeys(){
 112         typeKey(KeyEvent.VK_UP);
 113         typeKey(KeyEvent.VK_DOWN);
 114         typeKey(KeyEvent.VK_K);
 115         typeKey(KeyEvent.VK_PAGE_UP);
 116         typeKey(KeyEvent.VK_PAGE_DOWN);
 117     }
 118 
 119     private static void typeKey(int keyChar){
 120         try {
 121             robot.keyPress(keyChar);
 122             robot.delay(5);
 123         } finally {
 124             robot.keyRelease(keyChar);
 125         }
 126         robot.delay(100);
 127     }
 128 
< prev index next >