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