1/* 2 * Copyright (c) 2013, 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 4193219 26 @summary 27 @author Your Name: Hania Gajewska area=swing 28 @run main/manual IconCoord 29*/ 30 31import java.awt.*; 32import java.awt.event.*; 33import javax.swing.*; 34 35public class IconCoord { 36 static Test test = new Test(); 37 38 public static void main(String[] args) throws Exception { 39 UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); 40 SwingUtilities.invokeAndWait(new Runnable() { 41 public void run() { 42 new IconCoord().createAndShowGUI(); 43 } 44 }); 45 test.waitTestResult(); 46 } 47 48 private void createAndShowGUI() { 49 StringBuilder instrText = new StringBuilder(); 50 instrText.append("First, iconify internal frame \"Frame 1\" by clicking on its iconify button.\n"); 51 instrText.append("Now, maximize the top-level window \"IconCoord\".\n"); 52 instrText.append("The \"Frame 1\" icon should stay in the lower left corner of the desktop; "); 53 instrText.append("if it doesn't, press \"Fail\".\n"); 54 instrText.append("Now move the icon to the middle of the desktop by dragging it by its "); 55 instrText.append("bumpy left side. Then iconify \"Frame 2\" by clicking on its iconify button.\n"); 56 instrText.append("If the icon for frame two gets placed in the lower left corner of the "); 57 instrText.append("desktop (where the icon for \"Frame 1\" used to be before you moved it), "); 58 instrText.append("press \"Pass\". Otherwise, press \"Fail\".\n"); 59 60 JDesktopPane dt = new JDesktopPane(); 61 62 JButton tf; 63 JInternalFrame if1 = new JInternalFrame("Frame 1", false, false, false, true); 64 JComponent c = (JComponent) if1.getContentPane(); 65 c.setLayout(new BorderLayout()); 66 67 tf = new JButton ("ignore"); 68 c.add (tf, BorderLayout.NORTH); 69 70 tf = new JButton ("ignore"); 71 c.add (tf, BorderLayout.CENTER); 72 73 JInternalFrame if2 = new JInternalFrame("Frame 2", false, false, false, true); 74 c = (JComponent) if2.getContentPane(); 75 c.setLayout(new BorderLayout()); 76 77 tf = new JButton ("ignore"); 78 c.add (tf, BorderLayout.NORTH); 79 80 tf = new JButton ("ignore"); 81 c.add (tf, BorderLayout.CENTER); 82 83 if1.pack(); 84 if1.setBounds(300, 0, 300, 80); 85 if2.pack(); 86 if2.setBounds(0, 0, 300, 80); 87 dt.add(if1); 88 dt.add(if2); 89 90 if1.setVisible(true); 91 if2.setVisible(true); 92 93 int frameHeight = 500; 94 95 JScrollPane dtScrollPane = new JScrollPane(dt); 96 JFrame frame = test.createTestFrame("IconCoord", dtScrollPane, instrText.toString(), 250); 97 dt.setPreferredSize(new Dimension(650, frameHeight - 250)); 98 frame.setSize (600,500); 99 frame.setVisible(true); 100 } 101 102 static class Test { 103 private boolean pass; 104 JFrame createTestFrame(String name, Component topComponent, String instructions, int instrHeight) { 105 final String PASS = "Pass"; 106 final String FAIL = "Fail"; 107 JFrame frame = new JFrame(name); 108 frame.setLayout(new BorderLayout()); 109 110 JPanel testButtonsPanel = new JPanel(); 111 testButtonsPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20)); 112 113 ActionListener btnAL = new ActionListener() { 114 public void actionPerformed(ActionEvent event) { 115 switch (event.getActionCommand()) { 116 case PASS: 117 pass(); 118 break; 119 default: 120 throw new RuntimeException("Test failed."); 121 } 122 } 123 }; 124 JButton passBtn = new JButton(PASS); 125 passBtn.addActionListener(btnAL); 126 passBtn.setActionCommand(PASS); 127 128 JButton failBtn = new JButton(FAIL); 129 failBtn.addActionListener(btnAL); 130 failBtn.setActionCommand(FAIL); 131 132 testButtonsPanel.add(BorderLayout.WEST, passBtn); 133 testButtonsPanel.add(BorderLayout.EAST, failBtn); 134 135 JTextArea instrText = new JTextArea(); 136 instrText.setLineWrap(true); 137 instrText.setEditable(false); 138 JScrollPane instrScrollPane = new JScrollPane(instrText); 139 instrScrollPane.setMaximumSize(new Dimension(Integer.MAX_VALUE, instrHeight)); 140 instrText.append(instructions); 141 142 JPanel servicePanel = new JPanel(); 143 servicePanel.setLayout(new BorderLayout()); 144 servicePanel.add(BorderLayout.CENTER, instrScrollPane); 145 servicePanel.add(BorderLayout.SOUTH, testButtonsPanel); 146 147 frame.add(BorderLayout.SOUTH, servicePanel); 148 frame.add(BorderLayout.CENTER, topComponent); 149 return frame; 150 } 151 synchronized void pass() { 152 pass = true; 153 notifyAll(); 154 } 155 synchronized void waitTestResult() throws InterruptedException { 156 while (!pass) { 157 wait(); 158 } 159 } 160 } 161} 162