1 /* 2 * Copyright (c) 2018, 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 8208543 27 * @requires (os.family == "mac") 28 * @summary Support for apple.awt.documentModalSheet incomplete in Mac 29 * @run main/manual DocumentModalSheetTest 30 */ 31 32 import java.awt.Dialog; 33 import java.awt.event.ActionEvent; 34 import java.awt.event.ActionListener; 35 import java.awt.FlowLayout; 36 import javax.swing.JFrame; 37 import javax.swing.JDialog; 38 import javax.swing.JLabel; 39 import javax.swing.JButton; 40 import javax.swing.JTextArea; 41 import javax.swing.Timer; 42 import javax.swing.SwingUtilities; 43 44 public class DocumentModalSheetTest { 45 46 private static JFrame jFrame; 47 private static JDialog jDialog; 48 private static JFrame instructionFrame; 49 private static final int sleepTime = 300000; 50 private static volatile boolean testContinueFlag = true; 51 private static final String TEST_INSTRUCTIONS = 52 " This is a manual test\n\n" + 53 " 1) Press PASS if dialog appears as a sheet\n" + 54 " 2) Press FAIL otherwise\n"; 55 private static final String FAIL_MESSAGE = "Dialog appears as a new window"; 56 57 private void createAndShowInstructionFrame() throws Exception { 58 SwingUtilities.invokeAndWait(new Runnable() { 59 public void run() { 60 JButton passButton = new JButton("Pass"); 61 passButton.setEnabled(true); 62 63 JButton failButton = new JButton("Fail"); 64 failButton.setEnabled(true); 65 66 JTextArea instructions = new JTextArea(5, 60); 67 instructions.setText(TEST_INSTRUCTIONS); 68 69 instructionFrame = new JFrame("Test Instructions"); 70 instructionFrame.add(passButton); 71 instructionFrame.add(failButton); 72 instructionFrame.add(instructions); 73 instructionFrame.setSize(200,200); 74 instructionFrame.setLayout(new FlowLayout()); 75 instructionFrame.pack(); 76 instructionFrame.setVisible(true); 77 78 passButton.addActionListener(ae -> { 79 dispose(); 80 testContinueFlag = false; 81 }); 82 83 failButton.addActionListener(ae -> { 84 dispose() ; 85 testContinueFlag = false; 86 throw new RuntimeException(FAIL_MESSAGE); 87 }); 88 } 89 }); 90 } 91 92 private void createAndShowModalSheet() throws Exception { 93 SwingUtilities.invokeAndWait(new Runnable() { 94 public void run() { 95 jFrame = new JFrame(); 96 jDialog = new JDialog(jFrame, null, Dialog.ModalityType.DOCUMENT_MODAL); 97 jDialog.getRootPane().putClientProperty("apple.awt.documentModalSheet", Boolean.TRUE); 98 JLabel jLabel = new JLabel("Document Modal Sheet"); 99 jDialog.add(jLabel); 100 101 Timer timer = new Timer(sleepTime, new ActionListener() { 102 public void actionPerformed(ActionEvent e) { 103 jDialog.setVisible(false); 104 dispose(); 105 } 106 }); 107 timer.setRepeats(false); 108 timer.start(); 109 jDialog.pack(); 110 jDialog.setVisible(true); 111 } 112 }); 113 } 114 115 private static void dispose() { 116 jDialog.dispose(); 117 jFrame.dispose(); 118 instructionFrame.dispose(); 119 } 120 121 public static void main(String[] args) throws Exception { 122 DocumentModalSheetTest sheetObj = new DocumentModalSheetTest(); 123 sheetObj.createAndShowInstructionFrame(); 124 sheetObj.createAndShowModalSheet(); 125 126 if (testContinueFlag) { 127 SwingUtilities.invokeAndWait(DocumentModalSheetTest::dispose); 128 throw new RuntimeException("Timed out after " + 129 sleepTime / 1000 + " seconds"); 130 } 131 } 132 } 133