--- /dev/null 2015-11-23 11:44:53.000000000 +0530 +++ new/test/java/awt/FileDialog/8019280/ValidateDirectorySelection.java 2015-11-23 11:44:53.000000000 +0530 @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* @test + * @bug 8019280 + * @summary CFileDialog should show Choose for Mac OS X for Directory selection + * @requires (os.family=="mac") + * @run main/manual ValidateDirectorySelection + */ +import java.awt.Color; +import java.awt.FileDialog; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; +import javax.swing.border.Border; + +public class ValidateDirectorySelection { + + private static JFrame frame; + private static FileDialog chooser; + private static JTextArea textArea; + private static JButton openCFileDialogButton; + private static JButton passButton; + private static JButton failButton; + private static boolean theTestPassed; + private static boolean testGeneratedInterrupt; + private static Thread mainThread; + private static final int sleepTime = 20000; + + public static void main(String[] args) throws Exception { + mainThread = Thread.currentThread(); + try { + createUIandManualTest(); + } catch (Exception ex) { + Logger.getLogger(ValidateDirectorySelection.class.getName()) + .log(Level.SEVERE, null, ex); + return; + } + try { + mainThread.sleep(sleepTime); + } catch (InterruptedException ex) { + frame.dispose(); + if (!theTestPassed && testGeneratedInterrupt) { + throw new RuntimeException("Test Failed"); + } + } + if (!testGeneratedInterrupt) { + frame.dispose(); + throw new RuntimeException("Test Timed out"); + } + + } + + public static synchronized void pass() { + theTestPassed = true; + testGeneratedInterrupt = true; + mainThread.interrupt(); + } + + public static synchronized void fail() { + theTestPassed = false; + testGeneratedInterrupt = true; + mainThread.interrupt(); + } + + private static void createUIandManualTest() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frame = new JFrame("Validate for directory selection only"); + frame.setLayout(new GridBagLayout()); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setUndecorated(true); + String instructions = "\n(1) Press Directory Dialog button " + + "\n(2) Find a button labeled Choose" + + "\n(3) Click Cancel button" + + "\nIf this is validated, press Pass" + + "\nOtherwise, press Fail \n"; + textArea = new JTextArea(); + textArea.setText(instructions); + openCFileDialogButton = new JButton(" Directory Dialog "); + openCFileDialogButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + System.setProperty("apple.awt.fileDialogForDirectories", + "true"); + chooser = new FileDialog(frame, "Select Target Folder"); + chooser.setVisible(true); + } + }); + passButton = new JButton(" Pass "); + passButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ValidateDirectorySelection.pass(); + } + }); + failButton = new JButton(" Fail "); + failButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ValidateDirectorySelection.fail(); + } + }); + GridBagConstraints gbc = new GridBagConstraints(); + Border border = BorderFactory.createLineBorder(Color.BLACK); + textArea.setBorder(BorderFactory.createCompoundBorder(border, + BorderFactory.createEmptyBorder(10, 10, 10, 10))); + gbc.gridx = 0; + gbc.gridy = 0; + frame.getContentPane().add(textArea, gbc); + JPanel buttonPanel = new JPanel(); + gbc.gridx = 0; + gbc.gridy = 0; + buttonPanel.add(openCFileDialogButton, gbc); + gbc.gridx = 1; + gbc.gridy = 0; + buttonPanel.add(passButton, gbc); + gbc.gridx = 2; + gbc.gridy = 0; + buttonPanel.add(failButton, gbc); + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.gridx = 0; + gbc.gridy = 1; + frame.getContentPane().add(buttonPanel, gbc); + frame.pack(); + frame.setVisible(true); + } + }); + } +}