jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java
author rupashka
Mon, 07 Sep 2009 15:09:40 +0400
changeset 3751 8b0ac086b7c0
parent 2491 123954ad0034
child 5506 202f599c92aa
permissions -rw-r--r--
6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog Reviewed-by: peterz, loneid
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
     2
 * Copyright 1997-2009 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.swing.plaf.windows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.filechooser.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.*;
2491
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
    42
import java.security.AccessController;
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
    43
import java.security.PrivilegedAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.awt.shell.ShellFolder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Windows L&F implementation of a FileChooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class WindowsFileChooserUI extends BasicFileChooserUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // The following are private because the implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // Windows FileChooser L&F is not complete yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private JPanel centerPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private JLabel lookInLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private JComboBox directoryComboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private DirectoryComboBoxModel directoryComboBoxModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private ActionListener directoryComboBoxAction = new DirectoryComboBoxAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private FilterComboBoxModel filterComboBoxModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private JTextField filenameTextField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private FilePane filePane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private WindowsPlacesBar placesBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private JButton approveButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private JButton cancelButton;
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 hstrut10 = new Dimension(10, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static final Dimension vstrut4  = new Dimension(1, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static final Dimension vstrut6  = new Dimension(1, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static final Dimension vstrut8  = new Dimension(1, 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static final Insets shrinkwrap = new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // Preferred and Minimum sizes for the dialog box
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static int PREF_WIDTH = 425;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private static int PREF_HEIGHT = 245;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private static Dimension PREF_SIZE = new Dimension(PREF_WIDTH, PREF_HEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private static int MIN_WIDTH = 425;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static int MIN_HEIGHT = 245;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private static Dimension MIN_SIZE = new Dimension(MIN_WIDTH, MIN_HEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static int LIST_PREF_WIDTH = 444;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static int LIST_PREF_HEIGHT = 138;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private static Dimension LIST_PREF_SIZE = new Dimension(LIST_PREF_WIDTH, LIST_PREF_HEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    // Labels, mnemonics, and tooltips (oh my!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private int    lookInLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private String lookInLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private String saveInLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private int    fileNameLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private String fileNameLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private int    folderNameLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private String folderNameLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private int    filesOfTypeLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private String filesOfTypeLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private String upFolderToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private String upFolderAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private String newFolderToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private String newFolderAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private String viewMenuButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private String viewMenuButtonAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private BasicFileView fileView = new WindowsFileView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private JLabel fileNameLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private void populateFileNameLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (getFileChooser().getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            fileNameLabel.setText(folderNameLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            fileNameLabel.setDisplayedMnemonic(folderNameLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            fileNameLabel.setText(fileNameLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            fileNameLabel.setDisplayedMnemonic(fileNameLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    // ComponentUI Interface Implementation methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return new WindowsFileChooserUI((JFileChooser) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public WindowsFileChooserUI(JFileChooser filechooser) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        super(filechooser);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        super.installUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public void uninstallComponents(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        fc.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private class WindowsFileChooserUIAccessor implements FilePane.FileChooserUIAccessor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        public JFileChooser getFileChooser() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            return WindowsFileChooserUI.this.getFileChooser();
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 BasicDirectoryModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            return WindowsFileChooserUI.this.getModel();
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 JPanel createList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            return WindowsFileChooserUI.this.createList(getFileChooser());
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 JPanel createDetailsView() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            return WindowsFileChooserUI.this.createDetailsView(getFileChooser());
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 boolean isDirectorySelected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            return WindowsFileChooserUI.this.isDirectorySelected();
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 File getDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            return WindowsFileChooserUI.this.getDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        public Action getChangeToParentDirectoryAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            return WindowsFileChooserUI.this.getChangeToParentDirectoryAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        public Action getApproveSelectionAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            return WindowsFileChooserUI.this.getApproveSelectionAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        public Action getNewFolderAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            return WindowsFileChooserUI.this.getNewFolderAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        public MouseListener createDoubleClickListener(JList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            return WindowsFileChooserUI.this.createDoubleClickListener(getFileChooser(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                                                       list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        public ListSelectionListener createListSelectionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            return WindowsFileChooserUI.this.createListSelectionListener(getFileChooser());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public void installComponents(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        filePane = new FilePane(new WindowsFileChooserUIAccessor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        fc.addPropertyChangeListener(filePane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        FileSystemView fsv = fc.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        fc.setBorder(new EmptyBorder(4, 10, 10, 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        fc.setLayout(new BorderLayout(8, 8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        updateUseShellFolder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // ********************************* //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        // **** Construct the top panel **** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        // ********************************* //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // Directory manipulation buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        JToolBar topPanel = new JToolBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        topPanel.setFloatable(false);
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   222
        topPanel.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // Add the top panel to the fileChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        fc.add(topPanel, BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        // ComboBox Label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        lookInLabel = new JLabel(lookInLabelText, JLabel.TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                return getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                Dimension d = super.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                if (placesBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    d.width = Math.max(d.width, placesBar.getWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        lookInLabel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        lookInLabel.setAlignmentY(JComponent.CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        topPanel.add(lookInLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        topPanel.add(Box.createRigidArea(new Dimension(8,0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // CurrentDir ComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        directoryComboBox = new JComboBox() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                Dimension d = super.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                d.width = 60;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                Dimension d = super.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                // Must be small enough to not affect total width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                d.width = 150;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        directoryComboBox.putClientProperty( "JComboBox.lightweightKeyboardNavigation", "Lightweight" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        lookInLabel.setLabelFor(directoryComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        directoryComboBoxModel = createDirectoryComboBoxModel(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        directoryComboBox.setModel(directoryComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        directoryComboBox.addActionListener(directoryComboBoxAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        directoryComboBox.setAlignmentY(JComponent.CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        directoryComboBox.setMaximumRowCount(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        topPanel.add(directoryComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        topPanel.add(Box.createRigidArea(hstrut10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        // Up Button
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   276
        JButton upFolderButton = createToolButton(getChangeToParentDirectoryAction(), upFolderIcon,
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   277
            upFolderToolTipText, upFolderAccessibleName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        topPanel.add(upFolderButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        // New Directory Button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (!UIManager.getBoolean("FileChooser.readOnly")) {
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   282
            JButton newFolderButton = createToolButton(filePane.getNewFolderAction(), newFolderIcon,
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   283
                newFolderToolTipText, newFolderAccessibleName);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   284
            topPanel.add(newFolderButton);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   286
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   287
        // View button group
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   288
        ButtonGroup viewButtonGroup = new ButtonGroup();
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   289
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   290
        // Popup Menu
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   291
        final JPopupMenu viewTypePopupMenu = new JPopupMenu();
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   292
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   293
        final JRadioButtonMenuItem listViewMenuItem = new JRadioButtonMenuItem(
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   294
                filePane.getViewTypeAction(FilePane.VIEWTYPE_LIST));
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   295
        listViewMenuItem.setSelected(filePane.getViewType() == FilePane.VIEWTYPE_LIST);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   296
        viewTypePopupMenu.add(listViewMenuItem);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   297
        viewButtonGroup.add(listViewMenuItem);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   298
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   299
        final JRadioButtonMenuItem detailsViewMenuItem = new JRadioButtonMenuItem(
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   300
                filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS));
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   301
        detailsViewMenuItem.setSelected(filePane.getViewType() == FilePane.VIEWTYPE_DETAILS);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   302
        viewTypePopupMenu.add(detailsViewMenuItem);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   303
        viewButtonGroup.add(detailsViewMenuItem);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   305
        // Create icon for viewMenuButton
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   306
        BufferedImage image = new BufferedImage(viewMenuIcon.getIconWidth() + 7, viewMenuIcon.getIconHeight(),
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   307
                BufferedImage.TYPE_INT_ARGB);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   308
        Graphics graphics = image.getGraphics();
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   309
        viewMenuIcon.paintIcon(filePane, graphics, 0, 0);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   310
        int x = image.getWidth() - 5;
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   311
        int y = image.getHeight() / 2 - 1;
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   312
        graphics.setColor(Color.BLACK);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   313
        graphics.fillPolygon(new int[]{x, x + 5, x + 2}, new int[]{y, y, y + 3}, 3);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   314
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   315
        // Details Button
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   316
        final JButton viewMenuButton = createToolButton(null, new ImageIcon(image), viewMenuButtonToolTipText,
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   317
                viewMenuButtonAccessibleName);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   318
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   319
        viewMenuButton.addMouseListener(new MouseAdapter() {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   320
            public void mousePressed(MouseEvent e) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   321
                if (SwingUtilities.isLeftMouseButton(e) && !viewMenuButton.isSelected()) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   322
                    viewMenuButton.setSelected(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   324
                    viewTypePopupMenu.show(viewMenuButton, 0, viewMenuButton.getHeight());
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   325
                }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   326
            }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   327
        });
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   328
        viewMenuButton.addKeyListener(new KeyAdapter() {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   329
            public void keyPressed(KeyEvent e) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   330
                // Forbid keyboard actions if the button is not in rollover state
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   331
                if (e.getKeyCode() == KeyEvent.VK_SPACE && viewMenuButton.getModel().isRollover()) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   332
                    viewMenuButton.setSelected(true);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   333
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   334
                    viewTypePopupMenu.show(viewMenuButton, 0, viewMenuButton.getHeight());
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   335
                }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   336
            }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   337
        });
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   338
        viewTypePopupMenu.addPopupMenuListener(new PopupMenuListener() {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   339
            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   340
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   342
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   343
                SwingUtilities.invokeLater(new Runnable() {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   344
                    public void run() {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   345
                        viewMenuButton.setSelected(false);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   346
                    }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   347
                });
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   348
            }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   349
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   350
            public void popupMenuCanceled(PopupMenuEvent e) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   351
            }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   352
        });
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   353
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   354
        topPanel.add(viewMenuButton);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   356
        topPanel.add(Box.createRigidArea(new Dimension(80, 0)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   358
        filePane.addPropertyChangeListener(new PropertyChangeListener() {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   359
            public void propertyChange(PropertyChangeEvent e) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   360
                if ("viewType".equals(e.getPropertyName())) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   361
                    switch (filePane.getViewType()) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   362
                        case FilePane.VIEWTYPE_LIST:
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   363
                            listViewMenuItem.setSelected(true);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   364
                            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   366
                        case FilePane.VIEWTYPE_DETAILS:
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   367
                            detailsViewMenuItem.setSelected(true);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   368
                            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                }
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   371
            }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   372
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        // ************************************** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        // ******* Add the directory pane ******* //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        // ************************************** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        centerPanel = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        centerPanel.add(getAccessoryPanel(), BorderLayout.AFTER_LINE_ENDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        JComponent accessory = fc.getAccessory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if(accessory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            getAccessoryPanel().add(accessory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        filePane.setPreferredSize(LIST_PREF_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        centerPanel.add(filePane, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        fc.add(centerPanel, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        // ********************************** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        // **** Construct the bottom panel ** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        // ********************************** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        getBottomPanel().setLayout(new BoxLayout(getBottomPanel(), BoxLayout.LINE_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        // Add the bottom panel to file chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        centerPanel.add(getBottomPanel(), BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        // labels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        JPanel labelPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.PAGE_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        labelPanel.add(Box.createRigidArea(vstrut4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        fileNameLabel = new JLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        populateFileNameLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        fileNameLabel.setAlignmentY(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        labelPanel.add(fileNameLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        labelPanel.add(Box.createRigidArea(new Dimension(1,12)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        JLabel ftl = new JLabel(filesOfTypeLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        ftl.setDisplayedMnemonic(filesOfTypeLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        labelPanel.add(ftl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        getBottomPanel().add(labelPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        getBottomPanel().add(Box.createRigidArea(new Dimension(15, 0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        // file entry and filters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        JPanel fileAndFilterPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        fileAndFilterPanel.add(Box.createRigidArea(vstrut8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        fileAndFilterPanel.setLayout(new BoxLayout(fileAndFilterPanel, BoxLayout.Y_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        filenameTextField = new JTextField(35) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        fileNameLabel.setLabelFor(filenameTextField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        filenameTextField.addFocusListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            new FocusAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    if (!getFileChooser().isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                        filePane.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (fc.isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            setFileName(fileNameString(fc.getSelectedFiles()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            setFileName(fileNameString(fc.getSelectedFile()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        fileAndFilterPanel.add(filenameTextField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        fileAndFilterPanel.add(Box.createRigidArea(vstrut8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        filterComboBoxModel = createFilterComboBoxModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        fc.addPropertyChangeListener(filterComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        filterComboBox = new JComboBox(filterComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        ftl.setLabelFor(filterComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        filterComboBox.setRenderer(createFilterComboBoxRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        fileAndFilterPanel.add(filterComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        getBottomPanel().add(fileAndFilterPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        getBottomPanel().add(Box.createRigidArea(new Dimension(30, 0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        // buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        getButtonPanel().setLayout(new BoxLayout(getButtonPanel(), BoxLayout.Y_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        approveButton = new JButton(getApproveButtonText(fc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                return approveButton.getPreferredSize().width > cancelButton.getPreferredSize().width ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                       approveButton.getPreferredSize() : cancelButton.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        Insets buttonMargin = approveButton.getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        buttonMargin = new InsetsUIResource(buttonMargin.top,    buttonMargin.left  + 5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                            buttonMargin.bottom, buttonMargin.right + 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        approveButton.setMargin(buttonMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        approveButton.setMnemonic(getApproveButtonMnemonic(fc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        approveButton.addActionListener(getApproveSelectionAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        approveButton.setToolTipText(getApproveButtonToolTipText(fc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        getButtonPanel().add(Box.createRigidArea(vstrut6));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        getButtonPanel().add(approveButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        getButtonPanel().add(Box.createRigidArea(vstrut4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        cancelButton = new JButton(cancelButtonText) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                return approveButton.getPreferredSize().width > cancelButton.getPreferredSize().width ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                       approveButton.getPreferredSize() : cancelButton.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        cancelButton.setMargin(buttonMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        cancelButton.setToolTipText(cancelButtonToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        cancelButton.addActionListener(getCancelSelectionAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        getButtonPanel().add(cancelButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        if(fc.getControlButtonsAreShown()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            addControlButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    private void updateUseShellFolder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        // Decide whether to use the ShellFolder class to populate shortcut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        // panel and combobox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        JFileChooser fc = getFileChooser();
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   496
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   497
        if (FilePane.usesShellFolder(fc)) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   498
            if (placesBar == null && !UIManager.getBoolean("FileChooser.noPlacesBar")) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   499
                placesBar = new WindowsPlacesBar(fc, XPStyle.getXP() != null);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   500
                fc.add(placesBar, BorderLayout.BEFORE_LINE_BEGINS);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   501
                fc.addPropertyChangeListener(placesBar);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   502
            }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   503
        } else {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   504
            if (placesBar != null) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   505
                fc.remove(placesBar);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   506
                fc.removePropertyChangeListener(placesBar);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   507
                placesBar = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    protected JPanel getButtonPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        if(buttonPanel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            buttonPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        return buttonPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    protected JPanel getBottomPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if(bottomPanel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            bottomPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        return bottomPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    protected void installStrings(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        super.installStrings(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        Locale l = fc.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        lookInLabelMnemonic = UIManager.getInt("FileChooser.lookInLabelMnemonic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        lookInLabelText = UIManager.getString("FileChooser.lookInLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        saveInLabelText = UIManager.getString("FileChooser.saveInLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        fileNameLabelMnemonic = UIManager.getInt("FileChooser.fileNameLabelMnemonic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        folderNameLabelMnemonic = UIManager.getInt("FileChooser.folderNameLabelMnemonic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        folderNameLabelText = UIManager.getString("FileChooser.folderNameLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        filesOfTypeLabelMnemonic = UIManager.getInt("FileChooser.filesOfTypeLabelMnemonic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        filesOfTypeLabelText = UIManager.getString("FileChooser.filesOfTypeLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        upFolderToolTipText =  UIManager.getString("FileChooser.upFolderToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        upFolderAccessibleName = UIManager.getString("FileChooser.upFolderAccessibleName",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        newFolderToolTipText = UIManager.getString("FileChooser.newFolderToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        newFolderAccessibleName = UIManager.getString("FileChooser.newFolderAccessibleName",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        viewMenuButtonToolTipText = UIManager.getString("FileChooser.viewMenuButtonToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        viewMenuButtonAccessibleName = UIManager.getString("FileChooser.viewMenuButtonAccessibleName",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    protected void installListeners(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        super.installListeners(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        ActionMap actionMap = getActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        SwingUtilities.replaceUIActionMap(fc, actionMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    protected ActionMap getActionMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        return createActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    protected ActionMap createActionMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        ActionMap map = new ActionMapUIResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        FilePane.addActionsToMap(map, filePane.getActions());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    protected JPanel createList(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        return filePane.createList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    protected JPanel createDetailsView(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        return filePane.createDetailsView();
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
     * Creates a selection listener for the list of files and directories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @param fc a <code>JFileChooser</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @return a <code>ListSelectionListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    public ListSelectionListener createListSelectionListener(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        return super.createListSelectionListener(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    // Obsolete class, not used in this version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    protected class WindowsNewFolderAction extends NewFolderAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    // Obsolete class, not used in this version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    protected class SingleClickListener extends MouseAdapter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    // Obsolete class, not used in this version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    protected class FileRenderer extends DefaultListCellRenderer  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        // Remove listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        c.removePropertyChangeListener(filterComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        c.removePropertyChangeListener(filePane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        if (placesBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            c.removePropertyChangeListener(placesBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        cancelButton.removeActionListener(getCancelSelectionAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        approveButton.removeActionListener(getApproveSelectionAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        filenameTextField.removeActionListener(getApproveSelectionAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        if (filePane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            filePane.uninstallUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            filePane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        super.uninstallUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * Returns the preferred size of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * <code>JFileChooser</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * The preferred size is at least as large,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * in both height and width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * as the preferred size recommended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * by the file chooser's layout manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @param c  a <code>JFileChooser</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @return   a <code>Dimension</code> specifying the preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     *           width and height of the file chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        int prefWidth = PREF_SIZE.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        Dimension d = c.getLayout().preferredLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        if (d != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            return new Dimension(d.width < prefWidth ? prefWidth : d.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                                 d.height < PREF_SIZE.height ? PREF_SIZE.height : d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            return new Dimension(prefWidth, PREF_SIZE.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Returns the minimum size of the <code>JFileChooser</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @param c  a <code>JFileChooser</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @return   a <code>Dimension</code> specifying the minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *           width and height of the file chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        return MIN_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * Returns the maximum size of the <code>JFileChooser</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @param c  a <code>JFileChooser</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @return   a <code>Dimension</code> specifying the maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *           width and height of the file chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    private String fileNameString(File file) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        if (file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            if ((fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                (fc.isDirectorySelectionEnabled() && fc.isFileSelectionEnabled() && fc.getFileSystemView().isFileSystemRoot(file))){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                return file.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                return file.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    private String fileNameString(File[] files) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        StringBuffer buf = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        for (int i = 0; files != null && i < files.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                buf.append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            if (files.length > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                buf.append("\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            buf.append(fileNameString(files[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            if (files.length > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                buf.append("\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    /* The following methods are used by the PropertyChange Listener */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    private void doSelectedFileChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        File f = (File) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        if (f != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            && ((fc.isFileSelectionEnabled() && !f.isDirectory())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                || (f.isDirectory() && fc.isDirectorySelectionEnabled()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            setFileName(fileNameString(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    private void doSelectedFilesChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        File[] files = (File[]) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        if (files != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            && files.length > 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            && (files.length > 1 || fc.isDirectorySelectionEnabled() || !files[0].isDirectory())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            setFileName(fileNameString(files));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    private void doDirectoryChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        FileSystemView fsv = fc.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        clearIconCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        File currentDirectory = fc.getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        if(currentDirectory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            directoryComboBoxModel.addItem(currentDirectory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                if (fsv.isFileSystem(currentDirectory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                    setFileName(currentDirectory.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                    setFileName(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    private void doFilterChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        clearIconCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    private void doFileSelectionModeChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        if (fileNameLabel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            populateFileNameLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        clearIconCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        File currentDirectory = fc.getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        if (currentDirectory != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            && fc.isDirectorySelectionEnabled()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            && !fc.isFileSelectionEnabled()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            && fc.getFileSystemView().isFileSystem(currentDirectory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            setFileName(currentDirectory.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            setFileName(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    private void doAccessoryChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        if(getAccessoryPanel() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            if(e.getOldValue() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                getAccessoryPanel().remove((JComponent) e.getOldValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            JComponent accessory = (JComponent) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            if(accessory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                getAccessoryPanel().add(accessory, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    private void doApproveButtonTextChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        approveButton.setText(getApproveButtonText(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        approveButton.setMnemonic(getApproveButtonMnemonic(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    private void doDialogTypeChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        approveButton.setText(getApproveButtonText(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        approveButton.setMnemonic(getApproveButtonMnemonic(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        if (chooser.getDialogType() == JFileChooser.SAVE_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            lookInLabel.setText(saveInLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            lookInLabel.setText(lookInLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    private void doApproveButtonMnemonicChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        approveButton.setMnemonic(getApproveButtonMnemonic(getFileChooser()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    private void doControlButtonsChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        if(getFileChooser().getControlButtonsAreShown()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            addControlButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            removeControlButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * Listen for filechooser property changes, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * the selected file changing, or the type of the dialog changing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    public PropertyChangeListener createPropertyChangeListener(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        return new PropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                String s = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                if(s.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                    doSelectedFileChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                } else if (s.equals(JFileChooser.SELECTED_FILES_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                    doSelectedFilesChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                } else if(s.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                    doDirectoryChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                } else if(s.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                    doFilterChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                } else if(s.equals(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                    doFileSelectionModeChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                } else if(s.equals(JFileChooser.ACCESSORY_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                    doAccessoryChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                } else if (s.equals(JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                           s.equals(JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                    doApproveButtonTextChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                } else if(s.equals(JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                    doDialogTypeChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                } else if(s.equals(JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                    doApproveButtonMnemonicChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                } else if(s.equals(JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                    doControlButtonsChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                } else if (s == "FileChooser.useShellFolder") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                    updateUseShellFolder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                    doDirectoryChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                } else if (s.equals("componentOrientation")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                    ComponentOrientation o = (ComponentOrientation)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    JFileChooser cc = (JFileChooser)e.getSource();
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   837
                    if (o != e.getOldValue()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                        cc.applyComponentOrientation(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                } else if (s.equals("ancestor")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                    if (e.getOldValue() == null && e.getNewValue() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                        // Ancestor was added, set initial focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                        filenameTextField.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                        filenameTextField.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    protected void removeControlButtons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        getBottomPanel().remove(getButtonPanel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    protected void addControlButtons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        getBottomPanel().add(getButtonPanel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    public void ensureFileIsVisible(JFileChooser fc, File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        filePane.ensureFileIsVisible(fc, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    public void rescanCurrentDirectory(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        filePane.rescanCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    public String getFileName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        if(filenameTextField != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            return filenameTextField.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    public void setFileName(String filename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        if(filenameTextField != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            filenameTextField.setText(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * Property to remember whether a directory is currently selected in the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * This is normally called by the UI on a selection event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @param directorySelected if a directory is currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    protected void setDirectorySelected(boolean directorySelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        super.setDirectorySelected(directorySelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        if(directorySelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            approveButton.setText(directoryOpenButtonText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            approveButton.setToolTipText(directoryOpenButtonToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            approveButton.setMnemonic(directoryOpenButtonMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            approveButton.setText(getApproveButtonText(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            approveButton.setMnemonic(getApproveButtonMnemonic(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    public String getDirectoryName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        // PENDING(jeff) - get the name from the directory combobox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    public void setDirectoryName(String dirname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        // PENDING(jeff) - set the name in the directory combobox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        return new DirectoryComboBoxRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
3751
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   916
    private static JButton createToolButton(Action a, Icon defaultIcon, String toolTipText, String accessibleName) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   917
        final JButton result = new JButton(a);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   918
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   919
        result.setText(null);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   920
        result.setIcon(defaultIcon);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   921
        result.setToolTipText(toolTipText);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   922
        result.setRequestFocusEnabled(false);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   923
        result.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, accessibleName);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   924
        result.putClientProperty(WindowsLookAndFeel.HI_RES_DISABLED_ICON_CLIENT_KEY, Boolean.TRUE);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   925
        result.setAlignmentX(JComponent.LEFT_ALIGNMENT);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   926
        result.setAlignmentY(JComponent.CENTER_ALIGNMENT);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   927
        result.setMargin(shrinkwrap);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   928
        result.setFocusPainted(false);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   929
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   930
        result.setModel(new DefaultButtonModel() {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   931
            public void setPressed(boolean b) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   932
                // Forbid keyboard actions if the button is not in rollover state
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   933
                if (!b || isRollover()) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   934
                    super.setPressed(b);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   935
                }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   936
            }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   937
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   938
            public void setRollover(boolean b) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   939
                if (b && !isRollover()) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   940
                    // Reset other buttons
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   941
                    for (Component component : result.getParent().getComponents()) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   942
                        if (component instanceof JButton && component != result) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   943
                            ((JButton) component).getModel().setRollover(false);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   944
                        }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   945
                    }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   946
                }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   947
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   948
                super.setRollover(b);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   949
            }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   950
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   951
            public void setSelected(boolean b) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   952
                super.setSelected(b);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   953
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   954
                if (b) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   955
                    stateMask |= PRESSED | ARMED;
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   956
                } else {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   957
                    stateMask &= ~(PRESSED | ARMED);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   958
                }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   959
            }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   960
        });
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   961
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   962
        result.addFocusListener(new FocusAdapter() {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   963
            public void focusGained(FocusEvent e) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   964
                result.getModel().setRollover(true);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   965
            }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   966
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   967
            public void focusLost(FocusEvent e) {
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   968
                result.getModel().setRollover(false);
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   969
            }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   970
        });
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   971
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   972
        return result;
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   973
    }
8b0ac086b7c0 6589634: Unable to view focus on "Up one level", "create new folder" etc. of JFileChooser Dialog
rupashka
parents: 2491
diff changeset
   974
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    // Renderer for DirectoryComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    class DirectoryComboBoxRenderer extends DefaultListCellRenderer  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        IndentIcon ii = new IndentIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        public Component getListCellRendererComponent(JList list, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                                                      int index, boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                                                      boolean cellHasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            File directory = (File)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            setText(getFileChooser().getName(directory));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            Icon icon = getFileChooser().getIcon(directory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            ii.icon = icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            ii.depth = directoryComboBoxModel.getDepth(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            setIcon(ii);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            return this;
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
    final static int space = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    class IndentIcon implements Icon {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        Icon icon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        int depth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            if (c.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                icon.paintIcon(c, g, x+depth*space, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                icon.paintIcon(c, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        public int getIconWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            return icon.getIconWidth() + depth*space;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        public int getIconHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            return icon.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    // DataModel for DirectoryComboxbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    protected DirectoryComboBoxModel createDirectoryComboBoxModel(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        return new DirectoryComboBoxModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * Data model for a type-face selection combo-box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    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
  1036
        Vector<File> directories = new Vector<File>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        int[] depths = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        File selectedDirectory = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        FileSystemView fsv = chooser.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        public DirectoryComboBoxModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            // Add the current directory to the model, and make it the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            // selectedDirectory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            File dir = getFileChooser().getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            if(dir != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                addItem(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
         * Adds the directory to the model and sets it to be selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
         * additionally clears out the previous selected directory and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
         * the paths leading up to it, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        private void addItem(File directory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            if(directory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
1842
824c7f885a64 6776856: Code with useShellFolder field shuold be simplify
rupashka
parents: 1290
diff changeset
  1062
            boolean useShellFolder = FilePane.usesShellFolder(chooser);
824c7f885a64 6776856: Code with useShellFolder field shuold be simplify
rupashka
parents: 1290
diff changeset
  1063
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            directories.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            File[] baseFolders;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            if (useShellFolder) {
2491
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
  1068
                baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() {
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
  1069
                    public File[] run() {
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
  1070
                        return (File[]) ShellFolder.get("fileChooserComboBoxFolders");
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
  1071
                    }
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
  1072
                });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                baseFolders = fsv.getRoots();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            directories.addAll(Arrays.asList(baseFolders));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            // Get the canonical (full) path. This has the side
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            // benefit of removing extraneous chars from the path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            // 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
  1081
            File canonical;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                canonical = directory.getCanonicalFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                // Maybe drive is not ready. Can't abort here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                canonical = directory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            // create File instances of each directory leading up to the top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                File sf = useShellFolder ? ShellFolder.getShellFolder(canonical)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                                         : canonical;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                File f = sf;
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  1094
                Vector<File> path = new Vector<File>(10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                    path.addElement(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                } while ((f = f.getParentFile()) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                int pathCount = path.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                // Insert chain at appropriate place in vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                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
  1102
                    f = path.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                    if (directories.contains(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                        int topIndex = directories.indexOf(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                        for (int j = i-1; j >= 0; j--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                            directories.insertElementAt(path.get(j), topIndex+i-j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                calculateDepths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                setSelectedItem(sf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            } catch (FileNotFoundException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                calculateDepths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        private void calculateDepths() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            depths = new int[directories.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            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
  1121
                File dir = directories.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                File parent = dir.getParentFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                depths[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                    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
  1126
                        if (parent.equals(directories.get(j))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                            depths[i] = depths[j] + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        public int getDepth(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        public void setSelectedItem(Object selectedDirectory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            this.selectedDirectory = (File)selectedDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            fireContentsChanged(this, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        public Object getSelectedItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            return selectedDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        public int getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            return directories.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        public Object getElementAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            return directories.elementAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    // Renderer for Types ComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        return new FilterComboBoxRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * Render different type sizes and styles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    public class FilterComboBoxRenderer extends DefaultListCellRenderer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        public Component getListCellRendererComponent(JList list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            Object value, int index, boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            boolean cellHasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            if (value != null && value instanceof FileFilter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                setText(((FileFilter)value).getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    // DataModel for Types Comboxbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    protected FilterComboBoxModel createFilterComboBoxModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        return new FilterComboBoxModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * Data model for a type-face selection combo-box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    protected class FilterComboBoxModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        protected FileFilter[] filters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        protected FilterComboBoxModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            filters = getFileChooser().getChoosableFileFilters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            String prop = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                filters = (FileFilter[]) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                fireContentsChanged(this, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                fireContentsChanged(this, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        public void setSelectedItem(Object filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            if(filter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                getFileChooser().setFileFilter((FileFilter) filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                fireContentsChanged(this, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        public Object getSelectedItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            // Ensure that the current filter is in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            // NOTE: we shouldnt' have to do this, since JFileChooser adds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            // the filter to the choosable filters list when the filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            // is set. Lets be paranoid just in case someone overrides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            // setFileFilter in JFileChooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            FileFilter currentFilter = getFileChooser().getFileFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            if(currentFilter != null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  1225
                for (FileFilter filter : filters) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  1226
                    if (filter == currentFilter) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                        found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                if(found == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                    getFileChooser().addChoosableFileFilter(currentFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            return getFileChooser().getFileFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        public int getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
            if(filters != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                return filters.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        public Object getElementAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            if(index > getSize() - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                // This shouldn't happen. Try to recover gracefully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                return getFileChooser().getFileFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            if(filters != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                return filters[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
    public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        File f = fc.getSelectedFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            setFileName(fileNameString(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * Acts when DirectoryComboBox has changed the selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    protected class DirectoryComboBoxAction implements ActionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            File f = (File)directoryComboBox.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            getFileChooser().setCurrentDirectory(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    protected JButton getApproveButton(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        return approveButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    public FileView getFileView(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        return fileView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    // ***********************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    // * FileView operations *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    // ***********************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    protected class WindowsFileView extends BasicFileView {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        /* FileView type descriptions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        public Icon getIcon(File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            Icon icon = getCachedIcon(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            if (f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                icon = getFileChooser().getFileSystemView().getSystemIcon(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            if (icon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                icon = super.getIcon(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            cacheIcon(f, icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
}