Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JInternalFrame/6647340/bug6647340.java
38854 views
/*1* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 664734025* @summary Checks that iconified internal frame follows26* the main frame borders properly.27* @author Mikhail Lapshin28* @library ../../../../lib/testlibrary/29* @build ExtendedRobot30* @run main bug664734031*/3233import javax.swing.*;34import java.awt.*;35import java.beans.PropertyVetoException;3637public class bug6647340 {38private JFrame frame;39private Point location;40private JInternalFrame jif;41private static ExtendedRobot robot = createRobot();4243public static void main(String[] args) throws Exception {44final bug6647340 test = new bug6647340();45try {46SwingUtilities.invokeAndWait(new Runnable() {47public void run() {48test.setupUI();49}50});51test.test();52} finally {53if (test.frame != null) {54test.frame.dispose();55}56}57}5859private void setupUI() {60frame = new JFrame();61frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);6263JDesktopPane desktop = new JDesktopPane();64frame.add(desktop);6566jif = new JInternalFrame("Internal Frame", true, true, true, true);67jif.setBounds(20, 20, 200, 100);68desktop.add(jif);69jif.setVisible(true);7071Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();72frame.setBounds((screen.width - 400) / 2, (screen.height - 400) / 2, 400, 400);73frame.setLocationRelativeTo(null);74frame.setVisible(true);75}7677private void test() throws Exception {78sync();79test1();80sync();81check1();82sync();83test2();84sync();85check2();86}8788private void test1() throws Exception {89SwingUtilities.invokeAndWait(new Runnable() {90public void run() {91setIcon(true);92location = jif.getDesktopIcon().getLocation();93Dimension size = frame.getSize();94frame.setSize(size.width + 100, size.height + 100);95}96});97}9899private void test2() throws Exception {100SwingUtilities.invokeAndWait(new Runnable() {101public void run() {102setIcon(false);103}104});105sync();106SwingUtilities.invokeAndWait(new Runnable() {107public void run() {108Dimension size = frame.getSize();109frame.setSize(size.width - 100, size.height - 100);110}111});112sync();113SwingUtilities.invokeAndWait(new Runnable() {114public void run() {115setIcon(true);116}117});118}119120private void check1() {121if (!jif.getDesktopIcon().getLocation().equals(location)) {122System.out.println("First test passed");123} else {124throw new RuntimeException("Icon isn't shifted with the frame bounds");125}126}127128private void check2() {129if (jif.getDesktopIcon().getLocation().equals(location)) {130System.out.println("Second test passed");131} else {132throw new RuntimeException("Icon isn't located near the frame bottom");133}134}135136private static void sync() {137robot.waitForIdle();138}139private static ExtendedRobot createRobot() {140try {141ExtendedRobot robot = new ExtendedRobot();142return robot;143}catch(Exception ex) {144ex.printStackTrace();145throw new Error("Unexpected Failure");146}147}148149private void setIcon(boolean b) {150try {151jif.setIcon(b);152} catch (PropertyVetoException e) {153e.printStackTrace();154}155}156}157158159