jdk/test/java/awt/Mouse/GetMousePositionTest/GetMousePositionWithPopup.java
author pchelko
Fri, 13 Sep 2013 18:02:18 +0400
changeset 20134 8711b271f96c
child 40128 e635645d2a8a
permissions -rw-r--r--
8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS Reviewed-by: anthony, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20134
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     1
/*
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     4
 *
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     8
 *
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    13
 * accompanied this code).
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    14
 *
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    18
 *
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    21
 * questions.
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    22
 */
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    23
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    24
import test.java.awt.regtesthelpers.Util;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    25
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    26
import javax.swing.*;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    27
import java.awt.*;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    28
import java.awt.event.MouseEvent;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    29
import java.awt.event.MouseMotionAdapter;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    30
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    31
/**
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    32
 * @test
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    33
 * @bug 8012026
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    34
 * @summary Component.getMousePosition() does not work in an applet on MacOS
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    35
 * @author Petr Pchelko
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    36
 * @library ../../regtesthelpers
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    37
 * @build Util
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    38
 * @compile GetMousePositionWithPopup.java
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    39
 * @run main/othervm GetMousePositionWithPopup
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    40
 */
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    41
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    42
public class GetMousePositionWithPopup {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    43
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    44
    private static Frame frame1;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    45
    private static Frame frame2;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    46
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    47
    public static void main(String[] args) throws Exception {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    48
        try {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    49
        Robot r = Util.createRobot();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    50
        r.mouseMove(0, 0);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    51
        Util.waitForIdle(null);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    52
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    53
        SwingUtilities.invokeAndWait(new Runnable() {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    54
            @Override
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    55
            public void run() {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    56
                constructTestUI();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    57
            }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    58
        });
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    59
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    60
        Util.waitForIdle(null);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    61
        r.mouseMove(149, 149);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    62
        Util.waitForIdle(null);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    63
        r.mouseMove(150, 150);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    64
        Util.waitForIdle(null);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    65
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    66
        } finally {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    67
            SwingUtilities.invokeLater(new Runnable() {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    68
                @Override
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    69
                public void run() {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    70
                    frame1.dispose();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    71
                    frame2.dispose();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    72
                }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    73
            });
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    74
        }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    75
    }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    76
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    77
    private static void constructTestUI() {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    78
        frame1 = new Frame();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    79
        frame1.setBounds(100, 100, 100, 100);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    80
        frame1.addMouseMotionListener(new MouseMotionAdapter() {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    81
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    82
            private boolean shown = false;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    83
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    84
            @Override
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    85
            public void mouseMoved(MouseEvent e) {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    86
                if (shown) {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    87
                    return;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    88
                }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    89
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    90
                shown = true;
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    91
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    92
                frame2 = new Frame();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    93
                frame2.setBounds(120, 120, 120, 120);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    94
                frame2.setVisible(true);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    95
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    96
                Point positionInFrame2 = frame2.getMousePosition();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    97
                if (positionInFrame2.x != 30 || positionInFrame2.y != 30) {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    98
                    throw new RuntimeException("Wrong position reported. Should be [30, 30] but was [" +
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
    99
                            positionInFrame2.x + ", " + positionInFrame2.y + "]");
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   100
                }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   101
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   102
                Point positionInFrame1 = frame1.getMousePosition();
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   103
                if (positionInFrame1 != null) {
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   104
                    throw new RuntimeException("Wrong position reported. Should be null");
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   105
                }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   106
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   107
            }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   108
        });
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   109
        frame1.setVisible(true);
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   110
    }
8711b271f96c 8012026: [macosx] Component.getMousePosition() does not work in an applet on MacOS
pchelko
parents:
diff changeset
   111
}