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