601N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
601N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
601N/A *
601N/A * This code is free software; you can redistribute it and/or modify it
601N/A * under the terms of the GNU General Public License version 2 only, as
601N/A * published by the Free Software Foundation.
601N/A *
601N/A * This code is distributed in the hope that it will be useful, but WITHOUT
601N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
601N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
601N/A * version 2 for more details (a copy is included in the LICENSE file that
601N/A * accompanied this code).
601N/A *
601N/A * You should have received a copy of the GNU General Public License version
601N/A * 2 along with this work; if not, write to the Free Software Foundation,
601N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
601N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
601N/A */
601N/A
601N/A/* @test
601N/A * @bug 6647340
601N/A * @summary Checks that iconified internal frame follows
601N/A * the main frame borders properly.
601N/A * @author Mikhail Lapshin
601N/A */
601N/A
601N/Aimport sun.awt.SunToolkit;
601N/A
601N/Aimport javax.swing.*;
601N/Aimport java.awt.*;
601N/Aimport java.beans.PropertyVetoException;
601N/A
601N/Apublic class bug6647340 {
601N/A private JFrame frame;
601N/A private Point location;
601N/A private JInternalFrame jif;
601N/A
601N/A public static void main(String[] args) throws Exception {
601N/A final bug6647340 test = new bug6647340();
601N/A try {
601N/A SwingUtilities.invokeAndWait(new Runnable() {
601N/A public void run() {
601N/A test.setupUI();
601N/A }
601N/A });
601N/A test.test();
601N/A } finally {
601N/A if (test.frame != null) {
601N/A test.frame.dispose();
601N/A }
601N/A }
601N/A }
601N/A
601N/A private void setupUI() {
601N/A frame = new JFrame();
601N/A frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
601N/A
601N/A JDesktopPane desktop = new JDesktopPane();
601N/A frame.add(desktop);
601N/A
601N/A jif = new JInternalFrame("Internal Frame", true, true, true, true);
601N/A jif.setBounds(20, 20, 200, 100);
601N/A desktop.add(jif);
601N/A jif.setVisible(true);
601N/A
601N/A Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
601N/A frame.setBounds((screen.width - 400) / 2, (screen.height - 400) / 2, 400, 400);
601N/A frame.setLocationRelativeTo(null);
601N/A frame.setVisible(true);
601N/A }
601N/A
601N/A private void test() throws Exception {
601N/A realSync();
601N/A test1();
601N/A realSync();
601N/A check1();
601N/A realSync();
601N/A test2();
601N/A realSync();
601N/A check2();
601N/A }
601N/A
601N/A private void test1() throws Exception {
601N/A SwingUtilities.invokeAndWait(new Runnable() {
601N/A public void run() {
601N/A setIcon(true);
601N/A location = jif.getDesktopIcon().getLocation();
601N/A Dimension size = frame.getSize();
601N/A frame.setSize(size.width + 100, size.height + 100);
601N/A }
601N/A });
601N/A }
601N/A
601N/A private void test2() throws Exception {
601N/A SwingUtilities.invokeAndWait(new Runnable() {
601N/A public void run() {
601N/A setIcon(false);
601N/A }
601N/A });
601N/A realSync();
601N/A SwingUtilities.invokeAndWait(new Runnable() {
601N/A public void run() {
601N/A Dimension size = frame.getSize();
601N/A frame.setSize(size.width - 100, size.height - 100);
601N/A }
601N/A });
601N/A realSync();
601N/A SwingUtilities.invokeAndWait(new Runnable() {
601N/A public void run() {
601N/A setIcon(true);
601N/A }
601N/A });
601N/A }
601N/A
601N/A private void check1() {
601N/A if (!jif.getDesktopIcon().getLocation().equals(location)) {
601N/A System.out.println("First test passed");
601N/A } else {
601N/A throw new RuntimeException("Icon isn't shifted with the frame bounds");
601N/A }
601N/A }
601N/A
601N/A private void check2() {
601N/A if (jif.getDesktopIcon().getLocation().equals(location)) {
601N/A System.out.println("Second test passed");
601N/A } else {
601N/A throw new RuntimeException("Icon isn't located near the frame bottom");
601N/A }
601N/A }
601N/A
601N/A private static void realSync() {
601N/A ((SunToolkit) (Toolkit.getDefaultToolkit())).realSync();
601N/A }
601N/A
601N/A private void setIcon(boolean b) {
601N/A try {
601N/A jif.setIcon(b);
601N/A } catch (PropertyVetoException e) {
601N/A e.printStackTrace();
601N/A }
601N/A }
601N/A}