jdk/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java
author lana
Thu, 29 Jan 2009 09:25:47 -0800
changeset 1853 63c1129add13
parent 1639 a97859015238
parent 1842 824c7f885a64
child 2491 123954ad0034
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1639
a97859015238 6785258: Update copyright year
xdono
parents: 1290
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.swing.plaf.synth;
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.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.filechooser.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.filechooser.FileFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.plaf.synth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.awt.shell.ShellFolder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Synth FileChooserUI implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Note that the classes in the com.sun.java.swing.plaf.synth
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * package are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * part of the core Java APIs. They are a part of Sun's JDK and JRE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * distributions. Although other licensees may choose to distribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * these classes, developers cannot depend on their availability in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * non-Sun implementations. Additionally this API may change in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * incompatible ways between releases. While this class is public, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * shoud be considered an implementation detail, and subject to change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author Leif Samuelsson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class SynthFileChooserUIImpl extends SynthFileChooserUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private JLabel lookInLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private JComboBox directoryComboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private DirectoryComboBoxModel directoryComboBoxModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private Action directoryComboBoxAction = new DirectoryComboBoxAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private FilterComboBoxModel filterComboBoxModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private JTextField fileNameTextField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private FilePane filePane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private JToggleButton listViewButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private JToggleButton detailsViewButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private boolean readOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private JPanel buttonPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private JPanel bottomPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private JComboBox filterComboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final Dimension hstrut5 = new Dimension(5, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final Dimension vstrut5  = new Dimension(1, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static final Insets shrinkwrap = new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // Preferred and Minimum sizes for the dialog box
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static Dimension LIST_PREF_SIZE = new Dimension(405, 135);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // Labels, mnemonics, and tooltips (oh my!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private int    lookInLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private String lookInLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private String saveInLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private int    fileNameLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private String fileNameLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private int    folderNameLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private String folderNameLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private int    filesOfTypeLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private String filesOfTypeLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private String upFolderToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private String upFolderAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private String homeFolderToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private String homeFolderAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private String newFolderToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private String newFolderAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private String listViewButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private String listViewButtonAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private String detailsViewButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private String detailsViewButtonAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private AlignedLabel fileNameLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private final PropertyChangeListener modeListener = new PropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        public void propertyChange(PropertyChangeEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            if (fileNameLabel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                populateFileNameLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private void populateFileNameLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (getFileChooser().getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            fileNameLabel.setText(folderNameLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            fileNameLabel.setDisplayedMnemonic(folderNameLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            fileNameLabel.setText(fileNameLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            fileNameLabel.setDisplayedMnemonic(fileNameLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public SynthFileChooserUIImpl(JFileChooser b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        super(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private class SynthFileChooserUIAccessor implements FilePane.FileChooserUIAccessor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        public JFileChooser getFileChooser() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            return SynthFileChooserUIImpl.this.getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        public BasicDirectoryModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return SynthFileChooserUIImpl.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        public JPanel createList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        public JPanel createDetailsView() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        public boolean isDirectorySelected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            return SynthFileChooserUIImpl.this.isDirectorySelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        public File getDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            return SynthFileChooserUIImpl.this.getDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        public Action getChangeToParentDirectoryAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            return SynthFileChooserUIImpl.this.getChangeToParentDirectoryAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        public Action getApproveSelectionAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            return SynthFileChooserUIImpl.this.getApproveSelectionAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        public Action getNewFolderAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            return SynthFileChooserUIImpl.this.getNewFolderAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        public MouseListener createDoubleClickListener(JList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            return SynthFileChooserUIImpl.this.createDoubleClickListener(getFileChooser(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                                                     list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        public ListSelectionListener createListSelectionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            return SynthFileChooserUIImpl.this.createListSelectionListener(getFileChooser());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    protected void installDefaults(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        super.installDefaults(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        readOnly = UIManager.getBoolean("FileChooser.readOnly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public void installComponents(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        super.installComponents(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        SynthContext context = getContext(fc, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        fc.setLayout(new BorderLayout(0, 11));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        // ********************************* //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        // **** Construct the top panel **** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        // ********************************* //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        // Directory manipulation buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        JPanel topPanel = new JPanel(new BorderLayout(11, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    JPanel topButtonPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    topButtonPanel.setLayout(new BoxLayout(topButtonPanel, BoxLayout.LINE_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    topPanel.add(topButtonPanel, BorderLayout.AFTER_LINE_ENDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        // Add the top panel to the fileChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        fc.add(topPanel, BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // ComboBox Label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        lookInLabel = new JLabel(lookInLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        topPanel.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        // CurrentDir ComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        directoryComboBox = new JComboBox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        directoryComboBox.getAccessibleContext().setAccessibleDescription(lookInLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        directoryComboBox.putClientProperty( "JComboBox.isTableCellEditor", Boolean.TRUE );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        lookInLabel.setLabelFor(directoryComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        directoryComboBoxModel = createDirectoryComboBoxModel(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        directoryComboBox.setModel(directoryComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        directoryComboBox.addActionListener(directoryComboBoxAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        directoryComboBox.setAlignmentY(JComponent.TOP_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        directoryComboBox.setMaximumRowCount(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        topPanel.add(directoryComboBox, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        filePane = new FilePane(new SynthFileChooserUIAccessor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        fc.addPropertyChangeListener(filePane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        // Add 'Go Up' to context menu, plus 'Go Home' if on Unix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        JPopupMenu contextMenu = filePane.getComponentPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (contextMenu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            contextMenu.insert(getChangeToParentDirectoryAction(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (File.separatorChar == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                contextMenu.insert(getGoHomeAction(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    FileSystemView fsv = fc.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    // Up Button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    JButton upFolderButton = new JButton(getChangeToParentDirectoryAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    upFolderButton.setText(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    upFolderButton.setIcon(upFolderIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    upFolderButton.setToolTipText(upFolderToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    upFolderButton.getAccessibleContext().setAccessibleName(upFolderAccessibleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    upFolderButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    upFolderButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    upFolderButton.setMargin(shrinkwrap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    topButtonPanel.add(upFolderButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    topButtonPanel.add(Box.createRigidArea(hstrut5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    // Home Button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    File homeDir = fsv.getHomeDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    String toolTipText = homeFolderToolTipText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    if (fsv.isRoot(homeDir)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        toolTipText = getFileView(fc).getName(homeDir); // Probably "Desktop".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    JButton b = new JButton(homeFolderIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    b.setToolTipText(toolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    b.getAccessibleContext().setAccessibleName(homeFolderAccessibleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    b.setMargin(shrinkwrap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    b.addActionListener(getGoHomeAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    topButtonPanel.add(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    topButtonPanel.add(Box.createRigidArea(hstrut5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    // New Directory Button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    if (!readOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        b = new JButton(filePane.getNewFolderAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        b.setText(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        b.setIcon(newFolderIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        b.setToolTipText(newFolderToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        b.getAccessibleContext().setAccessibleName(newFolderAccessibleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        b.setMargin(shrinkwrap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    topButtonPanel.add(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    topButtonPanel.add(Box.createRigidArea(hstrut5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    // View button group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    ButtonGroup viewButtonGroup = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    // List Button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    listViewButton = new JToggleButton(listViewIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    listViewButton.setToolTipText(listViewButtonToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    listViewButton.getAccessibleContext().setAccessibleName(listViewButtonAccessibleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    listViewButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    listViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    listViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    listViewButton.setMargin(shrinkwrap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    listViewButton.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_LIST));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    topButtonPanel.add(listViewButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    viewButtonGroup.add(listViewButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    // Details Button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    detailsViewButton = new JToggleButton(detailsViewIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    detailsViewButton.setToolTipText(detailsViewButtonToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    detailsViewButton.getAccessibleContext().setAccessibleName(detailsViewButtonAccessibleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    detailsViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    detailsViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    detailsViewButton.setMargin(shrinkwrap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    detailsViewButton.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    topButtonPanel.add(detailsViewButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    viewButtonGroup.add(detailsViewButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    filePane.addPropertyChangeListener(new PropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            if ("viewType".equals(e.getPropertyName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                int viewType = filePane.getViewType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                switch (viewType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    case FilePane.VIEWTYPE_LIST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                        listViewButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    case FilePane.VIEWTYPE_DETAILS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                        detailsViewButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        // ************************************** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        // ******* Add the directory pane ******* //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        // ************************************** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        fc.add(getAccessoryPanel(), BorderLayout.AFTER_LINE_ENDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        JComponent accessory = fc.getAccessory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (accessory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            getAccessoryPanel().add(accessory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        filePane.setPreferredSize(LIST_PREF_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        fc.add(filePane, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        // ********************************** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        // **** Construct the bottom panel ** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        // ********************************** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        bottomPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        fc.add(bottomPanel, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        // FileName label and textfield
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        JPanel fileNamePanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        fileNamePanel.setLayout(new BoxLayout(fileNamePanel, BoxLayout.LINE_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        bottomPanel.add(fileNamePanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        bottomPanel.add(Box.createRigidArea(new Dimension(1, 5)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        fileNameLabel = new AlignedLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        populateFileNameLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        fileNamePanel.add(fileNameLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        fileNameTextField = new JTextField(35) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        fileNamePanel.add(fileNameTextField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        fileNameLabel.setLabelFor(fileNameTextField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        fileNameTextField.addFocusListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            new FocusAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    if (!getFileChooser().isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                        filePane.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (fc.isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            setFileName(fileNameString(fc.getSelectedFiles()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            setFileName(fileNameString(fc.getSelectedFile()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        // Filetype label and combobox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        JPanel filesOfTypePanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        filesOfTypePanel.setLayout(new BoxLayout(filesOfTypePanel, BoxLayout.LINE_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        bottomPanel.add(filesOfTypePanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        AlignedLabel filesOfTypeLabel = new AlignedLabel(filesOfTypeLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        filesOfTypeLabel.setDisplayedMnemonic(filesOfTypeLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        filesOfTypePanel.add(filesOfTypeLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        filterComboBoxModel = createFilterComboBoxModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        fc.addPropertyChangeListener(filterComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        filterComboBox = new JComboBox(filterComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        filterComboBox.getAccessibleContext().setAccessibleDescription(filesOfTypeLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        filesOfTypeLabel.setLabelFor(filterComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        filterComboBox.setRenderer(createFilterComboBoxRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        filesOfTypePanel.add(filterComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        // buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        buttonPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        buttonPanel.setLayout(new ButtonAreaLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        buttonPanel.add(getApproveButton(fc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        buttonPanel.add(getCancelButton(fc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if (fc.getControlButtonsAreShown()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            addControlButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        groupLabels(new AlignedLabel[] { fileNameLabel, filesOfTypeLabel });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    protected void installListeners(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        super.installListeners(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        fc.addPropertyChangeListener(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY, modeListener);
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 void uninstallListeners(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        fc.removePropertyChangeListener(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY, modeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        super.uninstallListeners(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    private String fileNameString(File file) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        if (file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                return file.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                return file.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    private String fileNameString(File[] files) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        StringBuffer buf = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        for (int i = 0; files != null && i < files.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                buf.append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            if (files.length > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                buf.append("\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            buf.append(fileNameString(files[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            if (files.length > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                buf.append("\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        // Remove listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        c.removePropertyChangeListener(filterComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        c.removePropertyChangeListener(filePane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        if (filePane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            filePane.uninstallUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            filePane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        super.uninstallUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    protected void installStrings(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        super.installStrings(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        Locale l = fc.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        lookInLabelMnemonic = getMnemonic("FileChooser.lookInLabelMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        lookInLabelText = UIManager.getString("FileChooser.lookInLabelText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        saveInLabelText = UIManager.getString("FileChooser.saveInLabelText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        fileNameLabelMnemonic = getMnemonic("FileChooser.fileNameLabelMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        folderNameLabelMnemonic = getMnemonic("FileChooser.folderNameLabelMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        folderNameLabelText = UIManager.getString("FileChooser.folderNameLabelText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        filesOfTypeLabelMnemonic = getMnemonic("FileChooser.filesOfTypeLabelMnemonic", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        filesOfTypeLabelText = UIManager.getString("FileChooser.filesOfTypeLabelText", l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    upFolderToolTipText =  UIManager.getString("FileChooser.upFolderToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    upFolderAccessibleName = UIManager.getString("FileChooser.upFolderAccessibleName",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    homeFolderToolTipText =  UIManager.getString("FileChooser.homeFolderToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    homeFolderAccessibleName = UIManager.getString("FileChooser.homeFolderAccessibleName",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    newFolderToolTipText = UIManager.getString("FileChooser.newFolderToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    newFolderAccessibleName = UIManager.getString("FileChooser.newFolderAccessibleName",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    listViewButtonToolTipText = UIManager.getString("FileChooser.listViewButtonToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    listViewButtonAccessibleName = UIManager.getString("FileChooser.listViewButtonAccessibleName",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    detailsViewButtonToolTipText = UIManager.getString("FileChooser.detailsViewButtonToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    detailsViewButtonAccessibleName = UIManager.getString("FileChooser.detailsViewButtonAccessibleName",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    private int getMnemonic(String key, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        return SwingUtilities2.getUIDefaultsInt(key, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    public String getFileName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        if (fileNameTextField != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            return fileNameTextField.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    public void setFileName(String fileName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (fileNameTextField != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            fileNameTextField.setText(fileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    protected void doSelectedFileChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        super.doSelectedFileChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        File f = (File) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        if (f != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            && ((fc.isFileSelectionEnabled() && !f.isDirectory())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                || (f.isDirectory() && fc.isDirectorySelectionEnabled()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            setFileName(fileNameString(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    protected void doSelectedFilesChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        super.doSelectedFilesChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        File[] files = (File[]) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        if (files != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            && files.length > 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            && (files.length > 1 || fc.isDirectorySelectionEnabled() || !files[0].isDirectory())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            setFileName(fileNameString(files));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    protected void doDirectoryChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        super.doDirectoryChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        FileSystemView fsv = fc.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        File currentDirectory = fc.getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if (!readOnly && currentDirectory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            getNewFolderAction().setEnabled(filePane.canWrite(currentDirectory));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        if (currentDirectory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            JComponent cb = getDirectoryComboBox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            if (cb instanceof JComboBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                ComboBoxModel model = ((JComboBox)cb).getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                if (model instanceof DirectoryComboBoxModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                    ((DirectoryComboBoxModel)model).addItem(currentDirectory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                if (fsv.isFileSystem(currentDirectory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    setFileName(currentDirectory.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                    setFileName(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    protected void doFileSelectionModeChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        super.doFileSelectionModeChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        File currentDirectory = fc.getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        if (currentDirectory != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            && fc.isDirectorySelectionEnabled()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            && !fc.isFileSelectionEnabled()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            && fc.getFileSystemView().isFileSystem(currentDirectory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            setFileName(currentDirectory.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            setFileName(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    protected void doAccessoryChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if (getAccessoryPanel() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            if (e.getOldValue() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                getAccessoryPanel().remove((JComponent)e.getOldValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            JComponent accessory = (JComponent)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            if (accessory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                getAccessoryPanel().add(accessory, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    protected void doControlButtonsChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        super.doControlButtonsChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        if (getFileChooser().getControlButtonsAreShown()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            addControlButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            removeControlButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    protected void addControlButtons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        if (bottomPanel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            bottomPanel.add(buttonPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    protected void removeControlButtons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (bottomPanel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            bottomPanel.remove(buttonPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    // *******************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    // ************ FileChooser UI PLAF methods **************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    // *******************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    // *****************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    // ***** Directory Actions *****
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    // *****************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    protected JComponent getDirectoryComboBox() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        return directoryComboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    protected Action getDirectoryComboBoxAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        return directoryComboBoxAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        return new DirectoryComboBoxRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    // Renderer for DirectoryComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    class DirectoryComboBoxRenderer extends DefaultListCellRenderer  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        IndentIcon ii = new IndentIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        public Component getListCellRendererComponent(JList list, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                                                      int index, boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                                                      boolean cellHasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            File directory = (File)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            setText(getFileChooser().getName(directory));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            Icon icon = getFileChooser().getIcon(directory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            ii.icon = icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            ii.depth = directoryComboBoxModel.getDepth(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            setIcon(ii);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    final static int space = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    class IndentIcon implements Icon {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        Icon icon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        int depth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                if (c.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    icon.paintIcon(c, g, x+depth*space, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    icon.paintIcon(c, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        public int getIconWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            return ((icon != null) ? icon.getIconWidth() : 0) + depth*space;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        public int getIconHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            return (icon != null) ? icon.getIconHeight() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    // DataModel for DirectoryComboxbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    protected DirectoryComboBoxModel createDirectoryComboBoxModel(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        return new DirectoryComboBoxModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * Data model for a type-face selection combo-box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   716
        Vector<File> directories = new Vector<File>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        int[] depths = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        File selectedDirectory = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        FileSystemView fsv = chooser.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        public DirectoryComboBoxModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            // Add the current directory to the model, and make it the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            // selectedDirectory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            File dir = getFileChooser().getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            if (dir != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                addItem(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
         * Adds the directory to the model and sets it to be selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
         * additionally clears out the previous selected directory and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
         * the paths leading up to it, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        public void addItem(File directory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            if (directory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
1842
824c7f885a64 6776856: Code with useShellFolder field shuold be simplify
rupashka
parents: 1290
diff changeset
   742
            boolean useShellFolder = FilePane.usesShellFolder(chooser);
824c7f885a64 6776856: Code with useShellFolder field shuold be simplify
rupashka
parents: 1290
diff changeset
   743
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            int oldSize = directories.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            directories.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            if (oldSize > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                fireIntervalRemoved(this, 0, oldSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            File[] baseFolders;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            if (useShellFolder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                baseFolders = (File[])ShellFolder.get("fileChooserComboBoxFolders");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                baseFolders = fsv.getRoots();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            directories.addAll(Arrays.asList(baseFolders));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            // Get the canonical (full) path. This has the side
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            // benefit of removing extraneous chars from the path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            // for example /foo/bar/ becomes /foo/bar
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   761
            File canonical;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                canonical = directory.getCanonicalFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                // Maybe drive is not ready. Can't abort here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                canonical = directory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            // create File instances of each directory leading up to the top
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                File sf = useShellFolder ? ShellFolder.getShellFolder(canonical)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                                         : canonical;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                File f = sf;
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   774
                Vector<File> path = new Vector<File>(10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    path.addElement(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                } while ((f = f.getParentFile()) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                int pathCount = path.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                // Insert chain at appropriate place in vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                for (int i = 0; i < pathCount; i++) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   782
                    f = path.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                    if (directories.contains(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                        int topIndex = directories.indexOf(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                        for (int j = i-1; j >= 0; j--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                            directories.insertElementAt(path.get(j), topIndex+i-j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                calculateDepths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                setSelectedItem(sf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            } catch (FileNotFoundException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                calculateDepths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        private void calculateDepths() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            depths = new int[directories.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            for (int i = 0; i < depths.length; i++) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   801
                File dir = directories.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                File parent = dir.getParentFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                depths[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    for (int j = i-1; j >= 0; j--) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   806
                        if (parent.equals(directories.get(j))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                            depths[i] = depths[j] + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        public int getDepth(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        public void setSelectedItem(Object selectedDirectory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            this.selectedDirectory = (File)selectedDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            fireContentsChanged(this, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        public Object getSelectedItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            return selectedDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        public int getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            return directories.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        public Object getElementAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            return directories.elementAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * Acts when DirectoryComboBox has changed the selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    protected class DirectoryComboBoxAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        protected DirectoryComboBoxAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            super("DirectoryComboBoxAction");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            directoryComboBox.hidePopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            JComponent cb = getDirectoryComboBox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            if (cb instanceof JComboBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                File f = (File)((JComboBox)cb).getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                getFileChooser().setCurrentDirectory(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    // Renderer for Types ComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        return new FilterComboBoxRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * Render different type sizes and styles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    public class FilterComboBoxRenderer extends DefaultListCellRenderer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        public Component getListCellRendererComponent(JList list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            Object value, int index, boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            boolean cellHasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            if (value != null && value instanceof FileFilter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                setText(((FileFilter)value).getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    // DataModel for Types Comboxbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    protected FilterComboBoxModel createFilterComboBoxModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        return new FilterComboBoxModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * Data model for a type-face selection combo-box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    protected class FilterComboBoxModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        protected FileFilter[] filters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        protected FilterComboBoxModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            filters = getFileChooser().getChoosableFileFilters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            String prop = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                filters = (FileFilter[]) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                fireContentsChanged(this, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                fireContentsChanged(this, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        public void setSelectedItem(Object filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            if(filter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                getFileChooser().setFileFilter((FileFilter) filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                fireContentsChanged(this, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        public Object getSelectedItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            // Ensure that the current filter is in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            // NOTE: we shouldnt' have to do this, since JFileChooser adds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            // the filter to the choosable filters list when the filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            // is set. Lets be paranoid just in case someone overrides
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            // setFileFilter in JFileChooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            FileFilter currentFilter = getFileChooser().getFileFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            if(currentFilter != null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   923
                for (FileFilter filter : filters) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   924
                    if (filter == currentFilter) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                        found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                if(found == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                    getFileChooser().addChoosableFileFilter(currentFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            return getFileChooser().getFileFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        public int getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            if(filters != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                return filters.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        public Object getElementAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            if(index > getSize() - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                // This shouldn't happen. Try to recover gracefully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                return getFileChooser().getFileFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            if(filters != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                return filters[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * <code>ButtonAreaLayout</code> behaves in a similar manner to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * <code>FlowLayout</code>. It lays out all components from left to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * right, flushed right. The widths of all components will be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * to the largest preferred size width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    private static class ButtonAreaLayout implements LayoutManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        private int hGap = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        private int topMargin = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        public void addLayoutComponent(String string, Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        public void layoutContainer(Container container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            Component[] children = container.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            if (children != null && children.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                int         numChildren = children.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                Dimension[] sizes = new Dimension[numChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                Insets      insets = container.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                int         yLocation = insets.top + topMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                int         maxWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                for (int counter = 0; counter < numChildren; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                    sizes[counter] = children[counter].getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                    maxWidth = Math.max(maxWidth, sizes[counter].width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                int xLocation, xOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                if (container.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                    xLocation = container.getSize().width - insets.left - maxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                    xOffset = hGap + maxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                    xLocation = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                    xOffset = -(hGap + maxWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                for (int counter = numChildren - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                    children[counter].setBounds(xLocation, yLocation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                                                maxWidth, sizes[counter].height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                    xLocation -= xOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        public Dimension minimumLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                Component[] children = c.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                if (children != null && children.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                    int       numChildren = children.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                    int       height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                    Insets    cInsets = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                    int       extraHeight = topMargin + cInsets.top + cInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                    int       extraWidth = cInsets.left + cInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                    int       maxWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                    for (int counter = 0; counter < numChildren; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                        Dimension aSize = children[counter].getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                        height = Math.max(height, aSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                        maxWidth = Math.max(maxWidth, aSize.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                    return new Dimension(extraWidth + numChildren * maxWidth +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                                         (numChildren - 1) * hGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                                         extraHeight + height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            return new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        public Dimension preferredLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            return minimumLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        public void removeLayoutComponent(Component c) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    private static void groupLabels(AlignedLabel[] group) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        for (int i = 0; i < group.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            group[i].group = group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    private class AlignedLabel extends JLabel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        private AlignedLabel[] group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        private int maxWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        AlignedLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        AlignedLabel(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            super(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            Dimension d = super.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            // Align the width with all other labels in group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            return new Dimension(getMaxWidth() + 11, d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        private int getMaxWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            if (maxWidth == 0 && group != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                int max = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                for (int i = 0; i < group.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                    max = Math.max(group[i].getSuperPreferredWidth(), max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                for (int i = 0; i < group.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                    group[i].maxWidth = max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            return maxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        private int getSuperPreferredWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            return super.getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
}