test/java/awt/Window/Grab/GrabTest.java

Print this page




  48 
  49     static volatile boolean ungrabbed;
  50     static volatile boolean buttonPressed;
  51     static volatile boolean windowPressed;
  52     static volatile boolean framePressed;
  53 
  54     static volatile boolean passed = true;
  55 
  56     public static void main(String[] args) {
  57 
  58         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
  59                 public void eventDispatched(AWTEvent e) {
  60                     System.out.println(e);
  61                     if (e instanceof sun.awt.UngrabEvent) {
  62                         ungrabbed = true;
  63                     }
  64                 }
  65             }, sun.awt.SunToolkit.GRAB_EVENT_MASK);
  66 
  67         f = new Frame("Frame");
  68         f.setSize(200, 200);
  69         f.addMouseListener(new MouseAdapter() {
  70                 public void mousePressed(MouseEvent e) {
  71                     System.out.println(e);
  72                     framePressed = true;
  73                 }
  74             });
  75 
  76         f1 = new Frame("OtherFrame");
  77         f1.setBounds(600, 100, 200, 200);
  78 
  79         w = new Window(f);
  80         w.setLayout(new FlowLayout());
  81         b = new Button("Press");
  82         b.addActionListener(new ActionListener() {
  83                 public void actionPerformed(ActionEvent e) {
  84                     System.out.println(e);
  85                     buttonPressed = true;
  86                 }
  87             });
  88         w.add(b);
  89         w.setBounds(300, 100, 200, 200);
  90         w.setBackground(Color.blue);
  91         w.addMouseListener(new MouseAdapter() {
  92                 public void mousePressed(MouseEvent e) {
  93                     System.out.println(e);
  94                     windowPressed = true;
  95                 }
  96             });
  97 
  98         f.setVisible(true);
  99         w.setVisible(true);
 100 
 101         tk = (sun.awt.SunToolkit)Toolkit.getDefaultToolkit();
 102 
 103         try {
 104             robot = new Robot();
 105         } catch (AWTException ex) {
 106             throw new RuntimeException(ex);
 107         }
 108 
 109         Util.waitForIdle(robot);


 158 
 159         // 5. Check that press on the other frame's title causes ungrab
 160         f1.setVisible(true);
 161         Util.waitForIdle(robot);
 162         Util.clickOnTitle(f1, robot);
 163         if (!ungrabbed) {
 164             passed = false;
 165             System.err.println("Failure: [5] Press inside of other Frame's title didn't cause ungrab");
 166         }
 167         f.requestFocus(); // restore focus
 168         Util.waitForIdle(robot);
 169         if (!f.hasFocus()) {
 170             System.err.println("Error: Frame can't be focused");
 171         }
 172         ungrabbed = false;
 173         tk.grab(w);
 174 
 175 
 176         // 6. Check that press on the outside area causes ungrab
 177         Point loc = f.getLocationOnScreen();
 178         robot.mouseMove(loc.x + 100, loc.y + f.getSize().height + 300);

 179         robot.mousePress(InputEvent.BUTTON1_MASK);
 180         robot.delay(50);
 181         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 182         Util.waitForIdle(robot);
 183         if (!ungrabbed) {
 184             passed = false;
 185             System.err.println("Failure: [6] Press on the outside area didn't cause ungrab");
 186         }
 187         ungrabbed = false;
 188         tk.grab(w);
 189 
 190 
 191         // 7. Check that disposing the window causes ungrab
 192         w.dispose();
 193         Util.waitForIdle(robot);
 194         if (!ungrabbed) {
 195             passed = false;
 196             System.err.println("Failure: [7] Window disposal didn't cause ungrab");
 197         }
 198 


  48 
  49     static volatile boolean ungrabbed;
  50     static volatile boolean buttonPressed;
  51     static volatile boolean windowPressed;
  52     static volatile boolean framePressed;
  53 
  54     static volatile boolean passed = true;
  55 
  56     public static void main(String[] args) {
  57 
  58         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
  59                 public void eventDispatched(AWTEvent e) {
  60                     System.out.println(e);
  61                     if (e instanceof sun.awt.UngrabEvent) {
  62                         ungrabbed = true;
  63                     }
  64                 }
  65             }, sun.awt.SunToolkit.GRAB_EVENT_MASK);
  66 
  67         f = new Frame("Frame");
  68         f.setBounds(0, 0, 300, 300);
  69         f.addMouseListener(new MouseAdapter() {
  70                 public void mousePressed(MouseEvent e) {
  71                     System.out.println(e);
  72                     framePressed = true;
  73                 }
  74             });
  75 
  76         f1 = new Frame("OtherFrame");
  77         f1.setBounds(700, 100, 200, 200);
  78 
  79         w = new Window(f);
  80         w.setLayout(new FlowLayout());
  81         b = new Button("Press");
  82         b.addActionListener(new ActionListener() {
  83                 public void actionPerformed(ActionEvent e) {
  84                     System.out.println(e);
  85                     buttonPressed = true;
  86                 }
  87             });
  88         w.add(b);
  89         w.setBounds(400, 100, 200, 200);
  90         w.setBackground(Color.blue);
  91         w.addMouseListener(new MouseAdapter() {
  92                 public void mousePressed(MouseEvent e) {
  93                     System.out.println(e);
  94                     windowPressed = true;
  95                 }
  96             });
  97 
  98         f.setVisible(true);
  99         w.setVisible(true);
 100 
 101         tk = (sun.awt.SunToolkit)Toolkit.getDefaultToolkit();
 102 
 103         try {
 104             robot = new Robot();
 105         } catch (AWTException ex) {
 106             throw new RuntimeException(ex);
 107         }
 108 
 109         Util.waitForIdle(robot);


 158 
 159         // 5. Check that press on the other frame's title causes ungrab
 160         f1.setVisible(true);
 161         Util.waitForIdle(robot);
 162         Util.clickOnTitle(f1, robot);
 163         if (!ungrabbed) {
 164             passed = false;
 165             System.err.println("Failure: [5] Press inside of other Frame's title didn't cause ungrab");
 166         }
 167         f.requestFocus(); // restore focus
 168         Util.waitForIdle(robot);
 169         if (!f.hasFocus()) {
 170             System.err.println("Error: Frame can't be focused");
 171         }
 172         ungrabbed = false;
 173         tk.grab(w);
 174 
 175 
 176         // 6. Check that press on the outside area causes ungrab
 177         Point loc = f.getLocationOnScreen();
 178         robot.mouseMove(loc.x + 100, loc.y + f.getSize().height + 1);
 179         Util.waitForIdle(robot);
 180         robot.mousePress(InputEvent.BUTTON1_MASK);
 181         robot.delay(50);
 182         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 183         Util.waitForIdle(robot);
 184         if (!ungrabbed) {
 185             passed = false;
 186             System.err.println("Failure: [6] Press on the outside area didn't cause ungrab");
 187         }
 188         ungrabbed = false;
 189         tk.grab(w);
 190 
 191 
 192         // 7. Check that disposing the window causes ungrab
 193         w.dispose();
 194         Util.waitForIdle(robot);
 195         if (!ungrabbed) {
 196             passed = false;
 197             System.err.println("Failure: [7] Window disposal didn't cause ungrab");
 198         }
 199