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