jdk/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java
author yan
Mon, 30 Jun 2014 16:32:36 +0400
changeset 25178 dbab904451e9
parent 24969 afa6934dd8e8
child 25565 ce603b34c98d
permissions -rw-r--r--
8046434: Fix doclint warnings from javax.swing.plaf.metal package Reviewed-by: alexsch Contributed-by: Andrei Eremeev <andrei.eremeev@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
     2
 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2491
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2491
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2491
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2491
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2491
diff changeset
    23
 * questions.
2
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 javax.swing.plaf.metal;
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.EmptyBorder;
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.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.*;
2491
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
    41
import java.security.AccessController;
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
    42
import java.security.PrivilegedAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.accessibility.*;
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
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 20100
diff changeset
    49
 * Metal L&amp;F implementation of a FileChooser.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class MetalFileChooserUI extends BasicFileChooserUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // Much of the Metal UI for JFilechooser is just a copy of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    // the windows implementation, but using Metal themed buttons, lists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // icons, etc. We are planning a complete rewrite, and hence we've
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // made most things in this class private.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private JLabel lookInLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private JComboBox directoryComboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private DirectoryComboBoxModel directoryComboBoxModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private Action directoryComboBoxAction = new DirectoryComboBoxAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private FilterComboBoxModel filterComboBoxModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private JTextField fileNameTextField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private FilePane filePane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private JToggleButton listViewButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private JToggleButton detailsViewButton;
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 hstrut5 = new Dimension(5, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final Dimension hstrut11 = new Dimension(11, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static final Dimension vstrut5  = new Dimension(1, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static final Insets shrinkwrap = new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // Preferred and Minimum sizes for the dialog box
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static int PREF_WIDTH = 500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static int PREF_HEIGHT = 326;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private static Dimension PREF_SIZE = new Dimension(PREF_WIDTH, PREF_HEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static int MIN_WIDTH = 500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private static int MIN_HEIGHT = 326;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static Dimension MIN_SIZE = new Dimension(MIN_WIDTH, MIN_HEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static int LIST_PREF_WIDTH = 405;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static int LIST_PREF_HEIGHT = 135;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static Dimension LIST_PREF_SIZE = new Dimension(LIST_PREF_WIDTH, LIST_PREF_HEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    // Labels, mnemonics, and tooltips (oh my!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private int    lookInLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private String lookInLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private String saveInLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private int    fileNameLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private String fileNameLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private int    folderNameLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private String folderNameLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private int    filesOfTypeLabelMnemonic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private String filesOfTypeLabelText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private String upFolderToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private String upFolderAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private String homeFolderToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private String homeFolderAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private String newFolderToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private String newFolderAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private String listViewButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private String listViewButtonAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private String detailsViewButtonToolTipText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private String detailsViewButtonAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private AlignedLabel fileNameLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private void populateFileNameLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (getFileChooser().getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            fileNameLabel.setText(folderNameLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            fileNameLabel.setDisplayedMnemonic(folderNameLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            fileNameLabel.setText(fileNameLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            fileNameLabel.setDisplayedMnemonic(fileNameLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   141
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   142
     * Constructs a new instance of {@code MetalFileChooserUI}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   143
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   144
     * @param c a component
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   145
     * @return a new instance of {@code MetalFileChooserUI}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   146
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return new MetalFileChooserUI((JFileChooser) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   151
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   152
     * Constructs a new instance of {@code MetalFileChooserUI}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   153
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   154
     * @param filechooser a {@code JFileChooser}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   155
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public MetalFileChooserUI(JFileChooser filechooser) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        super(filechooser);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        super.installUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public void uninstallComponents(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        fc.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        bottomPanel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        buttonPanel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    private class MetalFileChooserUIAccessor implements FilePane.FileChooserUIAccessor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        public JFileChooser getFileChooser() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            return MetalFileChooserUI.this.getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        public BasicDirectoryModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return MetalFileChooserUI.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        public JPanel createList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            return MetalFileChooserUI.this.createList(getFileChooser());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        public JPanel createDetailsView() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            return MetalFileChooserUI.this.createDetailsView(getFileChooser());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        public boolean isDirectorySelected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            return MetalFileChooserUI.this.isDirectorySelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        public File getDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return MetalFileChooserUI.this.getDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        public Action getChangeToParentDirectoryAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return MetalFileChooserUI.this.getChangeToParentDirectoryAction();
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 Action getApproveSelectionAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            return MetalFileChooserUI.this.getApproveSelectionAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        public Action getNewFolderAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return MetalFileChooserUI.this.getNewFolderAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        public MouseListener createDoubleClickListener(JList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return MetalFileChooserUI.this.createDoubleClickListener(getFileChooser(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                                                     list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        public ListSelectionListener createListSelectionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            return MetalFileChooserUI.this.createListSelectionListener(getFileChooser());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public void installComponents(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        FileSystemView fsv = fc.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        fc.setBorder(new EmptyBorder(12, 12, 11, 11));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        fc.setLayout(new BorderLayout(0, 11));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        filePane = new FilePane(new MetalFileChooserUIAccessor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        fc.addPropertyChangeListener(filePane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        // ********************************* //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        // **** Construct the top panel **** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        // ********************************* //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        // Directory manipulation buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        JPanel topPanel = new JPanel(new BorderLayout(11, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        JPanel topButtonPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        topButtonPanel.setLayout(new BoxLayout(topButtonPanel, BoxLayout.LINE_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        topPanel.add(topButtonPanel, BorderLayout.AFTER_LINE_ENDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        // Add the top panel to the fileChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        fc.add(topPanel, BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // ComboBox Label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        lookInLabel = new JLabel(lookInLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        topPanel.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        // CurrentDir ComboBox
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
   245
        @SuppressWarnings("serial") // anonymous class
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
   246
        JComboBox tmp1 = new JComboBox() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                Dimension d = super.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                // Must be small enough to not affect total width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                d.width = 150;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        };
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
   254
        directoryComboBox = tmp1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        directoryComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                            lookInLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        directoryComboBox.putClientProperty( "JComboBox.isTableCellEditor", Boolean.TRUE );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        lookInLabel.setLabelFor(directoryComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        directoryComboBoxModel = createDirectoryComboBoxModel(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        directoryComboBox.setModel(directoryComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        directoryComboBox.addActionListener(directoryComboBoxAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        directoryComboBox.setAlignmentY(JComponent.TOP_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        directoryComboBox.setMaximumRowCount(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        topPanel.add(directoryComboBox, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        // Up Button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        JButton upFolderButton = new JButton(getChangeToParentDirectoryAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        upFolderButton.setText(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        upFolderButton.setIcon(upFolderIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        upFolderButton.setToolTipText(upFolderToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        upFolderButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                         upFolderAccessibleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        upFolderButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        upFolderButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        upFolderButton.setMargin(shrinkwrap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        topButtonPanel.add(upFolderButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        topButtonPanel.add(Box.createRigidArea(hstrut5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        // Home Button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        File homeDir = fsv.getHomeDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        String toolTipText = homeFolderToolTipText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (fsv.isRoot(homeDir)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            toolTipText = getFileView(fc).getName(homeDir); // Probably "Desktop".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        JButton b = new JButton(homeFolderIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        b.setToolTipText(toolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        b.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                            homeFolderAccessibleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        b.setMargin(shrinkwrap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        b.addActionListener(getGoHomeAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        topButtonPanel.add(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        topButtonPanel.add(Box.createRigidArea(hstrut5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        // New Directory Button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if (!UIManager.getBoolean("FileChooser.readOnly")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            b = new JButton(filePane.getNewFolderAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            b.setText(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            b.setIcon(newFolderIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            b.setToolTipText(newFolderToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            b.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                                newFolderAccessibleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            b.setMargin(shrinkwrap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        topButtonPanel.add(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        topButtonPanel.add(Box.createRigidArea(hstrut5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        // View button group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        ButtonGroup viewButtonGroup = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        // List Button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        listViewButton = new JToggleButton(listViewIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        listViewButton.setToolTipText(listViewButtonToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        listViewButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                                         listViewButtonAccessibleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        listViewButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        listViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        listViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        listViewButton.setMargin(shrinkwrap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        listViewButton.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_LIST));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        topButtonPanel.add(listViewButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        viewButtonGroup.add(listViewButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        // Details Button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        detailsViewButton = new JToggleButton(detailsViewIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        detailsViewButton.setToolTipText(detailsViewButtonToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        detailsViewButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                                            detailsViewButtonAccessibleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        detailsViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        detailsViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        detailsViewButton.setMargin(shrinkwrap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        detailsViewButton.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        topButtonPanel.add(detailsViewButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        viewButtonGroup.add(detailsViewButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        filePane.addPropertyChangeListener(new PropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                if ("viewType".equals(e.getPropertyName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    int viewType = filePane.getViewType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                    switch (viewType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                      case FilePane.VIEWTYPE_LIST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                        listViewButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                      case FilePane.VIEWTYPE_DETAILS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                        detailsViewButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        // ************************************** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        // ******* Add the directory pane ******* //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        // ************************************** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        fc.add(getAccessoryPanel(), BorderLayout.AFTER_LINE_ENDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        JComponent accessory = fc.getAccessory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if(accessory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            getAccessoryPanel().add(accessory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        filePane.setPreferredSize(LIST_PREF_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        fc.add(filePane, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        // ********************************** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        // **** Construct the bottom panel ** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        // ********************************** //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        JPanel bottomPanel = getBottomPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        fc.add(bottomPanel, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        // FileName label and textfield
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        JPanel fileNamePanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        fileNamePanel.setLayout(new BoxLayout(fileNamePanel, BoxLayout.LINE_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        bottomPanel.add(fileNamePanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        bottomPanel.add(Box.createRigidArea(vstrut5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        fileNameLabel = new AlignedLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        populateFileNameLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        fileNamePanel.add(fileNameLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
   393
        @SuppressWarnings("serial") // anonymous class
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
   394
        JTextField tmp2 = new JTextField(35) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        };
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
   399
        fileNameTextField = tmp2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        fileNamePanel.add(fileNameTextField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        fileNameLabel.setLabelFor(fileNameTextField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        fileNameTextField.addFocusListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            new FocusAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    if (!getFileChooser().isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                        filePane.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if (fc.isMultiSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            setFileName(fileNameString(fc.getSelectedFiles()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            setFileName(fileNameString(fc.getSelectedFile()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        // Filetype label and combobox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        JPanel filesOfTypePanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        filesOfTypePanel.setLayout(new BoxLayout(filesOfTypePanel, BoxLayout.LINE_AXIS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        bottomPanel.add(filesOfTypePanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        AlignedLabel filesOfTypeLabel = new AlignedLabel(filesOfTypeLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        filesOfTypeLabel.setDisplayedMnemonic(filesOfTypeLabelMnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        filesOfTypePanel.add(filesOfTypeLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        filterComboBoxModel = createFilterComboBoxModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        fc.addPropertyChangeListener(filterComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        filterComboBox = new JComboBox(filterComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        filterComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                                         filesOfTypeLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        filesOfTypeLabel.setLabelFor(filterComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        filterComboBox.setRenderer(createFilterComboBoxRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        filesOfTypePanel.add(filterComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        // buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        getButtonPanel().setLayout(new ButtonAreaLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        approveButton = new JButton(getApproveButtonText(fc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        // Note: Metal does not use mnemonics for approve and cancel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        approveButton.addActionListener(getApproveSelectionAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        approveButton.setToolTipText(getApproveButtonToolTipText(fc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        getButtonPanel().add(approveButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        cancelButton = new JButton(cancelButtonText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        cancelButton.setToolTipText(cancelButtonToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        cancelButton.addActionListener(getCancelSelectionAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        getButtonPanel().add(cancelButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if(fc.getControlButtonsAreShown()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            addControlButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        groupLabels(new AlignedLabel[] { fileNameLabel, filesOfTypeLabel });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   457
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   458
     * Returns the button panel.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   459
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   460
     * @return the button panel
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   461
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    protected JPanel getButtonPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        if (buttonPanel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            buttonPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return buttonPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   469
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   470
     * Returns the bottom panel.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   471
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   472
     * @return the bottom panel
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   473
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    protected JPanel getBottomPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        if(bottomPanel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            bottomPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        return bottomPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    protected void installStrings(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        super.installStrings(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        Locale l = fc.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
10413
5bd4f81b6d45 7024118: possible hardcoded mnemonic for JFileChooser metal and motif l&f
rupashka
parents: 9665
diff changeset
   486
        lookInLabelMnemonic = getMnemonic("FileChooser.lookInLabelMnemonic", l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        lookInLabelText = UIManager.getString("FileChooser.lookInLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        saveInLabelText = UIManager.getString("FileChooser.saveInLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
10413
5bd4f81b6d45 7024118: possible hardcoded mnemonic for JFileChooser metal and motif l&f
rupashka
parents: 9665
diff changeset
   490
        fileNameLabelMnemonic = getMnemonic("FileChooser.fileNameLabelMnemonic", l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText",l);
10413
5bd4f81b6d45 7024118: possible hardcoded mnemonic for JFileChooser metal and motif l&f
rupashka
parents: 9665
diff changeset
   492
        folderNameLabelMnemonic = getMnemonic("FileChooser.folderNameLabelMnemonic", l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        folderNameLabelText = UIManager.getString("FileChooser.folderNameLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
10413
5bd4f81b6d45 7024118: possible hardcoded mnemonic for JFileChooser metal and motif l&f
rupashka
parents: 9665
diff changeset
   495
        filesOfTypeLabelMnemonic = getMnemonic("FileChooser.filesOfTypeLabelMnemonic", l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        filesOfTypeLabelText = UIManager.getString("FileChooser.filesOfTypeLabelText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        upFolderToolTipText =  UIManager.getString("FileChooser.upFolderToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        upFolderAccessibleName = UIManager.getString("FileChooser.upFolderAccessibleName",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        homeFolderToolTipText =  UIManager.getString("FileChooser.homeFolderToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        homeFolderAccessibleName = UIManager.getString("FileChooser.homeFolderAccessibleName",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        newFolderToolTipText = UIManager.getString("FileChooser.newFolderToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        newFolderAccessibleName = UIManager.getString("FileChooser.newFolderAccessibleName",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        listViewButtonToolTipText = UIManager.getString("FileChooser.listViewButtonToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        listViewButtonAccessibleName = UIManager.getString("FileChooser.listViewButtonAccessibleName",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        detailsViewButtonToolTipText = UIManager.getString("FileChooser.detailsViewButtonToolTipText",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        detailsViewButtonAccessibleName = UIManager.getString("FileChooser.detailsViewButtonAccessibleName",l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
10413
5bd4f81b6d45 7024118: possible hardcoded mnemonic for JFileChooser metal and motif l&f
rupashka
parents: 9665
diff changeset
   514
    private Integer getMnemonic(String key, Locale l) {
5bd4f81b6d45 7024118: possible hardcoded mnemonic for JFileChooser metal and motif l&f
rupashka
parents: 9665
diff changeset
   515
        return SwingUtilities2.getUIDefaultsInt(key, l);
5bd4f81b6d45 7024118: possible hardcoded mnemonic for JFileChooser metal and motif l&f
rupashka
parents: 9665
diff changeset
   516
    }
5bd4f81b6d45 7024118: possible hardcoded mnemonic for JFileChooser metal and motif l&f
rupashka
parents: 9665
diff changeset
   517
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    protected void installListeners(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        super.installListeners(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        ActionMap actionMap = getActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        SwingUtilities.replaceUIActionMap(fc, actionMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   524
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   525
     * Returns an instance of {@code ActionMap}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   526
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   527
     * @return an instance of {@code ActionMap}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   528
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    protected ActionMap getActionMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        return createActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   533
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   534
     * Constructs an instance of {@code ActionMap}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   535
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   536
     * @return an instance of {@code ActionMap}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   537
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    protected ActionMap createActionMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        ActionMap map = new ActionMapUIResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        FilePane.addActionsToMap(map, filePane.getActions());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   544
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   545
     * Constructs a details view.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   546
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   547
     * @param fc a {@code JFileChooser}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   548
     * @return the list
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   549
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    protected JPanel createList(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        return filePane.createList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   554
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   555
     * Constructs a details view.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   556
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   557
     * @param fc a {@code JFileChooser}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   558
     * @return the details view
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   559
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    protected JPanel createDetailsView(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return filePane.createDetailsView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * Creates a selection listener for the list of files and directories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @param fc a <code>JFileChooser</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @return a <code>ListSelectionListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    public ListSelectionListener createListSelectionListener(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        return super.createListSelectionListener(fc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    // Obsolete class, not used in this version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    protected class SingleClickListener extends MouseAdapter {
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   576
        /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   577
         * Constructs an instance of {@code SingleClickListener}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   578
         *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   579
         * @param list an instance of {@code JList}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   580
         */
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   581
        public SingleClickListener(JList list) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    // Obsolete class, not used in this version.
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
   586
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    protected class FileRenderer extends DefaultListCellRenderer  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        // Remove listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        c.removePropertyChangeListener(filterComboBoxModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        c.removePropertyChangeListener(filePane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        cancelButton.removeActionListener(getCancelSelectionAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        approveButton.removeActionListener(getApproveSelectionAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        fileNameTextField.removeActionListener(getApproveSelectionAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        if (filePane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            filePane.uninstallUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            filePane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        super.uninstallUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * Returns the preferred size of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * <code>JFileChooser</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * The preferred size is at least as large,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * in both height and width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * as the preferred size recommended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * by the file chooser's layout manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @param c  a <code>JFileChooser</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @return   a <code>Dimension</code> specifying the preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *           width and height of the file chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        int prefWidth = PREF_SIZE.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        Dimension d = c.getLayout().preferredLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        if (d != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            return new Dimension(d.width < prefWidth ? prefWidth : d.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                                 d.height < PREF_SIZE.height ? PREF_SIZE.height : d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            return new Dimension(prefWidth, PREF_SIZE.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * Returns the minimum size of the <code>JFileChooser</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * @param c  a <code>JFileChooser</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * @return   a <code>Dimension</code> specifying the minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     *           width and height of the file chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        return MIN_SIZE;
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
     * Returns the maximum size of the <code>JFileChooser</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * @param c  a <code>JFileChooser</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @return   a <code>Dimension</code> specifying the maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *           width and height of the file chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    private String fileNameString(File file) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if (file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            if ((fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                (fc.isDirectorySelectionEnabled() && fc.isFileSelectionEnabled() && fc.getFileSystemView().isFileSystemRoot(file))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                return file.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                return file.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    private String fileNameString(File[] files) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
   666
        StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        for (int i = 0; files != null && i < files.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            if (i > 0) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
   669
                sb.append(" ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            if (files.length > 1) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
   672
                sb.append("\"");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            }
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
   674
            sb.append(fileNameString(files[i]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            if (files.length > 1) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
   676
                sb.append("\"");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        }
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
   679
        return sb.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    /* The following methods are used by the PropertyChange Listener */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    private void doSelectedFileChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        File f = (File) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        if (f != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            && ((fc.isFileSelectionEnabled() && !f.isDirectory())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                || (f.isDirectory() && fc.isDirectorySelectionEnabled()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            setFileName(fileNameString(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    private void doSelectedFilesChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        File[] files = (File[]) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        if (files != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            && files.length > 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            && (files.length > 1 || fc.isDirectorySelectionEnabled() || !files[0].isDirectory())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            setFileName(fileNameString(files));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    private void doDirectoryChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        FileSystemView fsv = fc.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        clearIconCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        File currentDirectory = fc.getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        if(currentDirectory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            directoryComboBoxModel.addItem(currentDirectory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                if (fsv.isFileSystem(currentDirectory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                    setFileName(currentDirectory.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                    setFileName(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    private void doFilterChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        clearIconCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    private void doFileSelectionModeChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        if (fileNameLabel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            populateFileNameLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        clearIconCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        File currentDirectory = fc.getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        if (currentDirectory != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            && fc.isDirectorySelectionEnabled()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            && !fc.isFileSelectionEnabled()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            && fc.getFileSystemView().isFileSystem(currentDirectory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            setFileName(currentDirectory.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            setFileName(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    private void doAccessoryChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        if(getAccessoryPanel() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            if(e.getOldValue() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                getAccessoryPanel().remove((JComponent) e.getOldValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            JComponent accessory = (JComponent) e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            if(accessory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                getAccessoryPanel().add(accessory, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    private void doApproveButtonTextChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        approveButton.setText(getApproveButtonText(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    private void doDialogTypeChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        approveButton.setText(getApproveButtonText(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        if (chooser.getDialogType() == JFileChooser.SAVE_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            lookInLabel.setText(saveInLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            lookInLabel.setText(lookInLabelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    private void doApproveButtonMnemonicChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        // Note: Metal does not use mnemonics for approve and cancel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    private void doControlButtonsChanged(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        if(getFileChooser().getControlButtonsAreShown()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            addControlButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            removeControlButtons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * Listen for filechooser property changes, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * the selected file changing, or the type of the dialog changing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    public PropertyChangeListener createPropertyChangeListener(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        return new PropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                String s = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                if(s.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                    doSelectedFileChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                } else if (s.equals(JFileChooser.SELECTED_FILES_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                    doSelectedFilesChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                } else if(s.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                    doDirectoryChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                } else if(s.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                    doFilterChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                } else if(s.equals(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    doFileSelectionModeChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                } else if(s.equals(JFileChooser.ACCESSORY_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                    doAccessoryChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                } else if (s.equals(JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                           s.equals(JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                    doApproveButtonTextChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                } else if(s.equals(JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                    doDialogTypeChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                } else if(s.equals(JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                    doApproveButtonMnemonicChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                } else if(s.equals(JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                    doControlButtonsChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                } else if (s.equals("componentOrientation")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                    ComponentOrientation o = (ComponentOrientation)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                    JFileChooser cc = (JFileChooser)e.getSource();
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   820
                    if (o != e.getOldValue()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                        cc.applyComponentOrientation(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                } else if (s == "FileChooser.useShellFolder") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                    doDirectoryChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                } else if (s.equals("ancestor")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                    if (e.getOldValue() == null && e.getNewValue() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                        // Ancestor was added, set initial focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                        fileNameTextField.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                        fileNameTextField.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   836
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   837
     * Removes control buttons from bottom panel.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   838
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    protected void removeControlButtons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        getBottomPanel().remove(getButtonPanel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   843
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   844
     * Adds control buttons to bottom panel.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   845
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    protected void addControlButtons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        getBottomPanel().add(getButtonPanel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    public void ensureFileIsVisible(JFileChooser fc, File f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        filePane.ensureFileIsVisible(fc, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    public void rescanCurrentDirectory(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        filePane.rescanCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    public String getFileName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        if (fileNameTextField != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            return fileNameTextField.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    public void setFileName(String filename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        if (fileNameTextField != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            fileNameTextField.setText(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * Property to remember whether a directory is currently selected in the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * This is normally called by the UI on a selection event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * @param directorySelected if a directory is currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    protected void setDirectorySelected(boolean directorySelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        super.setDirectorySelected(directorySelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        if(directorySelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            if (approveButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                approveButton.setText(directoryOpenButtonText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                approveButton.setToolTipText(directoryOpenButtonToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            if (approveButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                approveButton.setText(getApproveButtonText(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   895
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   896
     * Returns the directory name.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   897
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   898
     * @return the directory name
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   899
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    public String getDirectoryName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        // PENDING(jeff) - get the name from the directory combobox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   905
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   906
     * Sets the directory name.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   907
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   908
     * @param dirname the directory name
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   909
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    public void setDirectoryName(String dirname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        // PENDING(jeff) - set the name in the directory combobox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   914
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   915
     * Constructs a new instance of {@code DirectoryComboBoxRenderer}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   916
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   917
     * @param fc a {@code JFileChooser}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   918
     * @return a new instance of {@code DirectoryComboBoxRenderer}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   919
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        return new DirectoryComboBoxRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    // Renderer for DirectoryComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    //
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
   927
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    class DirectoryComboBoxRenderer extends DefaultListCellRenderer  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        IndentIcon ii = new IndentIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        public Component getListCellRendererComponent(JList list, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                                                      int index, boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                                                      boolean cellHasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            File directory = (File)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            setText(getFileChooser().getName(directory));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            Icon icon = getFileChooser().getIcon(directory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            ii.icon = icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            ii.depth = directoryComboBoxModel.getDepth(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            setIcon(ii);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    final static int space = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    class IndentIcon implements Icon {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        Icon icon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        int depth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            if (c.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                icon.paintIcon(c, g, x+depth*space, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                icon.paintIcon(c, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        public int getIconWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            return icon.getIconWidth() + depth*space;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        public int getIconHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            return icon.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   975
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   976
     * Constructs a new instance of {@code DataModel} for {@code DirectoryComboBox}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   977
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   978
     * @param fc a {@code JFileChooser}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   979
     * @return a new instance of {@code DataModel} for {@code DirectoryComboBox}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   980
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    protected DirectoryComboBoxModel createDirectoryComboBoxModel(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        return new DirectoryComboBoxModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * Data model for a type-face selection combo-box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
   988
    @SuppressWarnings("serial") // Superclass is not serializable across versions
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
   989
    protected class DirectoryComboBoxModel extends AbstractListModel<Object> implements ComboBoxModel<Object> {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   990
        Vector<File> directories = new Vector<File>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        int[] depths = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        File selectedDirectory = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        JFileChooser chooser = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        FileSystemView fsv = chooser.getFileSystemView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   996
        /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   997
         * Constructs an instance of {@code DirectoryComboBoxModel}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
   998
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        public DirectoryComboBoxModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            // Add the current directory to the model, and make it the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            // selectedDirectory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            File dir = getFileChooser().getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            if(dir != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                addItem(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
         * Adds the directory to the model and sets it to be selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
         * additionally clears out the previous selected directory and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
         * the paths leading up to it, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        private void addItem(File directory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            if(directory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
1842
824c7f885a64 6776856: Code with useShellFolder field shuold be simplify
rupashka
parents: 1290
diff changeset
  1019
            boolean useShellFolder = FilePane.usesShellFolder(chooser);
824c7f885a64 6776856: Code with useShellFolder field shuold be simplify
rupashka
parents: 1290
diff changeset
  1020
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            directories.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            File[] baseFolders;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            if (useShellFolder) {
2491
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
  1025
                baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() {
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
  1026
                    public File[] run() {
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
  1027
                        return (File[]) ShellFolder.get("fileChooserComboBoxFolders");
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
  1028
                    }
123954ad0034 6738668: JFileChooser cannot be created under SecurityManager
rupashka
parents: 1853
diff changeset
  1029
                });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                baseFolders = fsv.getRoots();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            directories.addAll(Arrays.asList(baseFolders));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            // Get the canonical (full) path. This has the side
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            // benefit of removing extraneous chars from the path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            // 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
  1038
            File canonical;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                canonical = ShellFolder.getNormalizedFile(directory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                // Maybe drive is not ready. Can't abort here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                canonical = directory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            // create File instances of each directory leading up to the top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                File sf = useShellFolder ? ShellFolder.getShellFolder(canonical)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                                         : canonical;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                File f = sf;
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  1051
                Vector<File> path = new Vector<File>(10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                    path.addElement(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                } while ((f = f.getParentFile()) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                int pathCount = path.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                // Insert chain at appropriate place in vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                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
  1059
                    f = path.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                    if (directories.contains(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                        int topIndex = directories.indexOf(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                        for (int j = i-1; j >= 0; j--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                            directories.insertElementAt(path.get(j), topIndex+i-j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                calculateDepths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                setSelectedItem(sf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            } catch (FileNotFoundException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                calculateDepths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        private void calculateDepths() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            depths = new int[directories.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            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
  1078
                File dir = directories.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                File parent = dir.getParentFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                depths[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                    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
  1083
                        if (parent.equals(directories.get(j))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                            depths[i] = depths[j] + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1092
        /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1093
         * Returns the depth of {@code i}-th file.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1094
         *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1095
         * @param i an index
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1096
         * @return the depth of {@code i}-th file
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1097
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        public int getDepth(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        public void setSelectedItem(Object selectedDirectory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            this.selectedDirectory = (File)selectedDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            fireContentsChanged(this, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        public Object getSelectedItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            return selectedDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        public int getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            return directories.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        public Object getElementAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            return directories.elementAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1120
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1121
     * Constructs a {@code Renderer} for types {@code ComboBox}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1122
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1123
     * @return a {@code Renderer} for types {@code ComboBox}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1124
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        return new FilterComboBoxRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * Render different type sizes and styles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
  1132
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    public class FilterComboBoxRenderer extends DefaultListCellRenderer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        public Component getListCellRendererComponent(JList list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            Object value, int index, boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            boolean cellHasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            if (value != null && value instanceof FileFilter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                setText(((FileFilter)value).getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1148
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1149
     * Constructs a {@code DataModel} for types {@code ComboBox}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1150
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1151
     * @return a {@code DataModel} for types {@code ComboBox}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1152
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    protected FilterComboBoxModel createFilterComboBoxModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        return new FilterComboBoxModel();
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
     * Data model for a type-face selection combo-box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
  1160
    @SuppressWarnings("serial") // Same-version serialization only
23270
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1161
    protected class FilterComboBoxModel extends AbstractListModel<Object> implements ComboBoxModel<Object>, PropertyChangeListener {
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1162
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1163
        /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1164
         * An array of file filters.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1165
         */
23270
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1166
        protected FileFilter[] filters;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1167
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1168
        /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1169
         * Constructs an instance of {@code FilterComboBoxModel}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1170
         */
23270
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1171
        protected FilterComboBoxModel() {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1172
            super();
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1173
            filters = getFileChooser().getChoosableFileFilters();
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1174
        }
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1175
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1176
        public void propertyChange(PropertyChangeEvent e) {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1177
            String prop = e.getPropertyName();
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1178
            if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1179
                filters = (FileFilter[]) e.getNewValue();
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1180
                fireContentsChanged(this, -1, -1);
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1181
            } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1182
                fireContentsChanged(this, -1, -1);
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1183
            }
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1184
        }
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1185
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1186
        public void setSelectedItem(Object filter) {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1187
            if(filter != null) {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1188
                getFileChooser().setFileFilter((FileFilter) filter);
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1189
                fireContentsChanged(this, -1, -1);
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1190
            }
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1191
        }
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1192
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1193
        public Object getSelectedItem() {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1194
            // Ensure that the current filter is in the list.
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1195
            // NOTE: we shouldnt' have to do this, since JFileChooser adds
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1196
            // the filter to the choosable filters list when the filter
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1197
            // is set. Lets be paranoid just in case someone overrides
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1198
            // setFileFilter in JFileChooser.
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1199
            FileFilter currentFilter = getFileChooser().getFileFilter();
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1200
            boolean found = false;
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1201
            if(currentFilter != null) {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1202
                for (FileFilter filter : filters) {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1203
                    if (filter == currentFilter) {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1204
                        found = true;
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1205
                    }
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1206
                }
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1207
                if(found == false) {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1208
                    getFileChooser().addChoosableFileFilter(currentFilter);
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1209
                }
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1210
            }
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1211
            return getFileChooser().getFileFilter();
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1212
        }
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1213
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1214
        public int getSize() {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1215
            if(filters != null) {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1216
                return filters.length;
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1217
            } else {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1218
                return 0;
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1219
            }
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1220
        }
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1221
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1222
        public Object getElementAt(int index) {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1223
            if(index > getSize() - 1) {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1224
                // This shouldn't happen. Try to recover gracefully.
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1225
                return getFileChooser().getFileFilter();
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1226
            }
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1227
            if(filters != null) {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1228
                return filters[index];
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1229
            } else {
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1230
                return null;
b5073d208bbf 8032063: javax.swing.plaf.metal.MetalFileChooserUI$FilterComboBoxModel extends non-standard API
alexsch
parents: 20169
diff changeset
  1231
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1235
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1236
     * Invokes when {@code ListSelectionEvent} occurs.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1237
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1238
     * @param e an instance of {@code ListSelectionEvent}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1239
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
    public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        JFileChooser fc = getFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        File f = fc.getSelectedFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            setFileName(fileNameString(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * Acts when DirectoryComboBox has changed the selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
  1251
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    protected class DirectoryComboBoxAction extends AbstractAction {
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1253
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1254
        /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1255
         * Constructs a new instance of {@code DirectoryComboBoxAction}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24969
diff changeset
  1256
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        protected DirectoryComboBoxAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            super("DirectoryComboBoxAction");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            directoryComboBox.hidePopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            File f = (File)directoryComboBox.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            if (!getFileChooser().getCurrentDirectory().equals(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                getFileChooser().setCurrentDirectory(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    protected JButton getApproveButton(JFileChooser fc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        return approveButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * <code>ButtonAreaLayout</code> behaves in a similar manner to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * <code>FlowLayout</code>. It lays out all components from left to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * right, flushed right. The widths of all components will be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * to the largest preferred size width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    private static class ButtonAreaLayout implements LayoutManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        private int hGap = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        private int topMargin = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        public void addLayoutComponent(String string, Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        public void layoutContainer(Container container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
            Component[] children = container.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            if (children != null && children.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                int         numChildren = children.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                Dimension[] sizes = new Dimension[numChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                Insets      insets = container.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                int         yLocation = insets.top + topMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                int         maxWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                for (int counter = 0; counter < numChildren; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                    sizes[counter] = children[counter].getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                    maxWidth = Math.max(maxWidth, sizes[counter].width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                int xLocation, xOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                if (container.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                    xLocation = container.getSize().width - insets.left - maxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                    xOffset = hGap + maxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                    xLocation = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                    xOffset = -(hGap + maxWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                for (int counter = numChildren - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                    children[counter].setBounds(xLocation, yLocation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                                                maxWidth, sizes[counter].height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                    xLocation -= xOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        public Dimension minimumLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
            if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                Component[] children = c.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                if (children != null && children.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                    int       numChildren = children.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                    int       height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                    Insets    cInsets = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                    int       extraHeight = topMargin + cInsets.top + cInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                    int       extraWidth = cInsets.left + cInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                    int       maxWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                    for (int counter = 0; counter < numChildren; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                        Dimension aSize = children[counter].getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                        height = Math.max(height, aSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                        maxWidth = Math.max(maxWidth, aSize.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                    return new Dimension(extraWidth + numChildren * maxWidth +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                                         (numChildren - 1) * hGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                                         extraHeight + height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            return new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        public Dimension preferredLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            return minimumLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        public void removeLayoutComponent(Component c) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    private static void groupLabels(AlignedLabel[] group) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        for (int i = 0; i < group.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            group[i].group = group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23328
diff changeset
  1356
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    private class AlignedLabel extends JLabel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        private AlignedLabel[] group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        private int maxWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        AlignedLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        AlignedLabel(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            super(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            setAlignmentX(JComponent.LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            Dimension d = super.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
            // Align the width with all other labels in group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
            return new Dimension(getMaxWidth() + 11, d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        private int getMaxWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            if (maxWidth == 0 && group != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                int max = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                for (int i = 0; i < group.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                    max = Math.max(group[i].getSuperPreferredWidth(), max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                for (int i = 0; i < group.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                    group[i].maxWidth = max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            return maxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        private int getSuperPreferredWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
            return super.getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
}