jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 458 54413b296bdf
child 1837 efd004b550b7
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 458
diff changeset
     2
 * Copyright 2002-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package com.sun.java.swing.plaf.gtk;
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.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.text.MessageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.filechooser.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.plaf.basic.BasicDirectoryModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.table.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.swing.plaf.synth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.swing.FilePane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.awt.shell.ShellFolder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * GTK FileChooserUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Leif Samuelsson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
class GTKFileChooserUI extends SynthFileChooserUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // The accessoryPanel is a container to place the JFileChooser accessory component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private JPanel accessoryPanel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private String newFolderButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private String newFolderErrorSeparator = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private String newFolderErrorText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private String newFolderDialogText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private String newFolderNoDirectoryErrorTitleText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private String newFolderNoDirectoryErrorText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private String deleteFileButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private String renameFileButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private String newFolderButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private String deleteFileButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private String renameFileButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private int newFolderButtonMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private int deleteFileButtonMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private int renameFileButtonMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private int foldersLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private int filesLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private String renameFileDialogText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private String renameFileErrorTitle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private String renameFileErrorText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private JComboBox filterComboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private FilterComboBoxModel filterComboBoxModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // From Motif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private JPanel rightPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private JList directoryList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private JList fileList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private JLabel pathField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private JTextField fileNameTextField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static final Dimension hstrut3 = new Dimension(3, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static final Dimension vstrut10 = new Dimension(1, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private static Dimension prefListSize = new Dimension(75, 150);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static Dimension PREF_SIZE = new Dimension(435, 360);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private static Dimension MIN_SIZE = new Dimension(200, 300);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private static Dimension ZERO_ACC_SIZE = new Dimension(1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private static Dimension MAX_SIZE = new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private static final Insets buttonMargin = new Insets(3, 3, 3, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private String filesLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private String foldersLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private String pathLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private String filterLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private int pathLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private int filterLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private JComboBox directoryComboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private DirectoryComboBoxModel directoryComboBoxModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private Action directoryComboBoxAction = new DirectoryComboBoxAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private JPanel bottomButtonPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private GTKDirectoryModel model = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private Action newFolderAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private boolean readOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private boolean showDirectoryIcons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private boolean showFileIcons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private GTKFileView fileView = new GTKFileView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private PropertyChangeListener gtkFCPropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private Action approveSelectionAction = new GTKApproveSelectionAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private GTKDirectoryListModel directoryListModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public GTKFileChooserUI(JFileChooser filechooser) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        super(filechooser);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public String getFileName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        String typedInName = fileNameTextField != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            fileNameTextField.getText() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (!fc.isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            return typedInName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        int mode = fc.getFileSelectionMode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        JList list = mode == JFileChooser.DIRECTORIES_ONLY ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            directoryList : fileList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        Object[] files = list.getSelectedValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        int len = files.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        Vector result = new Vector(len + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        // we return all selected file names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            File file = (File)files[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            result.add(file.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        // plus the file name typed into the text field, if not already there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (typedInName != null && !result.contains(typedInName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            result.add(typedInName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        StringBuffer buf = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        len = result.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        // construct the resulting string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        for (int i=0; i<len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            if (len > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                buf.append(" \"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            buf.append(result.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (len > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                buf.append("\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public void setFileName(String fileName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (fileNameTextField != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            fileNameTextField.setText(fileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
//     public String getDirectoryName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
//      return pathField.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
//     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public void setDirectoryName(String dirname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        pathField.setText(dirname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public void ensureFileIsVisible(JFileChooser fc, File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        // PENDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public void rescanCurrentDirectory(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        getModel().validateFileCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public JPanel getAccessoryPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return accessoryPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    // ***********************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    // * FileView operations *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    // ***********************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public FileView getFileView(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return fileView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    private class GTKFileView extends BasicFileView {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        public GTKFileView() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            iconCache = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        public void clearIconCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        public Icon getCachedIcon(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        public void cacheIcon(File f, Icon i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        public Icon getIcon(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return (f != null && f.isDirectory()) ? directoryIcon : fileIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    private void updateDefaultButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        JFileChooser filechooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        JRootPane root = SwingUtilities.getRootPane(filechooser);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (root == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (filechooser.getControlButtonsAreShown()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (root.getDefaultButton() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                root.setDefaultButton(getApproveButton(filechooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                getCancelButton(filechooser).setDefaultCapable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            if (root.getDefaultButton() == getApproveButton(filechooser)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                root.setDefaultButton(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    protected void doSelectedFileChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        super.doSelectedFileChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        File f = (File) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            setFileName(getFileChooser().getName(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    protected void doDirectoryChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        directoryList.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        ListSelectionModel sm = directoryList.getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (sm instanceof DefaultListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            ((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        fileList.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        sm = fileList.getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (sm instanceof DefaultListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            ((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        File currentDirectory = getFileChooser().getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (currentDirectory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                setDirectoryName(ShellFolder.getNormalizedFile((File)e.getNewValue()).getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                setDirectoryName(((File)e.getNewValue()).getAbsolutePath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if ((getFileChooser().getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) && !getFileChooser().isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                setFileName(pathField.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            directoryComboBoxModel.addItem(currentDirectory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            directoryListModel.directoryChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        super.doDirectoryChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    protected void doAccessoryChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (getAccessoryPanel() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            if (e.getOldValue() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                getAccessoryPanel().remove((JComponent)e.getOldValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            JComponent accessory = (JComponent)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            if (accessory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                getAccessoryPanel().add(accessory, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                getAccessoryPanel().setPreferredSize(accessory.getPreferredSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                getAccessoryPanel().setMaximumSize(MAX_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                getAccessoryPanel().setPreferredSize(ZERO_ACC_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                getAccessoryPanel().setMaximumSize(ZERO_ACC_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
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 void doFileSelectionModeChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        directoryList.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        rightPanel.setVisible(((Integer)e.getNewValue()).intValue() != JFileChooser.DIRECTORIES_ONLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        super.doFileSelectionModeChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    protected void doMultiSelectionChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (getFileChooser().isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            fileList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            fileList.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        super.doMultiSelectionChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    protected void doControlButtonsChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        super.doControlButtonsChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        JFileChooser filechooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (filechooser.getControlButtonsAreShown()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            filechooser.add(bottomButtonPanel, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            filechooser.remove(bottomButtonPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        updateDefaultButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    protected void doAncestorChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (e.getOldValue() == null && e.getNewValue() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            // Ancestor was added, set initial focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            fileNameTextField.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            fileNameTextField.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            updateDefaultButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        super.doAncestorChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    // ********************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    // ************ Create Listeners **************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    // ********************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public ListSelectionListener createListSelectionListener(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return new SelectionListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    class DoubleClickListener extends MouseAdapter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        JList list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        public  DoubleClickListener(JList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            this.list = list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                int index = list.locationToIndex(e.getPoint());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    File f = (File) list.getModel().getElementAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                        // Strip trailing ".."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                        f = ShellFolder.getNormalizedFile(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                        // That's ok, we'll use f as is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    if (getFileChooser().isTraversable(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                        list.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                        if (getFileChooser().getCurrentDirectory().equals(f)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                            rescanCurrentDirectory(getFileChooser());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                            getFileChooser().setCurrentDirectory(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                        getFileChooser().approveSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        public void mouseEntered(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            if (list != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                TransferHandler th1 = getFileChooser().getTransferHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                TransferHandler th2 = list.getTransferHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                if (th1 != th2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    list.setTransferHandler(th1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                if (getFileChooser().getDragEnabled() != list.getDragEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    list.setDragEnabled(getFileChooser().getDragEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    protected MouseListener createDoubleClickListener(JFileChooser fc, JList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return new DoubleClickListener(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    protected class SelectionListener implements ListSelectionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            if (!e.getValueIsAdjusting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                JList list = (JList) e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                if (chooser.isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    File[] files = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    Object[] objects = list.getSelectedValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    if (objects != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                        if (objects.length == 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                            && ((File)objects[0]).isDirectory()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                            && chooser.isTraversable(((File)objects[0]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                            && (chooser.getFileSelectionMode() != chooser.DIRECTORIES_ONLY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                || !chooser.getFileSystemView().isFileSystem(((File)objects[0])))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                            setDirectorySelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                            setDirectory(((File)objects[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                            ArrayList fList = new ArrayList(objects.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                            for (int i = 0; i < objects.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                                File f = (File)objects[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                                if ((chooser.isFileSelectionEnabled() && f.isFile())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                    || (chooser.isDirectorySelectionEnabled() && f.isDirectory())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                                    fList.add(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                            if (fList.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                                files = (File[])fList.toArray(new File[fList.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                            setDirectorySelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    chooser.setSelectedFiles(files);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    File file = (File)list.getSelectedValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    if (file != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                        && file.isDirectory()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                        && chooser.isTraversable(file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                        && (chooser.getFileSelectionMode() == chooser.FILES_ONLY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                            || !chooser.getFileSystemView().isFileSystem(file))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                        setDirectorySelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                        setDirectory(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                        setDirectorySelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                        if (file != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                            chooser.setSelectedFile(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    // ComponentUI Interface Implementation methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        return new GTKFileChooserUI((JFileChooser)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        accessoryPanel = new JPanel(new BorderLayout(10, 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        accessoryPanel.setName("GTKFileChooser.accessoryPanel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        super.installUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        c.removePropertyChangeListener(filterComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        super.uninstallUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (accessoryPanel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            accessoryPanel.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        accessoryPanel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        getFileChooser().removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public void installComponents(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        super.installComponents(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        boolean leftToRight = fc.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        fc.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        fc.setAlignmentX(JComponent.CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        // Top row of buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        JPanel topButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        topButtonPanel.setBorder(new EmptyBorder(10, 10, 0, 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        topButtonPanel.setName("GTKFileChooser.topButtonPanel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        if (!UIManager.getBoolean("FileChooser.readOnly")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            JButton newFolderButton = new JButton(getNewFolderAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            newFolderButton.setName("GTKFileChooser.newFolderButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            newFolderButton.setMnemonic(newFolderButtonMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            newFolderButton.setToolTipText(newFolderButtonToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            newFolderButton.setText(newFolderButtonText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            topButtonPanel.add(newFolderButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        JButton deleteFileButton = new JButton(deleteFileButtonText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        deleteFileButton.setName("GTKFileChooser.deleteFileButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        deleteFileButton.setMnemonic(deleteFileButtonMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        deleteFileButton.setToolTipText(deleteFileButtonToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        deleteFileButton.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        topButtonPanel.add(deleteFileButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        RenameFileAction rfa = new RenameFileAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        JButton renameFileButton = new JButton(rfa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if (readOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            rfa.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        renameFileButton.setText(renameFileButtonText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        renameFileButton.setName("GTKFileChooser.renameFileButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        renameFileButton.setMnemonic(renameFileButtonMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        renameFileButton.setToolTipText(renameFileButtonToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        topButtonPanel.add(renameFileButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        fc.add(topButtonPanel, BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        JPanel interior = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        interior.setBorder(new EmptyBorder(0, 10, 10, 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        interior.setName("GTKFileChooser.interiorPanel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        align(interior);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        interior.setLayout(new BoxLayout(interior, BoxLayout.PAGE_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        fc.add(interior, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        JPanel comboBoxPanel = new JPanel(new FlowLayout(FlowLayout.CENTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                                                         0, 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            public void layoutContainer(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                super.layoutContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                JComboBox comboBox = directoryComboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                if (comboBox.getWidth() > target.getWidth()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    comboBox.setBounds(0, comboBox.getY(), target.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                                       comboBox.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        comboBoxPanel.setBorder(new EmptyBorder(0, 0, 4, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        comboBoxPanel.setName("GTKFileChooser.directoryComboBoxPanel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        // CurrentDir ComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        directoryComboBoxModel = createDirectoryComboBoxModel(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        directoryComboBox = new JComboBox(directoryComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        directoryComboBox.setName("GTKFileChooser.directoryComboBox");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        directoryComboBox.putClientProperty( "JComboBox.lightweightKeyboardNavigation", "Lightweight" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        directoryComboBox.addActionListener(directoryComboBoxAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        directoryComboBox.setMaximumRowCount(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        comboBoxPanel.add(directoryComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        interior.add(comboBoxPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        // CENTER: left, right, accessory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        JPanel centerPanel = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        centerPanel.setName("GTKFileChooser.centerPanel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        // SPLIT PANEL: left, right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        JSplitPane splitPanel = new JSplitPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        splitPanel.setName("GTKFileChooser.splitPanel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        splitPanel.setDividerLocation((PREF_SIZE.width-8)/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        // left panel - Filter & directoryList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        JPanel leftPanel = new JPanel(new GridBagLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        leftPanel.setName("GTKFileChooser.directoryListPanel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        // Add the Directory List
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        // Create a label that looks like button (should be a table header)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        TableCellRenderer headerRenderer = new JTableHeader().getDefaultRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        JLabel directoryListLabel =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            (JLabel)headerRenderer.getTableCellRendererComponent(null, foldersLabelText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                                                     false, false, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        directoryListLabel.setName("GTKFileChooser.directoryListLabel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        leftPanel.add(directoryListLabel, new GridBagConstraints(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                          0, 0, 1, 1, 1, 0, GridBagConstraints.WEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                          GridBagConstraints.HORIZONTAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                          new Insets(0, 0, 0, 0), 0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        leftPanel.add(createDirectoryList(), new GridBagConstraints(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                          0, 1, 1, 1, 1, 1, GridBagConstraints.EAST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                          GridBagConstraints.BOTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                          new Insets(0, 0, 0, 0), 0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        directoryListLabel.setDisplayedMnemonic(foldersLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        directoryListLabel.setLabelFor(directoryList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        // create files list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        rightPanel = new JPanel(new GridBagLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        rightPanel.setName("GTKFileChooser.fileListPanel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        headerRenderer = new JTableHeader().getDefaultRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        JLabel fileListLabel =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            (JLabel)headerRenderer.getTableCellRendererComponent(null, filesLabelText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                                                                     false, false, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        fileListLabel.setName("GTKFileChooser.fileListLabel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        rightPanel.add(fileListLabel, new GridBagConstraints(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                          0, 0, 1, 1, 1, 0, GridBagConstraints.WEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                          GridBagConstraints.HORIZONTAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                          new Insets(0, 0, 0, 0), 0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        rightPanel.add(createFilesList(), new GridBagConstraints(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                          0, 1, 1, 1, 1, 1, GridBagConstraints.EAST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                          GridBagConstraints.BOTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                          new Insets(0, 0, 0, 0), 0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        fileListLabel.setDisplayedMnemonic(filesLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        fileListLabel.setLabelFor(fileList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        splitPanel.add(leftPanel,  leftToRight ? JSplitPane.LEFT : JSplitPane.RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        splitPanel.add(rightPanel, leftToRight ? JSplitPane.RIGHT : JSplitPane.LEFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        centerPanel.add(splitPanel, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        JComponent accessoryPanel = getAccessoryPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        JComponent accessory = fc.getAccessory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        if (accessoryPanel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            if (accessory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                accessoryPanel.setPreferredSize(ZERO_ACC_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                accessoryPanel.setMaximumSize(ZERO_ACC_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                getAccessoryPanel().add(accessory, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                accessoryPanel.setPreferredSize(accessory.getPreferredSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                accessoryPanel.setMaximumSize(MAX_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            align(accessoryPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            centerPanel.add(accessoryPanel, BorderLayout.AFTER_LINE_ENDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        interior.add(centerPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        interior.add(Box.createRigidArea(vstrut10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        JPanel pathFieldPanel = new JPanel(new FlowLayout(FlowLayout.LEADING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                                                          0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        pathFieldPanel.setBorder(new EmptyBorder(0, 0, 4, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        JLabel pathFieldLabel = new JLabel(pathLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        pathFieldLabel.setName("GTKFileChooser.pathFieldLabel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        pathFieldLabel.setDisplayedMnemonic(pathLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        align(pathFieldLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        pathFieldPanel.add(pathFieldLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        pathFieldPanel.add(Box.createRigidArea(hstrut3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        File currentDirectory = fc.getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        String curDirName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        if (currentDirectory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            curDirName = currentDirectory.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        pathField = new JLabel(curDirName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                Dimension d = super.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                d.height = getPreferredSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        pathField.setName("GTKFileChooser.pathField");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        align(pathField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        pathFieldPanel.add(pathField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        interior.add(pathFieldPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        // add the fileName field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        fileNameTextField = new JTextField() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                Dimension d = super.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                d.height = getPreferredSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        pathFieldLabel.setLabelFor(fileNameTextField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        Set forwardTraversalKeys = fileNameTextField.getFocusTraversalKeys(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        forwardTraversalKeys = new HashSet(forwardTraversalKeys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        forwardTraversalKeys.remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        fileNameTextField.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardTraversalKeys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        fileNameTextField.setName("GTKFileChooser.fileNameTextField");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        fileNameTextField.getActionMap().put("fileNameCompletionAction", getFileNameCompletionAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        fileNameTextField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "fileNameCompletionAction");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        interior.add(fileNameTextField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        // Add the filter combo box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        JPanel panel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        panel.setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        panel.setBorder(new EmptyBorder(0, 0, 4, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        JLabel filterLabel = new JLabel(filterLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        filterLabel.setName("GTKFileChooser.filterLabel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        filterLabel.setDisplayedMnemonic(filterLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        panel.add(filterLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        filterComboBoxModel = createFilterComboBoxModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        fc.addPropertyChangeListener(filterComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        filterComboBox = new JComboBox(filterComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        filterComboBox.setRenderer(createFilterComboBoxRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        filterLabel.setLabelFor(filterComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        interior.add(Box.createRigidArea(vstrut10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        interior.add(panel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        interior.add(filterComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        // Add buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        bottomButtonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        bottomButtonPanel.setName("GTKFileChooser.bottomButtonPanel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        align(bottomButtonPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
458
54413b296bdf 6642612: JFileChooser approve buttons should use Open and Save text (GTK)
rupashka
parents: 2
diff changeset
   709
        JPanel pnButtons = new JPanel(new GridLayout(1, 2, 5, 0));
54413b296bdf 6642612: JFileChooser approve buttons should use Open and Save text (GTK)
rupashka
parents: 2
diff changeset
   710
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        JButton cancelButton = getCancelButton(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        align(cancelButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        cancelButton.setMargin(buttonMargin);
458
54413b296bdf 6642612: JFileChooser approve buttons should use Open and Save text (GTK)
rupashka
parents: 2
diff changeset
   714
        pnButtons.add(cancelButton);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
458
54413b296bdf 6642612: JFileChooser approve buttons should use Open and Save text (GTK)
rupashka
parents: 2
diff changeset
   716
        JButton approveButton = getApproveButton(fc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        align(approveButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        approveButton.setMargin(buttonMargin);
458
54413b296bdf 6642612: JFileChooser approve buttons should use Open and Save text (GTK)
rupashka
parents: 2
diff changeset
   719
        pnButtons.add(approveButton);
54413b296bdf 6642612: JFileChooser approve buttons should use Open and Save text (GTK)
rupashka
parents: 2
diff changeset
   720
54413b296bdf 6642612: JFileChooser approve buttons should use Open and Save text (GTK)
rupashka
parents: 2
diff changeset
   721
        bottomButtonPanel.add(pnButtons);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        if (fc.getControlButtonsAreShown()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            fc.add(bottomButtonPanel, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    protected void installListeners(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        super.installListeners(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        gtkFCPropertyChangeListener = new GTKFCPropertyChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        fc.addPropertyChangeListener(gtkFCPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    private int getMnemonic(String key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        return SwingUtilities2.getUIDefaultsInt(key, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    protected void uninstallListeners(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        super.uninstallListeners(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        if (gtkFCPropertyChangeListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            fc.removePropertyChangeListener(gtkFCPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    private class GTKFCPropertyChangeListener implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            String prop = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            if (prop.equals("GTKFileChooser.showDirectoryIcons")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                showDirectoryIcons = Boolean.TRUE.equals(e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            } else if (prop.equals("GTKFileChooser.showFileIcons")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                showFileIcons      = Boolean.TRUE.equals(e.getNewValue());
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
    protected void installDefaults(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        super.installDefaults(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        readOnly = UIManager.getBoolean("FileChooser.readOnly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        showDirectoryIcons =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            Boolean.TRUE.equals(fc.getClientProperty("GTKFileChooser.showDirectoryIcons"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        showFileIcons =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            Boolean.TRUE.equals(fc.getClientProperty("GTKFileChooser.showFileIcons"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    protected void installIcons(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        directoryIcon    = UIManager.getIcon("FileView.directoryIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        fileIcon         = UIManager.getIcon("FileView.fileIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    protected void installStrings(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        super.installStrings(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        Locale l = fc.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        newFolderDialogText = UIManager.getString("FileChooser.newFolderDialogText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        newFolderErrorText = UIManager.getString("FileChooser.newFolderErrorText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        newFolderErrorSeparator = UIManager.getString("FileChooser.newFolderErrorSeparator",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        newFolderButtonText = UIManager.getString("FileChooser.newFolderButtonText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        newFolderNoDirectoryErrorTitleText = UIManager.getString("FileChooser.newFolderNoDirectoryErrorTitleText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        newFolderNoDirectoryErrorText = UIManager.getString("FileChooser.newFolderNoDirectoryErrorText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        deleteFileButtonText = UIManager.getString("FileChooser.deleteFileButtonText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        renameFileButtonText = UIManager.getString("FileChooser.renameFileButtonText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        newFolderButtonMnemonic = getMnemonic("FileChooser.newFolderButtonMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        deleteFileButtonMnemonic = getMnemonic("FileChooser.deleteFileButtonMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        renameFileButtonMnemonic = getMnemonic("FileChooser.renameFileButtonMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        newFolderButtonToolTipText = UIManager.getString("FileChooser.newFolderButtonToolTipText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        deleteFileButtonToolTipText = UIManager.getString("FileChooser.deleteFileButtonToolTipText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        renameFileButtonToolTipText = UIManager.getString("FileChooser.renameFileButtonToolTipText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        renameFileDialogText = UIManager.getString("FileChooser.renameFileDialogText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        renameFileErrorTitle = UIManager.getString("FileChooser.renameFileErrorTitle", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        renameFileErrorText = UIManager.getString("FileChooser.renameFileErrorText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        foldersLabelText = UIManager.getString("FileChooser.foldersLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        foldersLabelMnemonic = getMnemonic("FileChooser.foldersLabelMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        filesLabelText = UIManager.getString("FileChooser.filesLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        filesLabelMnemonic = getMnemonic("FileChooser.filesLabelMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        pathLabelText = UIManager.getString("FileChooser.pathLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        pathLabelMnemonic = getMnemonic("FileChooser.pathLabelMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        filterLabelText = UIManager.getString("FileChooser.filterLabelText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        filterLabelMnemonic = UIManager.getInt("FileChooser.filterLabelMnemonic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    protected void uninstallStrings(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        super.uninstallStrings(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        newFolderButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        deleteFileButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        renameFileButtonText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        newFolderButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        deleteFileButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        renameFileButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        renameFileDialogText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        renameFileErrorTitle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        renameFileErrorText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        foldersLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        filesLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        pathLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        newFolderDialogText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        newFolderErrorText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        newFolderErrorSeparator = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    protected JScrollPane createFilesList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        fileList = new JList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        fileList.setName("GTKFileChooser.fileList");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        fileList.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, filesLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        if (getFileChooser().isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            fileList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        fileList.setModel(new GTKFileListModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        fileList.getSelectionModel().removeSelectionInterval(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        fileList.setCellRenderer(new FileCellRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        fileList.addListSelectionListener(createListSelectionListener(getFileChooser()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        fileList.addMouseListener(createDoubleClickListener(getFileChooser(), fileList));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        align(fileList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        JScrollPane scrollpane = new JScrollPane(fileList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        scrollpane.setName("GTKFileChooser.fileListScrollPane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        scrollpane.setPreferredSize(prefListSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        scrollpane.setMaximumSize(MAX_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        align(scrollpane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        return scrollpane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    protected JScrollPane createDirectoryList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        directoryList = new JList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        directoryList.setName("GTKFileChooser.directoryList");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        directoryList.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, foldersLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        align(directoryList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        directoryList.setCellRenderer(new DirectoryCellRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        directoryListModel = new GTKDirectoryListModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        directoryList.getSelectionModel().removeSelectionInterval(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        directoryList.setModel(directoryListModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        directoryList.addMouseListener(createDoubleClickListener(getFileChooser(), directoryList));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        directoryList.addListSelectionListener(createListSelectionListener(getFileChooser()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        JScrollPane scrollpane = new JScrollPane(directoryList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        scrollpane.setName("GTKFileChooser.directoryListScrollPane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        scrollpane.setMaximumSize(MAX_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        scrollpane.setPreferredSize(prefListSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        align(scrollpane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        return scrollpane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    protected void createModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        model = new GTKDirectoryModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    public BasicDirectoryModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        return model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    public Action getApproveSelectionAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        return approveSelectionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    private class GTKDirectoryModel extends BasicDirectoryModel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        FileSystemView fsv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        private Comparator fileComparator = new Comparator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            public int compare(Object o, Object o1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                return fsv.getSystemDisplayName((File) o).compareTo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                      (fsv.getSystemDisplayName((File) o1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        public GTKDirectoryModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            super(getFileChooser());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        protected void sort(Vector<? extends File> v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            fsv = getFileChooser().getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            Collections.sort(v, fileComparator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    protected class GTKDirectoryListModel extends AbstractListModel implements ListDataListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        File curDir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        public GTKDirectoryListModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            getModel().addListDataListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            directoryChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        public int getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            return getModel().getDirectories().size() + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        public Object getElementAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            return index > 0 ? getModel().getDirectories().elementAt(index - 1):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                    curDir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        public void intervalAdded(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            fireIntervalAdded(this, e.getIndex0(), e.getIndex1());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        public void intervalRemoved(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            fireIntervalRemoved(this, e.getIndex0(), e.getIndex1());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        // PENDING - this is inefficient - should sent out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        // incremental adjustment values instead of saying that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        // whole list has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        public void fireContentsChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            fireContentsChanged(this, 0, getModel().getDirectories().size()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        // PENDING - fire the correct interval changed - currently sending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        // out that everything has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        public void contentsChanged(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            fireContentsChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        private void directoryChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            curDir = getFileChooser().getFileSystemView().createFileObject(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                    getFileChooser().getCurrentDirectory(), ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    protected class GTKFileListModel extends AbstractListModel implements ListDataListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        public GTKFileListModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            getModel().addListDataListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        public int getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            return getModel().getFiles().size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        public boolean contains(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            return getModel().getFiles().contains(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        public int indexOf(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            return getModel().getFiles().indexOf(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        public Object getElementAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            return getModel().getFiles().elementAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        public void intervalAdded(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            fireIntervalAdded(this, e.getIndex0(), e.getIndex1());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        public void intervalRemoved(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            fireIntervalRemoved(this, e.getIndex0(), e.getIndex1());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        // PENDING - this is inefficient - should sent out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        // incremental adjustment values instead of saying that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        // whole list has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        public void fireContentsChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            fireContentsChanged(this, 0, getModel().getFiles().size()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        // PENDING - fire the interval changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        public void contentsChanged(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            fireContentsChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    protected class FileCellRenderer extends DefaultListCellRenderer  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        public Component getListCellRendererComponent(JList list, Object value, int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                                                      boolean isSelected, boolean cellHasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            setText(getFileChooser().getName((File) value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            if (showFileIcons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                setIcon(getFileChooser().getIcon((File)value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    protected class DirectoryCellRenderer extends DefaultListCellRenderer  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        public Component getListCellRendererComponent(JList list, Object value, int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                                                      boolean isSelected, boolean cellHasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            if (showDirectoryIcons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                setIcon(getFileChooser().getIcon((File)value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                setText(getFileChooser().getName((File)value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                setText(getFileChooser().getName((File)value) + "/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        Dimension prefSize = new Dimension(PREF_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        JComponent accessory = getFileChooser().getAccessory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        if (accessory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            prefSize.width += accessory.getPreferredSize().width + 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        Dimension d = c.getLayout().preferredLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        if (d != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            return new Dimension(d.width < prefSize.width ? prefSize.width : d.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                                 d.height < prefSize.height ? prefSize.height : d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            return prefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    public Dimension getMinimumSize(JComponent x)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        return new Dimension(MIN_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    public Dimension getMaximumSize(JComponent x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    protected void align(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        c.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        c.setAlignmentY(JComponent.TOP_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    public Action getNewFolderAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        if (newFolderAction == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            newFolderAction = new NewFolderAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            newFolderAction.setEnabled(!readOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        return newFolderAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    // DataModel for DirectoryComboxbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    protected DirectoryComboBoxModel createDirectoryComboBoxModel(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        return new DirectoryComboBoxModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * Data model for a type-face selection combo-box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        Vector directories = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        File selectedDirectory = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        FileSystemView fsv = chooser.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        public DirectoryComboBoxModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            // Add the current directory to the model, and make it the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            // selectedDirectory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            File dir = getFileChooser().getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            if (dir != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                addItem(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
         * Adds the directory to the model and sets it to be selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
         * additionally clears out the previous selected directory and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
         * the paths leading up to it, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        private void addItem(File directory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            if (directory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            int oldSize = directories.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            directories.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            if (oldSize > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                fireIntervalRemoved(this, 0, oldSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            // Get the canonical (full) path. This has the side
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            // benefit of removing extraneous chars from the path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            // for example /foo/bar/ becomes /foo/bar
458
54413b296bdf 6642612: JFileChooser approve buttons should use Open and Save text (GTK)
rupashka
parents: 2
diff changeset
  1111
            File canonical;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                canonical = fsv.createFileObject(ShellFolder.getNormalizedFile(directory).getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                // Maybe drive is not ready. Can't abort here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                canonical = directory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            // create File instances of each directory leading up to the top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            File f = canonical;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                directories.add(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            } while ((f = f.getParentFile()) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            int newSize = directories.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            if (newSize > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                fireIntervalAdded(this, 0, newSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            setSelectedItem(canonical);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        public void setSelectedItem(Object selectedDirectory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            this.selectedDirectory = (File)selectedDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            fireContentsChanged(this, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        public Object getSelectedItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            return selectedDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        public int getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            return directories.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        public Object getElementAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            return directories.elementAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * Acts when DirectoryComboBox has changed the selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    protected class DirectoryComboBoxAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        protected DirectoryComboBoxAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            super("DirectoryComboBoxAction");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            File f = (File)directoryComboBox.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            getFileChooser().setCurrentDirectory(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * Creates a new folder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    private class NewFolderAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        protected NewFolderAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            super(FilePane.ACTION_NEW_FOLDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            if (readOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            File currentDirectory = fc.getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            String dirName = JOptionPane.showInputDialog(fc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                    newFolderDialogText, newFolderButtonText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                    JOptionPane.PLAIN_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            if (dirName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                if (!currentDirectory.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                    JOptionPane.showMessageDialog(fc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                            MessageFormat.format(newFolderNoDirectoryErrorText, dirName),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                            newFolderNoDirectoryErrorTitleText, JOptionPane.ERROR_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                File newDir = fc.getFileSystemView().createFileObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                        (currentDirectory, dirName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                if (newDir == null || !newDir.mkdir()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                    JOptionPane.showMessageDialog(fc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                            newFolderErrorText + newFolderErrorSeparator + " \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                            dirName + "\"",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                            newFolderErrorText, JOptionPane.ERROR_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                fc.rescanCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    private class GTKApproveSelectionAction extends ApproveSelectionAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            if (isDirectorySelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                File dir = getDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                    // Strip trailing ".."
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                    if (dir != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                        dir = ShellFolder.getNormalizedFile(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                    // Ok, use f as is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                if (getFileChooser().getCurrentDirectory().equals(dir)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                    directoryList.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                    fileList.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                    ListSelectionModel sm = fileList.getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                    if (sm instanceof DefaultListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                        ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                        ((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                    rescanCurrentDirectory(getFileChooser());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            super.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * Renames file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    private class RenameFileAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        protected RenameFileAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            super(FilePane.ACTION_EDIT_FILE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            if (getFileName().equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            File currentDirectory = fc.getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            String newFileName = (String) JOptionPane.showInputDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                   (fc, new MessageFormat(renameFileDialogText).format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                           (new Object[] { getFileName() }),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                           renameFileButtonText, JOptionPane.PLAIN_MESSAGE, null, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                           getFileName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            if (newFileName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                File oldFile = fc.getFileSystemView().createFileObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                        (currentDirectory, getFileName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                File newFile = fc.getFileSystemView().createFileObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                        (currentDirectory, newFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                if (oldFile == null || newFile == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                        !getModel().renameFile(oldFile, newFile)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                    JOptionPane.showMessageDialog(fc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                            new MessageFormat(renameFileErrorText).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                            format(new Object[] { getFileName(), newFileName}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                            renameFileErrorTitle, JOptionPane.ERROR_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                    setFileName(getFileChooser().getName(newFile));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                    fc.rescanCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    // Renderer for Filter ComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        return new FilterComboBoxRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * Render different filters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    public class FilterComboBoxRenderer extends DefaultListCellRenderer implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            // As SynthComboBoxRenderer's are asked for a size BEFORE they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            // are parented getName is overriden to force the name to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            // ComboBox.renderer if it isn't set. If we didn't do this the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            // wrong style could be used for size calculations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            String name = super.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                return "ComboBox.renderer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        public Component getListCellRendererComponent(JList list, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                                                      int index, boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                                                      boolean cellHasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            setName("ComboBox.listRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                if (value instanceof FileFilter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                    setText(((FileFilter) value).getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    // DataModel for Filter Combobox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    protected FilterComboBoxModel createFilterComboBoxModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        return new FilterComboBoxModel();
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
     * Data model for filter combo-box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    protected class FilterComboBoxModel extends AbstractListModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            implements ComboBoxModel, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        protected FileFilter[] filters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        protected FilterComboBoxModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            filters = getFileChooser().getChoosableFileFilters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            String prop = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            if (prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                filters = (FileFilter[]) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                fireContentsChanged(this, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                fireContentsChanged(this, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        public void setSelectedItem(Object filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            if (filter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                getFileChooser().setFileFilter((FileFilter) filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                fireContentsChanged(this, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        public Object getSelectedItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            // Ensure that the current filter is in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            // NOTE: we shouldnt' have to do this, since JFileChooser adds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
            // the filter to the choosable filters list when the filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            // is set. Lets be paranoid just in case someone overrides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            // setFileFilter in JFileChooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            FileFilter currentFilter = getFileChooser().getFileFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
            if (currentFilter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                for (int i = 0; i < filters.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                    if (filters[i] == currentFilter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                        found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
                if (found == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                    getFileChooser().addChoosableFileFilter(currentFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
            return getFileChooser().getFileFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        public int getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            if (filters != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                return filters.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        public Object getElementAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
            if (index > getSize() - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                // This shouldn't happen. Try to recover gracefully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                return getFileChooser().getFileFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            if (filters != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                return filters[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
}