jdk/src/java.desktop/share/classes/javax/swing/JFileChooser.java
author ddehaven
Tue, 19 Aug 2014 10:32:16 -0700
changeset 26037 508779ce6619
parent 26001 jdk/src/share/classes/javax/swing/JFileChooser.java@991e1be0b235
parent 25859 jdk/src/share/classes/javax/swing/JFileChooser.java@3317bb8137f4
child 28231 b608ffcaed74
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3982
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3982
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3982
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3982
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3982
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.filechooser.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.plaf.FileChooserUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.AWTEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.BorderLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.Dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.Frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.HeadlessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.EventQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.beans.PropertyChangeEvent;
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
    53
import java.io.InvalidObjectException;
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
    54
import java.io.ObjectInputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <code>JFileChooser</code> provides a simple mechanism for the user to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * choose a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * For information about using <code>JFileChooser</code>, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20119
diff changeset
    62
 href="http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html">How to Use File Choosers</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * The following code pops up a file chooser for the user's home directory that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * sees only .jpg and .gif images:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *    JFileChooser chooser = new JFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *    FileNameExtensionFilter filter = new FileNameExtensionFilter(
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
    72
 *        "JPG &amp; GIF Images", "jpg", "gif");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *    chooser.setFileFilter(filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *    int returnVal = chooser.showOpenDialog(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *    if(returnVal == JFileChooser.APPROVE_OPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *       System.out.println("You chose to open this file: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *            chooser.getSelectedFile().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *   attribute: isContainer false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * description: A component which allows for the interactive selection of a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * @author Jeff Dinkins
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 23697
diff changeset
    91
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
    93
@SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
public class JFileChooser extends JComponent implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private static final String uiClassID = "FileChooserUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    // ************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    // ***** Dialog Types *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    // ************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Type value indicating that the <code>JFileChooser</code> supports an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * "Open" file operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public static final int OPEN_DIALOG = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Type value indicating that the <code>JFileChooser</code> supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * "Save" file operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public static final int SAVE_DIALOG = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Type value indicating that the <code>JFileChooser</code> supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * developer-specified file operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public static final int CUSTOM_DIALOG = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    // ***** Dialog Return Values *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Return value if cancel is chosen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public static final int CANCEL_OPTION = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Return value if approve (yes, ok) is chosen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public static final int APPROVE_OPTION = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20455
diff changeset
   140
     * Return value if an error occurred.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public static final int ERROR_OPTION = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    // **********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    // ***** JFileChooser properties *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    // **********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /** Instruction to display only files. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public static final int FILES_ONLY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /** Instruction to display only directories. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public static final int DIRECTORIES_ONLY = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /** Instruction to display both files and directories. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public static final int FILES_AND_DIRECTORIES = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /** Instruction to cancel the current selection. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public static final String CANCEL_SELECTION = "CancelSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Instruction to approve the current selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * (same as pressing yes or ok).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public static final String APPROVE_SELECTION = "ApproveSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /** Identifies change in the text on the approve (yes, ok) button. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public static final String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY = "ApproveButtonTextChangedProperty";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Identifies change in the tooltip text for the approve (yes, ok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public static final String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY = "ApproveButtonToolTipTextChangedProperty";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /** Identifies change in the mnemonic for the approve (yes, ok) button. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public static final String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY = "ApproveButtonMnemonicChangedProperty";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /** Instruction to display the control buttons. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public static final String CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY = "ControlButtonsAreShownChangedProperty";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /** Identifies user's directory change. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public static final String DIRECTORY_CHANGED_PROPERTY = "directoryChanged";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /** Identifies change in user's single-file selection. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public static final String SELECTED_FILE_CHANGED_PROPERTY = "SelectedFileChangedProperty";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /** Identifies change in user's multiple-file selection. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public static final String SELECTED_FILES_CHANGED_PROPERTY = "SelectedFilesChangedProperty";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /** Enables multiple-file selections. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public static final String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY = "MultiSelectionEnabledChangedProperty";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Says that a different object is being used to find available drives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * on the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public static final String FILE_SYSTEM_VIEW_CHANGED_PROPERTY = "FileSystemViewChanged";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Says that a different object is being used to retrieve file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public static final String FILE_VIEW_CHANGED_PROPERTY = "fileViewChanged";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /** Identifies a change in the display-hidden-files property. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public static final String FILE_HIDING_CHANGED_PROPERTY = "FileHidingChanged";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /** User changed the kind of files to display. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public static final String FILE_FILTER_CHANGED_PROPERTY = "fileFilterChanged";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Identifies a change in the kind of selection (single,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * multiple, etc.).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public static final String FILE_SELECTION_MODE_CHANGED_PROPERTY = "fileSelectionChanged";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Says that a different accessory component is in use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * (for example, to preview files).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public static final String ACCESSORY_CHANGED_PROPERTY = "AccessoryChangedProperty";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Identifies whether a the AcceptAllFileFilter is used or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public static final String ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY = "acceptAllFileFilterUsedChanged";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /** Identifies a change in the dialog title. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public static final String DIALOG_TITLE_CHANGED_PROPERTY = "DialogTitleChangedProperty";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Identifies a change in the type of files displayed (files only,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * directories only, or both files and directories).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public static final String DIALOG_TYPE_CHANGED_PROPERTY = "DialogTypeChangedProperty";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Identifies a change in the list of predefined file filters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * the user can choose from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public static final String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY = "ChoosableFileFilterChangedProperty";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    // ******************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    // ***** instance variables *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    // ******************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    private String dialogTitle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    private String approveButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    private String approveButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    private int approveButtonMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   254
    private Vector<FileFilter> filters = new Vector<FileFilter>(5);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    private JDialog dialog = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    private int dialogType = OPEN_DIALOG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    private int returnValue = ERROR_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    private JComponent accessory = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    private FileView fileView = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    private boolean controlsShown = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    private boolean useFileHiding = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    private static final String SHOW_HIDDEN_PROP = "awt.file.showHiddenFiles";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    // Listens to changes in the native setting for showing hidden files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    // The Listener is removed and the native setting is ignored if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    // setFileHidingEnabled() is ever called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private transient PropertyChangeListener showFilesListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    private int fileSelectionMode = FILES_ONLY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    private boolean multiSelectionEnabled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private boolean useAcceptAllFileFilter = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    private boolean dragEnabled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    private FileFilter fileFilter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    private FileSystemView fileSystemView = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    private File currentDirectory = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private File selectedFile = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private File[] selectedFiles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    // *************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    // ***** JFileChooser Constructors *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    // *************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Constructs a <code>JFileChooser</code> pointing to the user's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * default directory. This default depends on the operating system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * It is typically the "My Documents" folder on Windows, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * user's home directory on Unix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public JFileChooser() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        this((File) null, (FileSystemView) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Constructs a <code>JFileChooser</code> using the given path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Passing in a <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * string causes the file chooser to point to the user's default directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * This default depends on the operating system. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * typically the "My Documents" folder on Windows, and the user's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * home directory on Unix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @param currentDirectoryPath  a <code>String</code> giving the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *                          to a file or directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public JFileChooser(String currentDirectoryPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        this(currentDirectoryPath, (FileSystemView) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Constructs a <code>JFileChooser</code> using the given <code>File</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * as the path. Passing in a <code>null</code> file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * causes the file chooser to point to the user's default directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * This default depends on the operating system. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * typically the "My Documents" folder on Windows, and the user's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * home directory on Unix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @param currentDirectory  a <code>File</code> object specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *                          the path to a file or directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public JFileChooser(File currentDirectory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        this(currentDirectory, (FileSystemView) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Constructs a <code>JFileChooser</code> using the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * <code>FileSystemView</code>.
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   335
     *
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   336
     * @param fsv a {@code FileSystemView}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public JFileChooser(FileSystemView fsv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        this((File) null, fsv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * Constructs a <code>JFileChooser</code> using the given current directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * and <code>FileSystemView</code>.
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   346
     *
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   347
     * @param currentDirectory a {@code File} object specifying the path to a
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   348
     *                         file or directory
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   349
     * @param fsv a {@code FileSystemView}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public JFileChooser(File currentDirectory, FileSystemView fsv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        setup(fsv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        setCurrentDirectory(currentDirectory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Constructs a <code>JFileChooser</code> using the given current directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * path and <code>FileSystemView</code>.
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   359
     *
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   360
     * @param currentDirectoryPath a {@code String} specifying the path to a file
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   361
     *                             or directory
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   362
     * @param fsv a {@code FileSystemView}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public JFileChooser(String currentDirectoryPath, FileSystemView fsv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        setup(fsv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if(currentDirectoryPath == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            setCurrentDirectory(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            setCurrentDirectory(fileSystemView.createFileObject(currentDirectoryPath));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * Performs common constructor initialization and setup.
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   375
     *
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   376
     * @param view the {@code FileSystemView} used for setup
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    protected void setup(FileSystemView view) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        installShowFilesListener();
20119
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   380
        installHierarchyListener();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if(view == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            view = FileSystemView.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        setFileSystemView(view);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if(isAcceptAllFileFilterUsed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            setFileFilter(getAcceptAllFileFilter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        enableEvents(AWTEvent.MOUSE_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
20119
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   393
    private void installHierarchyListener() {
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   394
        addHierarchyListener(new HierarchyListener() {
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   395
            @Override
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   396
            public void hierarchyChanged(HierarchyEvent e) {
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   397
                if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED)
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   398
                        == HierarchyEvent.PARENT_CHANGED) {
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   399
                    JFileChooser fc = JFileChooser.this;
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   400
                    JRootPane rootPane = SwingUtilities.getRootPane(fc);
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   401
                    if (rootPane != null) {
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   402
                        rootPane.setDefaultButton(fc.getUI().getDefaultButton(fc));
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   403
                    }
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   404
                }
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   405
            }
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   406
        });
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   407
    }
e209efee23ed 8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents: 19018
diff changeset
   408
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    private void installShowFilesListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        // Track native setting for showing hidden files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        Toolkit tk = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        if (showHiddenProperty instanceof Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            showFilesListener = new WeakPCL(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * Sets the <code>dragEnabled</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * which must be <code>true</code> to enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * automatic drag handling (the first part of drag and drop)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * The <code>transferHandler</code> property needs to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * to a non-<code>null</code> value for the drag to do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * anything.  The default value of the <code>dragEnabled</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * is <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * When automatic drag handling is enabled,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * most look and feels begin a drag-and-drop operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * whenever the user presses the mouse button over an item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * and then moves the mouse a few pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * Setting this property to <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * can therefore have a subtle effect on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * how selections behave.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * Some look and feels might not support automatic drag and drop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * they will ignore this property.  You can work around such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * look and feels by modifying the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * to directly call the <code>exportAsDrag</code> method of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * <code>TransferHandler</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @param b the value to set the <code>dragEnabled</code> property to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *            <code>b</code> is <code>true</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *            <code>GraphicsEnvironment.isHeadless()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *            returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @see #getDragEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @see #setTransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @see TransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *  description: determines whether automatic drag handling is enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *        bound: false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public void setDragEnabled(boolean b) {
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   465
        checkDragEnabled(b);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   466
        dragEnabled = b;
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   467
    }
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   468
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   469
    private static void checkDragEnabled(boolean b) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (b && GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * Gets the value of the <code>dragEnabled</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @return  the value of the <code>dragEnabled</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @see #setDragEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    public boolean getDragEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return dragEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    // *****************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    // ****** File Operations ******
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    // *****************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * Returns the selected file. This can be set either by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * programmer via <code>setSelectedFile</code> or by a user action, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * either typing the filename into the UI or selecting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * file from a list in the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @see #setSelectedFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @return the selected file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    public File getSelectedFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        return selectedFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * Sets the selected file. If the file's parent directory is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * not the current directory, changes the current directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * to be the file's parent directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @see #getSelectedFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @param file the selected file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    public void setSelectedFile(File file) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        File oldValue = selectedFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        selectedFile = file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if(selectedFile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            if (file.isAbsolute() && !getFileSystemView().isParent(getCurrentDirectory(), selectedFile)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                setCurrentDirectory(selectedFile.getParentFile());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            if (!isMultiSelectionEnabled() || selectedFiles == null || selectedFiles.length == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                ensureFileIsVisible(selectedFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        firePropertyChange(SELECTED_FILE_CHANGED_PROPERTY, oldValue, selectedFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * Returns a list of selected files if the file chooser is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * set to allow multiple selection.
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   533
     *
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   534
     * @return an array of selected {@code File}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    public File[] getSelectedFiles() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        if(selectedFiles == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            return new File[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        } else {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   540
            return selectedFiles.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * Sets the list of selected files if the file chooser is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * set to allow multiple selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   548
     * @param selectedFiles an array {@code File}s to be selected
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * description: The list of selected files if the chooser is in multiple selection mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    public void setSelectedFiles(File[] selectedFiles) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        File[] oldValue = this.selectedFiles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if (selectedFiles == null || selectedFiles.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            selectedFiles = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            this.selectedFiles = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            setSelectedFile(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            this.selectedFiles = selectedFiles.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            setSelectedFile(this.selectedFiles[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        firePropertyChange(SELECTED_FILES_CHANGED_PROPERTY, oldValue, selectedFiles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * Returns the current directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @return the current directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @see #setCurrentDirectory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    public File getCurrentDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        return currentDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * Sets the current directory. Passing in <code>null</code> sets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * file chooser to point to the user's default directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * This default depends on the operating system. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * typically the "My Documents" folder on Windows, and the user's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * home directory on Unix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * If the file passed in as <code>currentDirectory</code> is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * directory, the parent of the file will be used as the currentDirectory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * If the parent is not traversable, then it will walk up the parent tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * until it finds a traversable directory, or hits the root of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * file system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * description: The directory that the JFileChooser is showing files of.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @param dir the current directory to point to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * @see #getCurrentDirectory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    public void setCurrentDirectory(File dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        File oldValue = currentDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        if (dir != null && !dir.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            dir = currentDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        if (dir == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            dir = getFileSystemView().getDefaultDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        if (currentDirectory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            /* Verify the toString of object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            if (this.currentDirectory.equals(dir)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        File prev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        while (!isTraversable(dir) && prev != dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            prev = dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            dir = getFileSystemView().getParentDirectory(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        currentDirectory = dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        firePropertyChange(DIRECTORY_CHANGED_PROPERTY, oldValue, currentDirectory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * Changes the directory to be set to the parent of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * current directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @see #getCurrentDirectory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    public void changeToParentDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        selectedFile = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        File oldValue = getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        setCurrentDirectory(getFileSystemView().getParentDirectory(oldValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * Tells the UI to rescan its files list from the current directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    public void rescanCurrentDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        getUI().rescanCurrentDirectory(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * Makes sure that the specified file is viewable, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * not hidden.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @param f  a File object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    public void ensureFileIsVisible(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        getUI().ensureFileIsVisible(this, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    // **************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    // ***** JFileChooser Dialog methods *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    // **************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * Pops up an "Open File" file chooser dialog. Note that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * text that appears in the approve button is determined by
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   659
     * the L&amp;F.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @param    parent  the parent component of the dialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     *                  can be <code>null</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *                  see <code>showDialog</code> for details
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * @return   the return state of the file chooser on popdown:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * <li>JFileChooser.CANCEL_OPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * <li>JFileChooser.APPROVE_OPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * <li>JFileChooser.ERROR_OPTION if an error occurs or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *                  dialog is dismissed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * @see #showDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    public int showOpenDialog(Component parent) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        setDialogType(OPEN_DIALOG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        return showDialog(parent, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * Pops up a "Save File" file chooser dialog. Note that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * text that appears in the approve button is determined by
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   684
     * the L&amp;F.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @param    parent  the parent component of the dialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     *                  can be <code>null</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     *                  see <code>showDialog</code> for details
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * @return   the return state of the file chooser on popdown:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * <li>JFileChooser.CANCEL_OPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * <li>JFileChooser.APPROVE_OPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * <li>JFileChooser.ERROR_OPTION if an error occurs or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *                  dialog is dismissed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @see #showDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    public int showSaveDialog(Component parent) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        setDialogType(SAVE_DIALOG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        return showDialog(parent, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * Pops a custom file chooser dialog with a custom approve button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * For example, the following code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * pops up a file chooser with a "Run Application" button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * (instead of the normal "Save" or "Open" button):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * filechooser.showDialog(parentFrame, "Run Application");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * Alternatively, the following code does the same thing:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     *    JFileChooser chooser = new JFileChooser(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     *    chooser.setApproveButtonText("Run Application");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *    chooser.showDialog(parentFrame, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * <!--PENDING(jeff) - the following method should be added to the api:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *      showDialog(Component parent);-->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * <!--PENDING(kwalrath) - should specify modality and what
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     *      "depends" means.-->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * The <code>parent</code> argument determines two things:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * the frame on which the open dialog depends and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * the component whose position the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * should consider when placing the dialog.  If the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * is a <code>Frame</code> object (such as a <code>JFrame</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * then the dialog depends on the frame and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * the look and feel positions the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * relative to the frame (for example, centered over the frame).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * If the parent is a component, then the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * depends on the frame containing the component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * and is positioned relative to the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * (for example, centered over the component).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * If the parent is <code>null</code>, then the dialog depends on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * no visible window, and it's placed in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * look-and-feel-dependent position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * such as the center of the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @param   parent  the parent component of the dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *                  can be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * @param   approveButtonText the text of the <code>ApproveButton</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @return  the return state of the file chooser on popdown:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * <li>JFileChooser.CANCEL_OPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * <li>JFileChooser.APPROVE_OPTION
3982
b8872825ad04 6489130: FileChooserDemo hung by keeping pressing Enter key
rupashka
parents: 3346
diff changeset
   753
     * <li>JFileChooser.ERROR_OPTION if an error occurs or the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     *                  dialog is dismissed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    public int showDialog(Component parent, String approveButtonText)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        throws HeadlessException {
3982
b8872825ad04 6489130: FileChooserDemo hung by keeping pressing Enter key
rupashka
parents: 3346
diff changeset
   762
        if (dialog != null) {
b8872825ad04 6489130: FileChooserDemo hung by keeping pressing Enter key
rupashka
parents: 3346
diff changeset
   763
            // Prevent to show second instance of dialog if the previous one still exists
b8872825ad04 6489130: FileChooserDemo hung by keeping pressing Enter key
rupashka
parents: 3346
diff changeset
   764
            return JFileChooser.ERROR_OPTION;
b8872825ad04 6489130: FileChooserDemo hung by keeping pressing Enter key
rupashka
parents: 3346
diff changeset
   765
        }
b8872825ad04 6489130: FileChooserDemo hung by keeping pressing Enter key
rupashka
parents: 3346
diff changeset
   766
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        if(approveButtonText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            setApproveButtonText(approveButtonText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            setDialogType(CUSTOM_DIALOG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        dialog = createDialog(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        dialog.addWindowListener(new WindowAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            public void windowClosing(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                returnValue = CANCEL_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        returnValue = ERROR_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        rescanCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        dialog.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        firePropertyChange("JFileChooserDialogIsClosingProperty", dialog, null);
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 1301
diff changeset
   782
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 1301
diff changeset
   783
        // Remove all components from dialog. The MetalFileChooserUI.installUI() method (and other LAFs)
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 1301
diff changeset
   784
        // registers AWT listener for dialogs and produces memory leaks. It happens when
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 1301
diff changeset
   785
        // installUI invoked after the showDialog method.
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 1301
diff changeset
   786
        dialog.getContentPane().removeAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        dialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        dialog = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        return returnValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * Creates and returns a new <code>JDialog</code> wrapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * <code>this</code> centered on the <code>parent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * in the <code>parent</code>'s frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * This method can be overriden to further manipulate the dialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * to disable resizing, set the location, etc. Example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     *     class MyFileChooser extends JFileChooser {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     *         protected JDialog createDialog(Component parent) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     *             JDialog dialog = super.createDialog(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     *             dialog.setLocation(300, 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     *             dialog.setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     *             return dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * @param   parent  the parent component of the dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     *                  can be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * @return a new <code>JDialog</code> containing this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    protected JDialog createDialog(Component parent) throws HeadlessException {
680
eaff686e34f7 5035693: "Open" button should be a default one in JFileChooser under Windows XP LAF
rupashka
parents: 2
diff changeset
   818
        FileChooserUI ui = getUI();
eaff686e34f7 5035693: "Open" button should be a default one in JFileChooser under Windows XP LAF
rupashka
parents: 2
diff changeset
   819
        String title = ui.getDialogTitle(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                          title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        JDialog dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        Window window = JOptionPane.getWindowForComponent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        if (window instanceof Frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            dialog = new JDialog((Frame)window, title, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            dialog = new JDialog((Dialog)window, title, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        dialog.setComponentOrientation(this.getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        Container contentPane = dialog.getContentPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        contentPane.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        contentPane.add(this, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        if (JDialog.isDefaultLookAndFeelDecorated()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            boolean supportsWindowDecorations =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            UIManager.getLookAndFeel().getSupportsWindowDecorations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            if (supportsWindowDecorations) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        dialog.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        dialog.setLocationRelativeTo(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        return dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    // **************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    // ***** Dialog Options *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    // **************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * Returns the value of the <code>controlButtonsAreShown</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @return   the value of the <code>controlButtonsAreShown</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     *     property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * @see #setControlButtonsAreShown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    public boolean getControlButtonsAreShown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        return controlsShown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * Sets the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * that indicates whether the <i>approve</i> and <i>cancel</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * buttons are shown in the file chooser.  This property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * is <code>true</code> by default.  Look and feels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * that always show these buttons will ignore the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * of this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * This method fires a property-changed event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * using the string value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * <code>CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * as the name of the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * @param b <code>false</code> if control buttons should not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *    shown; otherwise, <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     *       bound: true
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   886
     * description: Sets whether the approve &amp; cancel buttons are shown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * @see #getControlButtonsAreShown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * @see #CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    public void setControlButtonsAreShown(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        if(controlsShown == b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        boolean oldValue = controlsShown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        controlsShown = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        firePropertyChange(CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY, oldValue, controlsShown);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * Returns the type of this dialog.  The default is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * <code>JFileChooser.OPEN_DIALOG</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * @return   the type of dialog to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * <li>JFileChooser.OPEN_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * <li>JFileChooser.SAVE_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * <li>JFileChooser.CUSTOM_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * @see #setDialogType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    public int getDialogType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        return dialogType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * Sets the type of this dialog. Use <code>OPEN_DIALOG</code> when you
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * want to bring up a file chooser that the user can use to open a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * Likewise, use <code>SAVE_DIALOG</code> for letting the user choose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * a file for saving.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * Use <code>CUSTOM_DIALOG</code> when you want to use the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * chooser in a context other than "Open" or "Save".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * For instance, you might want to bring up a file chooser that allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * the user to choose a file to execute. Note that you normally would not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * need to set the <code>JFileChooser</code> to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * <code>CUSTOM_DIALOG</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * since a call to <code>setApproveButtonText</code> does this for you.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * The default dialog type is <code>JFileChooser.OPEN_DIALOG</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * @param dialogType the type of dialog to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * <li>JFileChooser.OPEN_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * <li>JFileChooser.SAVE_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * <li>JFileChooser.CUSTOM_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * @exception IllegalArgumentException if <code>dialogType</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     *                          not legal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * description: The type (open, save, custom) of the JFileChooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     *        enum:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     *              OPEN_DIALOG JFileChooser.OPEN_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     *              SAVE_DIALOG JFileChooser.SAVE_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     *              CUSTOM_DIALOG JFileChooser.CUSTOM_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * @see #getDialogType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * @see #setApproveButtonText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    // PENDING(jeff) - fire button text change property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    public void setDialogType(int dialogType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        if(this.dialogType == dialogType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        }
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   958
        checkDialogType(dialogType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        int oldValue = this.dialogType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        this.dialogType = dialogType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        if(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            setApproveButtonText(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        firePropertyChange(DIALOG_TYPE_CHANGED_PROPERTY, oldValue, dialogType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   967
    private static void checkDialogType(int dialogType) {
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   968
        if (!(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   969
                || dialogType == CUSTOM_DIALOG)) {
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   970
            throw new IllegalArgumentException(
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   971
                    "Incorrect Dialog Type: " + dialogType);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   972
        }
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   973
    }
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
   974
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * Sets the string that goes in the <code>JFileChooser</code> window's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * title bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * @param dialogTitle the new <code>String</code> for the title bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * description: The title of the JFileChooser dialog window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * @see #getDialogTitle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    public void setDialogTitle(String dialogTitle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        String oldValue = this.dialogTitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        this.dialogTitle = dialogTitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        if(dialog != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            dialog.setTitle(dialogTitle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        firePropertyChange(DIALOG_TITLE_CHANGED_PROPERTY, oldValue, dialogTitle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * Gets the string that goes in the <code>JFileChooser</code>'s titlebar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1001
     * @return the string from the {@code JFileChooser} window's title bar
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * @see #setDialogTitle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    public String getDialogTitle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        return dialogTitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    // ************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    // ***** JFileChooser View Options *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    // ************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * Sets the tooltip text used in the <code>ApproveButton</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * If <code>null</code>, the UI object will determine the button's text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * description: The tooltip text for the ApproveButton.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * @param toolTipText the tooltip text for the approve button
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * @see #setApproveButtonText
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * @see #setDialogType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * @see #showDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    public void setApproveButtonToolTipText(String toolTipText) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        if(approveButtonToolTipText == toolTipText) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        String oldValue = approveButtonToolTipText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        approveButtonToolTipText = toolTipText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        firePropertyChange(APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY, oldValue, approveButtonToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * Returns the tooltip text used in the <code>ApproveButton</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * If <code>null</code>, the UI object will determine the button's text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * @return the tooltip text used for the approve button
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * @see #setApproveButtonText
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * @see #setDialogType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * @see #showDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    public String getApproveButtonToolTipText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        return approveButtonToolTipText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * Returns the approve button's mnemonic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * @return an integer value for the mnemonic key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * @see #setApproveButtonMnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    public int getApproveButtonMnemonic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        return approveButtonMnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * Sets the approve button's mnemonic using a numeric keycode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * @param mnemonic  an integer value for the mnemonic key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * description: The mnemonic key accelerator for the ApproveButton.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * @see #getApproveButtonMnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    public void setApproveButtonMnemonic(int mnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        if(approveButtonMnemonic == mnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
           return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        int oldValue = approveButtonMnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        approveButtonMnemonic = mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        firePropertyChange(APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY, oldValue, approveButtonMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * Sets the approve button's mnemonic using a character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * @param mnemonic  a character value for the mnemonic key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * @see #getApproveButtonMnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    public void setApproveButtonMnemonic(char mnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        int vk = (int) mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        if(vk >= 'a' && vk <='z') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            vk -= ('a' - 'A');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        setApproveButtonMnemonic(vk);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * Sets the text used in the <code>ApproveButton</code> in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * <code>FileChooserUI</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * description: The text that goes in the ApproveButton.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * @param approveButtonText the text used in the <code>ApproveButton</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * @see #getApproveButtonText
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * @see #setDialogType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * @see #showDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    // PENDING(jeff) - have ui set this on dialog type change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    public void setApproveButtonText(String approveButtonText) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        if(this.approveButtonText == approveButtonText) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        String oldValue = this.approveButtonText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        this.approveButtonText = approveButtonText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        firePropertyChange(APPROVE_BUTTON_TEXT_CHANGED_PROPERTY, oldValue, approveButtonText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * Returns the text used in the <code>ApproveButton</code> in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * <code>FileChooserUI</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * If <code>null</code>, the UI object will determine the button's text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * Typically, this would be "Open" or "Save".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * @return the text used in the <code>ApproveButton</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * @see #setApproveButtonText
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * @see #setDialogType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * @see #showDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    public String getApproveButtonText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        return approveButtonText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * Gets the list of user choosable file filters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * @return a <code>FileFilter</code> array containing all the choosable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     *         file filters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * @see #addChoosableFileFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * @see #removeChoosableFileFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * @see #resetChoosableFileFilters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    public FileFilter[] getChoosableFileFilters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        FileFilter[] filterArray = new FileFilter[filters.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        filters.copyInto(filterArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        return filterArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     * Adds a filter to the list of user choosable file filters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * For information on setting the file selection mode, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * {@link #setFileSelectionMode setFileSelectionMode}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * @param filter the <code>FileFilter</code> to add to the choosable file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     *               filter list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * description: Adds a filter to the list of user choosable file filters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * @see #getChoosableFileFilters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * @see #removeChoosableFileFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * @see #resetChoosableFileFilters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * @see #setFileSelectionMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    public void addChoosableFileFilter(FileFilter filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        if(filter != null && !filters.contains(filter)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            FileFilter[] oldValue = getChoosableFileFilters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            filters.addElement(filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            if (fileFilter == null && filters.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                setFileFilter(filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * Removes a filter from the list of user choosable file filters. Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * true if the file filter was removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1189
     * @param f the file filter to be removed
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1190
     * @return true if the file filter was removed, false otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * @see #addChoosableFileFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * @see #getChoosableFileFilters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * @see #resetChoosableFileFilters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    public boolean removeChoosableFileFilter(FileFilter f) {
18134
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1196
        int index = filters.indexOf(f);
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1197
        if (index >= 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            if(getFileFilter() == f) {
19018
14d6859b9dcc 8019975: closed/javax/swing/JFileChooser/4966171/bug4966171.java throws java.io.NotSerializableException: javax.swing.plaf.basic.BasicFileChooserUI$AcceptAllFileFilter
malenkov
parents: 18134
diff changeset
  1199
                FileFilter aaff = getAcceptAllFileFilter();
14d6859b9dcc 8019975: closed/javax/swing/JFileChooser/4966171/bug4966171.java throws java.io.NotSerializableException: javax.swing.plaf.basic.BasicFileChooserUI$AcceptAllFileFilter
malenkov
parents: 18134
diff changeset
  1200
                if (isAcceptAllFileFilterUsed() && (aaff != f)) {
18134
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1201
                    // choose default filter if it is used
19018
14d6859b9dcc 8019975: closed/javax/swing/JFileChooser/4966171/bug4966171.java throws java.io.NotSerializableException: javax.swing.plaf.basic.BasicFileChooserUI$AcceptAllFileFilter
malenkov
parents: 18134
diff changeset
  1202
                    setFileFilter(aaff);
18134
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1203
                }
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1204
                else if (index > 0) {
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1205
                    // choose the first filter, because it is not removed
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1206
                    setFileFilter(filters.get(0));
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1207
                }
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1208
                else if (filters.size() > 1) {
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1209
                    // choose the second filter, because the first one is removed
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1210
                    setFileFilter(filters.get(1));
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1211
                }
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1212
                else {
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1213
                    // no more filters
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1214
                    setFileFilter(null);
af8df2260431 8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents: 9035
diff changeset
  1215
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            FileFilter[] oldValue = getChoosableFileFilters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            filters.removeElement(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * Resets the choosable file filter list to its starting state. Normally,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * this removes all added file filters while leaving the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * <code>AcceptAll</code> file filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * @see #addChoosableFileFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * @see #getChoosableFileFilters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * @see #removeChoosableFileFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    public void resetChoosableFileFilters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        FileFilter[] oldValue = getChoosableFileFilters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        setFileFilter(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        filters.removeAllElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        if(isAcceptAllFileFilterUsed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
           addChoosableFileFilter(getAcceptAllFileFilter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * Returns the <code>AcceptAll</code> file filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     * For example, on Microsoft Windows this would be All Files (*.*).
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1248
     *
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1249
     * @return the {@code AcceptAll} file filter
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    public FileFilter getAcceptAllFileFilter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        FileFilter filter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        if(getUI() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            filter = getUI().getAcceptAllFileFilter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        return filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    * Returns whether the <code>AcceptAll FileFilter</code> is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    * @return true if the <code>AcceptAll FileFilter</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
    * @see #setAcceptAllFileFilterUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    public boolean isAcceptAllFileFilterUsed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        return useAcceptAllFileFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    * Determines whether the <code>AcceptAll FileFilter</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    * as an available choice in the choosable filter list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    * If false, the <code>AcceptAll</code> file filter is removed from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    * the list of available file filters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    * If true, the <code>AcceptAll</code> file filter will become the
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1275
    * actively used file filter.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1277
    * @param b a {@code boolean} which determines whether the {@code AcceptAll}
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1278
    *          file filter is an available choice in the choosable filter list
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    * description: Sets whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    * @see #isAcceptAllFileFilterUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    * @see #getAcceptAllFileFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    * @see #setFileFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    public void setAcceptAllFileFilterUsed(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        boolean oldValue = useAcceptAllFileFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        useAcceptAllFileFilter = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        if(!b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            removeChoosableFileFilter(getAcceptAllFileFilter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            removeChoosableFileFilter(getAcceptAllFileFilter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            addChoosableFileFilter(getAcceptAllFileFilter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        firePropertyChange(ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY, oldValue, useAcceptAllFileFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * Returns the accessory component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * @return this JFileChooser's accessory component, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * @see #setAccessory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    public JComponent getAccessory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        return accessory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     * Sets the accessory component. An accessory is often used to show a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     * preview image of the selected file; however, it can be used for anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     * that the programmer wishes, such as extra custom file chooser controls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     * Note: if there was a previous accessory, you should unregister
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     * any listeners that the accessory might have registered with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * file chooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1321
     * @param newAccessory the accessory component to be set
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * description: Sets the accessory component on the JFileChooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    public void setAccessory(JComponent newAccessory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        JComponent oldValue = accessory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        accessory = newAccessory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        firePropertyChange(ACCESSORY_CHANGED_PROPERTY, oldValue, accessory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     * Sets the <code>JFileChooser</code> to allow the user to just
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     * select files, just select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
     * directories, or select both files and directories.  The default is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
     * <code>JFilesChooser.FILES_ONLY</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     * @param mode the type of files to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
     * <li>JFileChooser.FILES_ONLY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
     * <li>JFileChooser.DIRECTORIES_ONLY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     * <li>JFileChooser.FILES_AND_DIRECTORIES
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * @exception IllegalArgumentException  if <code>mode</code> is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     *                          illegal file selection mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * description: Sets the types of files that the JFileChooser can choose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     *        enum: FILES_ONLY JFileChooser.FILES_ONLY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     *              DIRECTORIES_ONLY JFileChooser.DIRECTORIES_ONLY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     *              FILES_AND_DIRECTORIES JFileChooser.FILES_AND_DIRECTORIES
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * @see #getFileSelectionMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
    public void setFileSelectionMode(int mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        if(fileSelectionMode == mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1364
        checkFileSelectionMode(mode);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
           int oldValue = fileSelectionMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
           fileSelectionMode = mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
           firePropertyChange(FILE_SELECTION_MODE_CHANGED_PROPERTY, oldValue, fileSelectionMode);
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1368
    }
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1369
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1370
    private static void checkFileSelectionMode(int mode) {
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1371
        if ((mode != FILES_ONLY) && (mode != DIRECTORIES_ONLY)
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1372
                && (mode != FILES_AND_DIRECTORIES)) {
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1373
            throw new IllegalArgumentException(
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1374
                    "Incorrect Mode for file selection: " + mode);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     * Returns the current file-selection mode.  The default is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     * <code>JFilesChooser.FILES_ONLY</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * @return the type of files to be displayed, one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     * <li>JFileChooser.FILES_ONLY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
     * <li>JFileChooser.DIRECTORIES_ONLY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * <li>JFileChooser.FILES_AND_DIRECTORIES
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * @see #setFileSelectionMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    public int getFileSelectionMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        return fileSelectionMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     * Convenience call that determines if files are selectable based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * current file selection mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1398
     * @return true if files are selectable, false otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     * @see #setFileSelectionMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     * @see #getFileSelectionMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    public boolean isFileSelectionEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        return ((fileSelectionMode == FILES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * Convenience call that determines if directories are selectable based
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * on the current file selection mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1410
     * @return true if directories are selectable, false otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * @see #setFileSelectionMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * @see #getFileSelectionMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
    public boolean isDirectorySelectionEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        return ((fileSelectionMode == DIRECTORIES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * Sets the file chooser to allow multiple file selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * @param b true if multiple files may be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * description: Sets multiple file selection mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     * @see #isMultiSelectionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
    public void setMultiSelectionEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        if(multiSelectionEnabled == b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        boolean oldValue = multiSelectionEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        multiSelectionEnabled = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        firePropertyChange(MULTI_SELECTION_ENABLED_CHANGED_PROPERTY, oldValue, multiSelectionEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * Returns true if multiple files can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * @return true if multiple files can be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * @see #setMultiSelectionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    public boolean isMultiSelectionEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        return multiSelectionEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     * Returns true if hidden files are not shown in the file chooser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * otherwise, returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * @return the status of the file hiding property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * @see #setFileHidingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    public boolean isFileHidingEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        return useFileHiding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     * Sets file hiding on or off. If true, hidden files are not shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     * in the file chooser. The job of determining which files are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     * shown is done by the <code>FileView</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     * description: Sets file hiding on or off.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     * @param b the boolean value that determines whether file hiding is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     *          turned on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     * @see #isFileHidingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    public void setFileHidingEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        // Dump showFilesListener since we'll ignore it from now on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        if (showFilesListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            Toolkit.getDefaultToolkit().removePropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
            showFilesListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        boolean oldValue = useFileHiding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        useFileHiding = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        firePropertyChange(FILE_HIDING_CHANGED_PROPERTY, oldValue, useFileHiding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     * Sets the current file filter. The file filter is used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     * file chooser to filter out files from the user's view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
     * description: Sets the File Filter used to filter out files of type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
     * @param filter the new current file filter to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
     * @see #getFileFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
    public void setFileFilter(FileFilter filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        FileFilter oldValue = fileFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        fileFilter = filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        if (filter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            if (isMultiSelectionEnabled() && selectedFiles != null && selectedFiles.length > 0) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1500
                Vector<File> fList = new Vector<File>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                boolean failed = false;
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1502
                for (File file : selectedFiles) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1503
                    if (filter.accept(file)) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1504
                        fList.add(file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                        failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                if (failed) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1510
                    setSelectedFiles((fList.size() == 0) ? null : fList.toArray(new File[fList.size()]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            } else if (selectedFile != null && !filter.accept(selectedFile)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                setSelectedFile(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, oldValue, fileFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     * Returns the currently selected file filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
     * @return the current file filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
     * @see #setFileFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
     * @see #addChoosableFileFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
    public FileFilter getFileFilter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        return fileFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
    /**
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1532
     * Sets the file view to be used to retrieve UI information, such as
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     * the icon that represents a file or the type description of a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1535
     * @param fileView a {@code FileView} to be used to retrieve UI information
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
     * description: Sets the File View used to get file type information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
     * @see #getFileView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
    public void setFileView(FileView fileView) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        FileView oldValue = this.fileView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        this.fileView = fileView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        firePropertyChange(FILE_VIEW_CHANGED_PROPERTY, oldValue, fileView);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
     * Returns the current file view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
     *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1552
     * @return the current file view
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
     * @see #setFileView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
    public FileView getFileView() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        return fileView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
    // ******************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
    // *****FileView delegation *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
    // ******************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
    // NOTE: all of the following methods attempt to delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    // first to the client set fileView, and if <code>null</code> is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    // (or there is now client defined fileView) then calls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    // UI's default fileView.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
     * Returns the filename.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
     * @param f the <code>File</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
     * @return the <code>String</code> containing the filename for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     *          <code>f</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     * @see FileView#getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
    public String getName(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        String filename = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
        if(f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            if(getFileView() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                filename = getFileView().getName(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
            }
7961
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1581
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1582
            FileView uiFileView = getUI().getFileView(this);
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1583
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
            if(filename == null && uiFileView != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                filename = uiFileView.getName(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
        return filename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     * Returns the file description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
     * @param f the <code>File</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
     * @return the <code>String</code> containing the file description for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
     *          <code>f</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
     * @see FileView#getDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    public String getDescription(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        String description = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
        if(f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
            if(getFileView() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                description = getFileView().getDescription(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
            }
7961
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1604
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1605
            FileView uiFileView = getUI().getFileView(this);
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1606
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            if(description == null && uiFileView != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                description = uiFileView.getDescription(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
        return description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
     * Returns the file type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
     * @param f the <code>File</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
     * @return the <code>String</code> containing the file type description for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
     *          <code>f</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
     * @see FileView#getTypeDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
    public String getTypeDescription(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
        String typeDescription = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        if(f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            if(getFileView() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                typeDescription = getFileView().getTypeDescription(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
            }
7961
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1627
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1628
            FileView uiFileView = getUI().getFileView(this);
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1629
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            if(typeDescription == null && uiFileView != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                typeDescription = uiFileView.getTypeDescription(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
        return typeDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
     * Returns the icon for this file or type of file, depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
     * on the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
     * @param f the <code>File</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
     * @return the <code>Icon</code> for this file, or type of file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
     * @see FileView#getIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
    public Icon getIcon(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        Icon icon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        if (f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
            if(getFileView() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                icon = getFileView().getIcon(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
            }
7961
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1650
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1651
            FileView uiFileView = getUI().getFileView(this);
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1652
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            if(icon == null && uiFileView != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                icon = uiFileView.getIcon(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
        return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     * Returns true if the file (directory) can be visited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     * Returns false if the directory cannot be traversed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
     * @param f the <code>File</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
     * @return true if the file/directory can be traversed, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
     * @see FileView#isTraversable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
    public boolean isTraversable(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
        Boolean traversable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
        if (f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
            if (getFileView() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                traversable = getFileView().isTraversable(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
            }
7961
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1673
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1674
            FileView uiFileView = getUI().getFileView(this);
252a7e8c37c1 6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents: 5506
diff changeset
  1675
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
            if (traversable == null && uiFileView != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                traversable = uiFileView.isTraversable(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
            if (traversable == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                traversable = getFileSystemView().isTraversable(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        return (traversable != null && traversable.booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
     * Returns true if the file should be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
     * @param f the <code>File</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
     * @return true if the file should be displayed, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
     * @see FileFilter#accept
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
    public boolean accept(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
        boolean shown = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
        if(f != null && fileFilter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
            shown = fileFilter.accept(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
        return shown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     * Sets the file system view that the <code>JFileChooser</code> uses for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
     * accessing and creating file system resources, such as finding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     * the floppy drive and getting a list of root drives.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     * @param fsv  the new <code>FileSystemView</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
     *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
     * description: Sets the FileSytemView used to get filesystem information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
     * @see FileSystemView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
    public void setFileSystemView(FileSystemView fsv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        FileSystemView oldValue = fileSystemView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
        fileSystemView = fsv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
        firePropertyChange(FILE_SYSTEM_VIEW_CHANGED_PROPERTY, oldValue, fileSystemView);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     * Returns the file system view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * @return the <code>FileSystemView</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     * @see #setFileSystemView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
    public FileSystemView getFileSystemView() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
        return fileSystemView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
    // **************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
    // ***** Event Handling *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
    // **************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     * Called by the UI when the user hits the Approve button
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     * (labeled "Open" or "Save", by default). This can also be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     * called by the programmer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     * This method causes an action event to fire
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
     * with the command string equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
     * <code>APPROVE_SELECTION</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
     * @see #APPROVE_SELECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
    public void approveSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
        returnValue = APPROVE_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
        if(dialog != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
            dialog.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        fireActionPerformed(APPROVE_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     * Called by the UI when the user chooses the Cancel button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     * This can also be called by the programmer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     * This method causes an action event to fire
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     * with the command string equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
     * <code>CANCEL_SELECTION</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
     * @see #CANCEL_SELECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
    public void cancelSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
        returnValue = CANCEL_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
        if(dialog != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
            dialog.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
        fireActionPerformed(CANCEL_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     * Adds an <code>ActionListener</code> to the file chooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     * @param l  the listener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
     * @see #approveSelection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     * @see #cancelSelection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
    public void addActionListener(ActionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
        listenerList.add(ActionListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
     * Removes an <code>ActionListener</code> from the file chooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
     * @param l  the listener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
     * @see #addActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
    public void removeActionListener(ActionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
        listenerList.remove(ActionListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     * Returns an array of all the action listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
     * registered on this file chooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     * @return all of this file chooser's <code>ActionListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     *         or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
     *         array if no action listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
     * @see #addActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     * @see #removeActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
    public ActionListener[] getActionListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1804
        return listenerList.getListeners(ActionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     * notification on this event type. The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     * is lazily created using the <code>command</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     *
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1812
     * @param command a string that may specify a command associated with
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  1813
     *                the event
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
    protected void fireActionPerformed(String command) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
        long mostRecentEventTime = EventQueue.getMostRecentEventTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
        int modifiers = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
        AWTEvent currentEvent = EventQueue.getCurrentEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
        if (currentEvent instanceof InputEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
            modifiers = ((InputEvent)currentEvent).getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
        } else if (currentEvent instanceof ActionEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
            modifiers = ((ActionEvent)currentEvent).getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
        ActionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
            if (listeners[i]==ActionListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                    e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                                        command, mostRecentEventTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                                        modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                ((ActionListener)listeners[i+1]).actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
    private static class WeakPCL implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
        WeakReference<JFileChooser> jfcRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
        public WeakPCL(JFileChooser jfc) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1847
            jfcRef = new WeakReference<JFileChooser>(jfc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
        public void propertyChange(PropertyChangeEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
            assert ev.getPropertyName().equals(SHOW_HIDDEN_PROP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
            JFileChooser jfc = jfcRef.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
            if (jfc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
                // Our JFileChooser is no longer around, so we no longer need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
                // listen for PropertyChangeEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                Toolkit.getDefaultToolkit().removePropertyChangeListener(SHOW_HIDDEN_PROP, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                boolean oldValue = jfc.useFileHiding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                jfc.useFileHiding = !((Boolean)ev.getNewValue()).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
                jfc.firePropertyChange(FILE_HIDING_CHANGED_PROPERTY, oldValue, jfc.useFileHiding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
    // *********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
    // ***** Pluggable L&F methods *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
    // *********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     * Resets the UI property to a value from the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
        if (isAcceptAllFileFilterUsed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
            removeChoosableFileFilter(getAcceptAllFileFilter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
        FileChooserUI ui = ((FileChooserUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
        if (fileSystemView == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
            // We were probably deserialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
            setFileSystemView(FileSystemView.getFileSystemView());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
        setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
        if(isAcceptAllFileFilterUsed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
            addChoosableFileFilter(getAcceptAllFileFilter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
    /**
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
  1891
     * Returns a string that specifies the name of the L&amp;F class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
     * that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
     * @return the string "FileChooserUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     *        expert: true
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
  1899
     *   description: A string that specifies the name of the L&amp;F class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
    /**
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
  1906
     * Gets the UI object which implements the L&amp;F for this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
     *
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
  1908
     * @return the FileChooserUI object that implements the FileChooserUI L&amp;F
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
    public FileChooserUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
        return (FileChooserUI) ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     * See <code>readObject</code> and <code>writeObject</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
     * <code>JComponent</code> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
    private void readObject(java.io.ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            throws IOException, ClassNotFoundException {
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1921
        ObjectInputStream.GetField f = in.readFields();
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1922
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1923
        dialogTitle = (String) f.get("dialogTitle", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1924
        approveButtonText = (String) f.get("approveButtonText", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1925
        approveButtonToolTipText =
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1926
                (String) f.get("approveButtonToolTipText", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1927
        approveButtonMnemonic = f.get("approveButtonMnemonic", 0);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1928
        @SuppressWarnings("unchecked")
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1929
        Vector<FileFilter> newFilters = (Vector<FileFilter>) f.get("filters", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1930
        if (newFilters == null) {
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1931
            throw new InvalidObjectException("Null filters");
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1932
        }
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1933
        filters = newFilters;
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1934
        dialog = (JDialog) f.get("dialog", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1935
        int newDialogType = f.get("dialogType", OPEN_DIALOG);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1936
        checkDialogType(newDialogType);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1937
        dialogType = newDialogType;
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1938
        returnValue = f.get("returnValue", 0);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1939
        accessory = (JComponent) f.get("accessory", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1940
        fileView = (FileView) f.get("fileView", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1941
        controlsShown = f.get("controlsShown", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1942
        useFileHiding = f.get("useFileHiding", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1943
        int newFileSelectionMode = f.get("fileSelectionMode", FILES_ONLY);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1944
        checkFileSelectionMode(newFileSelectionMode);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1945
        fileSelectionMode = newFileSelectionMode;
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1946
        multiSelectionEnabled = f.get("multiSelectionEnabled", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1947
        useAcceptAllFileFilter = f.get("useAcceptAllFileFilter", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1948
        boolean newDragEnabled = f.get("dragEnabled", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1949
        checkDragEnabled(newDragEnabled);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1950
        dragEnabled = newDragEnabled;
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1951
        fileFilter = (FileFilter) f.get("fileFilter", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1952
        fileSystemView = (FileSystemView) f.get("fileSystemView", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1953
        currentDirectory = (File) f.get("currentDirectory", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1954
        selectedFile = (File) f.get("selectedFile", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1955
        selectedFiles = (File[]) f.get("selectedFiles", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1956
        accessibleContext = (AccessibleContext) f.get("accessibleContext", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25386
diff changeset
  1957
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        installShowFilesListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
     * See <code>readObject</code> and <code>writeObject</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
     * <code>JComponent</code> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
        FileSystemView fsv = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
        if (isAcceptAllFileFilterUsed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
            //The AcceptAllFileFilter is UI specific, it will be reset by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
            //updateUI() after deserialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
            removeChoosableFileFilter(getAcceptAllFileFilter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
        if (fileSystemView.equals(FileSystemView.getFileSystemView())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
            //The default FileSystemView is platform specific, it will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            //reset by updateUI() after deserialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
            fsv = fileSystemView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
            fileSystemView = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
        if (fsv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
            fileSystemView = fsv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
        if (isAcceptAllFileFilterUsed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            addChoosableFileFilter(getAcceptAllFileFilter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
     * Returns a string representation of this <code>JFileChooser</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
     * @return  a string representation of this <code>JFileChooser</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
        String approveButtonTextString = (approveButtonText != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
                                          approveButtonText: "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
        String dialogTitleString = (dialogTitle != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
                                    dialogTitle: "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
        String dialogTypeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        if (dialogType == OPEN_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
            dialogTypeString = "OPEN_DIALOG";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        } else if (dialogType == SAVE_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            dialogTypeString = "SAVE_DIALOG";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        } else if (dialogType == CUSTOM_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
            dialogTypeString = "CUSTOM_DIALOG";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        } else dialogTypeString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
        String returnValueString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        if (returnValue == CANCEL_OPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
            returnValueString = "CANCEL_OPTION";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        } else if (returnValue == APPROVE_OPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
            returnValueString = "APPROVE_OPTION";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
        } else if (returnValue == ERROR_OPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
            returnValueString = "ERROR_OPTION";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
        } else returnValueString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
        String useFileHidingString = (useFileHiding ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
        String fileSelectionModeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
        if (fileSelectionMode == FILES_ONLY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
            fileSelectionModeString = "FILES_ONLY";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
        } else if (fileSelectionMode == DIRECTORIES_ONLY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
            fileSelectionModeString = "DIRECTORIES_ONLY";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
        } else if (fileSelectionMode == FILES_AND_DIRECTORIES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
            fileSelectionModeString = "FILES_AND_DIRECTORIES";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
        } else fileSelectionModeString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
        String currentDirectoryString = (currentDirectory != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
                                         currentDirectory.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
        String selectedFileString = (selectedFile != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                                     selectedFile.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
        ",approveButtonText=" + approveButtonTextString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
        ",currentDirectory=" + currentDirectoryString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
        ",dialogTitle=" + dialogTitleString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
        ",dialogType=" + dialogTypeString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
        ",fileSelectionMode=" + fileSelectionModeString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
        ",returnValue=" + returnValueString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
        ",selectedFile=" + selectedFileString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
        ",useFileHiding=" + useFileHidingString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  2058
    /**
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  2059
     * {@code AccessibleContext} associated with this {@code JFileChooser}
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
  2060
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
    protected AccessibleContext accessibleContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
     * Gets the AccessibleContext associated with this JFileChooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     * For file choosers, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     * AccessibleJFileChooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     * A new AccessibleJFileChooser instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     * @return an AccessibleJFileChooser that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     *         AccessibleContext of this JFileChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
            accessibleContext = new AccessibleJFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
     * <code>JFileChooser</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
     * Java Accessibility API appropriate to file chooser user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  2085
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
    protected class AccessibleJFileChooser extends AccessibleJComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
         * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
            return AccessibleRole.FILE_CHOOSER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
    } // inner class AccessibleJFileChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
}