< prev index next >

test/java/awt/Mouse/EnterExitEvents/DragWindowOutOfFrameTest.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 22,46 **** */ /* * @test * @key headful ! * @bug 7154048 * @summary Window created under a mouse does not receive mouse enter event. * Mouse Entered/Exited events should be generated during dragging the window * out of the frame and to the frame. * @library ../../regtesthelpers * @build Util * @author alexandr.scherbatiy area=awt.event * @run main DragWindowOutOfFrameTest */ ! import java.awt.*; ! import java.awt.event.*; ! import javax.swing.*; ! ! import java.util.concurrent.*; ! import test.java.awt.regtesthelpers.Util; public class DragWindowOutOfFrameTest { private static volatile int dragWindowMouseEnteredCount = 0; --- 22,57 ---- */ /* * @test * @key headful ! * @bug 7154048 8177326 * @summary Window created under a mouse does not receive mouse enter event. * Mouse Entered/Exited events should be generated during dragging the window * out of the frame and to the frame. * @library ../../regtesthelpers * @build Util * @author alexandr.scherbatiy area=awt.event * @run main DragWindowOutOfFrameTest */ ! import java.awt.Robot; ! import java.awt.Point; ! import java.awt.Component; ! import java.awt.Rectangle; ! import java.awt.Window; ! import java.awt.BorderLayout; ! import java.awt.Panel; ! import java.awt.event.InputEvent; ! import java.awt.event.MouseEvent; ! import java.awt.event.MouseAdapter; ! import javax.swing.JFrame; ! import javax.swing.JPanel; ! import javax.swing.JButton; ! import javax.swing.JLabel; ! import javax.swing.SwingUtilities; ! import java.util.concurrent.Callable; ! import java.util.Random; import test.java.awt.regtesthelpers.Util; public class DragWindowOutOfFrameTest { private static volatile int dragWindowMouseEnteredCount = 0;
*** 52,61 **** --- 63,73 ---- private static volatile int labelMouseExitedCount = 0; private static volatile int labelMouseReleasedCount = 0; private static MyDragWindow dragWindow; private static JLabel label; private static JButton button; + private static JFrame frame; public static void main(String[] args) throws Exception { Robot robot = new Robot(); robot.setAutoDelay(50);
*** 76,88 **** public Point call() throws Exception { return getCenterPoint(label); } }); robot.mouseMove(pointToClick.x, pointToClick.y); ! robot.mousePress(InputEvent.BUTTON1_MASK); robot.waitForIdle(); if (dragWindowMouseEnteredCount != 1 && dragWindowMouseExitedCount != 0) { throw new RuntimeException( "Wrong number mouse Entered/Exited events on Drag Window!"); --- 88,106 ---- public Point call() throws Exception { return getCenterPoint(label); } }); + /* The mouse is moved at the beginning of the test to make sure the initial mouse move + on the label always happens. + */ + robot.mouseMove(pointToClick.x, pointToClick.y + 10); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); robot.mouseMove(pointToClick.x, pointToClick.y); ! robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); robot.waitForIdle(); if (dragWindowMouseEnteredCount != 1 && dragWindowMouseExitedCount != 0) { throw new RuntimeException( "Wrong number mouse Entered/Exited events on Drag Window!");
*** 125,151 **** if (buttonMouseEnteredCount != 1 && buttonMouseExitedCount != 0) { throw new RuntimeException( "Wrong number Mouse Entered/Exited events on button!"); } ! robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.waitForIdle(); if (labelMouseReleasedCount != 1) { throw new RuntimeException("No MouseReleased event on label!"); } } private static Point getCenterPoint(Component comp) { Point p = comp.getLocationOnScreen(); Rectangle rect = comp.getBounds(); return new Point(p.x + rect.width / 2, p.y + rect.height / 2); } private static void createAndShowGUI() { ! JFrame frame = new JFrame("Main Frame"); frame.setLocation(100, 100); frame.setSize(300, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); label = new JLabel("Label"); --- 143,171 ---- if (buttonMouseEnteredCount != 1 && buttonMouseExitedCount != 0) { throw new RuntimeException( "Wrong number Mouse Entered/Exited events on button!"); } ! robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); robot.waitForIdle(); if (labelMouseReleasedCount != 1) { throw new RuntimeException("No MouseReleased event on label!"); } + + frame.dispose(); } private static Point getCenterPoint(Component comp) { Point p = comp.getLocationOnScreen(); Rectangle rect = comp.getBounds(); return new Point(p.x + rect.width / 2, p.y + rect.height / 2); } private static void createAndShowGUI() { ! frame = new JFrame("Main Frame"); frame.setLocation(100, 100); frame.setSize(300, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); label = new JLabel("Label");
< prev index next >