5124N/A/*
5124N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
5124N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5124N/A *
5124N/A * This code is free software; you can redistribute it and/or modify it
5124N/A * under the terms of the GNU General Public License version 2 only, as
5124N/A * published by the Free Software Foundation.
5124N/A *
5124N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5124N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5124N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5124N/A * version 2 for more details (a copy is included in the LICENSE file that
5124N/A * accompanied this code).
5124N/A *
5124N/A * You should have received a copy of the GNU General Public License version
5124N/A * 2 along with this work; if not, write to the Free Software Foundation,
5124N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5124N/A *
5124N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5124N/A * or visit www.oracle.com if you need additional information or have any
5124N/A * questions.
5124N/A */
5124N/A
5124N/A/*
5124N/A * @test
5124N/A * @bug 7154048
5124N/A * @summary Programmatically resized window does not receive mouse entered/exited events
5124N/A * @author alexandr.scherbatiy area=awt.event
5124N/A * @run main ResizingFrameTest
5124N/A */
5124N/A/*
5124N/A * To change this template, choose Tools | Templates
5124N/A * and open the template in the editor.
5124N/A */
5124N/A
5124N/Aimport java.awt.*;
5124N/Aimport java.awt.event.*;
5124N/Aimport javax.swing.*;
5124N/Aimport sun.awt.SunToolkit;
5124N/A
5124N/Apublic class ResizingFrameTest {
5124N/A
5124N/A private static volatile int mouseEnteredCount = 0;
5124N/A private static volatile int mouseExitedCount = 0;
5124N/A private static JFrame frame;
5124N/A
5124N/A public static void main(String[] args) throws Exception {
5124N/A
5124N/A SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
5124N/A Robot robot = new Robot();
5124N/A robot.setAutoDelay(50);
5124N/A robot.mouseMove(100, 100);
5124N/A
5124N/A // create a frame under the mouse cursor
5124N/A SwingUtilities.invokeAndWait(new Runnable() {
5124N/A
5124N/A @Override
5124N/A public void run() {
5124N/A createAndShowGUI();
5124N/A }
5124N/A });
5124N/A
5124N/A
5124N/A toolkit.realSync();
5124N/A
5124N/A if (mouseEnteredCount != 1 || mouseExitedCount != 0) {
5124N/A throw new RuntimeException("No Mouse Entered/Exited events!");
5124N/A }
5124N/A
5124N/A // iconify frame
5124N/A SwingUtilities.invokeAndWait(new Runnable() {
5124N/A
5124N/A @Override
5124N/A public void run() {
5124N/A frame.setExtendedState(Frame.ICONIFIED);
5124N/A }
5124N/A });
5124N/A
5124N/A toolkit.realSync();
5124N/A robot.delay(200);
5124N/A
5124N/A if (mouseEnteredCount != 1 || mouseExitedCount != 1) {
5124N/A throw new RuntimeException("No Mouse Entered/Exited events!");
5124N/A }
5124N/A
5124N/A // deiconify frame
5124N/A SwingUtilities.invokeAndWait(new Runnable() {
5124N/A
5124N/A @Override
5124N/A public void run() {
5124N/A frame.setExtendedState(Frame.NORMAL);
5124N/A }
5124N/A });
5124N/A
5124N/A toolkit.realSync();
5124N/A robot.delay(200);
5124N/A
5124N/A if (mouseEnteredCount != 2 || mouseExitedCount != 1) {
5124N/A throw new RuntimeException("No Mouse Entered/Exited events!");
5124N/A }
5124N/A
5124N/A // move the mouse out of the frame
5124N/A robot.mouseMove(500, 500);
5124N/A toolkit.realSync();
5124N/A robot.delay(200);
5124N/A
5124N/A if (mouseEnteredCount != 2 || mouseExitedCount != 2) {
5124N/A throw new RuntimeException("No Mouse Entered/Exited events!");
5124N/A }
5124N/A
5124N/A // maximize the frame
5124N/A SwingUtilities.invokeAndWait(new Runnable() {
5124N/A
5124N/A @Override
5124N/A public void run() {
5124N/A frame.setExtendedState(Frame.MAXIMIZED_BOTH);
5124N/A }
5124N/A });
5124N/A
5124N/A toolkit.realSync();
5124N/A robot.delay(200);
5124N/A
5124N/A if (mouseEnteredCount != 3 || mouseExitedCount != 2) {
5124N/A throw new RuntimeException("No Mouse Entered/Exited events!");
5124N/A }
5124N/A
5124N/A
5124N/A // demaximize the frame
5124N/A SwingUtilities.invokeAndWait(new Runnable() {
5124N/A
5124N/A @Override
5124N/A public void run() {
5124N/A frame.setExtendedState(Frame.NORMAL);
5124N/A }
5124N/A });
5124N/A
5124N/A toolkit.realSync();
5124N/A robot.delay(200);
5124N/A
5124N/A if (mouseEnteredCount != 3 || mouseExitedCount != 3) {
5124N/A throw new RuntimeException("No Mouse Entered/Exited events!");
5124N/A
5124N/A }
5124N/A
5124N/A // move the frame under the mouse
5124N/A SwingUtilities.invokeAndWait(new Runnable() {
5124N/A
5124N/A @Override
5124N/A public void run() {
5124N/A frame.setLocation(400, 400);
5124N/A }
5124N/A });
5124N/A
5124N/A toolkit.realSync();
5124N/A robot.delay(200);
5124N/A
5124N/A if (mouseEnteredCount != 4 || mouseExitedCount != 3) {
5124N/A throw new RuntimeException("No Mouse Entered/Exited events!");
5124N/A }
5124N/A
5124N/A // move the frame out of the mouse
5124N/A SwingUtilities.invokeAndWait(new Runnable() {
5124N/A
5124N/A @Override
5124N/A public void run() {
5124N/A frame.setLocation(100, 100);
5124N/A }
5124N/A });
5124N/A
5124N/A toolkit.realSync();
5124N/A robot.delay(400);
5124N/A
5124N/A if (mouseEnteredCount != 4 || mouseExitedCount != 4) {
5124N/A throw new RuntimeException("No Mouse Entered/Exited events!");
5124N/A }
5124N/A
5124N/A // enlarge the frame bounds
5124N/A SwingUtilities.invokeAndWait(new Runnable() {
5124N/A
5124N/A @Override
5124N/A public void run() {
5124N/A frame.setBounds(100, 100, 800, 800);
5124N/A }
5124N/A });
5124N/A
5124N/A toolkit.realSync();
5124N/A robot.delay(200);
5124N/A
5124N/A if (mouseEnteredCount != 5 || mouseExitedCount != 4) {
5124N/A throw new RuntimeException("No Mouse Entered/Exited events!");
5124N/A }
5124N/A
5124N/A // make the frame bounds smaller
5124N/A SwingUtilities.invokeAndWait(new Runnable() {
5124N/A
5124N/A @Override
5124N/A public void run() {
5124N/A frame.setBounds(100, 100, 200, 300);
5124N/A }
5124N/A });
5124N/A
5124N/A toolkit.realSync();
5124N/A robot.delay(400);
5124N/A
5124N/A
5124N/A if (mouseEnteredCount != 5 || mouseExitedCount != 5) {
5124N/A throw new RuntimeException("No Mouse Entered/Exited events!");
5124N/A }
5124N/A }
5124N/A
5124N/A private static void createAndShowGUI() {
5124N/A
5124N/A frame = new JFrame("Main Frame");
5124N/A frame.setSize(300, 200);
5124N/A frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
5124N/A
5124N/A frame.addMouseListener(new MouseAdapter() {
5124N/A
5124N/A @Override
5124N/A public void mouseEntered(MouseEvent e) {
5124N/A mouseEnteredCount++;
5124N/A }
5124N/A
5124N/A @Override
5124N/A public void mouseExited(MouseEvent e) {
5124N/A mouseExitedCount++;
5124N/A }
5124N/A });
5124N/A
5124N/A frame.setVisible(true);
5124N/A }
5124N/A}