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