jdk/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 20169 d7fa6d7586c9
child 23010 6dadb192ad81
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6837
diff changeset
     2
 * Copyright (c) 1998, 2010, 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: 3977
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: 3977
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: 3977
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3977
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3977
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.filechooser.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.filechooser.FileFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.datatransfer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.*;
1302
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
    39
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.regex.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.awt.shell.ShellFolder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 10412
diff changeset
    46
 * Basic L&F implementation of a FileChooser.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public class BasicFileChooserUI extends FileChooserUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /* FileView icons */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    protected Icon directoryIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected Icon fileIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected Icon computerIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    protected Icon hardDriveIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected Icon floppyDriveIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected Icon newFolderIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected Icon upFolderIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    protected Icon homeFolderIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    protected Icon listViewIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected Icon detailsViewIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    protected Icon viewMenuIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected int saveButtonMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected int openButtonMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected int cancelButtonMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected int updateButtonMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected int helpButtonMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * The mnemonic keycode used for the approve button when a directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * is selected and the current selection mode is FILES_ONLY.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    protected int directoryOpenButtonMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected String saveButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    protected String openButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    protected String cancelButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected String updateButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    protected String helpButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * The label text displayed on the approve button when a directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * is selected and the current selection mode is FILES_ONLY.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected String directoryOpenButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private String openDialogTitleText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private String saveDialogTitleText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    protected String saveButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    protected String openButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected String cancelButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    protected String updateButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    protected String helpButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * The tooltip text displayed on the approve button when a directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * is selected and the current selection mode is FILES_ONLY.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    protected String directoryOpenButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // Some generic FileChooser functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private Action approveSelectionAction = new ApproveSelectionAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private Action cancelSelectionAction = new CancelSelectionAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private Action updateAction = new UpdateAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private Action newFolderAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private Action goHomeAction = new GoHomeAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private Action changeToParentDirectoryAction = new ChangeToParentDirectoryAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private String newFolderErrorSeparator = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private String newFolderErrorText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private String newFolderParentDoesntExistTitleText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private String newFolderParentDoesntExistText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private String fileDescriptionText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private String directoryDescriptionText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private JFileChooser filechooser = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private boolean directorySelected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private File directory = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private PropertyChangeListener propertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private AcceptAllFileFilter acceptAllFileFilter = new AcceptAllFileFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private FileFilter actualFileFilter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private GlobFilter globFilter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private BasicDirectoryModel model = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private BasicFileView fileView = new BasicFileView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private boolean usesSingleFilePane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private boolean readOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    // The accessoryPanel is a container to place the JFileChooser accessory component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private JPanel accessoryPanel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
