diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index bdcf1722768..6a29a689b04 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -789,7 +789,7 @@ java/awt/event/MouseEvent/AltGraphModifierTest/AltGraphModifierTest.java 8162380 java/awt/image/VolatileImage/VolatileImageConfigurationTest.java 8171069 macosx-all,linux-all java/awt/Modal/InvisibleParentTest/InvisibleParentTest.java 8172245 linux-all java/awt/print/Dialog/RestoreActiveWindowTest/RestoreActiveWindowTest.java 8185429 macosx-all -java/awt/Frame/FrameStateTest/FrameStateTest.html 8203920 macosx-all,linux-all +java/awt/Frame/FrameStateTest/FrameStateTest.java 8203920 macosx-all,linux-all java/awt/print/PrinterJob/ScaledText/ScaledText.java 8231226 macosx-all java/awt/font/TextLayout/TestJustification.java 8250791 macosx-all java/awt/TrayIcon/DragEventSource/DragEventSource.java 8252242 macosx-all diff --git a/test/jdk/java/awt/Frame/FrameStateTest/FrameStateTest.html b/test/jdk/java/awt/Frame/FrameStateTest/FrameStateTest.html deleted file mode 100644 index 5c88ac2d1d8..00000000000 --- a/test/jdk/java/awt/Frame/FrameStateTest/FrameStateTest.html +++ /dev/null @@ -1,50 +0,0 @@ - - - - - FrameStateTest - - - -

FrameStateTest
Bug ID: 4157271

-

This test checks that when setState(Frame.ICONIFIED) is called before - setVisible(true) the Frame is shown in the proper iconified state. - The problem was that it did not honor the initial iconic state, but - instead was shown in the NORMAL state.

-

See the dialog box (usually in upper left corner) for instructions

