1/* 2 * Copyright (c) 2015, 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 24import java.awt.AWTException; 25import java.awt.Frame; 26import java.awt.GraphicsConfiguration; 27import java.awt.GraphicsDevice; 28import java.awt.GraphicsEnvironment; 29import java.awt.Robot; 30import java.awt.Window; 31import java.awt.event.InputEvent; 32 33import static java.awt.GraphicsEnvironment.*; 34 35/** 36 * @test 37 * @key headful 38 * @bug 6778087 39 */ 40public final class MouseWheelAbsXY { 41 42 private static boolean done; 43 private static int wheelX; 44 private static int wheelY; 45 private static int mouseX; 46 private static int mouseY; 47 48 public static void main(final String[] args) throws AWTException { 49 GraphicsEnvironment ge = getLocalGraphicsEnvironment(); 50 GraphicsDevice[] sds = ge.getScreenDevices(); 51 for (GraphicsDevice gd : sds) { 52 test(gd.getDefaultConfiguration()); 53 } 54 } 55 56 private static void test(GraphicsConfiguration gc) throws AWTException { 57 final Window frame = new Frame(gc); 58 try { 59 frame.addMouseWheelListener(e -> { 60 wheelX = e.getXOnScreen(); 61 wheelY = e.getYOnScreen(); 62 done = true; 63 }); 64 frame.setSize(300, 300); 65 frame.setVisible(true); 66 67 final Robot robot = new Robot(); 68 robot.setAutoDelay(50); 69 robot.setAutoWaitForIdle(true); 70 mouseX = frame.getX() + frame.getWidth() / 2; 71 mouseY = frame.getY() + frame.getHeight() / 2; 72 73 robot.mouseMove(mouseX, mouseY); 74 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); 75 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); 76 robot.mouseWheel(10); 77 78 validate(); 79 } finally { 80 frame.dispose(); 81 } 82 } 83 84 private static void validate() { 85 if (!done || wheelX != mouseX || wheelY != mouseY) { 86 System.err.println("Expected X: " + mouseX); 87 System.err.println("Expected Y: " + mouseY); 88 System.err.println("Actual X: " + wheelX); 89 System.err.println("Actual Y: " + wheelY); 90 throw new RuntimeException("Test failed"); 91 } 92 } 93} 94