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 Undecorated JFrame, try to change the properties
30  *          using setVisible() method.
31  * @author Aruna Samji
32  * @library ../../../lib/testlibrary
33  * @build ExtendedRobot
34  * @run main TaskUndJFrameProperties
35  */
36 
37 public class TaskUndJFrameProperties extends Task<GUIUndFrame> {
38 
main(String[] args)39     public static void main (String[] args) throws Exception {
40         new TaskUndJFrameProperties(GUIUndFrame.class, new ExtendedRobot()).task();
41     }
42 
TaskUndJFrameProperties(Class guiClass, ExtendedRobot robot)43     TaskUndJFrameProperties(Class guiClass, ExtendedRobot robot) throws Exception {
44         super(guiClass, robot);
45     }
46 
task()47     public void task() throws Exception {
48         SwingUtilities.invokeAndWait(() -> {
49             gui.jframe2.setVisible(true);
50             gui.jframe1.setVisible(true);
51 
52             gui.jframe1.getContentPane().removeAll();
53             gui.jframe2.getContentPane().removeAll();
54             gui.jframe1.getContentPane().add(gui.jbutton1);
55             gui.jframe2.getContentPane().add(gui.jbutton2);
56             gui.jframe1.revalidate();
57             gui.jframe2.revalidate();
58         });
59         robot.waitForIdle(1000);
60 
61         Point button1Origin = gui.jbutton1.getLocationOnScreen();
62         Point button1Center = gui.jbutton1.getLocationOnScreen();
63         button1Center.translate(gui.jbutton1.getWidth()/2, gui.jbutton1.getHeight()/2);
64         Point button2Origin = gui.jbutton2.getLocationOnScreen();
65         Point button2Center = gui.jbutton2.getLocationOnScreen();
66         button2Center.translate(gui.jbutton2.getWidth()/2, gui.jbutton2.getHeight()/2);
67 
68         robot.glide(button1Origin, button1Center);
69         robot.waitForIdle(1000);
70         robot.click();
71         //After Hide
72         if (gui.win_deact == false)
73             throw new RuntimeException("Undecorated JFrame has not triggered " +
74                     "WINDOW_DEACTIVATED event when in Hide state\n");
75 
76         if (gui.jframe1.hasFocus() == true)
77             throw new RuntimeException("Undecorated Frame Still has Focus even " +
78                     "when in Hide state\n");
79 
80         //click on the jbutton2 in jframe2
81         SwingUtilities.invokeAndWait(gui.jframe2::toFront);
82         robot.waitForIdle(1000);
83         robot.glide(button2Origin, button2Center);
84         robot.waitForIdle(1000);
85         robot.click();
86         //After Show
87         if (gui.win_act == false)
88             throw new RuntimeException("Undecorated Frame can't trigger " +
89                     "WINDOW_ACTIVATED when visible\n");
90     }
91 }
92