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