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 
  25 import jdk.testlibrary.OSInfo;
  26 import test.java.awt.regtesthelpers.Sysout;
  27 
  28 import java.applet.Applet;
  29 import java.awt.Button;
  30 import java.awt.FileDialog;
  31 import java.awt.Frame;
  32 import java.awt.GridLayout;
  33 import java.awt.event.ActionEvent;
  34 import java.awt.event.ActionListener;
  35 
  36 public 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