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