1 /* 2 * Copyright (c) 2008, 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 /* @test 25 * @key headful 26 * @bug 6647340 27 * @summary Checks that iconified internal frame follows 28 * the main frame borders properly. 29 * @author Mikhail Lapshin 30 */ 31 32 import sun.awt.SunToolkit; 33 34 import javax.swing.*; 35 import java.awt.*; 36 import java.beans.PropertyVetoException; 37 38 public class bug6647340 { 39 private JFrame frame; 40 private Point location; 41 private JInternalFrame jif; 42 43 public static void main(String[] args) throws Exception { 44 final bug6647340 test = new bug6647340(); 45 try { 46 SwingUtilities.invokeAndWait(new Runnable() { 47 public void run() { 48 test.setupUI(); 49 } 50 }); 51 test.test(); 52 } finally { 53 if (test.frame != null) { 54 test.frame.dispose(); 55 } 56 } 57 } 58 59 private void setupUI() { 60 frame = new JFrame(); 61 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 62 63 JDesktopPane desktop = new JDesktopPane(); 64 frame.add(desktop); 65 66 jif = new JInternalFrame("Internal Frame", true, true, true, true); 67 jif.setBounds(20, 20, 200, 100); 68 desktop.add(jif); 69 jif.setVisible(true); 70 71 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 72 frame.setBounds((screen.width - 400) / 2, (screen.height - 400) / 2, 400, 400); 73 frame.setLocationRelativeTo(null); 74 frame.setVisible(true); 75 } 76 77 private void test() throws Exception { 78 realSync(); 79 test1(); 80 realSync(); 81 check1(); 82 realSync(); 83 test2(); 84 realSync(); 85 check2(); 86 } 87 88 private void test1() throws Exception { 89 SwingUtilities.invokeAndWait(new Runnable() { 90 public void run() { 91 setIcon(true); 92 location = jif.getDesktopIcon().getLocation(); 93 Dimension size = frame.getSize(); 94 frame.setSize(size.width + 100, size.height + 100); 95 } 96 }); 97 } 98 99 private void test2() throws Exception { 100 SwingUtilities.invokeAndWait(new Runnable() { 101 public void run() { 102 setIcon(false); 103 } 104 }); 105 realSync(); 106 SwingUtilities.invokeAndWait(new Runnable() { 107 public void run() { 108 Dimension size = frame.getSize(); 109 frame.setSize(size.width - 100, size.height - 100); 110 } 111 }); 112 realSync(); 113 SwingUtilities.invokeAndWait(new Runnable() { 114 public void run() { 115 setIcon(true); 116 } 117 }); 118 } 119 120 private void check1() { 121 if (!jif.getDesktopIcon().getLocation().equals(location)) { 122 System.out.println("First test passed"); 123 } else { 124 throw new RuntimeException("Icon isn't shifted with the frame bounds"); 125 } 126 } 127 128 private void check2() { 129 if (jif.getDesktopIcon().getLocation().equals(location)) { 130 System.out.println("Second test passed"); 131 } else { 132 throw new RuntimeException("Icon isn't located near the frame bottom"); 133 } 134 } 135 136 private static void realSync() { 137 ((SunToolkit) (Toolkit.getDefaultToolkit())).realSync(); 138 } 139 140 private void setIcon(boolean b) { 141 try { 142 jif.setIcon(b); 143 } catch (PropertyVetoException e) { 144 e.printStackTrace(); 145 } 146 } 147 }