1 /*
   2  * Copyright (c) 2011, 2013, 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  @summary This is for <rdar://problem/3966067> jre1.4.2_05: Zoomed JFrame reports wrong location
  27  @summary com.apple.junit.java.awt.Frame
  28  @library ../../regtesthelpers
  29  @build VisibilityValidator
  30  @run main ZoomedFrame
  31  */
  32 
  33 // classes necessary for this test
  34 import java.awt.Frame;
  35 import java.awt.Point;
  36 import java.awt.Rectangle;
  37 
  38 import test.java.awt.regtesthelpers.VisibilityValidator;
  39 
  40 public class ZoomedFrame {
  41     private static final int mX = 100;
  42     private static final int mY = 100;
  43     private static final int mWidth = 100;
  44     private static final int mHeight = 100;
  45     private static final Point mOrigin = new Point(mX, mY);
  46     private static final Rectangle mNormalRect = new Rectangle(mX, mY, mWidth, mHeight);
  47 
  48     public static void main( String[] args ) throws Exception, RuntimeException {
  49         Point loc;
  50         Rectangle r;
  51         Frame f = new Frame("Hi");
  52         try {
  53             f.setBounds(mX, mY, mWidth, mHeight);
  54             VisibilityValidator.setVisibleAndConfirm(f);
  55 
  56             // Verify the frame's location and size
  57             loc = f.getLocation();
  58             if (!mOrigin.equals(loc)) {
  59                 throw new RuntimeException("Frame is at the wrong location.  Expected: " + mOrigin + "; Actual: " + loc);
  60             }
  61 
  62             f.setExtendedState(Frame.MAXIMIZED_BOTH);
  63             Thread.sleep(100);
  64 
  65             loc = f.getLocation();
  66             if (mOrigin.equals(loc)) {
  67                 throw new RuntimeException("Frame is at it's original location after frame was maximized (MAXIMIZED_BOTH).");
  68             }
  69             if (f.getWidth() == mWidth) {
  70                 throw new RuntimeException( "Frame is at it's original width after frame was maximized (MAXIMIZED_BOTH).");
  71             }
  72             if (f.getHeight() == mHeight) {
  73                 throw new RuntimeException( "Frame is at it's original height after frame was maximized (MAXIMIZED_BOTH).");
  74             }
  75 
  76             f.setExtendedState(Frame.NORMAL);
  77             Thread.sleep(100);
  78 
  79             r = f.getBounds();
  80             if (!r.equals(mNormalRect)) {
  81                 throw new RuntimeException( "Frame was not restored to it's original size and location.");
  82             }
  83 
  84         } finally {
  85             f.dispose();
  86             f = null;
  87         }
  88     }
  89 }
  90