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