jdk/src/share/classes/sun/swing/FilePane.java
author darcy
Thu, 30 Jan 2014 09:15:13 -0800
changeset 22618 927e4fe6cb24
parent 20099 fe931b18962c
child 22644 965bba13a5f0
permissions -rw-r--r--
8033221: Fix serial lint warnings in sun.swing.* Reviewed-by: alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22618
927e4fe6cb24 8033221: Fix serial lint warnings in sun.swing.*
darcy
parents: 20099
diff changeset
     2
 * Copyright (c) 2003, 2014, 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: 3346
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: 3346
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: 3346
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3346
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3346
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.text.DateFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.text.MessageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.List;
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1842
diff changeset
    36
import java.util.concurrent.Callable;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
10580
244113d67cf0 7032018: The file list in JFileChooser does not have an accessible name
rupashka
parents: 10100
diff changeset
    38
import javax.accessibility.AccessibleContext;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.filechooser.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.swing.table.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.awt.shell.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <b>WARNING:</b> This class is an implementation detail and is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * public so that it can be used by two packages. You should NOT consider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * this public API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * This component is intended to be used in a subclass of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * javax.swing.plaf.basic.BasicFileChooserUI. It realies heavily on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * implementation of BasicFileChooserUI, and is intended to be API compatible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * with earlier implementations of MetalFileChooserUI and WindowsFileChooserUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Leif Samuelsson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
22618
927e4fe6cb24 8033221: Fix serial lint warnings in sun.swing.*
darcy
parents: 20099
diff changeset
    61
@SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class FilePane extends JPanel implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // Constants for actions. These are used for the actions' ACTION_COMMAND_KEY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // and as keys in the action maps for FilePane and the corresponding UI classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public final static String ACTION_APPROVE_SELECTION = "approveSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public final static String ACTION_CANCEL            = "cancelSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public final static String ACTION_EDIT_FILE_NAME    = "editFileName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public final static String ACTION_REFRESH           = "refresh";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public final static String ACTION_CHANGE_TO_PARENT_DIRECTORY = "Go Up";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public final static String ACTION_NEW_FOLDER        = "New Folder";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public final static String ACTION_VIEW_LIST         = "viewTypeList";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public final static String ACTION_VIEW_DETAILS      = "viewTypeDetails";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private Action[] actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // "enums" for setViewType()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public  static final int VIEWTYPE_LIST     = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public  static final int VIEWTYPE_DETAILS  = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static final int VIEWTYPE_COUNT    = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private int viewType = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private JPanel[] viewPanels = new JPanel[VIEWTYPE_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private JPanel currentViewPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private String[] viewTypeActionNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
10580
244113d67cf0 7032018: The file list in JFileChooser does not have an accessible name
rupashka
parents: 10100
diff changeset
    87
    private String filesListAccessibleName = null;
244113d67cf0 7032018: The file list in JFileChooser does not have an accessible name
rupashka
parents: 10100
diff changeset
    88
    private String filesDetailsAccessibleName = null;
