877N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
877N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
877N/A *
877N/A * This code is free software; you can redistribute it and/or modify it
877N/A * under the terms of the GNU General Public License version 2 only, as
877N/A * published by the Free Software Foundation.
877N/A *
877N/A * This code is distributed in the hope that it will be useful, but WITHOUT
877N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
877N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
877N/A * version 2 for more details (a copy is included in the LICENSE file that
877N/A * accompanied this code).
877N/A *
877N/A * You should have received a copy of the GNU General Public License version
877N/A * 2 along with this work; if not, write to the Free Software Foundation,
877N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
877N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
877N/A */
877N/A
877N/A/*
877N/A test
877N/A @bug 6176814
877N/A @summary Metalworks frame maximizes after the move
877N/A @author Andrei.Dmitriev area=Event
877N/A @run applet MaximizedFrameTest.html
877N/A*/
877N/A
877N/Aimport java.applet.Applet;
877N/Aimport javax.swing.*;
877N/Aimport java.awt.event.*;
877N/Aimport java.awt.*;
877N/A
877N/Apublic class MaximizedFrameTest extends Applet
877N/A{
877N/A final int ITERATIONS_COUNT = 20;
877N/A Robot robot;
877N/A Point framePosition;
877N/A Point newFrameLocation;
877N/A JFrame frame;
877N/A Rectangle gcBounds;
877N/A public static Object LOCK = new Object();
877N/A
877N/A public void init()
877N/A {
877N/A String[] instructions =
877N/A {
877N/A "This is an AUTOMATIC test",
877N/A "simply wait until it is done"
877N/A };
877N/A JFrame.setDefaultLookAndFeelDecorated(true);
877N/A frame = new JFrame("JFrame Maximization Test");
877N/A frame.pack();
877N/A frame.setSize(450, 260);
877N/A }//End init()
877N/A
877N/A public void start ()
877N/A {
877N/A frame.setVisible(true);
877N/A validate();
877N/A JLayeredPane lPane = frame.getLayeredPane();
877N/A // System.out.println("JFrame's LayeredPane " + lPane );
877N/A Component titleComponent = null;
877N/A boolean titleFound = false;
877N/A for (int j=0; j < lPane.getComponentsInLayer(JLayeredPane.FRAME_CONTENT_LAYER.intValue()).length; j++){
877N/A titleComponent = lPane.getComponentsInLayer(JLayeredPane.FRAME_CONTENT_LAYER.intValue())[j];
877N/A if (titleComponent.getClass().getName().equals("javax.swing.plaf.metal.MetalTitlePane")){
877N/A titleFound = true;
877N/A break;
877N/A }
877N/A }
877N/A if ( !titleFound ){
877N/A throw new RuntimeException("Test Failed. Unable to determine title's size.");
877N/A }
877N/A //--------------------------------
877N/A // it is sufficient to get maximized Frame only once.
877N/A Point tempMousePosition;
877N/A framePosition = frame.getLocationOnScreen();
877N/A try {
877N/A robot = new Robot();
877N/A tempMousePosition = new Point(framePosition.x +
877N/A frame.getWidth()/2,
877N/A framePosition.y +
877N/A titleComponent.getHeight()/2);
877N/A robot.mouseMove(tempMousePosition.x, tempMousePosition.y);
877N/A for (int iteration=0; iteration < ITERATIONS_COUNT; iteration++){
877N/A robot.mousePress(InputEvent.BUTTON1_MASK);
877N/A gcBounds =
877N/A GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getConfigurations()[0].getBounds();
877N/A //Moving a mouse pointer less than a few pixels
877N/A //leads to rising a double click event.
877N/A //We have to use exceeded the AWT_MULTICLICK_SMUDGE
877N/A //const value (which is 4 by default on GNOME) to test that.
877N/A tempMousePosition.x += 5;
877N/A robot.mouseMove(tempMousePosition.x, tempMousePosition.y);
877N/A robot.delay(70);
877N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
877N/A if ( frame.getExtendedState() != 0 ){
877N/A throw new RuntimeException ("Test failed. JFrame was maximized. ExtendedState is : "+frame.getExtendedState());
877N/A }
877N/A robot.delay(500);
877N/A } //for iteration
877N/A
877N/A }catch(AWTException e) {
877N/A throw new RuntimeException("Test Failed. AWTException thrown.");
877N/A }
877N/A System.out.println("Test passed.");
877N/A }// start()
877N/A}// class