6837
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   144
    /**
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   145
     * Creates a {@code BasicFileChooserUI} implementation
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   146
     * for the specified component. By default
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   147
     * the {@code BasicLookAndFeel} class uses
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   148
     * {@code createUI} methods of all basic UIs classes
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   149
     * to instantiate UIs.
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   150
     *
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   151
     * @param c the {@code JFileChooser} which needs a UI
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   152
     * @return the {@code BasicFileChooserUI} object
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   153
     *
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   154
     * @see UIDefaults#getUI(JComponent)
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   155
     * @since 1.7
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   156
     */
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   157
    public static ComponentUI createUI(JComponent c) {
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   158
        return new BasicFileChooserUI((JFileChooser) c);
5beeaa777490 6984643: Unable to instantiate JFileChooser with a minimal BasicL&F descendant installed
rupashka
parents: 5506
diff changeset
   159
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public BasicFileChooserUI(JFileChooser b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        accessoryPanel = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        filechooser = (JFileChooser) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        createModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        clearIconCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        installDefaults(filechooser);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        installComponents(filechooser);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        installListeners(filechooser);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        filechooser.applyComponentOrientation(filechooser.getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public void uninstallUI(JComponent c) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 680
diff changeset
   179
        uninstallListeners(filechooser);
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 680
diff changeset
   180
        uninstallComponents(filechooser);
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 680
diff changeset
   181
        uninstallDefaults(filechooser);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if(accessoryPanel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            accessoryPanel.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        accessoryPanel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        getFileChooser().removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public void installComponents(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public void uninstallComponents(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    protected void installListeners(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        propertyChangeListener = createPropertyChangeListener(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if(propertyChangeListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            fc.addPropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        fc.addPropertyChangeListener(getModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        InputMap inputMap = getInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                                        WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        SwingUtilities.replaceUIInputMap(fc, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                         WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        ActionMap actionMap = getActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        SwingUtilities.replaceUIActionMap(fc, actionMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    InputMap getInputMap(int condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            return (InputMap)DefaultLookup.get(getFileChooser(), this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    "FileChooser.ancestorInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    ActionMap getActionMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return createActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    ActionMap createActionMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        ActionMap map = new ActionMapUIResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        Action refreshAction = new UIAction(FilePane.ACTION_REFRESH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            public void actionPerformed(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                getFileChooser().rescanCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        map.put(FilePane.ACTION_APPROVE_SELECTION, getApproveSelectionAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        map.put(FilePane.ACTION_CANCEL, getCancelSelectionAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        map.put(FilePane.ACTION_REFRESH, refreshAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        map.put(FilePane.ACTION_CHANGE_TO_PARENT_DIRECTORY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                getChangeToParentDirectoryAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    protected void uninstallListeners(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if(propertyChangeListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            fc.removePropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        fc.removePropertyChangeListener(getModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        SwingUtilities.replaceUIInputMap(fc, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                         WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        SwingUtilities.replaceUIActionMap(fc, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    protected void installDefaults(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        installIcons(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        installStrings(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        usesSingleFilePane = UIManager.getBoolean("FileChooser.usesSingleFilePane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        readOnly           = UIManager.getBoolean("FileChooser.readOnly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        TransferHandler th = fc.getTransferHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (th == null || th instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            fc.setTransferHandler(defaultTransferHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        LookAndFeel.installProperty(fc, "opaque", Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    protected void installIcons(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        directoryIcon    = UIManager.getIcon("FileView.directoryIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        fileIcon         = UIManager.getIcon("FileView.fileIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        computerIcon     = UIManager.getIcon("FileView.computerIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        hardDriveIcon    = UIManager.getIcon("FileView.hardDriveIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        floppyDriveIcon  = UIManager.getIcon("FileView.floppyDriveIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        newFolderIcon    = UIManager.getIcon("FileChooser.newFolderIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        upFolderIcon     = UIManager.getIcon("FileChooser.upFolderIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        homeFolderIcon   = UIManager.getIcon("FileChooser.homeFolderIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        detailsViewIcon  = UIManager.getIcon("FileChooser.detailsViewIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        listViewIcon     = UIManager.getIcon("FileChooser.listViewIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        viewMenuIcon     = UIManager.getIcon("FileChooser.viewMenuIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    protected void installStrings(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        Locale l = fc.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        newFolderErrorText = UIManager.getString("FileChooser.newFolderErrorText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        newFolderErrorSeparator = UIManager.getString("FileChooser.newFolderErrorSeparator",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        newFolderParentDoesntExistTitleText = UIManager.getString("FileChooser.newFolderParentDoesntExistTitleText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        newFolderParentDoesntExistText = UIManager.getString("FileChooser.newFolderParentDoesntExistText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        fileDescriptionText = UIManager.getString("FileChooser.fileDescriptionText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        directoryDescriptionText = UIManager.getString("FileChooser.directoryDescriptionText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        saveButtonText   = UIManager.getString("FileChooser.saveButtonText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        openButtonText   = UIManager.getString("FileChooser.openButtonText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        saveDialogTitleText = UIManager.getString("FileChooser.saveDialogTitleText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        openDialogTitleText = UIManager.getString("FileChooser.openDialogTitleText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        cancelButtonText = UIManager.getString("FileChooser.cancelButtonText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        updateButtonText = UIManager.getString("FileChooser.updateButtonText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        helpButtonText   = UIManager.getString("FileChooser.helpButtonText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        directoryOpenButtonText = UIManager.getString("FileChooser.directoryOpenButtonText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        saveButtonMnemonic   = getMnemonic("FileChooser.saveButtonMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        openButtonMnemonic   = getMnemonic("FileChooser.openButtonMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        cancelButtonMnemonic = getMnemonic("FileChooser.cancelButtonMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        updateButtonMnemonic = getMnemonic("FileChooser.updateButtonMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        helpButtonMnemonic   = getMnemonic("FileChooser.helpButtonMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        directoryOpenButtonMnemonic = getMnemonic("FileChooser.directoryOpenButtonMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        saveButtonToolTipText   = UIManager.getString("FileChooser.saveButtonToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        openButtonToolTipText   = UIManager.getString("FileChooser.openButtonToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        cancelButtonToolTipText = UIManager.getString("FileChooser.cancelButtonToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        updateButtonToolTipText = UIManager.getString("FileChooser.updateButtonToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        helpButtonToolTipText   = UIManager.getString("FileChooser.helpButtonToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        directoryOpenButtonToolTipText = UIManager.getString("FileChooser.directoryOpenButtonToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    protected void uninstallDefaults(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        uninstallIcons(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        uninstallStrings(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (fc.getTransferHandler() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            fc.setTransferHandler(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    protected void uninstallIcons(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        directoryIcon    = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        fileIcon         = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        computerIcon     = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        hardDriveIcon    = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        floppyDriveIcon  = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        newFolderIcon    = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        upFolderIcon     = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        homeFolderIcon   = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        detailsViewIcon  = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        listViewIcon     = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        viewMenuIcon     = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    protected void uninstallStrings(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        saveButtonText   = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        openButtonText   = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        cancelButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        updateButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        helpButtonText   = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        directoryOpenButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        saveButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        openButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        cancelButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        updateButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        helpButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        directoryOpenButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    protected void createModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            model.invalidateFileCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        model = new BasicDirectoryModel(getFileChooser());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public BasicDirectoryModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public PropertyChangeListener createPropertyChangeListener(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public String getFileName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    public String getDirectoryName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public void setFileName(String filename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public void setDirectoryName(String dirname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public void rescanCurrentDirectory(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public void ensureFileIsVisible(JFileChooser fc, File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public JFileChooser getFileChooser() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return filechooser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public JPanel getAccessoryPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return accessoryPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    protected JButton getApproveButton(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
680
eaff686e34f7 5035693: "Open" button should be a default one in JFileChooser under Windows XP LAF
rupashka
parents: 2
diff changeset
   404
    public JButton getDefaultButton(JFileChooser fc) {
eaff686e34f7 5035693: "Open" button should be a default one in JFileChooser under Windows XP LAF
rupashka
parents: 2
diff changeset
   405
        return getApproveButton(fc);
eaff686e34f7 5035693: "Open" button should be a default one in JFileChooser under Windows XP LAF
rupashka
parents: 2
diff changeset
   406
    }
eaff686e34f7 5035693: "Open" button should be a default one in JFileChooser under Windows XP LAF
rupashka
parents: 2
diff changeset
   407
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public String getApproveButtonToolTipText(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        String tooltipText = fc.getApproveButtonToolTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if(tooltipText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            return tooltipText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if(fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return openButtonToolTipText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        } else if(fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return saveButtonToolTipText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    public void clearIconCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        fileView.clearIconCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    // ********************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    // ************ Create Listeners **************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    // ********************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    private Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    protected MouseListener createDoubleClickListener(JFileChooser fc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                                                      JList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        return new Handler(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public ListSelectionListener createListSelectionListener(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    private class Handler implements MouseListener, ListSelectionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        JList list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        Handler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        Handler(JList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            this.list = list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        public void mouseClicked(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            // Note: we can't depend on evt.getSource() because of backward
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   459
            // compatibility
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            if (list != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                SwingUtilities.isLeftMouseButton(evt) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                (evt.getClickCount()%2 == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                int index = SwingUtilities2.loc2IndexFileList(list, evt.getPoint());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    File f = (File)list.getModel().getElementAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                        // Strip trailing ".."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                        f = ShellFolder.getNormalizedFile(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                    } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                        // That's ok, we'll use f as is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    if(getFileChooser().isTraversable(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                        list.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                        changeDirectory(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                        getFileChooser().approveSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        public void mouseEntered(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            if (list != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                TransferHandler th1 = getFileChooser().getTransferHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                TransferHandler th2 = list.getTransferHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                if (th1 != th2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    list.setTransferHandler(th1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                if (getFileChooser().getDragEnabled() != list.getDragEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                    list.setDragEnabled(getFileChooser().getDragEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        public void mouseExited(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        public void mousePressed(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        public void mouseReleased(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        public void valueChanged(ListSelectionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            if(!evt.getValueIsAdjusting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                FileSystemView fsv = chooser.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                JList list = (JList)evt.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                int fsm = chooser.getFileSelectionMode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                boolean useSetDirectory = usesSingleFilePane &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                                          (fsm == JFileChooser.FILES_ONLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                if (chooser.isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    File[] files = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                    Object[] objects = list.getSelectedValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                    if (objects != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                        if (objects.length == 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                            && ((File)objects[0]).isDirectory()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                            && chooser.isTraversable(((File)objects[0]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                            && (useSetDirectory || !fsv.isFileSystem(((File)objects[0])))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                            setDirectorySelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                            setDirectory(((File)objects[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                        } else {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 680
diff changeset
   526
                            ArrayList<File> fList = new ArrayList<File>(objects.length);
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 680
diff changeset
   527
                            for (Object object : objects) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 680
diff changeset
   528
                                File f = (File) object;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                boolean isDir = f.isDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                                if ((chooser.isFileSelectionEnabled() && !isDir)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                                    || (chooser.isDirectorySelectionEnabled()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                                        && fsv.isFileSystem(f)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                                        && isDir)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                                    fList.add(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                            if (fList.size() > 0) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 680
diff changeset
   538
                                files = fList.toArray(new File[fList.size()]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                            setDirectorySelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    chooser.setSelectedFiles(files);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    File file = (File)list.getSelectedValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    if (file != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                        && file.isDirectory()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        && chooser.isTraversable(file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                        && (useSetDirectory || !fsv.isFileSystem(file))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                        setDirectorySelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                        setDirectory(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                        if (usesSingleFilePane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                            chooser.setSelectedFile(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                        setDirectorySelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                        if (file != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                            chooser.setSelectedFile(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    protected class DoubleClickListener extends MouseAdapter {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   568
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        public  DoubleClickListener(JList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            handler = new Handler(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
         * The JList used for representing the files is created by subclasses, but the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
         * selection is monitored in this class.  The TransferHandler installed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
         * JFileChooser is also installed in the file list as it is used as the actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
         * transfer source.  The list is updated on a mouse enter to reflect the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
         * data transfer state of the file chooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            handler.mouseEntered(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            handler.mouseClicked(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    protected class SelectionListener implements ListSelectionListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   594
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            getHandler().valueChanged(e);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * Property to remember whether a directory is currently selected in the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @return <code>true</code> iff a directory is currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    protected boolean isDirectorySelected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        return directorySelected;
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
     * Property to remember whether a directory is currently selected in the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * This is normally called by the UI on a selection event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * @param b iff a directory is currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    protected void setDirectorySelected(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        directorySelected = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * Property to remember the directory that is currently selected in the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @return the value of the <code>directory</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @see #setDirectory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    protected File getDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        return directory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * Property to remember the directory that is currently selected in the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * This is normally called by the UI on a selection event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * @param f the <code>File</code> object representing the directory that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *          currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    protected void setDirectory(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        directory = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * Returns the mnemonic for the given key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    private int getMnemonic(String key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        return SwingUtilities2.getUIDefaultsInt(key, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    // *******************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    // ************ FileChooser UI PLAF methods **************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    // *******************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * Returns the default accept all file filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    public FileFilter getAcceptAllFileFilter(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        return acceptAllFileFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    public FileView getFileView(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        return fileView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
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
     * Returns the title of this dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    public String getDialogTitle(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        String dialogTitle = fc.getDialogTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        if (dialogTitle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            return dialogTitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        } else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            return openDialogTitleText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        } else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            return saveDialogTitleText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            return getApproveButtonText(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    public int getApproveButtonMnemonic(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        int mnemonic = fc.getApproveButtonMnemonic();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        if (mnemonic > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            return mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        } else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            return openButtonMnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        } else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            return saveButtonMnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            return mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    public String getApproveButtonText(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        String buttonText = fc.getApproveButtonText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        if (buttonText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            return buttonText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        } else if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            return openButtonText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        } else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            return saveButtonText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    // *****************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    // ***** Directory Actions *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    // *****************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    public Action getNewFolderAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        if (newFolderAction == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            newFolderAction = new NewFolderAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            // Note: Don't return null for readOnly, it might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            // break older apps.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            if (readOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                newFolderAction.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        return newFolderAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    public Action getGoHomeAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        return goHomeAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    public Action getChangeToParentDirectoryAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        return changeToParentDirectoryAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    public Action getApproveSelectionAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        return approveSelectionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    public Action getCancelSelectionAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        return cancelSelectionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    public Action getUpdateAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        return updateAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * Creates a new folder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    protected class NewFolderAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        protected NewFolderAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            super(FilePane.ACTION_NEW_FOLDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            if (readOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            File currentDirectory = fc.getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            if (!currentDirectory.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                JOptionPane.showMessageDialog(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                    fc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                    newFolderParentDoesntExistText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                    newFolderParentDoesntExistTitleText, JOptionPane.WARNING_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            File newFolder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                newFolder = fc.getFileSystemView().createNewFolder(currentDirectory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                if (fc.isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    fc.setSelectedFiles(new File[] { newFolder });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                    fc.setSelectedFile(newFolder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            } catch (IOException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                JOptionPane.showMessageDialog(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                    fc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                    newFolderErrorText + newFolderErrorSeparator + exc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                    newFolderErrorText, JOptionPane.ERROR_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            fc.rescanCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * Acts on the "home" key event or equivalent event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    protected class GoHomeAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        protected GoHomeAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            super("Go Home");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            changeDirectory(fc.getFileSystemView().getHomeDirectory());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    protected class ChangeToParentDirectoryAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        protected ChangeToParentDirectoryAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            super("Go Up");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            putValue(Action.ACTION_COMMAND_KEY, FilePane.ACTION_CHANGE_TO_PARENT_DIRECTORY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        public void actionPerformed(ActionEvent e) {
10092
aff525ea8b17 7019963: The goto parent directory button doesn't operate in JFileChooser
rupashka
parents: 7668
diff changeset
   813
            getFileChooser().changeToParentDirectory();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * Responds to an Open or Save request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    protected class ApproveSelectionAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        protected ApproveSelectionAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            super(FilePane.ACTION_APPROVE_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            if (isDirectorySelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                File dir = getDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                if (dir != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                        // Strip trailing ".."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                        dir = ShellFolder.getNormalizedFile(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                    } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                        // Ok, use f as is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                    changeDirectory(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            String filename = getFileName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            FileSystemView fs = chooser.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            File dir = chooser.getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            if (filename != null) {
1302
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   846
                // Remove whitespaces from end of filename
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   847
                int i = filename.length() - 1;
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   848
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   849
                while (i >=0 && filename.charAt(i) <= ' ') {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   850
                    i--;
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   851
                }
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   852
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   853
                filename = filename.substring(0, i + 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
1302
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   856
            if (filename == null || filename.length() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                // no file selected, multiple selection off, therefore cancel the approve action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                resetGlobFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            File selectedFile = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            File[] selectedFiles = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
1302
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   865
            // Unix: Resolve '~' to user's home directory
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   866
            if (File.separatorChar == '/') {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   867
                if (filename.startsWith("~/")) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   868
                    filename = System.getProperty("user.home") + filename.substring(1);
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   869
                } else if (filename.equals("~")) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   870
                    filename = System.getProperty("user.home");
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   871
                }
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   872
            }
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   873
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   874
            if (chooser.isMultiSelectionEnabled() && filename.length() > 1 &&
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   875
                    filename.charAt(0) == '"' && filename.charAt(filename.length() - 1) == '"') {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   876
                List<File> fList = new ArrayList<File>();
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   877
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   878
                String[] files = filename.substring(1, filename.length() - 1).split("\" \"");
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   879
                // Optimize searching files by names in "children" array
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   880
                Arrays.sort(files);
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   881
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   882
                File[] children = null;
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   883
                int childIndex = 0;
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   884
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   885
                for (String str : files) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   886
                    File file = fs.createFileObject(str);
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   887
                    if (!file.isAbsolute()) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   888
                        if (children == null) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   889
                            children = fs.getFiles(dir, false);
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   890
                            Arrays.sort(children);
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   891
                        }
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   892
                        for (int k = 0; k < children.length; k++) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   893
                            int l = (childIndex + k) % children.length;
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   894
                            if (children[l].getName().equals(str)) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   895
                                file = children[l];
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   896
                                childIndex = l + 1;
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   897
                                break;
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   898
                            }
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   899
                        }
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   900
                    }
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   901
                    fList.add(file);
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   902
                }
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   903
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   904
                if (!fList.isEmpty()) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   905
                    selectedFiles = fList.toArray(new File[fList.size()]);
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   906
                }
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   907
                resetGlobFilter();
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   908
            } else {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   909
                selectedFile = fs.createFileObject(filename);
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   910
                if (!selectedFile.isAbsolute()) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   911
                    selectedFile = fs.getChild(dir, filename);
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   912
                }
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   913
                // check for wildcard pattern
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   914
                FileFilter currentFilter = chooser.getFileFilter();
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   915
                if (!selectedFile.exists() && isGlobPattern(filename)) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   916
                    changeDirectory(selectedFile.getParentFile());
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   917
                    if (globFilter == null) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   918
                        globFilter = new GlobFilter();
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   919
                    }
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   920
                    try {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   921
                        globFilter.setPattern(selectedFile.getName());
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   922
                        if (!(currentFilter instanceof GlobFilter)) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   923
                            actualFileFilter = currentFilter;
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   924
                        }
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   925
                        chooser.setFileFilter(null);
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   926
                        chooser.setFileFilter(globFilter);
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   927
                        return;
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   928
                    } catch (PatternSyntaxException pse) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   929
                        // Not a valid glob pattern. Abandon filter.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
1302
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   933
                resetGlobFilter();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
1302
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   935
                // Check for directory change action
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   936
                boolean isDir = (selectedFile != null && selectedFile.isDirectory());
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   937
                boolean isTrav = (selectedFile != null && chooser.isTraversable(selectedFile));
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   938
                boolean isDirSelEnabled = chooser.isDirectorySelectionEnabled();
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   939
                boolean isFileSelEnabled = chooser.isFileSelectionEnabled();
3977
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 1841
diff changeset
   940
                boolean isCtrl = (e != null && (e.getModifiers() &
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 1841
diff changeset
   941
                            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
1302
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   943
                if (isDir && isTrav && (isCtrl || !isDirSelEnabled)) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   944
                    changeDirectory(selectedFile);
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   945
                    return;
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   946
                } else if ((isDir || !isFileSelEnabled)
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   947
                        && (!isDir || !isDirSelEnabled)
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   948
                        && (!isDirSelEnabled || selectedFile.exists())) {
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   949
                    selectedFile = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            }
1302
ac8b63707542 6351074: JFileChooser removes leading space in filename
rupashka
parents: 1299
diff changeset
   952
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            if (selectedFiles != null || selectedFile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                if (selectedFiles != null || chooser.isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                    if (selectedFiles == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                        selectedFiles = new File[] { selectedFile };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                    chooser.setSelectedFiles(selectedFiles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                    // Do it again. This is a fix for bug 4949273 to force the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                    // selected value in case the ListSelectionModel clears it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                    // for non-existing file names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                    chooser.setSelectedFiles(selectedFiles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                    chooser.setSelectedFile(selectedFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                chooser.approveSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                if (chooser.isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    chooser.setSelectedFiles(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                    chooser.setSelectedFile(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                chooser.cancelSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    private void resetGlobFilter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        if (actualFileFilter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            FileFilter currentFilter = chooser.getFileFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            if (currentFilter != null && currentFilter.equals(globFilter)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                chooser.setFileFilter(actualFileFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                chooser.removeChoosableFileFilter(globFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            actualFileFilter = null;
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
    private static boolean isGlobPattern(String filename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        return ((File.separatorChar == '\\' && (filename.indexOf('*') >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                                                  || filename.indexOf('?') >= 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                || (File.separatorChar == '/' && (filename.indexOf('*') >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                                                  || filename.indexOf('?') >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                                                  || filename.indexOf('[') >= 0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    /* A file filter which accepts file patterns containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * the special wildcards *? on Windows and *?[] on Unix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    class GlobFilter extends FileFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        Pattern pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        String globPattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        public void setPattern(String globPattern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            char[] gPat = globPattern.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            char[] rPat = new char[gPat.length * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            boolean isWin32 = (File.separatorChar == '\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            boolean inBrackets = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            int j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            this.globPattern = globPattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            if (isWin32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                // On windows, a pattern ending with *.* is equal to ending with *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                int len = gPat.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                if (globPattern.endsWith("*.*")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                    len -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                    switch(gPat[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                      case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                        rPat[j++] = '.';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                        rPat[j++] = '*';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                      case '?':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                        rPat[j++] = '.';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                      case '\\':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                        rPat[j++] = '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                        rPat[j++] = '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                      default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                        if ("+()^$.{}[]".indexOf(gPat[i]) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                            rPat[j++] = '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                        rPat[j++] = gPat[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                for (int i = 0; i < gPat.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                    switch(gPat[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                      case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                        if (!inBrackets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                            rPat[j++] = '.';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                        rPat[j++] = '*';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                      case '?':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                        rPat[j++] = inBrackets ? '?' : '.';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                      case '[':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                        inBrackets = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                        rPat[j++] = gPat[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                        if (i < gPat.length - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                            switch (gPat[i+1]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                              case '!':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                              case '^':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                                rPat[j++] = '^';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                              case ']':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                                rPat[j++] = gPat[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                      case ']':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                        rPat[j++] = gPat[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                        inBrackets = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                      case '\\':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                        if (i == 0 && gPat.length > 1 && gPat[1] == '~') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                            rPat[j++] = gPat[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                            rPat[j++] = '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                            if (i < gPat.length - 1 && "*?[]".indexOf(gPat[i+1]) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                                rPat[j++] = gPat[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                                rPat[j++] = '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                      default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                        //if ("+()|^$.{}<>".indexOf(gPat[i]) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                        if (!Character.isLetterOrDigit(gPat[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                            rPat[j++] = '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                        rPat[j++] = gPat[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            this.pattern = Pattern.compile(new String(rPat, 0, j), Pattern.CASE_INSENSITIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        public boolean accept(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            if (f.isDirectory()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            return pattern.matcher(f.getName()).matches();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        public String getDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            return globPattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * Responds to a cancel request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    protected class CancelSelectionAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            getFileChooser().cancelSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * Rescans the files in the current directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    protected class UpdateAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            fc.setCurrentDirectory(fc.getFileSystemView().createFileObject(getDirectoryName()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            fc.rescanCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
    private void changeDirectory(File dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        // Traverse shortcuts on Windows
1840
984ba55ac827 6698013: JFileChooser can no longer navigate non-local file systems.
rupashka
parents: 1302
diff changeset
  1149
        if (dir != null && FilePane.usesShellFolder(fc)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            try {
1841
516419c55144 6560349: REGRESSION :folder having ".lnk" in the name can not be opened by 5.0 and later versions
rupashka
parents: 1840
diff changeset
  1151
                ShellFolder shellFolder = ShellFolder.getShellFolder(dir);
516419c55144 6560349: REGRESSION :folder having ".lnk" in the name can not be opened by 5.0 and later versions
rupashka
parents: 1840
diff changeset
  1152
516419c55144 6560349: REGRESSION :folder having ".lnk" in the name can not be opened by 5.0 and later versions
rupashka
parents: 1840
diff changeset
  1153
                if (shellFolder.isLink()) {
516419c55144 6560349: REGRESSION :folder having ".lnk" in the name can not be opened by 5.0 and later versions
rupashka
parents: 1840
diff changeset
  1154
                    File linkedTo = shellFolder.getLinkLocation();
516419c55144 6560349: REGRESSION :folder having ".lnk" in the name can not be opened by 5.0 and later versions
rupashka
parents: 1840
diff changeset
  1155
10412
0c262c47967c 7012783: JFileChooser fails to resolve DFS links on Windows Vista SP2
vikram
parents: 10092
diff changeset
  1156
                    // If linkedTo is null we try to use dir
0c262c47967c 7012783: JFileChooser fails to resolve DFS links on Windows Vista SP2
vikram
parents: 10092
diff changeset
  1157
                    if (linkedTo != null) {
0c262c47967c 7012783: JFileChooser fails to resolve DFS links on Windows Vista SP2
vikram
parents: 10092
diff changeset
  1158
                        if (fc.isTraversable(linkedTo)) {
0c262c47967c 7012783: JFileChooser fails to resolve DFS links on Windows Vista SP2
vikram
parents: 10092
diff changeset
  1159
                            dir = linkedTo;
0c262c47967c 7012783: JFileChooser fails to resolve DFS links on Windows Vista SP2
vikram
parents: 10092
diff changeset
  1160
                        } else {
0c262c47967c 7012783: JFileChooser fails to resolve DFS links on Windows Vista SP2
vikram
parents: 10092
diff changeset
  1161
                            return;
0c262c47967c 7012783: JFileChooser fails to resolve DFS links on Windows Vista SP2
vikram
parents: 10092
diff changeset
  1162
                        }
1841
516419c55144 6560349: REGRESSION :folder having ".lnk" in the name can not be opened by 5.0 and later versions
rupashka
parents: 1840
diff changeset
  1163
                    } else {
10412
0c262c47967c 7012783: JFileChooser fails to resolve DFS links on Windows Vista SP2
vikram
parents: 10092
diff changeset
  1164
                        dir = shellFolder;
1841
516419c55144 6560349: REGRESSION :folder having ".lnk" in the name can not be opened by 5.0 and later versions
rupashka
parents: 1840
diff changeset
  1165
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            } catch (FileNotFoundException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        fc.setCurrentDirectory(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        if (fc.getFileSelectionMode() == JFileChooser.FILES_AND_DIRECTORIES &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            fc.getFileSystemView().isFileSystem(dir)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            setFileName(dir.getAbsolutePath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    // *****************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    // ***** default AcceptAll file filter *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    // *****************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    protected class AcceptAllFileFilter extends FileFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        public AcceptAllFileFilter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        public boolean accept(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        public String getDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            return UIManager.getString("FileChooser.acceptAllFileFilterText");
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
    // ***********************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    // * FileView operations *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    // ***********************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    protected class BasicFileView extends FileView {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        /* FileView type descriptions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        // PENDING(jeff) - pass in the icon cache size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        protected Hashtable<File,Icon> iconCache = new Hashtable<File,Icon>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        public BasicFileView() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        public void clearIconCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            iconCache = new Hashtable<File,Icon>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        public String getName(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            // Note: Returns display name rather than file name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            String fileName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            if(f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                fileName = getFileChooser().getFileSystemView().getSystemDisplayName(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            return fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        public String getDescription(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            return f.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        public String getTypeDescription(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            String type = getFileChooser().getFileSystemView().getSystemTypeDescription(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            if (type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                if (f.isDirectory()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                    type = directoryDescriptionText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                    type = fileDescriptionText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        public Icon getCachedIcon(File f) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 680
diff changeset
  1240
            return iconCache.get(f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        public void cacheIcon(File f, Icon i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            if(f == null || i == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            iconCache.put(f, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        public Icon getIcon(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            Icon icon = getCachedIcon(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            if(icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            icon = fileIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            if (f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                FileSystemView fsv = getFileChooser().getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                if (fsv.isFloppyDrive(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                    icon = floppyDriveIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                } else if (fsv.isDrive(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                    icon = hardDriveIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                } else if (fsv.isComputerNode(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                    icon = computerIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                } else if (f.isDirectory()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                    icon = directoryIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            cacheIcon(f, icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        public Boolean isHidden(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
            String name = f.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            if(name != null && name.charAt(0) == '.') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                return Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                return Boolean.FALSE;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    private static final TransferHandler defaultTransferHandler = new FileTransferHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * Data transfer support for the file chooser.  Since files are currently presented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * as a list, the list support is reused with the added flavor of DataFlavor.javaFileListFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    static class FileTransferHandler extends TransferHandler implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
         * Create a Transferable to use as the source for a data transfer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
         * @param c  The component holding the data to be transfered.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
         *  argument is provided to enable sharing of TransferHandlers by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
         *  multiple components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
         * @return  The representation of the data to be transfered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        protected Transferable createTransferable(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            Object[] values = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            if (c instanceof JList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                values = ((JList)c).getSelectedValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            } else if (c instanceof JTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                JTable table = (JTable)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                int[] rows = table.getSelectedRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                if (rows != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                    values = new Object[rows.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                    for (int i=0; i<rows.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                        values[i] = table.getValueAt(rows[i], 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            if (values == null || values.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            StringBuffer plainBuf = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
            StringBuffer htmlBuf = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            htmlBuf.append("<html>\n<body>\n<ul>\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 680
diff changeset
  1323
            for (Object obj : values) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                String val = ((obj == null) ? "" : obj.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                plainBuf.append(val + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                htmlBuf.append("  <li>" + val + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            // remove the last newline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            plainBuf.deleteCharAt(plainBuf.length() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            htmlBuf.append("</ul>\n</body>\n</html>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            return new FileTransferable(plainBuf.toString(), htmlBuf.toString(), values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        public int getSourceActions(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            return COPY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        static class FileTransferable extends BasicTransferable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            Object[] fileData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            FileTransferable(String plainData, String htmlData, Object[] fileData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                super(plainData, htmlData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
                this.fileData = fileData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
             * Best format of the file chooser is DataFlavor.javaFileListFlavor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            protected DataFlavor[] getRicherFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                DataFlavor[] flavors = new DataFlavor[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                flavors[0] = DataFlavor.javaFileListFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                return flavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
             * The only richer format supported is the file list flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            protected Object getRicherData(DataFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                if (DataFlavor.javaFileListFlavor.equals(flavor)) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 680
diff changeset
  1363
                    ArrayList<Object> files = new ArrayList<Object>();
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 680
diff changeset
  1364
                    for (Object file : this.fileData) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 680
diff changeset
  1365
                        files.add(file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                    return files;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                return null;
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
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
}