< prev index next >

test/jdk/java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java

Print this page


   1 /*
   2  * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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 import test.java.awt.regtesthelpers.Util;
  25 
  26 import javax.swing.*;
  27 import java.awt.*;
  28 import java.awt.event.MouseEvent;
  29 import java.awt.event.MouseMotionAdapter;
  30 
  31 /**
  32  * @test
  33  * @key headful
  34  * @bug 8012026 8027154

  35  * @summary Component.getMousePosition() does not work in an applet on MacOS
  36  * @author Petr Pchelko
  37  * @library ../../regtesthelpers
  38  * @build Util
  39  * @compile GetMousePositionWithPopup.java
  40  * @run main/othervm GetMousePositionWithPopup
  41  */
  42 
  43 public class GetMousePositionWithPopup {
  44 
  45     private static Frame frame1;
  46     private static Frame frame2;
  47 
  48     public static void main(String[] args) throws Exception {
  49         try {
  50         Robot r = Util.createRobot();
  51         r.mouseMove(0, 0);
  52         Util.waitForIdle(null);
  53 
  54         SwingUtilities.invokeAndWait(new Runnable() {
  55             @Override
  56             public void run() {
  57                 constructTestUI();
  58             }
  59         });
  60 


  73                 }
  74             });
  75         }
  76     }
  77 
  78     private static void constructTestUI() {
  79         frame1 = new Frame();
  80         frame1.setBounds(100, 100, 100, 100);
  81         frame1.addMouseMotionListener(new MouseMotionAdapter() {
  82 
  83             @Override
  84             public void mouseMoved(MouseEvent e) {
  85                 frame2 = new Frame();
  86                 frame2.setBounds(120, 120, 120, 120);
  87 
  88                 frame2.addMouseMotionListener(new MouseMotionAdapter() {
  89                     @Override
  90                     public void mouseMoved(MouseEvent e)
  91                     {
  92                         Point positionInFrame2 = frame2.getMousePosition();
  93                         if (positionInFrame2.x != 30 || positionInFrame2.y != 30) {
  94                             throw new RuntimeException("Wrong position reported. Should be [30, 30] but was [" +
  95                                     positionInFrame2.x + ", " + positionInFrame2.y + "]");
  96                         }
  97 
  98                         Point positionInFrame1 = frame1.getMousePosition();
  99                         if (positionInFrame1 != null) {
 100                             throw new RuntimeException("Wrong position reported. Should be null");
 101                         }
 102                     }
 103                 });
 104 
 105                 frame2.setVisible(true);
 106             }
 107         });
 108         frame1.setVisible(true);
 109     }
 110 }
   1 /*
   2  * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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 import test.java.awt.regtesthelpers.Util;
  25 
  26 import javax.swing.*;
  27 import java.awt.*;
  28 import java.awt.event.MouseEvent;
  29 import java.awt.event.MouseMotionAdapter;
  30 
  31 /**
  32  * @test
  33  * @key headful
  34  * @bug 8012026 8027154 8196017
  35  * @requires (os.family == "mac")
  36  * @summary Component.getMousePosition() does not work in an applet on MacOS
  37  * @author Petr Pchelko
  38  * @library ../../regtesthelpers
  39  * @build Util
  40  * @compile GetMousePositionWithPopup.java
  41  * @run main GetMousePositionWithPopup
  42  */
  43 
  44 public class GetMousePositionWithPopup {
  45 
  46     private static Frame frame1;
  47     private static Frame frame2;
  48 
  49     public static void main(String[] args) throws Exception {
  50         try {
  51         Robot r = Util.createRobot();
  52         r.mouseMove(0, 0);
  53         Util.waitForIdle(null);
  54 
  55         SwingUtilities.invokeAndWait(new Runnable() {
  56             @Override
  57             public void run() {
  58                 constructTestUI();
  59             }
  60         });
  61 


  74                 }
  75             });
  76         }
  77     }
  78 
  79     private static void constructTestUI() {
  80         frame1 = new Frame();
  81         frame1.setBounds(100, 100, 100, 100);
  82         frame1.addMouseMotionListener(new MouseMotionAdapter() {
  83 
  84             @Override
  85             public void mouseMoved(MouseEvent e) {
  86                 frame2 = new Frame();
  87                 frame2.setBounds(120, 120, 120, 120);
  88 
  89                 frame2.addMouseMotionListener(new MouseMotionAdapter() {
  90                     @Override
  91                     public void mouseMoved(MouseEvent e)
  92                     {
  93                         Point positionInFrame2 = frame2.getMousePosition();
  94                         if ((Math.abs(positionInFrame2.x - 30) > 2) || (Math.abs(positionInFrame2.y - 30) > 2)) {
  95                             throw new RuntimeException("Wrong position reported. Should be [30, 30] but was [" +
  96                                     positionInFrame2.x + ", " + positionInFrame2.y + "]");
  97                         }
  98 
  99                         Point positionInFrame1 = frame1.getMousePosition();
 100                         if (positionInFrame1 != null) {
 101                             throw new RuntimeException("Wrong position reported. Should be null");
 102                         }
 103                     }
 104                 });
 105 
 106                 frame2.setVisible(true);
 107             }
 108         });
 109         frame1.setVisible(true);
 110     }
 111 }
< prev index next >