1 /*
   2  * Copyright (c) 2008, 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 
  24 /*
  25   test
  26   @bug 6176814
  27   @summary  Metalworks frame maximizes after the move
  28   @author Andrei.Dmitriev area=Event
  29   @run applet MaximizedFrameTest.html
  30 */
  31 
  32 import java.applet.Applet;
  33 import javax.swing.*;
  34 import java.awt.event.*;
  35 import java.awt.*;
  36 
  37 public class MaximizedFrameTest extends Applet
  38 {
  39     final int ITERATIONS_COUNT = 20;
  40     Robot robot;
  41     Point framePosition;
  42     Point newFrameLocation;
  43     JFrame  frame;
  44     Rectangle gcBounds;
  45     public static Object LOCK = new Object();
  46 
  47     public void init()
  48     {
  49         String[] instructions =
  50         {
  51             "This is an AUTOMATIC test",
  52             "simply wait until it is done"
  53         };
  54         JFrame.setDefaultLookAndFeelDecorated(true);
  55         frame = new JFrame("JFrame Maximization Test");
  56         frame.pack();
  57         frame.setSize(450, 260);
  58     }//End  init()
  59 
  60     public void start ()
  61     {
  62         frame.setVisible(true);
  63         validate();
  64         JLayeredPane lPane = frame.getLayeredPane();
  65         //        System.out.println("JFrame's LayeredPane " + lPane );
  66         Component titleComponent = null;
  67         boolean titleFound = false;
  68         for (int j=0; j < lPane.getComponentsInLayer(JLayeredPane.FRAME_CONTENT_LAYER.intValue()).length; j++){
  69             titleComponent = lPane.getComponentsInLayer(JLayeredPane.FRAME_CONTENT_LAYER.intValue())[j];
  70             if (titleComponent.getClass().getName().equals("javax.swing.plaf.metal.MetalTitlePane")){
  71                 titleFound = true;
  72                 break;
  73             }
  74         }
  75         if ( !titleFound ){
  76             throw new RuntimeException("Test Failed. Unable to determine title's size.");
  77         }
  78         //--------------------------------
  79         // it is sufficient to get maximized Frame only once.
  80         Point tempMousePosition;
  81         framePosition = frame.getLocationOnScreen();
  82         try {
  83             robot = new Robot();
  84             tempMousePosition = new Point(framePosition.x +
  85                                           frame.getWidth()/2,
  86                                           framePosition.y +
  87                                           titleComponent.getHeight()/2);
  88             robot.mouseMove(tempMousePosition.x, tempMousePosition.y);
  89             for (int iteration=0; iteration < ITERATIONS_COUNT; iteration++){
  90                 robot.mousePress(InputEvent.BUTTON1_MASK);
  91                 gcBounds =
  92                     GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getConfigurations()[0].getBounds();
  93                 //Moving a mouse pointer less than a few pixels
  94                 //leads to rising a double click event.
  95                 //We have to use exceeded the AWT_MULTICLICK_SMUDGE
  96                 //const value (which is 4 by default on GNOME) to test that.
  97                 tempMousePosition.x += 5;
  98                 robot.mouseMove(tempMousePosition.x, tempMousePosition.y);
  99                 robot.delay(70);
 100                 robot.mouseRelease(InputEvent.BUTTON1_MASK);
 101                 if ( frame.getExtendedState() != 0 ){
 102                     throw new RuntimeException ("Test failed. JFrame was maximized. ExtendedState is : "+frame.getExtendedState());
 103                 }
 104                 robot.delay(500);
 105             } //for iteration
 106 
 107             }catch(AWTException e) {
 108                 throw new RuntimeException("Test Failed. AWTException thrown.");
 109             }
 110         System.out.println("Test passed.");
 111     }// start()
 112 }// class