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