244113d67cf0 7032018: The file list in JFileChooser does not have an accessible name
rupashka
parents: 10100
diff changeset
    89
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private JPopupMenu contextMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private JMenu viewMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private String viewMenuLabelText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private String refreshActionLabelText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private String newFolderActionLabelText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private String kiloByteString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private String megaByteString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private String gigaByteString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private String renameErrorTitleText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private String renameErrorText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private String renameErrorFileExistsText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private static final Cursor waitCursor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private final KeyListener detailsKeyListener = new KeyAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        private final long timeFactor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        private final StringBuilder typedString = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        private long lastTime = 1000L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            Long l = (Long) UIManager.get("Table.timeFactor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            timeFactor = (l != null) ? l : 1000L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         * Moves the keyboard focus to the first element whose prefix matches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         * the sequence of alphanumeric keys pressed by the user with delay
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
         * less than value of <code>timeFactor</code>. Subsequent same key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         * presses move the keyboard focus to the next object that starts with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         * the same letter until another key is pressed, then it is treated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         * as the prefix with appropriate number of the same letters followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         * by first typed another letter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        public void keyTyped(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            BasicDirectoryModel model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            int rowCount = model.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            if (detailsTable == null || rowCount == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    e.isAltDown() || e.isControlDown() || e.isMetaDown()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            InputMap inputMap = detailsTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            KeyStroke key = KeyStroke.getKeyStrokeForEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            if (inputMap != null && inputMap.get(key) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            int startIndex = detailsTable.getSelectionModel().getLeadSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (startIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                startIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            if (startIndex >= rowCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                startIndex = rowCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            char c = e.getKeyChar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            long time = e.getWhen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            if (time - lastTime < timeFactor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                if (typedString.length() == 1 && typedString.charAt(0) == c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    // Subsequent same key presses move the keyboard focus to the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    // object that starts with the same letter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    startIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    typedString.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                startIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                typedString.setLength(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                typedString.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            lastTime = time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            if (startIndex >= rowCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                startIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            // Find next file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            int index = getNextMatch(startIndex, rowCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            if (index < 0 && startIndex > 0) { // wrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                index = getNextMatch(0, startIndex - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                detailsTable.getSelectionModel().setSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                Rectangle cellRect = detailsTable.getCellRect(index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                        detailsTable.convertColumnIndexToView(COLUMN_FILENAME), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                detailsTable.scrollRectToVisible(cellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        private int getNextMatch(int startIndex, int finishIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            BasicDirectoryModel model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            JFileChooser fileChooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            DetailsTableRowSorter rowSorter = getRowSorter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            String prefix = typedString.toString().toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            // Search element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            for (int index = startIndex; index <= finishIndex; index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                File file = (File) model.getElementAt(rowSorter.convertRowIndexToModel(index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                String fileName = fileChooser.getName(file).toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                if (fileName.startsWith(prefix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    private FocusListener editorFocusListener = new FocusAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            if (! e.isTemporary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                applyEdit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    private static FocusListener repaintListener = new FocusListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        public void focusGained(FocusEvent fe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            repaintSelection(fe.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        public void focusLost(FocusEvent fe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            repaintSelection(fe.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        private void repaintSelection(Object source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (source instanceof JList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                repaintListSelection((JList)source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            } else if (source instanceof JTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                repaintTableSelection((JTable)source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        private void repaintListSelection(JList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            int[] indices = list.getSelectedIndices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            for (int i : indices) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                Rectangle bounds = list.getCellBounds(i, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                list.repaint(bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        private void repaintTableSelection(JTable table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            int minRow = table.getSelectionModel().getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            int maxRow = table.getSelectionModel().getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if (minRow == -1 || maxRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            int col0 = table.convertColumnIndexToView(COLUMN_FILENAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            Rectangle first = table.getCellRect(minRow, col0, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            Rectangle last = table.getCellRect(maxRow, col0, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            Rectangle dirty = first.union(last);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            table.repaint(dirty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    private boolean smallIconsView = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    private Border  listViewBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    private Color   listViewBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private boolean listViewWindowsStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    private boolean readOnly;
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2489
diff changeset
   272
    private boolean fullRowSelection = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    private ListSelectionModel listSelectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private JList list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private JTable detailsTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    private static final int COLUMN_FILENAME = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    // Provides a way to recognize a newly created folder, so it can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    // be selected when it appears in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    private File newFolderFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    // Used for accessing methods in the corresponding UI class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private FileChooserUIAccessor fileChooserUIAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private DetailsTableModel detailsTableModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    private DetailsTableRowSorter rowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public FilePane(FileChooserUIAccessor fileChooserUIAccessor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        super(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        this.fileChooserUIAccessor = fileChooserUIAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        createActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public void uninstallUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if (getModel() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            getModel().removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    protected JFileChooser getFileChooser() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return fileChooserUIAccessor.getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    protected BasicDirectoryModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return fileChooserUIAccessor.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public int getViewType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return viewType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public void setViewType(int viewType) {
1305
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   317
        if (viewType == this.viewType) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
1305
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   320
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   321
        int oldValue = this.viewType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        this.viewType = viewType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
1305
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   324
        JPanel createdViewPanel = null;
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   325
        Component newFocusOwner = null;
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   326
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        switch (viewType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
          case VIEWTYPE_LIST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            if (viewPanels[viewType] == null) {
1305
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   330
                createdViewPanel = fileChooserUIAccessor.createList();
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   331
                if (createdViewPanel == null) {
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   332
                    createdViewPanel = createList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                }
1305
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   334
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   335
                list = (JList) findChildComponent(createdViewPanel, JList.class);
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   336
                if (listSelectionModel == null) {
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   337
                    listSelectionModel = list.getSelectionModel();
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   338
                    if (detailsTable != null) {
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   339
                        detailsTable.setSelectionModel(listSelectionModel);
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   340
                    }
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   341
                } else {
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   342
                    list.setSelectionModel(listSelectionModel);
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   343
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            list.setLayoutOrientation(JList.VERTICAL_WRAP);
1305
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   346
            newFocusOwner = list;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
          case VIEWTYPE_DETAILS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            if (viewPanels[viewType] == null) {
1305
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   351
                createdViewPanel = fileChooserUIAccessor.createDetailsView();
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   352
                if (createdViewPanel == null) {
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   353
                    createdViewPanel = createDetailsView();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                }
1305
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   355
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   356
                detailsTable = (JTable) findChildComponent(createdViewPanel, JTable.class);
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   357
                detailsTable.setRowHeight(Math.max(detailsTable.getFont().getSize() + 4, 16 + 1));
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   358
                if (listSelectionModel != null) {
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   359
                    detailsTable.setSelectionModel(listSelectionModel);
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   360
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
1305
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   362
            newFocusOwner = detailsTable;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
1305
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   365
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   366
        if (createdViewPanel != null) {
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   367
            viewPanels[viewType] = createdViewPanel;
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   368
            recursivelySetInheritsPopupMenu(createdViewPanel, true);
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   369
        }
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   370
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   371
        boolean isFocusOwner = false;
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   372
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   373
        if (currentViewPanel != null) {
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   374
            Component owner = DefaultKeyboardFocusManager.
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   375
                    getCurrentKeyboardFocusManager().getPermanentFocusOwner();
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   376
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   377
            isFocusOwner = owner == detailsTable || owner == list;
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   378
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   379
            remove(currentViewPanel);
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   380
        }
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   381
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        currentViewPanel = viewPanels[viewType];
1305
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   383
        add(currentViewPanel, BorderLayout.CENTER);
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   384
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   385
        if (isFocusOwner && newFocusOwner != null) {
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   386
            newFocusOwner.requestFocusInWindow();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
1305
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   388
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   389
        revalidate();
e6f0b298de50 6554743: JFileChooser dn't close after pressing escape key after changing the views
rupashka
parents: 1301
diff changeset
   390
        repaint();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        updateViewMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        firePropertyChange("viewType", oldValue, viewType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
22618
927e4fe6cb24 8033221: Fix serial lint warnings in sun.swing.*
darcy
parents: 20099
diff changeset
   395
    @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    class ViewTypeAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        private int viewType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        ViewTypeAction(int viewType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            super(viewTypeActionNames[viewType]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            this.viewType = viewType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            String cmd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            switch (viewType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                case VIEWTYPE_LIST:    cmd = ACTION_VIEW_LIST;    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                case VIEWTYPE_DETAILS: cmd = ACTION_VIEW_DETAILS; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                default:               cmd = (String)getValue(Action.NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            putValue(Action.ACTION_COMMAND_KEY, cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            setViewType(viewType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    public Action getViewTypeAction(int viewType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return new ViewTypeAction(viewType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    private static void recursivelySetInheritsPopupMenu(Container container, boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        if (container instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            ((JComponent)container).setInheritsPopupMenu(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        int n = container.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            recursivelySetInheritsPopupMenu((Container)container.getComponent(i), b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        Locale l = getFileChooser().getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        listViewBorder       = UIManager.getBorder("FileChooser.listViewBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        listViewBackground   = UIManager.getColor("FileChooser.listViewBackground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        listViewWindowsStyle = UIManager.getBoolean("FileChooser.listViewWindowsStyle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        readOnly             = UIManager.getBoolean("FileChooser.readOnly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        // TODO: On windows, get the following localized strings from the OS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        viewMenuLabelText =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                        UIManager.getString("FileChooser.viewMenuLabelText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        refreshActionLabelText =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                        UIManager.getString("FileChooser.refreshActionLabelText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        newFolderActionLabelText =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                        UIManager.getString("FileChooser.newFolderActionLabelText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        viewTypeActionNames = new String[VIEWTYPE_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        viewTypeActionNames[VIEWTYPE_LIST] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                        UIManager.getString("FileChooser.listViewActionLabelText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        viewTypeActionNames[VIEWTYPE_DETAILS] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                        UIManager.getString("FileChooser.detailsViewActionLabelText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        kiloByteString = UIManager.getString("FileChooser.fileSizeKiloBytes", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        megaByteString = UIManager.getString("FileChooser.fileSizeMegaBytes", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        gigaByteString = UIManager.getString("FileChooser.fileSizeGigaBytes", l);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2489
diff changeset
   457
        fullRowSelection = UIManager.getBoolean("FileView.fullRowSelection");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
10580
244113d67cf0 7032018: The file list in JFileChooser does not have an accessible name
rupashka
parents: 10100
diff changeset
   459
        filesListAccessibleName = UIManager.getString("FileChooser.filesListAccessibleName", l);
244113d67cf0 7032018: The file list in JFileChooser does not have an accessible name
rupashka
parents: 10100
diff changeset
   460
        filesDetailsAccessibleName = UIManager.getString("FileChooser.filesDetailsAccessibleName", l);
244113d67cf0 7032018: The file list in JFileChooser does not have an accessible name
rupashka
parents: 10100
diff changeset
   461
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        renameErrorTitleText = UIManager.getString("FileChooser.renameErrorTitleText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        renameErrorText = UIManager.getString("FileChooser.renameErrorText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        renameErrorFileExistsText = UIManager.getString("FileChooser.renameErrorFileExistsText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * Fetches the command list for the FilePane. These commands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * are useful for binding to events, such as in a keymap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @return the command list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public Action[] getActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        if (actions == null) {
22618
927e4fe6cb24 8033221: Fix serial lint warnings in sun.swing.*
darcy
parents: 20099
diff changeset
   475
            @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            class FilePaneAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                FilePaneAction(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    this(name, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                FilePaneAction(String name, String cmd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                    putValue(Action.ACTION_COMMAND_KEY, cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    String cmd = (String)getValue(Action.ACTION_COMMAND_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    if (cmd == ACTION_CANCEL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                        if (editFile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                           cancelEdit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                           getFileChooser().cancelSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    } else if (cmd == ACTION_EDIT_FILE_NAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                        int index = listSelectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                        if (index >= 0 && editFile == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                            (!fc.isMultiSelectionEnabled() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                             fc.getSelectedFiles().length <= 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                            editFileName(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                    } else if (cmd == ACTION_REFRESH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                        getFileChooser().rescanCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                    String cmd = (String)getValue(Action.ACTION_COMMAND_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    if (cmd == ACTION_CANCEL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                        return getFileChooser().isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    } else if (cmd == ACTION_EDIT_FILE_NAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                        return !readOnly && getFileChooser().isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            ArrayList<Action> actionList = new ArrayList<Action>(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            Action action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            actionList.add(new FilePaneAction(ACTION_CANCEL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            actionList.add(new FilePaneAction(ACTION_EDIT_FILE_NAME));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            actionList.add(new FilePaneAction(refreshActionLabelText, ACTION_REFRESH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            action = fileChooserUIAccessor.getApproveSelectionAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            if (action != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                actionList.add(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            action = fileChooserUIAccessor.getChangeToParentDirectoryAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            if (action != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                actionList.add(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            action = getNewFolderAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            if (action != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                actionList.add(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            action = getViewTypeAction(VIEWTYPE_LIST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            if (action != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                actionList.add(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            action = getViewTypeAction(VIEWTYPE_DETAILS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            if (action != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                actionList.add(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            actions = actionList.toArray(new Action[actionList.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        return actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    protected void createActionMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        addActionsToMap(super.getActionMap(), getActions());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    public static void addActionsToMap(ActionMap map, Action[] actions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        if (map != null && actions != null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   561
            for (Action a : actions) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                String cmd = (String)a.getValue(Action.ACTION_COMMAND_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                if (cmd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                    cmd = (String)a.getValue(Action.NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                map.put(cmd, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    private void updateListRowCount(JList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if (smallIconsView) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            list.setVisibleRowCount(getModel().getSize() / 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            list.setVisibleRowCount(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    public JPanel createList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        JPanel p = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        final JFileChooser fileChooser = getFileChooser();
22618
927e4fe6cb24 8033221: Fix serial lint warnings in sun.swing.*
darcy
parents: 20099
diff changeset
   583
927e4fe6cb24 8033221: Fix serial lint warnings in sun.swing.*
darcy
parents: 20099
diff changeset
   584
        @SuppressWarnings("serial") // anonymous class
10100
c525c5fbb86c 7031941: Use generificated JComboBox and JList in core libraries
rupashka
parents: 9488
diff changeset
   585
        final JList<Object> list = new JList<Object>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            public int getNextMatch(String prefix, int startIndex, Position.Bias bias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                ListModel model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                int max = model.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                if (prefix == null || startIndex < 0 || startIndex >= max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                // start search from the next element before/after the selected element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                boolean backwards = (bias == Position.Bias.Backward);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                for (int i = startIndex; backwards ? i >= 0 : i < max; i += (backwards ?  -1 : 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                    String filename = fileChooser.getName((File)model.getElementAt(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                    if (filename.regionMatches(true, 0, prefix, 0, prefix.length())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                        return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        list.setCellRenderer(new FileRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        list.setLayoutOrientation(JList.VERTICAL_WRAP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        // 4835633 : tell BasicListUI that this is a file list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        list.putClientProperty("List.isFileList", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (listViewWindowsStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            list.addFocusListener(repaintListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        updateListRowCount(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        getModel().addListDataListener(new ListDataListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            public void intervalAdded(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                updateListRowCount(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            public void intervalRemoved(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                updateListRowCount(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            public void contentsChanged(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                updateListRowCount(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        getModel().addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        if (fileChooser.isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        list.setModel(new SortableListModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        list.addListSelectionListener(createListSelectionListener());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        list.addMouseListener(getMouseHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        JScrollPane scrollpane = new JScrollPane(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        if (listViewBackground != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            list.setBackground(listViewBackground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        if (listViewBorder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            scrollpane.setBorder(listViewBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        }
10580
244113d67cf0 7032018: The file list in JFileChooser does not have an accessible name
rupashka
parents: 10100
diff changeset
   649
244113d67cf0 7032018: The file list in JFileChooser does not have an accessible name
rupashka
parents: 10100
diff changeset
   650
        list.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, filesListAccessibleName);
244113d67cf0 7032018: The file list in JFileChooser does not have an accessible name
rupashka
parents: 10100
diff changeset
   651
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        p.add(scrollpane, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * This model allows for sorting JList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     */
22618
927e4fe6cb24 8033221: Fix serial lint warnings in sun.swing.*
darcy
parents: 20099
diff changeset
   659
    @SuppressWarnings("serial") // JDK-implementation class
10100
c525c5fbb86c 7031941: Use generificated JComboBox and JList in core libraries
rupashka
parents: 9488
diff changeset
   660
    private class SortableListModel extends AbstractListModel<Object>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            implements TableModelListener, RowSorterListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        public SortableListModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            getDetailsTableModel().addTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            getRowSorter().addRowSorterListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        public int getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            return getModel().getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        public Object getElementAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            // JList doesn't support RowSorter so far, so we put it into the list model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            return getModel().getElementAt(getRowSorter().convertRowIndexToModel(index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        public void tableChanged(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            fireContentsChanged(this, 0, getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        public void sorterChanged(RowSorterEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            fireContentsChanged(this, 0, getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    private DetailsTableModel getDetailsTableModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        if(detailsTableModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            detailsTableModel = new DetailsTableModel(getFileChooser());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        return detailsTableModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
22618
927e4fe6cb24 8033221: Fix serial lint warnings in sun.swing.*
darcy
parents: 20099
diff changeset
   693
    @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    class DetailsTableModel extends AbstractTableModel implements ListDataListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        JFileChooser chooser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        BasicDirectoryModel directoryModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        ShellFolderColumnInfo[] columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        int[] columnMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        DetailsTableModel(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            this.chooser = fc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            directoryModel = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            directoryModel.addListDataListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            updateColumnInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        void updateColumnInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            File dir = chooser.getCurrentDirectory();
1842
824c7f885a64 6776856: Code with useShellFolder field shuold be simplify
rupashka
parents: 1840
diff changeset
   711
            if (dir != null && usesShellFolder(chooser)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    dir = ShellFolder.getShellFolder(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                    // Leave dir without changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            ShellFolderColumnInfo[] allColumns = ShellFolder.getFolderColumns(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            ArrayList<ShellFolderColumnInfo> visibleColumns =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                    new ArrayList<ShellFolderColumnInfo>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            columnMap = new int[allColumns.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            for (int i = 0; i < allColumns.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                ShellFolderColumnInfo column = allColumns[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                if (column.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                    columnMap[visibleColumns.size()] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                    visibleColumns.add(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            columns = new ShellFolderColumnInfo[visibleColumns.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            visibleColumns.toArray(columns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            columnMap = Arrays.copyOf(columnMap, columns.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   736
            List<? extends RowSorter.SortKey> sortKeys =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                    (rowSorter == null) ? null : rowSorter.getSortKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            fireTableStructureChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            restoreSortKeys(sortKeys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   742
        private void restoreSortKeys(List<? extends RowSorter.SortKey> sortKeys) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            if (sortKeys != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                // check if preserved sortKeys are valid for this folder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                for (int i = 0; i < sortKeys.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                    RowSorter.SortKey sortKey = sortKeys.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    if (sortKey.getColumn() >= columns.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                        sortKeys = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                if (sortKeys != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                    rowSorter.setSortKeys(sortKeys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        public int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            return directoryModel.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        public int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            return columns.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        public Object getValueAt(int row, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            // Note: It is very important to avoid getting info on drives, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            // this will trigger "No disk in A:" and similar dialogs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            // Use (f.exists() && !chooser.getFileSystemView().isFileSystemRoot(f)) to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            // determine if it is safe to call methods directly on f.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            return getFileColumnValue((File)directoryModel.getElementAt(row), col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        private Object getFileColumnValue(File f, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            return (col == COLUMN_FILENAME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                    ? f // always return the file itself for the 1st column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    : ShellFolder.getFolderColumnValue(f, columnMap[col]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        public void setValueAt(Object value, int row, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            if (col == COLUMN_FILENAME) {
9488
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   783
                final JFileChooser chooser = getFileChooser();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                File f = (File)getValueAt(row, col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                if (f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                    String oldDisplayName = chooser.getName(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                    String oldFileName = f.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                    String newDisplayName = ((String)value).trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    String newFileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                    if (!newDisplayName.equals(oldDisplayName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                        newFileName = newDisplayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                        //Check if extension is hidden from user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                        int i1 = oldFileName.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                        int i2 = oldDisplayName.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                        if (i1 > i2 && oldFileName.charAt(i2) == '.') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                            newFileName = newDisplayName + oldFileName.substring(i2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                        // rename
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                        FileSystemView fsv = chooser.getFileSystemView();
9488
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   802
                        final File f2 = fsv.createFileObject(f.getParentFile(), newFileName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                        if (f2.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                            JOptionPane.showMessageDialog(chooser, MessageFormat.format(renameErrorFileExistsText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                                    oldFileName), renameErrorTitleText, JOptionPane.ERROR_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                            if (FilePane.this.getModel().renameFile(f, f2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                                if (fsv.isParent(chooser.getCurrentDirectory(), f2)) {
9488
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   809
                                    // The setSelectedFile method produces a new setValueAt invocation while the JTable
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   810
                                    // is editing. Postpone file selection to be sure that edit mode of the JTable
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   811
                                    // is completed
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   812
                                    SwingUtilities.invokeLater(new Runnable() {
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   813
                                        public void run() {
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   814
                                            if (chooser.isMultiSelectionEnabled()) {
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   815
                                                chooser.setSelectedFiles(new File[]{f2});
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   816
                                            } else {
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   817
                                                chooser.setSelectedFile(f2);
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   818
                                            }
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   819
                                        }
2adfccb3fb48 7021058: The Create folder button produces error in the Details mode (JFileChooser)
rupashka
parents: 5506
diff changeset
   820
                                    });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                                    // Could be because of delay in updating Desktop folder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                                    // chooser.setSelectedFile(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                                JOptionPane.showMessageDialog(chooser, MessageFormat.format(renameErrorText, oldFileName),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                                        renameErrorTitleText, JOptionPane.ERROR_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        public boolean isCellEditable(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            File currentDirectory = getFileChooser().getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            return (!readOnly && column == COLUMN_FILENAME && canWrite(currentDirectory));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        public void contentsChanged(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            // Update the selection after the model has been updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            new DelayedSelectionUpdater();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            fireTableDataChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        public void intervalAdded(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            int i0 = e.getIndex0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            int i1 = e.getIndex1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            if (i0 == i1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                File file = (File)getModel().getElementAt(i0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                if (file.equals(newFolderFile)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                    new DelayedSelectionUpdater(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                    newFolderFile = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            fireTableRowsInserted(e.getIndex0(), e.getIndex1());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        public void intervalRemoved(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            fireTableRowsDeleted(e.getIndex0(), e.getIndex1());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        public ShellFolderColumnInfo[] getColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            return columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    private void updateDetailsColumnModel(JTable table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        if (table != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            ShellFolderColumnInfo[] columns = detailsTableModel.getColumns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            TableColumnModel columnModel = new DefaultTableColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            for (int i = 0; i < columns.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                ShellFolderColumnInfo dataItem = columns[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                TableColumn column = new TableColumn(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                String title = dataItem.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                if (title != null && title.startsWith("FileChooser.") && title.endsWith("HeaderText")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                    // the column must have a string resource that we try to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                    String uiTitle = UIManager.getString(title, table.getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                    if (uiTitle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                        title = uiTitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                column.setHeaderValue(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                Integer width = dataItem.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                if (width != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                    column.setPreferredWidth(width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                    // otherwise we let JTable to decide the actual width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                columnModel.addColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            // Install cell editor for editing file name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            if (!readOnly && columnModel.getColumnCount() > COLUMN_FILENAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                columnModel.getColumn(COLUMN_FILENAME).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                        setCellEditor(getDetailsTableCellEditor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            table.setColumnModel(columnModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    private DetailsTableRowSorter getRowSorter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        if (rowSorter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            rowSorter = new DetailsTableRowSorter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        return rowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   914
    private class DetailsTableRowSorter extends TableRowSorter<TableModel> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        public DetailsTableRowSorter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            setModelWrapper(new SorterModelWrapper());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        public void updateComparators(ShellFolderColumnInfo [] columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            for (int i = 0; i < columns.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                Comparator c = columns[i].getComparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                    c = new DirectoriesFirstComparatorWrapper(i, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                setComparator(i, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1842
diff changeset
   929
        @Override
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1842
diff changeset
   930
        public void sort() {
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2658
diff changeset
   931
            ShellFolder.invoke(new Callable<Void>() {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2658
diff changeset
   932
                public Void call() {
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1842
diff changeset
   933
                    DetailsTableRowSorter.super.sort();
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1842
diff changeset
   934
                    return null;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1842
diff changeset
   935
                }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1842
diff changeset
   936
            });
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1842
diff changeset
   937
        }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1842
diff changeset
   938
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        public void modelStructureChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            super.modelStructureChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            updateComparators(detailsTableModel.getColumns());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   944
        private class SorterModelWrapper extends ModelWrapper<TableModel, Integer> {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   945
            public TableModel getModel() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                return getDetailsTableModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            public int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                return getDetailsTableModel().getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            public int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                return getDetailsTableModel().getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            public Object getValueAt(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                return FilePane.this.getModel().getElementAt(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   961
            public Integer getIdentifier(int row) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                return row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * This class sorts directories before files, comparing directory to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * directory and file to file using the wrapped comparator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    private class DirectoriesFirstComparatorWrapper implements Comparator<File> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        private Comparator comparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        private int column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        public DirectoriesFirstComparatorWrapper(int column, Comparator comparator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            this.column = column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            this.comparator = comparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        public int compare(File f1, File f2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            if (f1 != null && f2 != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                boolean traversable1 = getFileChooser().isTraversable(f1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                boolean traversable2 = getFileChooser().isTraversable(f2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                // directories go first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                if (traversable1 && !traversable2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                if (!traversable1 && traversable2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            if (detailsTableModel.getColumns()[column].isCompareByColumn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                return comparator.compare(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                        getDetailsTableModel().getFileColumnValue(f1, column),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                        getDetailsTableModel().getFileColumnValue(f2, column)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            // For this column we need to pass the file itself (not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            // column value) to the comparator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            return comparator.compare(f1, f2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    private DetailsTableCellEditor tableCellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    private DetailsTableCellEditor getDetailsTableCellEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        if (tableCellEditor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            tableCellEditor = new DetailsTableCellEditor(new JTextField());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        return tableCellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
22618
927e4fe6cb24 8033221: Fix serial lint warnings in sun.swing.*
darcy
parents: 20099
diff changeset
  1013
    @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    private class DetailsTableCellEditor extends DefaultCellEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        private final JTextField tf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        public DetailsTableCellEditor(JTextField tf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            super(tf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            this.tf = tf;
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2489
diff changeset
  1020
            tf.setName("Table.editor");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            tf.addFocusListener(editorFocusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        public Component getTableCellEditorComponent(JTable table, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                                                     boolean isSelected, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            Component comp = super.getTableCellEditorComponent(table, value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                    isSelected, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            if (value instanceof File) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                tf.setText(getFileChooser().getName((File) value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                tf.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
22618
927e4fe6cb24 8033221: Fix serial lint warnings in sun.swing.*
darcy
parents: 20099
diff changeset
  1036
    @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    class DetailsTableCellRenderer extends DefaultTableCellRenderer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        JFileChooser chooser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        DateFormat df;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        DetailsTableCellRenderer(JFileChooser chooser) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            this.chooser = chooser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                                                chooser.getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        public void setBounds(int x, int y, int width, int height) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2489
diff changeset
  1048
        if (getHorizontalAlignment() == SwingConstants.LEADING &&
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2489
diff changeset
  1049
                    !fullRowSelection) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                // Restrict width to actual text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                width = Math.min(width, this.getPreferredSize().width+4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                x -= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            super.setBounds(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        public Insets getInsets(Insets i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            // Provide some space between columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            i = super.getInsets(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            i.left  += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            i.right += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        public Component getTableCellRendererComponent(JTable table, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                              boolean isSelected, boolean hasFocus, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2489
diff changeset
  1070
            if ((table.convertColumnIndexToModel(column) != COLUMN_FILENAME ||
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2489
diff changeset
  1071
                    (listViewWindowsStyle && !table.isFocusOwner())) &&
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2489
diff changeset
  1072
                    !fullRowSelection) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                isSelected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            super.getTableCellRendererComponent(table, value, isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                                                       hasFocus, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            setIcon(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            int modelColumn = table.convertColumnIndexToModel(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            ShellFolderColumnInfo columnInfo = detailsTableModel.getColumns()[modelColumn];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            Integer alignment = columnInfo.getAlignment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            if (alignment == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                alignment = (value instanceof Number)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                        ? SwingConstants.RIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                        : SwingConstants.LEADING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            setHorizontalAlignment(alignment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            // formatting cell text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            // TODO: it's rather a temporary trick, to be revised
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            String text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                text = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            } else if (value instanceof File) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                File file = (File)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                text = chooser.getName(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                Icon icon = chooser.getIcon(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                setIcon(icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            } else if (value instanceof Long) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                long len = ((Long) value) / 1024L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                if (listViewWindowsStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                    text = MessageFormat.format(kiloByteString, len + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                } else if (len < 1024L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                    text = MessageFormat.format(kiloByteString, (len == 0L) ? 1L : len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                    len /= 1024L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                    if (len < 1024L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                        text = MessageFormat.format(megaByteString, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                        len /= 1024L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                        text = MessageFormat.format(gigaByteString, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            } else if (value instanceof Date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                text = df.format((Date)value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                text = value.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            setText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            return this;
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
    public JPanel createDetailsView() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        final JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        JPanel p = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
22618
927e4fe6cb24 8033221: Fix serial lint warnings in sun.swing.*
darcy
parents: 20099
diff changeset
  1140
        @SuppressWarnings("serial") // anonymous class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        final JTable detailsTable = new JTable(getDetailsTableModel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            // Handle Escape key events here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                if (e.getKeyCode() == KeyEvent.VK_ESCAPE && getCellEditor() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                    // We are not editing, forward to filechooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                    chooser.dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                return super.processKeyBinding(ks, e, condition, pressed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            public void tableChanged(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                super.tableChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                    // update header with possibly changed column set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                    updateDetailsColumnModel(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        detailsTable.setRowSorter(getRowSorter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        detailsTable.setAutoCreateColumnsFromModel(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        detailsTable.setComponentOrientation(chooser.getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        detailsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        detailsTable.setShowGrid(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        detailsTable.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        detailsTable.addKeyListener(detailsKeyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        Font font = list.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        detailsTable.setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        detailsTable.setIntercellSpacing(new Dimension(0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        TableCellRenderer headerRenderer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                new AlignableTableHeaderRenderer(detailsTable.getTableHeader().getDefaultRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        detailsTable.getTableHeader().setDefaultRenderer(headerRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        TableCellRenderer cellRenderer = new DetailsTableCellRenderer(chooser);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        detailsTable.setDefaultRenderer(Object.class, cellRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        // So that drag can be started on a mouse press
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        detailsTable.getColumnModel().getSelectionModel().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        detailsTable.addMouseListener(getMouseHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        // No need to addListSelectionListener because selections are forwarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        // to our JList.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        // 4835633 : tell BasicTableUI that this is a file list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        detailsTable.putClientProperty("Table.isFileList", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        if (listViewWindowsStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            detailsTable.addFocusListener(repaintListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        // TAB/SHIFT-TAB should transfer focus and ENTER should select an item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        // We don't want them to navigate within the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        ActionMap am = SwingUtilities.getUIActionMap(detailsTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        am.remove("selectNextRowCell");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        am.remove("selectPreviousRowCell");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        am.remove("selectNextColumnCell");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        am.remove("selectPreviousColumnCell");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        detailsTable.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                     null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        detailsTable.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                     null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        JScrollPane scrollpane = new JScrollPane(detailsTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        scrollpane.setComponentOrientation(chooser.getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        LookAndFeel.installColors(scrollpane.getViewport(), "Table.background", "Table.foreground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        // Adjust width of first column so the table fills the viewport when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        // first displayed (temporary listener).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        scrollpane.addComponentListener(new ComponentAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            public void componentResized(ComponentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                JScrollPane sp = (JScrollPane)e.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                fixNameColumnWidth(sp.getViewport().getSize().width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                sp.removeComponentListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        // 4835633.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        // If the mouse is pressed in the area below the Details view table, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        // event is not dispatched to the Table MouseListener but to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        // scrollpane.  Listen for that here so we can clear the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        scrollpane.addMouseListener(new MouseAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                JScrollPane jsp = ((JScrollPane)e.getComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                JTable table = (JTable)jsp.getViewport().getView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                if (!e.isShiftDown() || table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                    clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                    TableCellEditor tce = table.getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                    if (tce != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                        tce.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        detailsTable.setForeground(list.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        detailsTable.setBackground(list.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        if (listViewBorder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            scrollpane.setBorder(listViewBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        p.add(scrollpane, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        detailsTableModel.fireTableStructureChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
10580
244113d67cf0 7032018: The file list in JFileChooser does not have an accessible name
rupashka
parents: 10100
diff changeset
  1250
        detailsTable.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, filesDetailsAccessibleName);
244113d67cf0 7032018: The file list in JFileChooser does not have an accessible name
rupashka
parents: 10100
diff changeset
  1251
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    } // createDetailsView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    private class AlignableTableHeaderRenderer implements TableCellRenderer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        TableCellRenderer wrappedRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        public AlignableTableHeaderRenderer(TableCellRenderer wrappedRenderer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
            this.wrappedRenderer = wrappedRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        public Component getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                                JTable table, Object value, boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                                boolean hasFocus, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            Component c = wrappedRenderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                                table, value, isSelected, hasFocus, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            int modelColumn = table.convertColumnIndexToModel(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            ShellFolderColumnInfo columnInfo = detailsTableModel.getColumns()[modelColumn];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            Integer alignment = columnInfo.getAlignment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            if (alignment == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                alignment = SwingConstants.CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            if (c instanceof JLabel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                ((JLabel) c).setHorizontalAlignment(alignment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    private void fixNameColumnWidth(int viewWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        TableColumn nameCol = detailsTable.getColumnModel().getColumn(COLUMN_FILENAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        int tableWidth = detailsTable.getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        if (tableWidth < viewWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
            nameCol.setPreferredWidth(nameCol.getPreferredWidth() + viewWidth - tableWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    private class DelayedSelectionUpdater implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        File editFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        DelayedSelectionUpdater() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            this(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        DelayedSelectionUpdater(File editFile) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            this.editFile = editFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                SwingUtilities.invokeLater(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            setFileSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            if (editFile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                editFileName(getRowSorter().convertRowIndexToView(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                        getModel().indexOf(editFile)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                editFile = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * Creates a selection listener for the list of files and directories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * @return a <code>ListSelectionListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    public ListSelectionListener createListSelectionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        return fileChooserUIAccessor.createListSelectionListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    int lastIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    File editFile = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    private int getEditIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        return lastIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    private void setEditIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        lastIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    private void resetEditIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        lastIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    private void cancelEdit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        if (editFile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            editFile = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            list.remove(editCell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        } else if (detailsTable != null && detailsTable.isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            detailsTable.getCellEditor().cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    JTextField editCell = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * @param index visual index of the file to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    private void editFileName(int index) {
464
9c414b00e007 6635277: Incorrect text seen when creating a new folder, when selection is on the image file in JFileChooser
rupashka
parents: 2
diff changeset
  1358
        JFileChooser chooser = getFileChooser();
9c414b00e007 6635277: Incorrect text seen when creating a new folder, when selection is on the image file in JFileChooser
rupashka
parents: 2
diff changeset
  1359
        File currentDirectory = chooser.getCurrentDirectory();
9c414b00e007 6635277: Incorrect text seen when creating a new folder, when selection is on the image file in JFileChooser
rupashka
parents: 2
diff changeset
  1360
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        if (readOnly || !canWrite(currentDirectory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        ensureIndexIsVisible(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        switch (viewType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
          case VIEWTYPE_LIST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            editFile = (File)getModel().getElementAt(getRowSorter().convertRowIndexToModel(index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            Rectangle r = list.getCellBounds(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            if (editCell == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                editCell = new JTextField();
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2489
diff changeset
  1372
                editCell.setName("Tree.cellEditor");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                editCell.addActionListener(new EditActionListener());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                editCell.addFocusListener(editorFocusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                editCell.setNextFocusableComponent(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
            list.add(editCell);
464
9c414b00e007 6635277: Incorrect text seen when creating a new folder, when selection is on the image file in JFileChooser
rupashka
parents: 2
diff changeset
  1378
            editCell.setText(chooser.getName(editFile));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            ComponentOrientation orientation = list.getComponentOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            editCell.setComponentOrientation(orientation);
464
9c414b00e007 6635277: Incorrect text seen when creating a new folder, when selection is on the image file in JFileChooser
rupashka
parents: 2
diff changeset
  1381
9c414b00e007 6635277: Incorrect text seen when creating a new folder, when selection is on the image file in JFileChooser
rupashka
parents: 2
diff changeset
  1382
            Icon icon = chooser.getIcon(editFile);
9c414b00e007 6635277: Incorrect text seen when creating a new folder, when selection is on the image file in JFileChooser
rupashka
parents: 2
diff changeset
  1383
9c414b00e007 6635277: Incorrect text seen when creating a new folder, when selection is on the image file in JFileChooser
rupashka
parents: 2
diff changeset
  1384
            // PENDING - grab padding (4) below from defaults table.
9c414b00e007 6635277: Incorrect text seen when creating a new folder, when selection is on the image file in JFileChooser
rupashka
parents: 2
diff changeset
  1385
            int editX = icon == null ? 20 : icon.getIconWidth() + 4;
9c414b00e007 6635277: Incorrect text seen when creating a new folder, when selection is on the image file in JFileChooser
rupashka
parents: 2
diff changeset
  1386
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            if (orientation.isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                editCell.setBounds(editX + r.x, r.y, r.width - editX, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                editCell.setBounds(r.x, r.y, r.width - editX, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
            editCell.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
            editCell.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
          case VIEWTYPE_DETAILS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
            detailsTable.editCellAt(index, COLUMN_FILENAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    class EditActionListener implements ActionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            applyEdit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
    private void applyEdit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        if (editFile != null && editFile.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
            String oldDisplayName = chooser.getName(editFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
            String oldFileName = editFile.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
            String newDisplayName = editCell.getText().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            String newFileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
            if (!newDisplayName.equals(oldDisplayName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                newFileName = newDisplayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                //Check if extension is hidden from user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                int i1 = oldFileName.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                int i2 = oldDisplayName.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                if (i1 > i2 && oldFileName.charAt(i2) == '.') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                    newFileName = newDisplayName + oldFileName.substring(i2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                // rename
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                FileSystemView fsv = chooser.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                File f2 = fsv.createFileObject(editFile.getParentFile(), newFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                if (f2.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                    JOptionPane.showMessageDialog(chooser, MessageFormat.format(renameErrorFileExistsText, oldFileName),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                            renameErrorTitleText, JOptionPane.ERROR_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                    if (getModel().renameFile(editFile, f2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                        if (fsv.isParent(chooser.getCurrentDirectory(), f2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                            if (chooser.isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                                chooser.setSelectedFiles(new File[]{f2});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                                chooser.setSelectedFile(f2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                            //Could be because of delay in updating Desktop folder
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                            //chooser.setSelectedFile(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                        JOptionPane.showMessageDialog(chooser, MessageFormat.format(renameErrorText, oldFileName),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                                renameErrorTitleText, JOptionPane.ERROR_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        if (detailsTable != null && detailsTable.isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
            detailsTable.getCellEditor().stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        cancelEdit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    protected Action newFolderAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
22618
927e4fe6cb24 8033221: Fix serial lint warnings in sun.swing.*
darcy
parents: 20099
diff changeset
  1459
    @SuppressWarnings("serial") // anonymous class inside
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    public Action getNewFolderAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        if (!readOnly && newFolderAction == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            newFolderAction = new AbstractAction(newFolderActionLabelText) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                private Action basicNewFolderAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
                // Initializer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                    putValue(Action.ACTION_COMMAND_KEY, FilePane.ACTION_NEW_FOLDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                    File currentDirectory = getFileChooser().getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                    if (currentDirectory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                        setEnabled(canWrite(currentDirectory));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                    if (basicNewFolderAction == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                        basicNewFolderAction = fileChooserUIAccessor.getNewFolderAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                    JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                    File oldFile = fc.getSelectedFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                    basicNewFolderAction.actionPerformed(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                    File newFile = fc.getSelectedFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                    if (newFile != null && !newFile.equals(oldFile) && newFile.isDirectory()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                        newFolderFile = newFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        return newFolderAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
22618
927e4fe6cb24 8033221: Fix serial lint warnings in sun.swing.*
darcy
parents: 20099
diff changeset
  1492
    @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
    protected class FileRenderer extends DefaultListCellRenderer  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        public Component getListCellRendererComponent(JList list, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                                                      int index, boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                                                      boolean cellHasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            if (listViewWindowsStyle && !list.isFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                isSelected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            File file = (File) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            String fileName = getFileChooser().getName(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            setText(fileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            setFont(list.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            Icon icon = getFileChooser().getIcon(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                setIcon(icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                if (getFileChooser().getFileSystemView().isTraversable(file)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                    setText(fileName+File.separator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
    void setFileSelected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        if (getFileChooser().isMultiSelectionEnabled() && !isDirectorySelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            File[] files = getFileChooser().getSelectedFiles(); // Should be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
            Object[] selectedObjects = list.getSelectedValues(); // Are actually selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
            listSelectionModel.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                int lead = listSelectionModel.getLeadSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                int anchor = listSelectionModel.getAnchorSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                Arrays.sort(files);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                Arrays.sort(selectedObjects);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                int shouldIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                int actuallyIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                // Remove files that shouldn't be selected and add files which should be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                // Note: Assume files are already sorted in compareTo order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                while (shouldIndex < files.length &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                       actuallyIndex < selectedObjects.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                    int comparison = files[shouldIndex].compareTo((File)selectedObjects[actuallyIndex]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                    if (comparison < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                        doSelectFile(files[shouldIndex++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                    } else if (comparison > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                        doDeselectFile(selectedObjects[actuallyIndex++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                        // Do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                        shouldIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                        actuallyIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                while (shouldIndex < files.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                    doSelectFile(files[shouldIndex++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                while (actuallyIndex < selectedObjects.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                    doDeselectFile(selectedObjects[actuallyIndex++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                // restore the anchor and lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                if (listSelectionModel instanceof DefaultListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                    ((DefaultListSelectionModel)listSelectionModel).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                        moveLeadSelectionIndex(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                    listSelectionModel.setAnchorSelectionIndex(anchor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                listSelectionModel.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
            File f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
            if (isDirectorySelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                f = getDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                f = chooser.getSelectedFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
            if (f != null && (i = getModel().indexOf(f)) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                int viewIndex = getRowSorter().convertRowIndexToView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                listSelectionModel.setSelectionInterval(viewIndex, viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                ensureIndexIsVisible(viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
    private void doSelectFile(File fileToSelect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        int index = getModel().indexOf(fileToSelect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        // could be missed in the current directory if it changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
            index = getRowSorter().convertRowIndexToView(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
            listSelectionModel.addSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
    private void doDeselectFile(Object fileToDeselect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
        int index = getRowSorter().convertRowIndexToView(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                                getModel().indexOf(fileToDeselect));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
        listSelectionModel.removeSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
    /* The following methods are used by the PropertyChange Listener */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
    private void doSelectedFileChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        applyEdit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
        File f = (File) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
        if (f != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
            && ((fc.isFileSelectionEnabled() && !f.isDirectory())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                || (f.isDirectory() && fc.isDirectorySelectionEnabled()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
            setFileSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
    private void doSelectedFilesChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
        applyEdit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        File[] files = (File[]) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
        if (files != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
            && files.length > 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
            && (files.length > 1 || fc.isDirectorySelectionEnabled() || !files[0].isDirectory())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
            setFileSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
    private void doDirectoryChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
        getDetailsTableModel().updateColumnInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
        FileSystemView fsv = fc.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        applyEdit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
        resetEditIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
        ensureIndexIsVisible(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
        File currentDirectory = fc.getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        if (currentDirectory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            if (!readOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                getNewFolderAction().setEnabled(canWrite(currentDirectory));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            fileChooserUIAccessor.getChangeToParentDirectoryAction().setEnabled(!fsv.isRoot(currentDirectory));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        if (list != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
            list.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
    private void doFilterChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        applyEdit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        resetEditIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
    private void doFileSelectionModeChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
        applyEdit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        resetEditIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    private void doMultiSelectionChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
        if (getFileChooser().isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
            listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
            listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
            clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
            getFileChooser().setSelectedFiles(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     * Listen for filechooser property changes, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
     * the selected file changing, or the type of the dialog changing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
            if (viewType == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                setViewType(VIEWTYPE_LIST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
        String s = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
        if (s.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            doSelectedFileChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        } else if (s.equals(JFileChooser.SELECTED_FILES_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
            doSelectedFilesChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
        } else if (s.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
            doDirectoryChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
        } else if (s.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
            doFilterChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
        } else if (s.equals(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
            doFileSelectionModeChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
        } else if (s.equals(JFileChooser.MULTI_SELECTION_ENABLED_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
            doMultiSelectionChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
        } else if (s.equals(JFileChooser.CANCEL_SELECTION)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
            applyEdit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
        } else if (s.equals("busy")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
            setCursor((Boolean)e.getNewValue() ? waitCursor : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
        } else if (s.equals("componentOrientation")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
            ComponentOrientation o = (ComponentOrientation)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
            JFileChooser cc = (JFileChooser)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
            if (o != e.getOldValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                cc.applyComponentOrientation(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
            if (detailsTable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                detailsTable.setComponentOrientation(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
                detailsTable.getParent().getParent().setComponentOrientation(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
    private void ensureIndexIsVisible(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
        if (i >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
            if (list != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
                list.ensureIndexIsVisible(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
            if (detailsTable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
                detailsTable.scrollRectToVisible(detailsTable.getCellRect(i, COLUMN_FILENAME, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    public void ensureFileIsVisible(JFileChooser fc, File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
        int modelIndex = getModel().indexOf(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
        if (modelIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
            ensureIndexIsVisible(getRowSorter().convertRowIndexToView(modelIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
    public void rescanCurrentDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
        getModel().validateFileCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
    public void clearSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        if (listSelectionModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            listSelectionModel.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            if (listSelectionModel instanceof DefaultListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
                ((DefaultListSelectionModel)listSelectionModel).moveLeadSelectionIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
                listSelectionModel.setAnchorSelectionIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
    public JMenu getViewMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        if (viewMenu == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
            viewMenu = new JMenu(viewMenuLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
            ButtonGroup viewButtonGroup = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
            for (int i = 0; i < VIEWTYPE_COUNT; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
                JRadioButtonMenuItem mi =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                    new JRadioButtonMenuItem(new ViewTypeAction(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                viewButtonGroup.add(mi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                viewMenu.add(mi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
            updateViewMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
        return viewMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
    private void updateViewMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        if (viewMenu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
            Component[] comps = viewMenu.getMenuComponents();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1765
            for (Component comp : comps) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1766
                if (comp instanceof JRadioButtonMenuItem) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1767
                    JRadioButtonMenuItem mi = (JRadioButtonMenuItem) comp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                    if (((ViewTypeAction)mi.getAction()).viewType == viewType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                        mi.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
    public JPopupMenu getComponentPopupMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
        JPopupMenu popupMenu = getFileChooser().getComponentPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
        if (popupMenu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            return popupMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        JMenu viewMenu = getViewMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
        if (contextMenu == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
            contextMenu = new JPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            if (viewMenu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                contextMenu.add(viewMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                if (listViewWindowsStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                    contextMenu.addSeparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
            ActionMap actionMap = getActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
            Action refreshAction   = actionMap.get(ACTION_REFRESH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
            Action newFolderAction = actionMap.get(ACTION_NEW_FOLDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
            if (refreshAction != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
                contextMenu.add(refreshAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                if (listViewWindowsStyle && newFolderAction != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                    contextMenu.addSeparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
            if (newFolderAction != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
                contextMenu.add(newFolderAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
        if (viewMenu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
            viewMenu.getPopupMenu().setInvoker(viewMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
        return contextMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
    private Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
    protected Handler getMouseHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
    private class Handler implements MouseListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
        private MouseListener doubleClickListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
        public void mouseClicked(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
            JComponent source = (JComponent)evt.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
            int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
            if (source instanceof JList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                index = SwingUtilities2.loc2IndexFileList(list, evt.getPoint());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
            } else if (source instanceof JTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                JTable table = (JTable)source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                Point p = evt.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                index = table.rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2489
diff changeset
  1834
                boolean pointOutsidePrefSize =
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2489
diff changeset
  1835
                        SwingUtilities2.pointOutsidePrefSize(
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2489
diff changeset
  1836
                            table, index, table.columnAtPoint(p), p);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2489
diff changeset
  1838
                if (pointOutsidePrefSize && !fullRowSelection) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                // Translate point from table to list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                if (index >= 0 && list != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                    listSelectionModel.isSelectedIndex(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                    // Make a new event with the list as source, placing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                    // click in the corresponding list cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                    Rectangle r = list.getCellBounds(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
                    evt = new MouseEvent(list, evt.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
                                         evt.getWhen(), evt.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
                                         r.x + 1, r.y + r.height/2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
                                         evt.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
                                         evt.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
                                         evt.getClickCount(), evt.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                                         evt.getButton());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
            if (index >= 0 && SwingUtilities.isLeftMouseButton(evt)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
                // For single click, we handle editing file name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
                if (evt.getClickCount() == 1 && source instanceof JList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                    if ((!fc.isMultiSelectionEnabled() || fc.getSelectedFiles().length <= 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                        && index >= 0 && listSelectionModel.isSelectedIndex(index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                        && getEditIndex() == index && editFile == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
                        editFileName(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                        if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
                            setEditIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                            resetEditIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                } else if (evt.getClickCount() == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                    // on double click (open or drill down one directory) be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                    // sure to clear the edit index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                    resetEditIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
            // Forward event to Basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
            if (getDoubleClickListener() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                getDoubleClickListener().mouseClicked(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        public void mouseEntered(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
            JComponent source = (JComponent)evt.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            if (source instanceof JTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
                JTable table = (JTable)evt.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                TransferHandler th1 = getFileChooser().getTransferHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                TransferHandler th2 = table.getTransferHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                if (th1 != th2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
                    table.setTransferHandler(th1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                boolean dragEnabled = getFileChooser().getDragEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                if (dragEnabled != table.getDragEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                    table.setDragEnabled(dragEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
            } else if (source instanceof JList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                // Forward event to Basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
                if (getDoubleClickListener() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                    getDoubleClickListener().mouseEntered(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        public void mouseExited(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
            if (evt.getSource() instanceof JList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
                // Forward event to Basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
                if (getDoubleClickListener() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                    getDoubleClickListener().mouseExited(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
        public void mousePressed(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
            if (evt.getSource() instanceof JList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
                // Forward event to Basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
                if (getDoubleClickListener() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
                    getDoubleClickListener().mousePressed(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
        public void mouseReleased(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
            if (evt.getSource() instanceof JList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
                // Forward event to Basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
                if (getDoubleClickListener() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
                    getDoubleClickListener().mouseReleased(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
        private MouseListener getDoubleClickListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
            // Lazy creation of Basic's listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
            if (doubleClickListener == null && list != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
                doubleClickListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
                    fileChooserUIAccessor.createDoubleClickListener(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
            return doubleClickListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     * Property to remember whether a directory is currently selected in the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
     * @return <code>true</code> iff a directory is currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
    protected boolean isDirectorySelected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
        return fileChooserUIAccessor.isDirectorySelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
     * Property to remember the directory that is currently selected in the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
     * @return the value of the <code>directory</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
     * @see javax.swing.plaf.basic.BasicFileChooserUI#setDirectory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
    protected File getDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        return fileChooserUIAccessor.getDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
    private Component findChildComponent(Container container, Class cls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
        int n = container.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
            Component comp = container.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
            if (cls.isInstance(comp)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
                return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
            } else if (comp instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
                Component c = findChildComponent((Container)comp, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
                if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                    return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
    public boolean canWrite(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
        // Return false for non FileSystem files or if file doesn't exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
        if (!f.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
        if (f instanceof ShellFolder) {
20099
fe931b18962c 8021379: JFileChooser Create New Folder button enabled in write proteced directory
malenkov
parents: 10580
diff changeset
  1994
            return f.canWrite();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
        } else {
1842
824c7f885a64 6776856: Code with useShellFolder field shuold be simplify
rupashka
parents: 1840
diff changeset
  1996
            if (usesShellFolder(getFileChooser())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                try {
20099
fe931b18962c 8021379: JFileChooser Create New Folder button enabled in write proteced directory
malenkov
parents: 10580
diff changeset
  1998
                    return ShellFolder.getShellFolder(f).canWrite();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
                } catch (FileNotFoundException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                    // File doesn't exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
                // Ordinary file
20099
fe931b18962c 8021379: JFileChooser Create New Folder button enabled in write proteced directory
malenkov
parents: 10580
diff changeset
  2005
                return f.canWrite();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
1840
984ba55ac827 6698013: JFileChooser can no longer navigate non-local file systems.
rupashka
parents: 1305
diff changeset
  2010
    /**
984ba55ac827 6698013: JFileChooser can no longer navigate non-local file systems.
rupashka
parents: 1305
diff changeset
  2011
     * Returns true if specified FileChooser should use ShellFolder
984ba55ac827 6698013: JFileChooser can no longer navigate non-local file systems.
rupashka
parents: 1305
diff changeset
  2012
     */
984ba55ac827 6698013: JFileChooser can no longer navigate non-local file systems.
rupashka
parents: 1305
diff changeset
  2013
    public static boolean usesShellFolder(JFileChooser chooser) {
984ba55ac827 6698013: JFileChooser can no longer navigate non-local file systems.
rupashka
parents: 1305
diff changeset
  2014
        Boolean prop = (Boolean) chooser.getClientProperty("FileChooser.useShellFolder");
984ba55ac827 6698013: JFileChooser can no longer navigate non-local file systems.
rupashka
parents: 1305
diff changeset
  2015
984ba55ac827 6698013: JFileChooser can no longer navigate non-local file systems.
rupashka
parents: 1305
diff changeset
  2016
        return prop == null ? chooser.getFileSystemView().equals(FileSystemView.getFileSystemView())
984ba55ac827 6698013: JFileChooser can no longer navigate non-local file systems.
rupashka
parents: 1305
diff changeset
  2017
                : prop.booleanValue();
984ba55ac827 6698013: JFileChooser can no longer navigate non-local file systems.
rupashka
parents: 1305
diff changeset
  2018
    }
984ba55ac827 6698013: JFileChooser can no longer navigate non-local file systems.
rupashka
parents: 1305
diff changeset
  2019
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
    // This interface is used to access methods in the FileChooserUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
    // that are not public.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
    public interface FileChooserUIAccessor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        public JFileChooser getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
        public BasicDirectoryModel getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
        public JPanel createList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
        public JPanel createDetailsView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
        public boolean isDirectorySelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
        public File getDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
        public Action getApproveSelectionAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
        public Action getChangeToParentDirectoryAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
        public Action getNewFolderAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
        public MouseListener createDoubleClickListener(JList list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
        public ListSelectionListener createListSelectionListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
}