Path: blob/master/test/jdk/javax/swing/JInternalFrame/4193219/IconCoord.java
41153 views
/*1* Copyright (c) 2013, 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*/22/*23@test24@bug 419321925@summary26@author Your Name: Hania Gajewska area=swing27@run main/manual IconCoord28*/2930import java.awt.*;31import java.awt.event.*;32import javax.swing.*;3334public class IconCoord {35static Test test = new Test();3637public static void main(String[] args) throws Exception {38UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());39SwingUtilities.invokeAndWait(new Runnable() {40public void run() {41new IconCoord().createAndShowGUI();42}43});44test.waitTestResult();45}4647private void createAndShowGUI() {48StringBuilder instrText = new StringBuilder();49instrText.append("First, iconify internal frame \"Frame 1\" by clicking on its iconify button.\n");50instrText.append("Now, maximize the top-level window \"IconCoord\".\n");51instrText.append("The \"Frame 1\" icon should stay in the lower left corner of the desktop; ");52instrText.append("if it doesn't, press \"Fail\".\n");53instrText.append("Now move the icon to the middle of the desktop by dragging it by its ");54instrText.append("bumpy left side. Then iconify \"Frame 2\" by clicking on its iconify button.\n");55instrText.append("If the icon for frame two gets placed in the lower left corner of the ");56instrText.append("desktop (where the icon for \"Frame 1\" used to be before you moved it), ");57instrText.append("press \"Pass\". Otherwise, press \"Fail\".\n");5859JDesktopPane dt = new JDesktopPane();6061JButton tf;62JInternalFrame if1 = new JInternalFrame("Frame 1", false, false, false, true);63JComponent c = (JComponent) if1.getContentPane();64c.setLayout(new BorderLayout());6566tf = new JButton ("ignore");67c.add (tf, BorderLayout.NORTH);6869tf = new JButton ("ignore");70c.add (tf, BorderLayout.CENTER);7172JInternalFrame if2 = new JInternalFrame("Frame 2", false, false, false, true);73c = (JComponent) if2.getContentPane();74c.setLayout(new BorderLayout());7576tf = new JButton ("ignore");77c.add (tf, BorderLayout.NORTH);7879tf = new JButton ("ignore");80c.add (tf, BorderLayout.CENTER);8182if1.pack();83if1.setBounds(300, 0, 300, 80);84if2.pack();85if2.setBounds(0, 0, 300, 80);86dt.add(if1);87dt.add(if2);8889if1.setVisible(true);90if2.setVisible(true);9192int frameHeight = 500;9394JScrollPane dtScrollPane = new JScrollPane(dt);95JFrame frame = test.createTestFrame("IconCoord", dtScrollPane, instrText.toString(), 250);96dt.setPreferredSize(new Dimension(650, frameHeight - 250));97frame.setSize (600,500);98frame.setVisible(true);99}100101static class Test {102private boolean pass;103JFrame createTestFrame(String name, Component topComponent, String instructions, int instrHeight) {104final String PASS = "Pass";105final String FAIL = "Fail";106JFrame frame = new JFrame(name);107frame.setLayout(new BorderLayout());108109JPanel testButtonsPanel = new JPanel();110testButtonsPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));111112ActionListener btnAL = new ActionListener() {113public void actionPerformed(ActionEvent event) {114switch (event.getActionCommand()) {115case PASS:116pass();117break;118default:119throw new RuntimeException("Test failed.");120}121}122};123JButton passBtn = new JButton(PASS);124passBtn.addActionListener(btnAL);125passBtn.setActionCommand(PASS);126127JButton failBtn = new JButton(FAIL);128failBtn.addActionListener(btnAL);129failBtn.setActionCommand(FAIL);130131testButtonsPanel.add(BorderLayout.WEST, passBtn);132testButtonsPanel.add(BorderLayout.EAST, failBtn);133134JTextArea instrText = new JTextArea();135instrText.setLineWrap(true);136instrText.setEditable(false);137JScrollPane instrScrollPane = new JScrollPane(instrText);138instrScrollPane.setMaximumSize(new Dimension(Integer.MAX_VALUE, instrHeight));139instrText.append(instructions);140141JPanel servicePanel = new JPanel();142servicePanel.setLayout(new BorderLayout());143servicePanel.add(BorderLayout.CENTER, instrScrollPane);144servicePanel.add(BorderLayout.SOUTH, testButtonsPanel);145146frame.add(BorderLayout.SOUTH, servicePanel);147frame.add(BorderLayout.CENTER, topComponent);148return frame;149}150synchronized void pass() {151pass = true;152notifyAll();153}154synchronized void waitTestResult() throws InterruptedException {155while (!pass) {156wait();157}158}159}160}161162163