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