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