FileDialogForDirectories.java revision 10730:07156012ab78
1/* 2 * Copyright (c) 2013, 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 25import jdk.testlibrary.OSInfo; 26import test.java.awt.regtesthelpers.Sysout; 27 28import java.applet.Applet; 29import java.awt.Button; 30import java.awt.FileDialog; 31import java.awt.Frame; 32import java.awt.GridLayout; 33import java.awt.event.ActionEvent; 34import java.awt.event.ActionListener; 35 36public class FileDialogForDirectories extends Applet implements ActionListener { 37 private volatile Button showBtn; 38 private volatile FileDialog fd; 39 40 @Override 41 public void init() { 42 if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) { 43 Sysout.createDialogWithInstructions(new String[]{ 44 "Press PASS, this test is for MacOS X only."}); 45 return; 46 } 47 48 System.setProperty("apple.awt.fileDialogForDirectories", "true"); 49 50 setLayout(new GridLayout(1, 1)); 51 52 fd = new FileDialog(new Frame(), "Open"); 53 54 showBtn = new Button("Show File Dialog"); 55 showBtn.addActionListener(this); 56 add(showBtn); 57 String[] instructions = { 58 "1) Click on 'Show File Dialog' button. A file dialog will come up.", 59 "2) Check that files can't be selected.", 60 "3) Check that directories can be selected.", 61 "4) Repeat steps 1 - 3 a few times for different files and directories.", 62 "5) If it's true then the test passed, otherwise it failed."}; 63 Sysout.createDialogWithInstructions(instructions); 64 }//End init() 65 66 @Override 67 public void start() { 68 setSize(200, 200); 69 show(); 70 }// start() 71 72 @Override 73 public void actionPerformed(ActionEvent e) { 74 if (e.getSource() == showBtn) { 75 fd.setVisible(true); 76 String output = fd.getFile(); 77 if (output != null) { 78 Sysout.println(output + " is selected"); 79 } 80 } 81 } 82}// class ManualYesNoTest 83