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