|
| 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.FileDialog; |
| 25 | +import java.awt.Frame; |
| 26 | +import java.lang.reflect.InvocationTargetException; |
| 27 | +import javax.swing.JButton; |
| 28 | + |
| 29 | +/* |
| 30 | + * @test |
| 31 | + * @bug 8026869 |
| 32 | + * @summary Support apple.awt.use-file-dialog-packages property. |
| 33 | + * @requires (os.family == "mac") |
| 34 | + * @library /java/awt/regtesthelpers |
| 35 | + * @build PassFailJFrame |
| 36 | + * @run main/manual FileDialogForPackages |
| 37 | +*/ |
| 38 | + |
| 39 | +public class FileDialogForPackages { |
| 40 | + |
| 41 | + private static JButton initialize() { |
| 42 | + System.setProperty("apple.awt.use-file-dialog-packages", "true"); |
| 43 | + |
| 44 | + FileDialog fd = new FileDialog((Frame) null, "Open"); |
| 45 | + String APPLICATIONS_FOLDER = "/Applications"; |
| 46 | + fd.setDirectory(APPLICATIONS_FOLDER); |
| 47 | + |
| 48 | + JButton showBtn = new JButton("Show File Dialog"); |
| 49 | + showBtn.addActionListener(e -> { |
| 50 | + fd.setVisible(true); |
| 51 | + String output = fd.getFile(); |
| 52 | + if (output != null) { |
| 53 | + PassFailJFrame.log(output + " is selected\n"); |
| 54 | + } |
| 55 | + }); |
| 56 | + return showBtn; |
| 57 | + } |
| 58 | + |
| 59 | + public static void main(String[] args) throws InterruptedException, |
| 60 | + InvocationTargetException { |
| 61 | + String instructions = """ |
| 62 | + 1) Click on 'Show File Dialog' button. A file dialog will come up. |
| 63 | + 2) Navigate to the Applications folder if not already there. |
| 64 | + 3) Check that the application bundles can be selected |
| 65 | + but can not be navigated. |
| 66 | + 4) If it's true then press Pass, otherwise press Fail. |
| 67 | + """; |
| 68 | + |
| 69 | + PassFailJFrame.builder() |
| 70 | + .title("Directory File Dialog Test Instructions") |
| 71 | + .instructions(instructions) |
| 72 | + .rows((int) instructions.lines().count() + 1) |
| 73 | + .columns(40) |
| 74 | + .logArea(8) |
| 75 | + .splitUIBottom(FileDialogForPackages::initialize) |
| 76 | + .build() |
| 77 | + .awaitAndCheck(); |
| 78 | + } |
| 79 | +} |
0 commit comments