1 /* 2 * Copyright (c) 2007, 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.applet.Applet; 26 import java.awt.*; 27 import java.awt.event.ActionEvent; 28 import java.awt.event.ActionListener; 29 import java.util.HashMap; 30 import java.util.Map; 31 32 import static jdk.testlibrary.Asserts.*; 33 34 /* 35 * @test 1.1 2001/05/14 36 * @summary Checking Whether 37 * 1.When Frame.setExtendedStateBounds() is called for a 38 * Frame with state as Frame.NORMAL, the bounds of the 39 * Frame must be the same as what is specified when frame 40 * is in normal state. 41 * 42 * 2.When Frame.setExtendedStateBounds()is called for a 43 * Frame with state as Frame.MAXIMIZED_VERT,the bounds 44 * of the Frame must be the same as what is specified 45 * when frame is in vertically maximized state. 46 * 47 * 3.When Frame.setExtendedStateBounds()is called for a 48 * Frame with state as Frame.MAXIMIZED_HORZ,the bounds 49 * of the Frame must be the same as what is specified 50 * when frame is in horizontally maximized state. 51 * 52 * 4.When Frame.setExtendedStateBounds()is called for a 53 * Frame with state as Frame.MAXIMIZED_BOTH,the bounds 54 * of the Frame must be the same as what is specified 55 * when frame is in maximized state. 56 * 57 * @library ../../../../lib/testlibrary 58 * @build ExtendedRobot jdk.testlibrary.Asserts 59 * @run main SetBounds 60 */ 61 62 public class SetBounds extends Applet implements ActionListener { 63 64 Frame testFrame; 65 Button[] buttons = new Button[4]; 66 Map<String, Rectangle> borders = new HashMap<String, Rectangle>(); 67 { 68 borders.put("NORMAL", new Rectangle(50,50,350,350)); 69 borders.put("MAXIMIZED_HORIZ", new Rectangle(50,50,500,350)); 70 borders.put("MAXIMIZED_VERT", new Rectangle(50,50,350,500)); 71 borders.put("MAXIMIZED_BOTH", new Rectangle(50,50,600,600)); 72 } 73 Rectangle bound = null; 74 ExtendedRobot robot; 75 boolean flag = false; 76 boolean actionPerformed; 77 78 public Point targetCenter(Component target) { 79 int w = target.getWidth(); 80 int h = target.getHeight(); 81 Point loc = target.getLocationOnScreen(); 82 loc.x += (w/2); 83 loc.y += (h/2); 84 return loc; 85 } 86 87 public SetBounds() throws Exception { 88 // CONFIG: Do any other initialization here. 89 try { 90 robot = new ExtendedRobot(); 91 } catch (AWTException e) { 92 e.printStackTrace(); 93 } 94 95 SwingUtilities.invokeAndWait(() -> { 96 testFrame = new Frame( "TestFrame "); 97 testFrame.setLayout(new FlowLayout()); 98 99 buttons[0] = new Button("NORMAL"); 100 buttons[1] = new Button("BOTH"); 101 buttons[2] = new Button("HORIZ"); 102 buttons[3] = new Button("VERT"); 103 104 for (Button button : buttons) { 105 button.addActionListener(this); 106 testFrame.add(button); 107 } 108 109 testFrame.setSize(200, 200); 110 testFrame.setVisible(true); 111 }); 112 113 robot.waitForIdle(); 114 115 } 116 117 String getKey(Button button){ 118 if (button.getLabel().equals("NORMAL")) { 119 return button.getLabel(); 120 } else { 121 return "MAXIMIZED_"+button.getLabel(); 122 } 123 } 124 125 void verify(String state) throws Exception { 126 if(Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.class.getField(state).getInt(null)) ) { 127 testFrame.setBounds(borders.get(state)); 128 bound = testFrame.getBounds(); 129 } else { 130 flag = true; 131 System.out.println("Frame."+state+" not supported"); 132 } 133 actionPerformed = true; 134 } 135 public void actionPerformed(ActionEvent ae) { 136 try { 137 verify(getKey((Button) ae.getSource())); 138 } catch (Exception e) { 139 e.printStackTrace(); 140 } 141 } 142 143 public void doTest() { 144 // CONFIG: Put here the code to exercise and verify the GUI. 145 146 for (Button button : buttons) { 147 actionPerformed = false; 148 bound = null; 149 flag = false; 150 robot.mouseMove(targetCenter(button)); 151 robot.waitForIdle(); 152 robot.click(); 153 robot.waitForIdle(); 154 155 assertTrue(actionPerformed, "'"+getKey(button)+"' button did not trigger action when clicked"); 156 157 if (!flag) { 158 assertEquals(bound, borders.get(getKey(button)), 159 "The Bounds of the Frame is not same as what" 160 + " is specified when the frame is in Frame. "+getKey(button)+" state"); 161 } 162 } 163 } 164 165 public static void main(String[] args) throws Exception { 166 new SetBounds().doTest(); 167 } 168 }