- - - - diff --git a/test/jdk/java/awt/Frame/FrameStateTest/FrameStateTest.java b/test/jdk/java/awt/Frame/FrameStateTest/FrameStateTest.java index 33ea9b304ff..496be463513 100644 --- a/test/jdk/java/awt/Frame/FrameStateTest/FrameStateTest.java +++ b/test/jdk/java/awt/Frame/FrameStateTest/FrameStateTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,17 +22,6 @@ */ /* - test - @bug 4157271 - @summary Checks that when a Frame is created it honors the state it - was set to. The bug was that if setState(Frame.ICONIFIED) was - called before setVisible(true) the Frame would be shown in NORMAL - state instead of ICONIFIED. - @author JTG East Team: area=awt.Frame - @run applet/manual=yesno FrameStateTest.html -*/ - -/** * FrameStateTest.java * * summary: Checks that when setState(Frame.ICONIFIED) is called before @@ -41,82 +30,127 @@ * instead was shown in the NORMAL state. */ -import java.awt.event.*; -import java.awt.*; -import java.lang.*; -import java.applet.Applet; +import java.awt.Button; +import java.awt.Checkbox; +import java.awt.CheckboxGroup; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.Rectangle; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Deque; +import javax.swing.JPanel; +import javax.swing.Timer; +/* + * @test + * @bug 4157271 + * @summary Checks that when a Frame is created it honors the state it + * was set to. The bug was that if setState(Frame.ICONIFIED) was + * called before setVisible(true) the Frame would be shown in NORMAL + * state instead of ICONIFIED. + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual FrameStateTest + */ -public class FrameStateTest extends Applet implements ActionListener, ItemListener{ +public class FrameStateTest implements ActionListener { - Button btnCreate = new Button("Create Frame"); - Button btnDispose = new Button("Dispose Frame"); - CheckboxGroup cbgState = new CheckboxGroup(); - CheckboxGroup cbgResize = new CheckboxGroup(); - Checkbox cbIconState = new Checkbox("Frame state ICONIFIED",cbgState,false); - Checkbox cbNormState = new Checkbox("Frame state NORMAL",cbgState,true); - Checkbox cbNonResize = new Checkbox("Frame Nonresizable",cbgResize,false); - Checkbox cbResize = new Checkbox("Frame Resizable",cbgResize,true); - int iState = 0; - boolean bResize = true; - CreateFrame icontst; + private static final String INSTRUCTIONS = """ +

+ This test checks that when setState(Frame.ICONIFIED) is called before + setVisible(true) the Frame is shown in the proper iconified state. + The problem was that it did not honor the initial iconic state, but + instead was shown in the NORMAL state. +


- public void init() { - this.setLayout (new BorderLayout ()); + Steps to try to reproduce this problem: +

+ Select the different options for the Frame: +

+ After choosing the Frame's state click the + Create Frame button.
+ After the Frame (Frame State Test (Window2)) comes + up make sure the proper behavior occurred
+ (Frame shown in proper state).
+ Click the Dispose button to close the Frame.
- String[] instructions = - { - "Steps to try to reproduce this problem:", - "When this test is run an Applet Viewer window will display. In the", - "Applet Viewer window select the different options for the Frame (i.e.", - "{Normal, Non-resizalbe}, {Normal, Resizable}, {Iconified, Resizable},", - "{Iconified, Non-resizalbe}). After chosing the Frame's state click the", - "Create Frame button. After the Frame (Frame State Test (Window2)) comes", - "up make sure the proper behavior occurred (Frame shown in proper state).", - "Click the Dispose button to close the Frame. Do the above steps for all", - "the different Frame state combinations available. If you observe the", - "proper behavior the test has passed, Press the Pass button. Otherwise", - "the test has failed, Press the Fail button.", - "Note: In Frame State Test (Window2) you can also chose the different", - "buttons to see different Frame behavior. An example of a problem that", - "has been seen, With the Frame nonresizable you can not iconify the Frame." - }; - Sysout.createDialogWithInstructions( instructions ); +


- btnDispose.setEnabled(false); - add(btnCreate, BorderLayout.NORTH); - add(btnDispose, BorderLayout.SOUTH); + Do the above steps for all the different Frame state combinations available.
+ If you observe the proper behavior the test has passed, Press the Pass button.
+ Otherwise the test has failed, Press the Fail button. +

+ Note: In Frame State Test (Window2) you can also chose the different + buttons to see different Frame behavior.
An example of a problem that + has been seen, with the Frame non-resizable you can not iconify the Frame. +

+ + + """; - Panel p = new Panel(new GridLayout(0,1)); - p.add(cbIconState); - p.add(cbResize); - add(p, BorderLayout.WEST); + public static final int DELAY = 1000; - p = new Panel(new GridLayout(0,1)); - p.add(cbNormState); - p.add(cbNonResize); - add(p, BorderLayout.EAST); + Button btnCreate = new Button("Create Frame"); + Button btnDispose = new Button("Dispose Frame"); + CheckboxGroup cbgState = new CheckboxGroup(); + CheckboxGroup cbgResize = new CheckboxGroup(); + Checkbox cbIconState = new Checkbox("Frame state ICONIFIED", cbgState, true); + Checkbox cbNormState = new Checkbox("Frame state NORMAL", cbgState, false); + Checkbox cbNonResize = new Checkbox("Frame non-resizable", cbgResize, false); + Checkbox cbResize = new Checkbox("Frame Resizable", cbgResize, true); - // Add Listeners - btnDispose.addActionListener(this); - btnCreate.addActionListener(this); - cbNormState.addItemListener(this); - cbResize.addItemListener(this); - cbIconState.addItemListener(this); - cbNonResize.addItemListener(this); + CreateFrame icontst; - resize(600, 200); + public static void main(String[] args) throws Exception { + PassFailJFrame + .builder() + .title("GetBoundsResizeTest Instructions") + .instructions(INSTRUCTIONS) + .testTimeOut(10) + .rows(25) + .columns(70) + .logArea(10) + .splitUIBottom(() -> new FrameStateTest().createPanel()) + .build() + .awaitAndCheck(); + } - }//End init() + public JPanel createPanel() { + JPanel panel = new JPanel(); + panel.setLayout(new GridLayout(0, 3)); + btnDispose.setEnabled(false); - public void actionPerformed(ActionEvent evt) { + panel.add(cbIconState); + panel.add(cbResize); + panel.add(btnCreate); + panel.add(cbNormState); + panel.add(cbNonResize); + panel.add(btnDispose); + btnDispose.addActionListener(this); + btnCreate.addActionListener(this); + return panel; + } + + public void actionPerformed(ActionEvent evt) { if (evt.getSource() == btnCreate) { btnCreate.setEnabled(false); btnDispose.setEnabled(true); - icontst = new CreateFrame(iState, bResize); - icontst.show(); + icontst =new CreateFrame(cbIconState.getState(), cbResize.getState()); + icontst.setVisible(true); } else if (evt.getSource() == btnDispose) { btnCreate.setEnabled(true); btnDispose.setEnabled(false); @@ -124,336 +158,173 @@ public class FrameStateTest extends Applet implements ActionListener, ItemListen } } - public void itemStateChanged(ItemEvent evt) { + static class CreateFrame extends Frame + implements ActionListener, WindowListener { - if (cbNormState.getState()) iState = 0; - if (cbIconState.getState()) iState = 1; - if (cbResize.getState()) bResize = true; - if (cbNonResize.getState()) bResize = false; + Button b1, b2, b3, b4, b5, b6, b7; + boolean isResizable; + String name = "Frame State Test"; - } + CreateFrame(boolean iconified, boolean resizable) { + setTitle("Frame State Test (Window 2)"); -}// class FrameStateTest + isResizable = resizable; + PassFailJFrame.log("CREATING FRAME - Initially " + + ((iconified) ? "ICONIFIED" : "NORMAL (NON-ICONIFIED)") + " and " + + ((isResizable) ? "RESIZABLE" : "NON-RESIZABLE")); -class CreateFrame extends Frame implements ActionListener , WindowListener { + setLayout(new FlowLayout()); + add(b1 = new Button("resizable")); + add(b2 = new Button("resize")); + add(b3 = new Button("iconify")); + add(b4 = new Button("iconify and restore")); + add(b5 = new Button("hide and show")); + add(b6 = new Button("hide, iconify and show")); + add(b7 = new Button("hide, iconify, show, and restore")); + b1.addActionListener(this); + b2.addActionListener(this); + b3.addActionListener(this); + b4.addActionListener(this); + b5.addActionListener(this); + b6.addActionListener(this); + b7.addActionListener(this); + addWindowListener(this); - static int e=0; - static int u=0; - static int p=0; - static int i=0; - static int v=0; + setBounds(100, 2, 200, 200); + setState(iconified ? Frame.ICONIFIED : Frame.NORMAL); + setResizable(isResizable); + pack(); + setVisible(true); + } - Button b1, b2, b3, b4, b5, b6, b7; - boolean resizable = true; - boolean iconic = false; - String name = "Frame State Test"; + /** + * Calls all runnables on EDT with a {@code DELAY} delay before each run. + * @param runnables to run + */ + private static void delayedActions(Runnable... runnables) { + setTimer(new ArrayDeque<>(Arrays.asList(runnables))); + } - CreateFrame (int iFrameState, boolean bFrameResizable) { + private static void setTimer(Deque deque) { + if (deque == null || deque.isEmpty()) return; - setTitle("Frame State Test (Window 2)"); + Timer timer = new Timer(DELAY, e -> { + deque.pop().run(); + setTimer(deque); + }); + timer.setRepeats(false); + timer.start(); + } - if (iFrameState == 1) { - iconic = true; - } + public void actionPerformed(ActionEvent e) { + if (e.getSource() == b2) { + Rectangle r = this.getBounds(); + r.width += 10; + stateLog(" - button pressed - setting bounds on Frame to: " + r); + setBounds(r); + validate(); + } else if (e.getSource() == b1) { + isResizable = !isResizable; + stateLog(" - button pressed - setting Resizable to: " + isResizable); + ((Frame) (b1.getParent())).setResizable(isResizable); + } else if (e.getSource() == b3) { + stateLog(" - button pressed - setting Iconic: "); + ((Frame) (b1.getParent())).setState(Frame.ICONIFIED); + stateLog(); + } else if (e.getSource() == b4) { + stateLog(" - button pressed - setting Iconic: "); + ((Frame) (b1.getParent())).setState(Frame.ICONIFIED); + stateLog(); + delayedActions(() -> { + stateLog(" - now restoring: "); + ((Frame) (b1.getParent())).setState(Frame.NORMAL); + stateLog(); + }); + } else if (e.getSource() == b5) { + stateLog(" - button pressed - hiding : "); + b1.getParent().setVisible(false); + stateLog(); + delayedActions(() -> { + stateLog(" - now reshowing: "); + b1.getParent().setVisible(true); + stateLog(); + }); + } else if (e.getSource() == b6) { + stateLog(" - button pressed - hiding : "); + b1.getParent().setVisible(false); + stateLog(); + delayedActions( + () -> { + stateLog(" - setting Iconic: "); + ((Frame) (b1.getParent())).setState(Frame.ICONIFIED); + }, + () -> { + stateLog(" - now reshowing: "); + b1.getParent().setVisible(true); + stateLog(); + } + ); + } else if (e.getSource() == b7) { + stateLog(" - button pressed - hiding : "); + b1.getParent().setVisible(false); + stateLog(); - if (!(bFrameResizable)) { - resizable = false; - } + delayedActions( + () -> { + stateLog(" - setting Iconic: "); + ((Frame) (b1.getParent())).setState(Frame.ICONIFIED); + }, + () -> { + stateLog(" - now reshowing: "); + b1.getParent().setVisible(true); + stateLog(); + }, + () -> { + stateLog(" - now restoring: "); + ((Frame) (b1.getParent())).setState(Frame.NORMAL); + stateLog(); + } + ); + } + } - System.out.println("CREATING FRAME - Initially "+ - ((iconic) ? "ICONIFIED" : "NORMAL (NON-ICONIFIED)") + " and " + - ((resizable) ? "RESIZABLE" : "NON-RESIZABLE") ); + public void windowActivated(WindowEvent e) { + stateLog("Activated"); + } - Sysout.println("CREATING FRAME - Initially "+ - ((iconic) ? "ICONIFIED" : "NORMAL (NON-ICONIFIED)") + " and " + - ((resizable) ? "RESIZABLE" : "NON-RESIZABLE") ); + public void windowClosed(WindowEvent e) { + stateLog("Closed"); + } - setLayout(new FlowLayout() ); - b1 = new Button("resizable"); - add(b1); - b2 = new Button("resize"); - add(b2); - b3 = new Button("iconify"); - add(b3); - b4 = new Button("iconify and restore"); - add(b4); - b5 = new Button("hide and show"); - add(b5); - b6 = new Button("hide, iconify and show"); - add(b6); - b7 = new Button("hide, iconify, show, and restore"); - add(b7); - b1.addActionListener(this); - b2.addActionListener(this); - b3.addActionListener(this); - b4.addActionListener(this); - b5.addActionListener(this); - b6.addActionListener(this); - b7.addActionListener(this); - addWindowListener(this); + public void windowClosing(WindowEvent e) { + ((Window) (e.getSource())).dispose(); + stateLog("Closing"); + } - setBounds(100,2,200, 200); - setState(iconic ? Frame.ICONIFIED: Frame.NORMAL); - setResizable(resizable); - pack(); - setVisible(true); + public void windowDeactivated(WindowEvent e) { + stateLog("Deactivated"); + } - } + public void windowDeiconified(WindowEvent e) { + stateLog("Deiconified"); + } - public void actionPerformed ( ActionEvent e ) - { - if ( e.getSource() == b2 ) { - Rectangle r = this.getBounds(); - r.width += 10; - System.out.println(" - button pressed - setting bounds on Frame to: "+r); - setBounds(r); - validate(); - } else if ( e.getSource() == b1 ) { - resizable = !resizable; - System.out.println(" - button pressed - setting Resizable to: "+resizable); - ((Frame)(b1.getParent())).setResizable(resizable); - } else if ( e.getSource() == b3 ) { - System.out.println(" - button pressed - setting Iconic: "); - dolog(); - ((Frame)(b1.getParent())).setState(Frame.ICONIFIED); - dolog(); - } else if ( e.getSource() == b4 ) { - System.out.println(" - button pressed - setting Iconic: "); - dolog(); - ((Frame)(b1.getParent())).setState(Frame.ICONIFIED); - dolog(); - try { - Thread.sleep(1000); - } catch (Exception ex) {}; - System.out.println(" - now restoring: "); - ((Frame)(b1.getParent())).setState(Frame.NORMAL); - dolog(); - } else if ( e.getSource() == b5 ) { - System.out.println(" - button pressed - hiding : "); - dolog(); - ((Frame)(b1.getParent())).setVisible(false); - dolog(); - try { - Thread.sleep(1000); - } catch (Exception ex) {}; - System.out.println(" - now reshowing: "); - ((Frame)(b1.getParent())).setVisible(true); - dolog(); - } else if ( e.getSource() == b6 ) { - System.out.println(" - button pressed - hiding : "); - dolog(); - ((Frame)(b1.getParent())).setVisible(false); - dolog(); - try { - Thread.sleep(1000); - } catch (Exception ex) {}; - System.out.println(" - setting Iconic: "); - dolog(); - ((Frame)(b1.getParent())).setState(Frame.ICONIFIED); - try { - Thread.sleep(1000); - } catch (Exception ex) {}; - System.out.println(" - now reshowing: "); - ((Frame)(b1.getParent())).setVisible(true); - dolog(); - } else if ( e.getSource() == b7 ) { - System.out.println(" - button pressed - hiding : "); - dolog(); - ((Frame)(b1.getParent())).setVisible(false); - dolog(); - try { - Thread.sleep(1000); - } catch (Exception ex) {}; - System.out.println(" - setting Iconic: "); - dolog(); - ((Frame)(b1.getParent())).setState(Frame.ICONIFIED); - try { - Thread.sleep(1000); - } catch (Exception ex) {}; - System.out.println(" - now reshowing: "); - ((Frame)(b1.getParent())).setVisible(true); - dolog(); - try { - Thread.sleep(1000); - } catch (Exception ex) {}; - System.out.println(" - now restoring: "); - ((Frame)(b1.getParent())).setState(Frame.NORMAL); - dolog(); - } - } + public void windowIconified(WindowEvent e) { + stateLog("Iconified"); + } - public void windowActivated(WindowEvent e) { - System.out.println(name + " Activated"); - dolog(); - } - public void windowClosed(WindowEvent e) { - System.out.println(name + " Closed"); - dolog(); - } - public void windowClosing(WindowEvent e) { - ((Window)(e.getSource())).dispose(); - System.out.println(name + " Closing"); - dolog(); - } - public void windowDeactivated(WindowEvent e) { - System.out.println(name + " Deactivated"); - dolog(); - } - public void windowDeiconified(WindowEvent e) { - System.out.println(name + " Deiconified"); - dolog(); - } - public void windowIconified(WindowEvent e) { - System.out.println(name + " Iconified"); - dolog(); - } - public void windowOpened(WindowEvent e) { - System.out.println(name + " Opened"); - dolog(); - } + public void windowOpened(WindowEvent e) { + stateLog("Opened"); + } - public void dolog() { - System.out.println(" getState returns: "+getState()); + public void stateLog(String message) { + PassFailJFrame + .log("[State=%d] %s %s".formatted(getState(), name, message)); + } + + public void stateLog() { + PassFailJFrame.log("[State=" + getState() + "]"); + } } } - -// }// class FrameStateTest - -/**************************************************** - Standard Test Machinery - DO NOT modify anything below -- it's a standard - chunk of code whose purpose is to make user - interaction uniform, and thereby make it simpler - to read and understand someone else's test. - ****************************************************/ - -/** - This is part of the standard test machinery. - It creates a dialog (with the instructions), and is the interface - for sending text messages to the user. - To print the instructions, send an array of strings to Sysout.createDialog - WithInstructions method. Put one line of instructions per array entry. - To display a message for the tester to see, simply call Sysout.println - with the string to be displayed. - This mimics System.out.println but works within the test harness as well - as standalone. - */ - -class Sysout - { - private static TestDialog dialog; - - public static void createDialogWithInstructions( String[] instructions ) - { - dialog = new TestDialog( new Frame(), "Instructions" ); - dialog.printInstructions( instructions ); - dialog.show(); - println( "Any messages for the tester will display here." ); - } - - public static void createDialog( ) - { - dialog = new TestDialog( new Frame(), "Instructions" ); - String[] defInstr = { "Instructions will appear here. ", "" } ; - dialog.printInstructions( defInstr ); - dialog.show(); - println( "Any messages for the tester will display here." ); - } - - - public static void printInstructions( String[] instructions ) - { - dialog.printInstructions( instructions ); - } - - - public static void println( String messageIn ) - { - dialog.displayMessage( messageIn ); - } - - }// Sysout class - -/** - This is part of the standard test machinery. It provides a place for the - test instructions to be displayed, and a place for interactive messages - to the user to be displayed. - To have the test instructions displayed, see Sysout. - To have a message to the user be displayed, see Sysout. - Do not call anything in this dialog directly. - */ -class TestDialog extends Dialog - { - - TextArea instructionsText; - TextArea messageText; - int maxStringLength = 80; - - //DO NOT call this directly, go through Sysout - public TestDialog( Frame frame, String name ) - { - super( frame, name ); - int scrollBoth = TextArea.SCROLLBARS_BOTH; - int scrollNone = TextArea.SCROLLBARS_NONE; - instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); - add( "North", instructionsText ); - - messageText = new TextArea( "", 10, maxStringLength, scrollBoth ); - add("South", messageText); - - pack(); - - show(); - }// TestDialog() - - //DO NOT call this directly, go through Sysout - public void printInstructions( String[] instructions ) - { - //Clear out any current instructions - instructionsText.setText( "" ); - - //Go down array of instruction strings - - String printStr, remainingStr; - for( int i=0; i < instructions.length; i++ ) - { - //chop up each into pieces maxSringLength long - remainingStr = instructions[ i ]; - while( remainingStr.length() > 0 ) - { - //if longer than max then chop off first max chars to print - if( remainingStr.length() >= maxStringLength ) - { - //Try to chop on a word boundary - int posOfSpace = remainingStr. - lastIndexOf( ' ', maxStringLength - 1 ); - - if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; - - printStr = remainingStr.substring( 0, posOfSpace + 1 ); - remainingStr = remainingStr.substring( posOfSpace + 1 ); - } - //else just print - else - { - printStr = remainingStr; - remainingStr = ""; - } - - instructionsText.append( printStr + "\n" ); - - }// while - - }// for - - }//printInstructions() - - //DO NOT call this directly, go through Sysout - public void displayMessage( String messageIn ) - { - messageText.append( messageIn + "\n" ); - } - - - }// TestDialog class