test/jdk/javax/swing/JFileChooser/8067660/FileChooserTest.java
author ssadetsky
Wed, 03 Apr 2019 15:43:25 -0700
branchJDK-8200758-branch
changeset 57303 eff0cf668c29
parent 47216 71c04702a3d5
permissions -rw-r--r--
8221876:[macOS] JPackage install takes long time Reviewed-by: almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34799
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
     1
/*
47170
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
34799
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
     4
 *
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
     8
 *
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    13
 * accompanied this code).
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    14
 *
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    18
 *
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    21
 * questions.
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    22
 */
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    23
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    24
/*
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    25
 * @test
47170
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    26
 * @bug 8067660 8178106
34799
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    27
 * @summary JFileChooser create new folder fails silently
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    28
 * @requires (os.family == "windows")
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    29
 * @run main/manual FileChooserTest
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    30
 */
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    31
import java.awt.Panel;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    32
import java.awt.TextArea;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    33
import java.awt.event.ActionEvent;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    34
import java.awt.event.ActionListener;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    35
import javax.swing.JButton;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    36
import javax.swing.JDialog;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    37
import javax.swing.JFileChooser;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    38
import javax.swing.JFrame;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    39
import javax.swing.SwingUtilities;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    40
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    41
public class FileChooserTest {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    42
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    43
    private static boolean theTestPassed;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    44
    private static boolean testGeneratedInterrupt;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    45
    private static Thread mainThread;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    46
    private static int sleepTime = 30000;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    47
    public static  JFileChooser fileChooser;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    48
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    49
    private static void init() throws Exception {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    50
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    51
        SwingUtilities.invokeAndWait(new Runnable() {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    52
            @Override
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    53
            public void run() {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    54
                String[] instructions
47170
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    55
                     = {
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    56
                       "1) Create a folder with read only permissions by "
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    57
                       + "changing security permission through Security tab"
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    58
                       + "under Folder->Properties menu to deny write permission"
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    59
                       + " to the newly created folder",
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    60
                       "2) Click on run test button.It will open a open dialog"
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    61
                       + " Navigate to the newly created read only folder",
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    62
                       "3) Click on the create new folder button in open dialog",
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    63
                       "4) If an error message does not pops up"
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    64
                       + "test failed otherwise passed.",
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    65
                       "5) Pressing Pass/Fail button will mark test as "
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    66
                       + "pass/fail and will shutdown JVM",
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    67
                       "6) Newly created folder permissions can now be restored"
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    68
                       + " back to default",
ac621266a4b8 8178106: There is no error message pop up when clicking 'create folder' button
aghaisas
parents: 34799
diff changeset
    69
                };
34799
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    70
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    71
                Sysout.createDialogWithInstructions(instructions);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    72
                Sysout.printInstructions(instructions);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    73
            }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    74
        });
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    75
    }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    76
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    77
    /**
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    78
     * ***************************************************
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    79
     * Standard Test Machinery Section DO NOT modify anything in this section --
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    80
     * it's a standard chunk of code which has all of the synchronisation
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    81
     * necessary for the test harness. By keeping it the same in all tests, it
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    82
     * is easier to read and understand someone else's test, as well as insuring
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    83
     * that all tests behave correctly with the test harness. There is a section
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    84
     * following this for test-defined classes
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    85
     */
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    86
    public static void main(String args[]) throws Exception {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    87
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    88
        mainThread = Thread.currentThread();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    89
        try {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    90
            init();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    91
        } catch (Exception ex) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    92
            return;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    93
        }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    94
        try {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    95
            mainThread.sleep(sleepTime);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    96
        } catch (InterruptedException ex) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    97
            Sysout.dispose();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    98
            if (!theTestPassed && testGeneratedInterrupt) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
    99
                throw new RuntimeException("Test Failed");
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   100
            }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   101
        }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   102
        if (!testGeneratedInterrupt) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   103
            Sysout.dispose();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   104
            throw new RuntimeException("Test Failed");
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   105
        }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   106
    }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   107
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   108
    public static synchronized void pass() {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   109
        theTestPassed = true;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   110
        testGeneratedInterrupt = true;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   111
        mainThread.interrupt();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   112
    }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   113
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   114
    public static synchronized void fail() {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   115
        theTestPassed = false;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   116
        testGeneratedInterrupt = true;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   117
        mainThread.interrupt();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   118
    }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   119
}
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   120
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   121
/**
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   122
 * This is part of the standard test machinery. It creates a dialog (with the
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   123
 * instructions), and is the interface for sending text messages to the user. To
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   124
 * print the instructions, send an array of strings to Sysout.createDialog
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   125
 * WithInstructions method. Put one line of instructions per array entry. To
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   126
 * display a message for the tester to see, simply call Sysout.println with the
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   127
 * string to be displayed. This mimics System.out.println but works within the
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   128
 * test harness as well as standalone.
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   129
 */
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   130
class Sysout {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   131
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   132
    private static TestDialog dialog;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   133
    private static JFrame frame;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   134
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   135
    public static void createDialogWithInstructions(String[] instructions) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   136
        frame = new JFrame();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   137
        dialog = new TestDialog(frame, "Instructions");
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   138
        dialog.printInstructions(instructions);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   139
        dialog.setVisible(true);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   140
        println("Any messages for the tester will display here.");
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   141
    }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   142
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   143
    public static void printInstructions(String[] instructions) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   144
        dialog.printInstructions(instructions);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   145
    }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   146
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   147
    public static void println(String messageIn) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   148
        dialog.displayMessage(messageIn);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   149
    }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   150
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   151
    public static void dispose() {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   152
        Sysout.println("Shutting down the Java process..");
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   153
        if(FileChooserTest.fileChooser != null) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   154
            FileChooserTest.fileChooser.cancelSelection();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   155
        }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   156
        frame.dispose();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   157
        dialog.dispose();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   158
    }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   159
}
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   160
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   161
/**
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   162
 * This is part of the standard test machinery. It provides a place for the test
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   163
 * instructions to be displayed, and a place for interactive messages to the
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   164
 * user to be displayed. To have the test instructions displayed, see Sysout. To
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   165
 * have a message to the user be displayed, see Sysout. Do not call anything in
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   166
 * this dialog directly.
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   167
 */
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   168
class TestDialog extends JDialog {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   169
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   170
    private TextArea instructionsText;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   171
    private TextArea messageText;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   172
    private int maxStringLength = 80;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   173
    private Panel buttonP = new Panel();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   174
    private JButton run = new JButton("Run");
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   175
    private JButton passB = new JButton("Pass");
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   176
    private JButton failB = new JButton("Fail");
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   177
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   178
    public TestDialog(JFrame frame, String name) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   179
        super(frame, name);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   180
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   181
        int scrollBoth = TextArea.SCROLLBARS_BOTH;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   182
        instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   183
        add("North", instructionsText);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   184
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   185
        messageText = new TextArea("", 5, maxStringLength, scrollBoth);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   186
        add("Center", messageText);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   187
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   188
        buttonP.add("East", run);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   189
        buttonP.add("East", passB);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   190
        buttonP.add("West", failB);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   191
        passB.setEnabled(false);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   192
        failB.setEnabled(false);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   193
        add("South", buttonP);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   194
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   195
        run.addActionListener(new ActionListener() {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   196
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   197
            @Override
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   198
            public void actionPerformed(ActionEvent ae) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   199
                FileChooserTest.fileChooser = new JFileChooser();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   200
                FileChooserTest.fileChooser.showOpenDialog(null);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   201
                passB.setEnabled(true);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   202
                failB.setEnabled(true);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   203
            }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   204
        });
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   205
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   206
        passB.addActionListener(new ActionListener() {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   207
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   208
            @Override
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   209
            public void actionPerformed(ActionEvent ae) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   210
                FileChooserTest.pass();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   211
            }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   212
        });
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   213
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   214
        failB.addActionListener(new ActionListener() {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   215
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   216
            @Override
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   217
            public void actionPerformed(ActionEvent ae) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   218
                FileChooserTest.fail();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   219
            }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   220
        });
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   221
        pack();
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   222
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   223
        setVisible(true);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   224
    }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   225
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   226
    public void printInstructions(String[] instructions) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   227
        instructionsText.setText("");
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   228
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   229
        String printStr, remainingStr;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   230
        for (String instruction : instructions) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   231
            remainingStr = instruction;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   232
            while (remainingStr.length() > 0) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   233
                if (remainingStr.length() >= maxStringLength) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   234
                    int posOfSpace = remainingStr.
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   235
                            lastIndexOf(' ', maxStringLength - 1);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   236
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   237
                    if (posOfSpace <= 0) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   238
                        posOfSpace = maxStringLength - 1;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   239
                    }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   240
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   241
                    printStr = remainingStr.substring(0, posOfSpace + 1);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   242
                    remainingStr = remainingStr.substring(posOfSpace + 1);
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   243
                } else {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   244
                    printStr = remainingStr;
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   245
                    remainingStr = "";
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   246
                }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   247
                instructionsText.append(printStr + "\n");
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   248
            }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   249
        }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   250
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   251
    }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   252
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   253
    public void displayMessage(String messageIn) {
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   254
        messageText.append(messageIn + "\n");
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   255
    }
0aaf5e7f0af9 8067660: JFileChooser create new folder fails silently
rchamyal
parents:
diff changeset
   256
}