jdk/test/java/awt/Robot/MultiScreenRobotPosition/MultiScreenRobotPosition.java
author serb
Thu, 02 Mar 2017 16:24:53 +0300
changeset 44148 35def8dd7581
child 47147 857d25fae728
permissions -rw-r--r--
8176009: The awt robot use incorrect location in a multi-screen environment Reviewed-by: azvegint, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44148
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
     1
/*
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
     4
 *
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
     8
 *
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    13
 * accompanied this code).
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    14
 *
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    18
 *
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    21
 * questions.
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    22
 */
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    23
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    24
import java.awt.Frame;
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    25
import java.awt.GraphicsDevice;
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    26
import java.awt.GraphicsEnvironment;
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    27
import java.awt.Rectangle;
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    28
import java.awt.Robot;
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    29
import java.awt.event.MouseAdapter;
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    30
import java.awt.event.MouseEvent;
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    31
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    32
/**
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    33
 * @test
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    34
 * @bug 8176009
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    35
 */
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    36
public class MultiScreenRobotPosition {
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    37
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    38
    private static volatile boolean fail = true;
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    39
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    41
        GraphicsDevice[] sds = GraphicsEnvironment.getLocalGraphicsEnvironment()
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    42
                                                  .getScreenDevices();
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    43
        for (final GraphicsDevice gd : sds) {
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    44
            fail = true;
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    45
            Robot robot = new Robot(gd);
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    46
            robot.setAutoDelay(100);
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    47
            robot.setAutoWaitForIdle(true);
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    48
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    49
            Frame frame = new Frame(gd.getDefaultConfiguration());
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    50
            frame.setUndecorated(true);
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    51
            frame.setSize(400, 400);
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    52
            frame.setVisible(true);
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    53
            robot.waitForIdle();
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    54
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    55
            frame.addMouseListener(new MouseAdapter() {
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    56
                @Override
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    57
                public void mouseClicked(MouseEvent e) {
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    58
                    System.out.println("e = " + e);
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    59
                    fail = false;
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    60
                }
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    61
            });
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    62
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    63
            Rectangle bounds = frame.getBounds();
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    64
            robot.mouseMove(bounds.x + bounds.width / 2,
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    65
                            bounds.y + bounds.height / 2);
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    66
            robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    67
            robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    68
            frame.dispose();
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    69
            if (fail) {
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    70
                System.err.println("Frame bounds = " + bounds);
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    71
                throw new RuntimeException("Click in the wrong location");
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    72
            }
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    73
        }
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    74
    }
35def8dd7581 8176009: The awt robot use incorrect location in a multi-screen environment
serb
parents:
diff changeset
    75
}