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