Path: blob/master/test/jdk/javax/swing/JFrame/8037575/bug8037575.java
41154 views
/*1* Copyright (c) 2015, 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*/2223/*24* @test @bug 803757525* @summary JFrame doesn't animate when setting ICONIFIED state26* @requires (os.family == "windows")27* @run main/manual bug803757528*/29import java.awt.Frame;30import javax.swing.JFrame;31import javax.swing.SwingUtilities;32import java.awt.*;33import java.awt.event.*;34import java.util.logging.Level;35import java.util.logging.Logger;36import javax.swing.AbstractAction;37import javax.swing.JButton;38import javax.swing.JDialog;39import javax.swing.Timer;4041public class bug8037575 {4243private static boolean theTestPassed;44private static boolean testGeneratedInterrupt;45private static Thread mainThread;46private static int sleepTime = 30000;47private static int waitTime = 2000;48private final static JFrame frame = new JFrame("bug8037575");4950private static void init() throws Exception {5152SwingUtilities.invokeAndWait(new Runnable() {53@Override54public void run() {55String[] instructions56= {57"1) You see a dialog with buttons and text area.",58"2) Pressing Run button will start test. A new Frame will open automatically"59+ " and minimize after 2 seconds.",60"3) Frame should minimize gradually with animation effect.",61"4) If frame disappers without animation then test "62+ "failed otherwise passed.",63"5) Pressing Pass/Fail button will mark test as "64+ "pass/fail and will shutdown JVM as well"};6566Sysout.createDialogWithInstructions(instructions);67Sysout.printInstructions(instructions);68}69});70}7172/**73* ***************************************************74* Standard Test Machinery Section DO NOT modify anything in this section --75* it's a standard chunk of code which has all of the synchronisation76* necessary for the test harness. By keeping it the same in all tests, it77* is easier to read and understand someone else's test, as well as insuring78* that all tests behave correctly with the test harness. There is a section79* following this for test-defined classes80*/81public static void main(String args[]) throws InterruptedException {8283mainThread = Thread.currentThread();84try {85init();86} catch (Exception ex) {87Logger.getLogger(bug8037575.class.getName()).log(Level.SEVERE, null, ex);88}89try {90mainThread.sleep(sleepTime);91} catch (InterruptedException ex) {92Sysout.dispose();93if (!theTestPassed && testGeneratedInterrupt) {94throw new RuntimeException("Test Failed");95}96}97if (!testGeneratedInterrupt) {98Sysout.dispose();99throw new RuntimeException("Test Failed");100}101}102103public static synchronized void pass() {104theTestPassed = true;105testGeneratedInterrupt = true;106mainThread.interrupt();107}108109public static synchronized void runTest() {110frame.setSize(800, 600);111frame.setVisible(true);112frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);113Timer timer = new Timer(waitTime, new AbstractAction() {114@Override115public void actionPerformed(ActionEvent ae) {116frame.setExtendedState(Frame.ICONIFIED);117frame.dispose();118Sysout.println("Test completed please press/fail button");119}120});121timer.setRepeats(false);122timer.start();123}124125public static synchronized void fail() {126theTestPassed = false;127testGeneratedInterrupt = true;128mainThread.interrupt();129}130}131132/**133* This is part of the standard test machinery. It creates a dialog (with the134* instructions), and is the interface for sending text messages to the user. To135* print the instructions, send an array of strings to Sysout.createDialog136* WithInstructions method. Put one line of instructions per array entry. To137* display a message for the tester to see, simply call Sysout.println with the138* string to be displayed. This mimics System.out.println but works within the139* test harness as well as standalone.140*/141class Sysout {142143private static TestDialog dialog;144private static JFrame frame;145146public static void createDialogWithInstructions(String[] instructions) {147frame = new JFrame();148dialog = new TestDialog(frame, "Instructions");149dialog.printInstructions(instructions);150dialog.setVisible(true);151println("Any messages for the tester will display here.");152}153154public static void printInstructions(String[] instructions) {155dialog.printInstructions(instructions);156}157158public static void println(String messageIn) {159dialog.displayMessage(messageIn);160}161162public static void dispose() {163Sysout.println("Shutting down the Java process..");164frame.dispose();165dialog.dispose();166}167}168169/**170* This is part of the standard test machinery. It provides a place for the test171* instructions to be displayed, and a place for interactive messages to the172* user to be displayed. To have the test instructions displayed, see Sysout. To173* have a message to the user be displayed, see Sysout. Do not call anything in174* this dialog directly.175*/176class TestDialog extends JDialog {177178private TextArea instructionsText;179private TextArea messageText;180private int maxStringLength = 80;181private Panel buttonP = new Panel();182private JButton run = new JButton("Run");183private JButton passB = new JButton("Pass");184private JButton failB = new JButton("Fail");185186public TestDialog(JFrame frame, String name) {187super(frame, name);188frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);189int scrollBoth = TextArea.SCROLLBARS_BOTH;190instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);191add("North", instructionsText);192193messageText = new TextArea("", 5, maxStringLength, scrollBoth);194add("Center", messageText);195196buttonP.add("East", run);197buttonP.add("East", passB);198buttonP.add("West", failB);199passB.setEnabled(false);200failB.setEnabled(false);201add("South", buttonP);202203run.addActionListener(new ActionListener() {204205@Override206public void actionPerformed(ActionEvent ae) {207bug8037575.runTest();208passB.setEnabled(true);209failB.setEnabled(true);210}211});212213passB.addActionListener(new ActionListener() {214215@Override216public void actionPerformed(ActionEvent ae) {217bug8037575.pass();218}219});220221failB.addActionListener(new ActionListener() {222223@Override224public void actionPerformed(ActionEvent ae) {225bug8037575.fail();226}227});228pack();229230setVisible(true);231}232233public void printInstructions(String[] instructions) {234instructionsText.setText("");235String printStr, remainingStr;236for (String instruction : instructions) {237remainingStr = instruction;238while (remainingStr.length() > 0) {239if (remainingStr.length() >= maxStringLength) {240int posOfSpace = remainingStr.241lastIndexOf(' ', maxStringLength - 1);242243if (posOfSpace <= 0) {244posOfSpace = maxStringLength - 1;245}246247printStr = remainingStr.substring(0, posOfSpace + 1);248remainingStr = remainingStr.substring(posOfSpace + 1);249} else {250printStr = remainingStr;251remainingStr = "";252}253instructionsText.append(printStr + "\n");254}255}256257}258259public void displayMessage(String messageIn) {260messageText.append(messageIn + "\n");261}262}263264