|
| 1 | +/* |
| 2 | + * Copyright (c) 2013, 2024, 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 | +import java.awt.BorderLayout; |
| 25 | +import java.awt.Button; |
| 26 | +import java.awt.FileDialog; |
| 27 | +import java.awt.Frame; |
| 28 | +import java.lang.reflect.InvocationTargetException; |
| 29 | +import javax.swing.JFrame; |
| 30 | +import javax.swing.JScrollPane; |
| 31 | +import javax.swing.JTextArea; |
| 32 | + |
| 33 | +/* |
| 34 | + * @test |
| 35 | + * @bug 7161437 |
| 36 | + * @summary We should support "apple.awt.fileDialogForDirectories" property. |
| 37 | + * @requires (os.family == "mac") |
| 38 | + * @library /java/awt/regtesthelpers |
| 39 | + * @build PassFailJFrame |
| 40 | + * @run main/manual FileDialogForDirectories |
| 41 | + */ |
| 42 | + |
| 43 | +public class FileDialogForDirectories { |
| 44 | + |
| 45 | + private static JFrame initialize() { |
| 46 | + System.setProperty("apple.awt.fileDialogForDirectories", "true"); |
| 47 | + |
| 48 | + JFrame frame = new JFrame("Directory File Dialog Test Frame"); |
| 49 | + frame.setLayout(new BorderLayout()); |
| 50 | + JTextArea textOutput = new JTextArea(8, 30); |
| 51 | + textOutput.setLineWrap(true); |
| 52 | + JScrollPane textScrollPane = new JScrollPane(textOutput); |
| 53 | + frame.add(textScrollPane, BorderLayout.CENTER); |
| 54 | + |
| 55 | + FileDialog fd = new FileDialog(new Frame(), "Open"); |
| 56 | + |
| 57 | + Button showBtn = new Button("Show File Dialog"); |
| 58 | + showBtn.addActionListener(e -> { |
| 59 | + fd.setVisible(true); |
| 60 | + String output = fd.getFile(); |
| 61 | + if (output != null) { |
| 62 | + textOutput.append(output + " is selected\n"); |
| 63 | + textOutput.setCaretPosition(textOutput.getText().length()); |
| 64 | + } |
| 65 | + }); |
| 66 | + frame.add(showBtn, BorderLayout.NORTH); |
| 67 | + frame.pack(); |
| 68 | + return frame; |
| 69 | + } |
| 70 | + |
| 71 | + public static void main(String[] args) throws InterruptedException, |
| 72 | + InvocationTargetException { |
| 73 | + String instructions = """ |
| 74 | + 1) Click on 'Show File Dialog' button. A file dialog will come up. |
| 75 | + 2) Check that files can't be selected. |
| 76 | + 3) Check that directories can be selected. |
| 77 | + 4) Repeat steps 1 - 3 a few times for different files and directories. |
| 78 | + 5) If it's true then the press Pass, otherwise press Fail. |
| 79 | + """; |
| 80 | + |
| 81 | + PassFailJFrame.builder() |
| 82 | + .title("Directory File Dialog Test Instructions") |
| 83 | + .instructions(instructions) |
| 84 | + .rows((int) instructions.lines().count() + 1) |
| 85 | + .columns(40) |
| 86 | + .testUI(FileDialogForDirectories::initialize) |
| 87 | + .build() |
| 88 | + .awaitAndCheck(); |
| 89 | + } |
| 90 | +} |
0 commit comments