1 /* 2 * Copyright (c) 2013, 2015, 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 /* 25 test 26 @bug 6401700 6412803 27 @summary Tests that modal dialog is shown on the screen and 28 iconified/restored correctly if some of its blocked windows are invisible 29 @author artem.ananiev: area=awt.modal 30 @run applet/manual=yesno InvisibleParentTest.html 31 */ 32 33 import java.applet.Applet; 34 import java.awt.BorderLayout; 35 import java.awt.Button; 36 import java.awt.Component; 37 import java.awt.Dialog; 38 import java.awt.Frame; 39 import java.awt.TextArea; 40 import java.awt.Window; 41 42 public class InvisibleParentTest extends Applet 43 { 44 public void init() 45 { 46 setLayout(new BorderLayout()); 47 48 String[] instructions = 49 { 50 "If your system is Windows, press PASS button.", 51 "When the test starts two windows should appear: frame G1 and", 52 " dialog D1. Another one frame F1 should be minimized.", 53 " If the dialog is not shown (minimizied), press FAIL button.", 54 "Then minimize frame G1 and restore F1. If the dialog D1 is not", 55 " restored together with F1, press FAIL, else PASS" 56 }; 57 Sysout.createDialogWithInstructions( instructions ); 58 } 59 60 public void start () 61 { 62 Button b; 63 64 setSize (200,200); 65 setVisible(true); 66 validate(); 67 68 Component c = this; 69 while ((c != null) && !(c instanceof Window)) 70 { 71 c = c.getParent(); 72 } 73 if (c != null) 74 { 75 ((Window)c).setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); 76 } 77 78 Frame f1 = new Frame("F1"); 79 f1.setBounds(100, 300, 100, 100); 80 f1.setVisible(true); 81 f1.setExtendedState(Frame.ICONIFIED); 82 83 Frame g1 = new Frame("G1"); 84 g1.setBounds(150, 350, 100, 100); 85 g1.setVisible(true); 86 87 final Dialog d1 = new Dialog((Frame)null, "D1", Dialog.ModalityType.APPLICATION_MODAL); 88 d1.setBounds(200, 400, 100, 100); 89 new Thread(new Runnable() 90 { 91 public void run() 92 { 93 d1.setVisible(true); 94 } 95 }).start(); 96 } 97 } 98 99 /**************************************************** 100 Standard Test Machinery 101 DO NOT modify anything below -- it's a standard 102 chunk of code whose purpose is to make user 103 interaction uniform, and thereby make it simpler 104 to read and understand someone else's test. 105 ****************************************************/ 106 107 /** 108 This is part of the standard test machinery. 109 It creates a dialog (with the instructions), and is the interface 110 for sending text messages to the user. 111 To print the instructions, send an array of strings to Sysout.createDialog 112 WithInstructions method. Put one line of instructions per array entry. 113 To display a message for the tester to see, simply call Sysout.println 114 with the string to be displayed. 115 This mimics System.out.println but works within the test harness as well 116 as standalone. 117 */ 118 119 class Sysout 120 { 121 private static TestDialog dialog; 122 123 public static void createDialogWithInstructions( String[] instructions ) 124 { 125 dialog = new TestDialog( new Frame(), "Instructions" ); 126 dialog.printInstructions( instructions ); 127 dialog.setVisible(true); 128 println( "Any messages for the tester will display here." ); 129 } 130 131 public static void createDialog( ) 132 { 133 dialog = new TestDialog( new Frame(), "Instructions" ); 134 String[] defInstr = { "Instructions will appear here. ", "" } ; 135 dialog.printInstructions( defInstr ); 136 dialog.setVisible(true); 137 println( "Any messages for the tester will display here." ); 138 } 139 140 141 public static void printInstructions( String[] instructions ) 142 { 143 dialog.printInstructions( instructions ); 144 } 145 146 147 public static void println( String messageIn ) 148 { 149 dialog.displayMessage( messageIn ); 150 } 151 152 }// Sysout class 153 154 /** 155 This is part of the standard test machinery. It provides a place for the 156 test instructions to be displayed, and a place for interactive messages 157 to the user to be displayed. 158 To have the test instructions displayed, see Sysout. 159 To have a message to the user be displayed, see Sysout. 160 Do not call anything in this dialog directly. 161 */ 162 class TestDialog extends Dialog 163 { 164 165 TextArea instructionsText; 166 TextArea messageText; 167 int maxStringLength = 80; 168 169 //DO NOT call this directly, go through Sysout 170 public TestDialog( Frame frame, String name ) 171 { 172 super( frame, name ); 173 setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); 174 int scrollBoth = TextArea.SCROLLBARS_BOTH; 175 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); 176 add( "North", instructionsText ); 177 178 messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); 179 add("Center", messageText); 180 181 pack(); 182 183 setVisible(true); 184 }// TestDialog() 185 186 //DO NOT call this directly, go through Sysout 187 public void printInstructions( String[] instructions ) 188 { 189 //Clear out any current instructions 190 instructionsText.setText( "" ); 191 192 //Go down array of instruction strings 193 194 String printStr, remainingStr; 195 for( int i=0; i < instructions.length; i++ ) 196 { 197 //chop up each into pieces maxSringLength long 198 remainingStr = instructions[ i ]; 199 while( remainingStr.length() > 0 ) 200 { 201 //if longer than max then chop off first max chars to print 202 if( remainingStr.length() >= maxStringLength ) 203 { 204 //Try to chop on a word boundary 205 int posOfSpace = remainingStr. 206 lastIndexOf( ' ', maxStringLength - 1 ); 207 208 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; 209 210 printStr = remainingStr.substring( 0, posOfSpace + 1 ); 211 remainingStr = remainingStr.substring( posOfSpace + 1 ); 212 } 213 //else just print 214 else 215 { 216 printStr = remainingStr; 217 remainingStr = ""; 218 } 219 220 instructionsText.append( printStr + "\n" ); 221 222 }// while 223 224 }// for 225 226 }//printInstructions() 227 228 //DO NOT call this directly, go through Sysout 229 public void displayMessage( String messageIn ) 230 { 231 messageText.append( messageIn + "\n" ); 232 System.out.println(messageIn); 233 } 234 235 }// TestDialog class | 1 /* 2 * Copyright (c) 2016, 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 /* 25 * @test 26 * @bug 6401700 6412803 8058950 27 * @summary Tests that modal dialog is shown on the screen and 28 * iconified/restored correctly if some of its blocked windows are invisible 29 * @run main/manual InvisibleParentTest 30 */ 31 import java.awt.Dialog; 32 import java.awt.Frame; 33 import java.awt.GridBagConstraints; 34 import java.awt.GridBagLayout; 35 import java.awt.event.ActionEvent; 36 import java.awt.event.ActionListener; 37 import java.util.concurrent.CountDownLatch; 38 import java.util.concurrent.TimeUnit; 39 import javax.swing.BorderFactory; 40 import javax.swing.JButton; 41 import javax.swing.JFrame; 42 import javax.swing.JPanel; 43 import javax.swing.JTextArea; 44 import javax.swing.SwingUtilities; 45 46 public class InvisibleParentTest { 47 48 public static void main(String args[]) throws Exception { 49 final CountDownLatch latch = new CountDownLatch(1); 50 TestUI test = new TestUI(latch); 51 52 SwingUtilities.invokeLater(new Runnable() { 53 @Override 54 public void run() { 55 try { 56 test.createUI(); 57 } catch (Exception ex) { 58 throw new RuntimeException("Exception while creating test UI"); 59 } 60 } 61 }); 62 63 boolean status = latch.await(5, TimeUnit.MINUTES); 64 65 if (!status) { 66 System.out.println("Test timed out."); 67 } 68 69 SwingUtilities.invokeAndWait(new Runnable() { 70 @Override 71 public void run() { 72 try { 73 test.disposeUI(); 74 } catch (Exception ex) { 75 throw new RuntimeException("Exception while disposing test UI"); 76 } 77 } 78 }); 79 80 if (test.testResult == false) { 81 throw new RuntimeException("Test Failed."); 82 } 83 } 84 } 85 86 class TestUI { 87 88 private static JFrame mainFrame; 89 private static JPanel mainControlPanel; 90 91 private static JTextArea instructionTextArea; 92 93 private static JPanel resultButtonPanel; 94 private static JButton passButton; 95 private static JButton failButton; 96 97 private static GridBagLayout layout; 98 private final CountDownLatch latch; 99 public boolean testResult = false; 100 101 public TestUI(CountDownLatch latch) throws Exception { 102 this.latch = latch; 103 } 104 105 public final void createUI() throws Exception { 106 107 mainFrame = new JFrame("InvisibleParentTest"); 108 mainFrame.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); 109 110 layout = new GridBagLayout(); 111 mainControlPanel = new JPanel(layout); 112 resultButtonPanel = new JPanel(layout); 113 114 GridBagConstraints gbc = new GridBagConstraints(); 115 116 // Create Test instructions 117 String instructions 118 = "If your system is Windows, press PASS button.\n" 119 + "When the test starts two windows should appear: frame G1 and\n" 120 + " dialog D1. Another one frame F1 should be minimized.\n" 121 + " If the dialog is not shown (minimizied), press FAIL button.\n" 122 + "Then minimize frame G1 and restore F1. If the dialog D1 is not\n" 123 + " restored together with F1, press FAIL, else PASS"; 124 125 instructionTextArea = new JTextArea(); 126 instructionTextArea.setText(instructions); 127 instructionTextArea.setEditable(false); 128 instructionTextArea.setBorder(BorderFactory. 129 createTitledBorder("Test Instructions")); 130 131 gbc.gridx = 0; 132 gbc.gridy = 0; 133 gbc.fill = GridBagConstraints.HORIZONTAL; 134 mainControlPanel.add(instructionTextArea, gbc); 135 136 // Create resultButtonPanel with Pass, Fail buttons 137 passButton = new JButton("Pass"); 138 passButton.setActionCommand("Pass"); 139 passButton.addActionListener((ActionEvent e) -> { 140 System.out.println("Pass Button pressed!"); 141 testResult = true; 142 latch.countDown(); 143 144 }); 145 146 failButton = new JButton("Fail"); 147 failButton.setActionCommand("Fail"); 148 failButton.addActionListener(new ActionListener() { 149 @Override 150 public void actionPerformed(ActionEvent e) { 151 System.out.println("Fail Button pressed!"); 152 testResult = false; 153 latch.countDown(); 154 } 155 }); 156 157 gbc.gridx = 0; 158 gbc.gridy = 0; 159 resultButtonPanel.add(passButton, gbc); 160 gbc.gridx = 1; 161 gbc.gridy = 0; 162 resultButtonPanel.add(failButton, gbc); 163 164 gbc.gridx = 0; 165 gbc.gridy = 1; 166 mainControlPanel.add(resultButtonPanel, gbc); 167 168 mainFrame.add(mainControlPanel); 169 170 mainFrame.pack(); 171 mainFrame.setVisible(true); 172 173 // Create AWT frames and modal dialog 174 createAWTComponents(); 175 } 176 177 public void disposeUI() { 178 mainFrame.setVisible(false); 179 mainFrame.dispose(); 180 } 181 182 private void createAWTComponents() { 183 Frame f1 = new Frame("F1"); 184 f1.setBounds(100, 300, 100, 100); 185 f1.setVisible(true); 186 187 try { 188 Thread.sleep(500); 189 } catch (Exception ex) { 190 } 191 192 f1.setExtendedState(Frame.ICONIFIED); 193 194 Frame g1 = new Frame("G1"); 195 g1.setBounds(150, 350, 100, 100); 196 g1.setVisible(true); 197 198 final Dialog d1 = new Dialog((Frame) null, "D1", Dialog.ModalityType.APPLICATION_MODAL); 199 d1.setBounds(200, 400, 100, 100); 200 new Thread(new Runnable() { 201 public void run() { 202 d1.setVisible(true); 203 } 204 }).start(); 205 } 206 } 207 208 209 210 |