1 /*
   2  * Copyright (c) 2004, 2014, 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 import java.awt.*;
  25 
  26 /*
  27  * @test
  28  * @summary Construct a frame with some components and zoom the frame and bring
  29  *          it back to normal state.
  30  * @author Aruna Samji
  31  * @library ../../../lib/testlibrary
  32  * @build ExtendedRobot
  33  * @run main TaskZoomFrameRepaint
  34  */
  35 
  36 public class TaskZoomFrameRepaint extends Task<GUIZoomFrame> {
  37 
  38     public static void main (String[] args) throws Exception {
  39         new TaskZoomFrameRepaint(new GUIZoomFrame(), new ExtendedRobot()).runTask();
  40     }
  41 
  42     TaskZoomFrameRepaint(GUIZoomFrame gui, ExtendedRobot robot) {
  43          super(gui, robot);
  44     }
  45 
  46     public void task() throws Exception {
  47         gui.frame2.setVisible(true);
  48         gui.frame2.removeAll();
  49         gui.frame2.add(gui.button);
  50         gui.frame2.add(gui.textarea);
  51         if (gui.frame2.getExtendedState() != Frame.NORMAL)
  52             gui.frame2.setExtendedState(Frame.NORMAL);
  53         robot.waitForIdle(1000);
  54 
  55         Point buttonOrigin, newbuttonOrigin, newbuttonCenter;
  56         Point textareaOrigin, newtextareaOrigin, newtextareaCenter ;
  57 
  58         //to find the lenght and width of the component originally
  59         buttonOrigin = gui.button.getLocationOnScreen();
  60         textareaOrigin = gui.textarea.getLocationOnScreen();
  61 
  62         if (Toolkit.getDefaultToolkit().isFrameStateSupported(
  63             Frame.MAXIMIZED_BOTH)){
  64             //Maximising the Frame fully.........
  65             gui.frame2.setExtendedState(Frame.MAXIMIZED_BOTH);
  66             robot.waitForIdle(1000);
  67             //To check whether the bitwise mask for MAXIMIZED_BOTH state is set...
  68             if (gui.frame2.getExtendedState() != Frame.MAXIMIZED_BOTH)
  69                 throw new RuntimeException("The bitwise mask Frame.MAXIMIZED_BOTH " +
  70                         "is not set when the frame is in MAXIMIZED_BOTH state");
  71 
  72             //To check whether the Frame is maximized fully..........
  73             if (gui.maxBoth == false)
  74                 throw new RuntimeException("Frame is not maximized fully");
  75         }
  76 
  77         //Normalising the Frame....
  78         gui.frame2.setExtendedState(Frame.NORMAL);
  79         robot.waitForIdle(1000);
  80 
  81         //To check whether the bitwise mask for NORMAL state is set...
  82         if (gui.frame2.getExtendedState() != Frame.NORMAL)
  83             throw new RuntimeException("The bitwise mask Frame.NORMAL is not " +
  84                     "set when the frame is in NORMAL state");
  85 
  86         //To check whether the Frame is normalised programmatically..........
  87         if (! gui.normal)
  88             throw new RuntimeException("Frame is not restored to normal");
  89 
  90         //to find the lenght and width of the component after zommed and back to normal
  91         newbuttonOrigin = gui.button.getLocationOnScreen();
  92         newtextareaOrigin = gui.textarea.getLocationOnScreen();
  93         newbuttonCenter = gui.button.getLocationOnScreen();
  94         newbuttonCenter.translate(gui.button.getWidth()/2, gui.button.getHeight()/2);
  95         newtextareaCenter = gui.textarea.getLocationOnScreen();
  96         newtextareaCenter.translate(gui.textarea.getWidth()/2, gui.textarea.getHeight()/2);
  97 
  98         if((buttonOrigin.x != newbuttonOrigin.x)&(buttonOrigin.y != newbuttonOrigin.y))
  99             throw new RuntimeException("The button is not positioned back to the " +
 100                     "original place  on the screen after iconified");
 101 
 102         if((textareaOrigin.x != newtextareaOrigin.x)&(textareaOrigin.y != newtextareaOrigin.y))
 103             throw new RuntimeException("The TextArea is not positioned back to the " +
 104                     "original place  on the screen after iconified");
 105 
 106         gui.frame2.remove(gui.button);
 107         gui.frame2.remove(gui.textarea);
 108         robot.waitForIdle(100);
 109     }
 110 }