0N/A/*
2362N/A * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.java.swing.plaf.windows;
0N/A
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.border.*;
0N/Aimport javax.swing.filechooser.*;
0N/Aimport javax.swing.event.*;
0N/Aimport javax.swing.plaf.*;
0N/Aimport javax.swing.plaf.basic.*;
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.beans.*;
0N/Aimport java.io.File;
0N/Aimport java.io.FileNotFoundException;
0N/Aimport java.io.IOException;
0N/Aimport java.util.*;
1085N/Aimport java.security.AccessController;
1085N/Aimport java.security.PrivilegedAction;
0N/A
0N/Aimport sun.awt.shell.ShellFolder;
0N/Aimport sun.swing.*;
0N/A
0N/Aimport javax.accessibility.*;
0N/A
0N/A/**
0N/A * Windows L&F implementation of a FileChooser.
0N/A *
0N/A * @author Jeff Dinkins
0N/A */
0N/Apublic class WindowsFileChooserUI extends BasicFileChooserUI {
0N/A
0N/A // The following are private because the implementation of the
0N/A // Windows FileChooser L&F is not complete yet.
0N/A
0N/A private JPanel centerPanel;
0N/A
0N/A private JLabel lookInLabel;
0N/A private JComboBox directoryComboBox;
0N/A private DirectoryComboBoxModel directoryComboBoxModel;
0N/A private ActionListener directoryComboBoxAction = new DirectoryComboBoxAction();
0N/A
0N/A private FilterComboBoxModel filterComboBoxModel;
0N/A
0N/A private JTextField filenameTextField;
0N/A private FilePane filePane;
0N/A private WindowsPlacesBar placesBar;
0N/A
0N/A private JButton approveButton;
0N/A private JButton cancelButton;
0N/A
0N/A private JPanel buttonPanel;
0N/A private JPanel bottomPanel;
0N/A
0N/A private JComboBox filterComboBox;
0N/A
0N/A private static final Dimension hstrut10 = new Dimension(10, 1);
0N/A
0N/A private static final Dimension vstrut4 = new Dimension(1, 4);
0N/A private static final Dimension vstrut6 = new Dimension(1, 6);
0N/A private static final Dimension vstrut8 = new Dimension(1, 8);
0N/A
0N/A private static final Insets shrinkwrap = new Insets(0,0,0,0);
0N/A
0N/A // Preferred and Minimum sizes for the dialog box
0N/A private static int PREF_WIDTH = 425;
0N/A private static int PREF_HEIGHT = 245;
0N/A private static Dimension PREF_SIZE = new Dimension(PREF_WIDTH, PREF_HEIGHT);
0N/A
0N/A private static int MIN_WIDTH = 425;
0N/A private static int MIN_HEIGHT = 245;
0N/A private static Dimension MIN_SIZE = new Dimension(MIN_WIDTH, MIN_HEIGHT);
0N/A
0N/A private static int LIST_PREF_WIDTH = 444;
0N/A private static int LIST_PREF_HEIGHT = 138;
0N/A private static Dimension LIST_PREF_SIZE = new Dimension(LIST_PREF_WIDTH, LIST_PREF_HEIGHT);
0N/A
0N/A // Labels, mnemonics, and tooltips (oh my!)
0N/A private int lookInLabelMnemonic = 0;
0N/A private String lookInLabelText = null;
0N/A private String saveInLabelText = null;
0N/A
0N/A private int fileNameLabelMnemonic = 0;
0N/A private String fileNameLabelText = null;
0N/A private int folderNameLabelMnemonic = 0;
0N/A private String folderNameLabelText = null;
0N/A
0N/A private int filesOfTypeLabelMnemonic = 0;
0N/A private String filesOfTypeLabelText = null;
0N/A
0N/A private String upFolderToolTipText = null;
0N/A private String upFolderAccessibleName = null;
0N/A
0N/A private String newFolderToolTipText = null;
0N/A private String newFolderAccessibleName = null;
0N/A
0N/A private String viewMenuButtonToolTipText = null;
0N/A private String viewMenuButtonAccessibleName = null;
0N/A
0N/A private BasicFileView fileView = new WindowsFileView();
0N/A
0N/A private JLabel fileNameLabel;
0N/A
0N/A private void populateFileNameLabel() {
0N/A if (getFileChooser().getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
0N/A fileNameLabel.setText(folderNameLabelText);
0N/A fileNameLabel.setDisplayedMnemonic(folderNameLabelMnemonic);
0N/A } else {
0N/A fileNameLabel.setText(fileNameLabelText);
0N/A fileNameLabel.setDisplayedMnemonic(fileNameLabelMnemonic);
0N/A }
0N/A }
0N/A
0N/A //
0N/A // ComponentUI Interface Implementation methods
0N/A //
0N/A public static ComponentUI createUI(JComponent c) {
0N/A return new WindowsFileChooserUI((JFileChooser) c);
0N/A }
0N/A
0N/A public WindowsFileChooserUI(JFileChooser filechooser) {
0N/A super(filechooser);
0N/A }
0N/A
0N/A public void installUI(JComponent c) {
0N/A super.installUI(c);
0N/A }
0N/A
0N/A public void uninstallComponents(JFileChooser fc) {
0N/A fc.removeAll();
0N/A }
0N/A
0N/A private class WindowsFileChooserUIAccessor implements FilePane.FileChooserUIAccessor {
0N/A public JFileChooser getFileChooser() {
0N/A return WindowsFileChooserUI.this.getFileChooser();
0N/A }
0N/A
0N/A public BasicDirectoryModel getModel() {
0N/A return WindowsFileChooserUI.this.getModel();
0N/A }
0N/A
0N/A public JPanel createList() {
0N/A return WindowsFileChooserUI.this.createList(getFileChooser());
0N/A }
0N/A
0N/A public JPanel createDetailsView() {
0N/A return WindowsFileChooserUI.this.createDetailsView(getFileChooser());
0N/A }
0N/A
0N/A public boolean isDirectorySelected() {
0N/A return WindowsFileChooserUI.this.isDirectorySelected();
0N/A }
0N/A
0N/A public File getDirectory() {
0N/A return WindowsFileChooserUI.this.getDirectory();
0N/A }
0N/A
0N/A public Action getChangeToParentDirectoryAction() {
0N/A return WindowsFileChooserUI.this.getChangeToParentDirectoryAction();
0N/A }
0N/A
0N/A public Action getApproveSelectionAction() {
0N/A return WindowsFileChooserUI.this.getApproveSelectionAction();
0N/A }
0N/A
0N/A public Action getNewFolderAction() {
0N/A return WindowsFileChooserUI.this.getNewFolderAction();
0N/A }
0N/A
0N/A public MouseListener createDoubleClickListener(JList list) {
0N/A return WindowsFileChooserUI.this.createDoubleClickListener(getFileChooser(),
0N/A list);
0N/A }
0N/A
0N/A public ListSelectionListener createListSelectionListener() {
0N/A return WindowsFileChooserUI.this.createListSelectionListener(getFileChooser());
0N/A }
0N/A }
0N/A
0N/A public void installComponents(JFileChooser fc) {
0N/A filePane = new FilePane(new WindowsFileChooserUIAccessor());
0N/A fc.addPropertyChangeListener(filePane);
0N/A
0N/A FileSystemView fsv = fc.getFileSystemView();
0N/A
0N/A fc.setBorder(new EmptyBorder(4, 10, 10, 10));
0N/A fc.setLayout(new BorderLayout(8, 8));
0N/A
0N/A updateUseShellFolder();
0N/A
0N/A // ********************************* //
0N/A // **** Construct the top panel **** //
0N/A // ********************************* //
0N/A
0N/A // Directory manipulation buttons
0N/A JToolBar topPanel = new JToolBar();
0N/A topPanel.setFloatable(false);
1639N/A topPanel.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
0N/A
0N/A // Add the top panel to the fileChooser
0N/A fc.add(topPanel, BorderLayout.NORTH);
0N/A
0N/A // ComboBox Label
0N/A lookInLabel = new JLabel(lookInLabelText, JLabel.TRAILING) {
0N/A public Dimension getPreferredSize() {
0N/A return getMinimumSize();
0N/A }
0N/A
0N/A public Dimension getMinimumSize() {
0N/A Dimension d = super.getPreferredSize();
0N/A if (placesBar != null) {
0N/A d.width = Math.max(d.width, placesBar.getWidth());
0N/A }
0N/A return d;
0N/A }
0N/A };
0N/A lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic);
0N/A lookInLabel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
0N/A lookInLabel.setAlignmentY(JComponent.CENTER_ALIGNMENT);
0N/A topPanel.add(lookInLabel);
0N/A topPanel.add(Box.createRigidArea(new Dimension(8,0)));
0N/A
0N/A // CurrentDir ComboBox
0N/A directoryComboBox = new JComboBox() {
0N/A public Dimension getMinimumSize() {
0N/A Dimension d = super.getMinimumSize();
0N/A d.width = 60;
0N/A return d;
0N/A }
0N/A
0N/A public Dimension getPreferredSize() {
0N/A Dimension d = super.getPreferredSize();
0N/A // Must be small enough to not affect total width.
0N/A d.width = 150;
0N/A return d;
0N/A }
0N/A };
0N/A directoryComboBox.putClientProperty( "JComboBox.lightweightKeyboardNavigation", "Lightweight" );
0N/A lookInLabel.setLabelFor(directoryComboBox);
0N/A directoryComboBoxModel = createDirectoryComboBoxModel(fc);
0N/A directoryComboBox.setModel(directoryComboBoxModel);
0N/A directoryComboBox.addActionListener(directoryComboBoxAction);
0N/A directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc));
0N/A directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
0N/A directoryComboBox.setAlignmentY(JComponent.CENTER_ALIGNMENT);
0N/A directoryComboBox.setMaximumRowCount(8);
0N/A
0N/A topPanel.add(directoryComboBox);
0N/A topPanel.add(Box.createRigidArea(hstrut10));
0N/A
0N/A // Up Button
1639N/A JButton upFolderButton = createToolButton(getChangeToParentDirectoryAction(), upFolderIcon,
1639N/A upFolderToolTipText, upFolderAccessibleName);
0N/A topPanel.add(upFolderButton);
0N/A
0N/A // New Directory Button
0N/A if (!UIManager.getBoolean("FileChooser.readOnly")) {
1639N/A JButton newFolderButton = createToolButton(filePane.getNewFolderAction(), newFolderIcon,
1639N/A newFolderToolTipText, newFolderAccessibleName);
1639N/A topPanel.add(newFolderButton);
0N/A }
1639N/A
1639N/A // View button group
1639N/A ButtonGroup viewButtonGroup = new ButtonGroup();
1639N/A
1639N/A // Popup Menu
1639N/A final JPopupMenu viewTypePopupMenu = new JPopupMenu();
1639N/A
1639N/A final JRadioButtonMenuItem listViewMenuItem = new JRadioButtonMenuItem(
1639N/A filePane.getViewTypeAction(FilePane.VIEWTYPE_LIST));
1639N/A listViewMenuItem.setSelected(filePane.getViewType() == FilePane.VIEWTYPE_LIST);
1639N/A viewTypePopupMenu.add(listViewMenuItem);
1639N/A viewButtonGroup.add(listViewMenuItem);
1639N/A
1639N/A final JRadioButtonMenuItem detailsViewMenuItem = new JRadioButtonMenuItem(
1639N/A filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS));
1639N/A detailsViewMenuItem.setSelected(filePane.getViewType() == FilePane.VIEWTYPE_DETAILS);
1639N/A viewTypePopupMenu.add(detailsViewMenuItem);
1639N/A viewButtonGroup.add(detailsViewMenuItem);
0N/A
1639N/A // Create icon for viewMenuButton
1639N/A BufferedImage image = new BufferedImage(viewMenuIcon.getIconWidth() + 7, viewMenuIcon.getIconHeight(),
1639N/A BufferedImage.TYPE_INT_ARGB);
1639N/A Graphics graphics = image.getGraphics();
1639N/A viewMenuIcon.paintIcon(filePane, graphics, 0, 0);
1639N/A int x = image.getWidth() - 5;
1639N/A int y = image.getHeight() / 2 - 1;
1639N/A graphics.setColor(Color.BLACK);
1639N/A graphics.fillPolygon(new int[]{x, x + 5, x + 2}, new int[]{y, y, y + 3}, 3);
1639N/A
1639N/A // Details Button
1639N/A final JButton viewMenuButton = createToolButton(null, new ImageIcon(image), viewMenuButtonToolTipText,
1639N/A viewMenuButtonAccessibleName);
1639N/A
1639N/A viewMenuButton.addMouseListener(new MouseAdapter() {
1639N/A public void mousePressed(MouseEvent e) {
1639N/A if (SwingUtilities.isLeftMouseButton(e) && !viewMenuButton.isSelected()) {
1639N/A viewMenuButton.setSelected(true);
0N/A
1639N/A viewTypePopupMenu.show(viewMenuButton, 0, viewMenuButton.getHeight());
1639N/A }
1639N/A }
1639N/A });
1639N/A viewMenuButton.addKeyListener(new KeyAdapter() {
1639N/A public void keyPressed(KeyEvent e) {
1639N/A // Forbid keyboard actions if the button is not in rollover state
1639N/A if (e.getKeyCode() == KeyEvent.VK_SPACE && viewMenuButton.getModel().isRollover()) {
1639N/A viewMenuButton.setSelected(true);
1639N/A
1639N/A viewTypePopupMenu.show(viewMenuButton, 0, viewMenuButton.getHeight());
1639N/A }
1639N/A }
1639N/A });
1639N/A viewTypePopupMenu.addPopupMenuListener(new PopupMenuListener() {
1639N/A public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
1639N/A }
0N/A
1639N/A public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
1639N/A SwingUtilities.invokeLater(new Runnable() {
1639N/A public void run() {
1639N/A viewMenuButton.setSelected(false);
1639N/A }
1639N/A });
1639N/A }
1639N/A
1639N/A public void popupMenuCanceled(PopupMenuEvent e) {
1639N/A }
1639N/A });
1639N/A
1639N/A topPanel.add(viewMenuButton);
0N/A
1639N/A topPanel.add(Box.createRigidArea(new Dimension(80, 0)));
0N/A
1639N/A filePane.addPropertyChangeListener(new PropertyChangeListener() {
1639N/A public void propertyChange(PropertyChangeEvent e) {
1639N/A if ("viewType".equals(e.getPropertyName())) {
1639N/A switch (filePane.getViewType()) {
1639N/A case FilePane.VIEWTYPE_LIST:
1639N/A listViewMenuItem.setSelected(true);
1639N/A break;
0N/A
1639N/A case FilePane.VIEWTYPE_DETAILS:
1639N/A detailsViewMenuItem.setSelected(true);
1639N/A break;
0N/A }
0N/A }
1639N/A }
1639N/A });
0N/A
0N/A // ************************************** //
0N/A // ******* Add the directory pane ******* //
0N/A // ************************************** //
0N/A centerPanel = new JPanel(new BorderLayout());
0N/A centerPanel.add(getAccessoryPanel(), BorderLayout.AFTER_LINE_ENDS);
0N/A JComponent accessory = fc.getAccessory();
0N/A if(accessory != null) {
0N/A getAccessoryPanel().add(accessory);
0N/A }
0N/A filePane.setPreferredSize(LIST_PREF_SIZE);
0N/A centerPanel.add(filePane, BorderLayout.CENTER);
0N/A fc.add(centerPanel, BorderLayout.CENTER);
0N/A
0N/A // ********************************** //
0N/A // **** Construct the bottom panel ** //
0N/A // ********************************** //
0N/A getBottomPanel().setLayout(new BoxLayout(getBottomPanel(), BoxLayout.LINE_AXIS));
0N/A
0N/A // Add the bottom panel to file chooser
0N/A centerPanel.add(getBottomPanel(), BorderLayout.SOUTH);
0N/A
0N/A // labels
0N/A JPanel labelPanel = new JPanel();
0N/A labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.PAGE_AXIS));
0N/A labelPanel.add(Box.createRigidArea(vstrut4));
0N/A
0N/A fileNameLabel = new JLabel();
0N/A populateFileNameLabel();
0N/A fileNameLabel.setAlignmentY(0);
0N/A labelPanel.add(fileNameLabel);
0N/A
0N/A labelPanel.add(Box.createRigidArea(new Dimension(1,12)));
0N/A
0N/A JLabel ftl = new JLabel(filesOfTypeLabelText);
0N/A ftl.setDisplayedMnemonic(filesOfTypeLabelMnemonic);
0N/A labelPanel.add(ftl);
0N/A
0N/A getBottomPanel().add(labelPanel);
0N/A getBottomPanel().add(Box.createRigidArea(new Dimension(15, 0)));
0N/A
0N/A // file entry and filters
0N/A JPanel fileAndFilterPanel = new JPanel();
0N/A fileAndFilterPanel.add(Box.createRigidArea(vstrut8));
0N/A fileAndFilterPanel.setLayout(new BoxLayout(fileAndFilterPanel, BoxLayout.Y_AXIS));
0N/A
0N/A
0N/A filenameTextField = new JTextField(35) {
0N/A public Dimension getMaximumSize() {
0N/A return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height);
0N/A }
0N/A };
0N/A
0N/A fileNameLabel.setLabelFor(filenameTextField);
0N/A filenameTextField.addFocusListener(
0N/A new FocusAdapter() {
0N/A public void focusGained(FocusEvent e) {
0N/A if (!getFileChooser().isMultiSelectionEnabled()) {
0N/A filePane.clearSelection();
0N/A }
0N/A }
0N/A }
0N/A );
0N/A
0N/A if (fc.isMultiSelectionEnabled()) {
0N/A setFileName(fileNameString(fc.getSelectedFiles()));
0N/A } else {
0N/A setFileName(fileNameString(fc.getSelectedFile()));
0N/A }
0N/A
0N/A fileAndFilterPanel.add(filenameTextField);
0N/A fileAndFilterPanel.add(Box.createRigidArea(vstrut8));
0N/A
0N/A filterComboBoxModel = createFilterComboBoxModel();
0N/A fc.addPropertyChangeListener(filterComboBoxModel);
0N/A filterComboBox = new JComboBox(filterComboBoxModel);
0N/A ftl.setLabelFor(filterComboBox);
0N/A filterComboBox.setRenderer(createFilterComboBoxRenderer());
0N/A fileAndFilterPanel.add(filterComboBox);
0N/A
0N/A getBottomPanel().add(fileAndFilterPanel);
0N/A getBottomPanel().add(Box.createRigidArea(new Dimension(30, 0)));
0N/A
0N/A // buttons
0N/A getButtonPanel().setLayout(new BoxLayout(getButtonPanel(), BoxLayout.Y_AXIS));
0N/A
0N/A approveButton = new JButton(getApproveButtonText(fc)) {
0N/A public Dimension getMaximumSize() {
0N/A return approveButton.getPreferredSize().width > cancelButton.getPreferredSize().width ?
0N/A approveButton.getPreferredSize() : cancelButton.getPreferredSize();
0N/A }
0N/A };
0N/A Insets buttonMargin = approveButton.getMargin();
0N/A buttonMargin = new InsetsUIResource(buttonMargin.top, buttonMargin.left + 5,
0N/A buttonMargin.bottom, buttonMargin.right + 5);
0N/A approveButton.setMargin(buttonMargin);
0N/A approveButton.setMnemonic(getApproveButtonMnemonic(fc));
0N/A approveButton.addActionListener(getApproveSelectionAction());
0N/A approveButton.setToolTipText(getApproveButtonToolTipText(fc));
0N/A getButtonPanel().add(Box.createRigidArea(vstrut6));
0N/A getButtonPanel().add(approveButton);
0N/A getButtonPanel().add(Box.createRigidArea(vstrut4));
0N/A
0N/A cancelButton = new JButton(cancelButtonText) {
0N/A public Dimension getMaximumSize() {
0N/A return approveButton.getPreferredSize().width > cancelButton.getPreferredSize().width ?
0N/A approveButton.getPreferredSize() : cancelButton.getPreferredSize();
0N/A }
0N/A };
0N/A cancelButton.setMargin(buttonMargin);
0N/A cancelButton.setToolTipText(cancelButtonToolTipText);
0N/A cancelButton.addActionListener(getCancelSelectionAction());
0N/A getButtonPanel().add(cancelButton);
0N/A
0N/A if(fc.getControlButtonsAreShown()) {
0N/A addControlButtons();
0N/A }
0N/A }
0N/A
0N/A private void updateUseShellFolder() {
0N/A // Decide whether to use the ShellFolder class to populate shortcut
0N/A // panel and combobox.
0N/A JFileChooser fc = getFileChooser();
1639N/A
1639N/A if (FilePane.usesShellFolder(fc)) {
1639N/A if (placesBar == null && !UIManager.getBoolean("FileChooser.noPlacesBar")) {
1639N/A placesBar = new WindowsPlacesBar(fc, XPStyle.getXP() != null);
1639N/A fc.add(placesBar, BorderLayout.BEFORE_LINE_BEGINS);
1639N/A fc.addPropertyChangeListener(placesBar);
1639N/A }
1639N/A } else {
1639N/A if (placesBar != null) {
1639N/A fc.remove(placesBar);
1639N/A fc.removePropertyChangeListener(placesBar);
1639N/A placesBar = null;
0N/A }
0N/A }
0N/A }
0N/A
0N/A protected JPanel getButtonPanel() {
0N/A if(buttonPanel == null) {
0N/A buttonPanel = new JPanel();
0N/A }
0N/A return buttonPanel;
0N/A }
0N/A
0N/A protected JPanel getBottomPanel() {
0N/A if(bottomPanel == null) {
0N/A bottomPanel = new JPanel();
0N/A }
0N/A return bottomPanel;
0N/A }
0N/A
0N/A protected void installStrings(JFileChooser fc) {
0N/A super.installStrings(fc);
0N/A
0N/A Locale l = fc.getLocale();
0N/A
5371N/A lookInLabelMnemonic = getMnemonic("FileChooser.lookInLabelMnemonic", l);
0N/A lookInLabelText = UIManager.getString("FileChooser.lookInLabelText",l);
0N/A saveInLabelText = UIManager.getString("FileChooser.saveInLabelText",l);
0N/A
5371N/A fileNameLabelMnemonic = getMnemonic("FileChooser.fileNameLabelMnemonic", l);
0N/A fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText",l);
5371N/A folderNameLabelMnemonic = getMnemonic("FileChooser.folderNameLabelMnemonic", l);
0N/A folderNameLabelText = UIManager.getString("FileChooser.folderNameLabelText",l);
0N/A
5371N/A filesOfTypeLabelMnemonic = getMnemonic("FileChooser.filesOfTypeLabelMnemonic", l);
0N/A filesOfTypeLabelText = UIManager.getString("FileChooser.filesOfTypeLabelText",l);
0N/A
0N/A upFolderToolTipText = UIManager.getString("FileChooser.upFolderToolTipText",l);
0N/A upFolderAccessibleName = UIManager.getString("FileChooser.upFolderAccessibleName",l);
0N/A
0N/A newFolderToolTipText = UIManager.getString("FileChooser.newFolderToolTipText",l);
0N/A newFolderAccessibleName = UIManager.getString("FileChooser.newFolderAccessibleName",l);
0N/A
0N/A viewMenuButtonToolTipText = UIManager.getString("FileChooser.viewMenuButtonToolTipText",l);
0N/A viewMenuButtonAccessibleName = UIManager.getString("FileChooser.viewMenuButtonAccessibleName",l);
0N/A }
0N/A
5371N/A private Integer getMnemonic(String key, Locale l) {
5371N/A return SwingUtilities2.getUIDefaultsInt(key, l);
5371N/A }
5371N/A
0N/A protected void installListeners(JFileChooser fc) {
0N/A super.installListeners(fc);
0N/A ActionMap actionMap = getActionMap();
0N/A SwingUtilities.replaceUIActionMap(fc, actionMap);
0N/A }
0N/A
0N/A protected ActionMap getActionMap() {
0N/A return createActionMap();
0N/A }
0N/A
0N/A protected ActionMap createActionMap() {
0N/A ActionMap map = new ActionMapUIResource();
0N/A FilePane.addActionsToMap(map, filePane.getActions());
0N/A return map;
0N/A }
0N/A
0N/A protected JPanel createList(JFileChooser fc) {
0N/A return filePane.createList();
0N/A }
0N/A
0N/A protected JPanel createDetailsView(JFileChooser fc) {
0N/A return filePane.createDetailsView();
0N/A }
0N/A
0N/A /**
0N/A * Creates a selection listener for the list of files and directories.
0N/A *
0N/A * @param fc a <code>JFileChooser</code>
0N/A * @return a <code>ListSelectionListener</code>
0N/A */
0N/A public ListSelectionListener createListSelectionListener(JFileChooser fc) {
0N/A return super.createListSelectionListener(fc);
0N/A }
0N/A
0N/A // Obsolete class, not used in this version.
0N/A protected class WindowsNewFolderAction extends NewFolderAction {
0N/A }
0N/A
0N/A // Obsolete class, not used in this version.
0N/A protected class SingleClickListener extends MouseAdapter {
0N/A }
0N/A
0N/A // Obsolete class, not used in this version.
0N/A protected class FileRenderer extends DefaultListCellRenderer {
0N/A }
0N/A
0N/A public void uninstallUI(JComponent c) {
0N/A // Remove listeners
0N/A c.removePropertyChangeListener(filterComboBoxModel);
0N/A c.removePropertyChangeListener(filePane);
0N/A if (placesBar != null) {
0N/A c.removePropertyChangeListener(placesBar);
0N/A }
0N/A cancelButton.removeActionListener(getCancelSelectionAction());
0N/A approveButton.removeActionListener(getApproveSelectionAction());
0N/A filenameTextField.removeActionListener(getApproveSelectionAction());
0N/A
0N/A if (filePane != null) {
0N/A filePane.uninstallUI();
0N/A filePane = null;
0N/A }
0N/A
0N/A super.uninstallUI(c);
0N/A }
0N/A
0N/A /**
0N/A * Returns the preferred size of the specified
0N/A * <code>JFileChooser</code>.
0N/A * The preferred size is at least as large,
0N/A * in both height and width,
0N/A * as the preferred size recommended
0N/A * by the file chooser's layout manager.
0N/A *
0N/A * @param c a <code>JFileChooser</code>
0N/A * @return a <code>Dimension</code> specifying the preferred
0N/A * width and height of the file chooser
0N/A */
0N/A public Dimension getPreferredSize(JComponent c) {
0N/A int prefWidth = PREF_SIZE.width;
0N/A Dimension d = c.getLayout().preferredLayoutSize(c);
0N/A if (d != null) {
0N/A return new Dimension(d.width < prefWidth ? prefWidth : d.width,
0N/A d.height < PREF_SIZE.height ? PREF_SIZE.height : d.height);
0N/A } else {
0N/A return new Dimension(prefWidth, PREF_SIZE.height);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the minimum size of the <code>JFileChooser</code>.
0N/A *
0N/A * @param c a <code>JFileChooser</code>
0N/A * @return a <code>Dimension</code> specifying the minimum
0N/A * width and height of the file chooser
0N/A */
0N/A public Dimension getMinimumSize(JComponent c) {
0N/A return MIN_SIZE;
0N/A }
0N/A
0N/A /**
0N/A * Returns the maximum size of the <code>JFileChooser</code>.
0N/A *
0N/A * @param c a <code>JFileChooser</code>
0N/A * @return a <code>Dimension</code> specifying the maximum
0N/A * width and height of the file chooser
0N/A */
0N/A public Dimension getMaximumSize(JComponent c) {
0N/A return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
0N/A }
0N/A
0N/A private String fileNameString(File file) {
0N/A if (file == null) {
0N/A return null;
0N/A } else {
0N/A JFileChooser fc = getFileChooser();
0N/A if ((fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) ||
0N/A (fc.isDirectorySelectionEnabled() && fc.isFileSelectionEnabled() && fc.getFileSystemView().isFileSystemRoot(file))){
0N/A return file.getPath();
0N/A } else {
0N/A return file.getName();
0N/A }
0N/A }
0N/A }
0N/A
0N/A private String fileNameString(File[] files) {
0N/A StringBuffer buf = new StringBuffer();
0N/A for (int i = 0; files != null && i < files.length; i++) {
0N/A if (i > 0) {
0N/A buf.append(" ");
0N/A }
0N/A if (files.length > 1) {
0N/A buf.append("\"");
0N/A }
0N/A buf.append(fileNameString(files[i]));
0N/A if (files.length > 1) {
0N/A buf.append("\"");
0N/A }
0N/A }
0N/A return buf.toString();
0N/A }
0N/A
0N/A /* The following methods are used by the PropertyChange Listener */
0N/A
0N/A private void doSelectedFileChanged(PropertyChangeEvent e) {
0N/A File f = (File) e.getNewValue();
0N/A JFileChooser fc = getFileChooser();
0N/A if (f != null
0N/A && ((fc.isFileSelectionEnabled() && !f.isDirectory())
0N/A || (f.isDirectory() && fc.isDirectorySelectionEnabled()))) {
0N/A
0N/A setFileName(fileNameString(f));
0N/A }
0N/A }
0N/A
0N/A private void doSelectedFilesChanged(PropertyChangeEvent e) {
0N/A File[] files = (File[]) e.getNewValue();
0N/A JFileChooser fc = getFileChooser();
0N/A if (files != null
0N/A && files.length > 0
0N/A && (files.length > 1 || fc.isDirectorySelectionEnabled() || !files[0].isDirectory())) {
0N/A setFileName(fileNameString(files));
0N/A }
0N/A }
0N/A
0N/A private void doDirectoryChanged(PropertyChangeEvent e) {
0N/A JFileChooser fc = getFileChooser();
0N/A FileSystemView fsv = fc.getFileSystemView();
0N/A
0N/A clearIconCache();
0N/A File currentDirectory = fc.getCurrentDirectory();
0N/A if(currentDirectory != null) {
0N/A directoryComboBoxModel.addItem(currentDirectory);
0N/A
0N/A if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
0N/A if (fsv.isFileSystem(currentDirectory)) {
0N/A setFileName(currentDirectory.getPath());
0N/A } else {
0N/A setFileName(null);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A private void doFilterChanged(PropertyChangeEvent e) {
0N/A clearIconCache();
0N/A }
0N/A
0N/A private void doFileSelectionModeChanged(PropertyChangeEvent e) {
0N/A if (fileNameLabel != null) {
0N/A populateFileNameLabel();
0N/A }
0N/A clearIconCache();
0N/A
0N/A JFileChooser fc = getFileChooser();
0N/A File currentDirectory = fc.getCurrentDirectory();
0N/A if (currentDirectory != null
0N/A && fc.isDirectorySelectionEnabled()
0N/A && !fc.isFileSelectionEnabled()
0N/A && fc.getFileSystemView().isFileSystem(currentDirectory)) {
0N/A
0N/A setFileName(currentDirectory.getPath());
0N/A } else {
0N/A setFileName(null);
0N/A }
0N/A }
0N/A
0N/A private void doAccessoryChanged(PropertyChangeEvent e) {
0N/A if(getAccessoryPanel() != null) {
0N/A if(e.getOldValue() != null) {
0N/A getAccessoryPanel().remove((JComponent) e.getOldValue());
0N/A }
0N/A JComponent accessory = (JComponent) e.getNewValue();
0N/A if(accessory != null) {
0N/A getAccessoryPanel().add(accessory, BorderLayout.CENTER);
0N/A }
0N/A }
0N/A }
0N/A
0N/A private void doApproveButtonTextChanged(PropertyChangeEvent e) {
0N/A JFileChooser chooser = getFileChooser();
0N/A approveButton.setText(getApproveButtonText(chooser));
0N/A approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
0N/A approveButton.setMnemonic(getApproveButtonMnemonic(chooser));
0N/A }
0N/A
0N/A private void doDialogTypeChanged(PropertyChangeEvent e) {
0N/A JFileChooser chooser = getFileChooser();
0N/A approveButton.setText(getApproveButtonText(chooser));
0N/A approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
0N/A approveButton.setMnemonic(getApproveButtonMnemonic(chooser));
0N/A if (chooser.getDialogType() == JFileChooser.SAVE_DIALOG) {
0N/A lookInLabel.setText(saveInLabelText);
0N/A } else {
0N/A lookInLabel.setText(lookInLabelText);
0N/A }
0N/A }
0N/A
0N/A private void doApproveButtonMnemonicChanged(PropertyChangeEvent e) {
0N/A approveButton.setMnemonic(getApproveButtonMnemonic(getFileChooser()));
0N/A }
0N/A
0N/A private void doControlButtonsChanged(PropertyChangeEvent e) {
0N/A if(getFileChooser().getControlButtonsAreShown()) {
0N/A addControlButtons();
0N/A } else {
0N/A removeControlButtons();
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Listen for filechooser property changes, such as
0N/A * the selected file changing, or the type of the dialog changing.
0N/A */
0N/A public PropertyChangeListener createPropertyChangeListener(JFileChooser fc) {
0N/A return new PropertyChangeListener() {
0N/A public void propertyChange(PropertyChangeEvent e) {
0N/A String s = e.getPropertyName();
0N/A if(s.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
0N/A doSelectedFileChanged(e);
0N/A } else if (s.equals(JFileChooser.SELECTED_FILES_CHANGED_PROPERTY)) {
0N/A doSelectedFilesChanged(e);
0N/A } else if(s.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
0N/A doDirectoryChanged(e);
0N/A } else if(s.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) {
0N/A doFilterChanged(e);
0N/A } else if(s.equals(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY)) {
0N/A doFileSelectionModeChanged(e);
0N/A } else if(s.equals(JFileChooser.ACCESSORY_CHANGED_PROPERTY)) {
0N/A doAccessoryChanged(e);
0N/A } else if (s.equals(JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY) ||
0N/A s.equals(JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY)) {
0N/A doApproveButtonTextChanged(e);
0N/A } else if(s.equals(JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY)) {
0N/A doDialogTypeChanged(e);
0N/A } else if(s.equals(JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY)) {
0N/A doApproveButtonMnemonicChanged(e);
0N/A } else if(s.equals(JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY)) {
0N/A doControlButtonsChanged(e);
0N/A } else if (s == "FileChooser.useShellFolder") {
0N/A updateUseShellFolder();
0N/A doDirectoryChanged(e);
0N/A } else if (s.equals("componentOrientation")) {
0N/A ComponentOrientation o = (ComponentOrientation)e.getNewValue();
0N/A JFileChooser cc = (JFileChooser)e.getSource();
614N/A if (o != e.getOldValue()) {
0N/A cc.applyComponentOrientation(o);
0N/A }
0N/A } else if (s.equals("ancestor")) {
0N/A if (e.getOldValue() == null && e.getNewValue() != null) {
0N/A // Ancestor was added, set initial focus
0N/A filenameTextField.selectAll();
0N/A filenameTextField.requestFocus();
0N/A }
0N/A }
0N/A }
0N/A };
0N/A }
0N/A
0N/A
0N/A protected void removeControlButtons() {
0N/A getBottomPanel().remove(getButtonPanel());
0N/A }
0N/A
0N/A protected void addControlButtons() {
0N/A getBottomPanel().add(getButtonPanel());
0N/A }
0N/A
0N/A public void ensureFileIsVisible(JFileChooser fc, File f) {
0N/A filePane.ensureFileIsVisible(fc, f);
0N/A }
0N/A
0N/A public void rescanCurrentDirectory(JFileChooser fc) {
0N/A filePane.rescanCurrentDirectory();
0N/A }
0N/A
0N/A public String getFileName() {
0N/A if(filenameTextField != null) {
0N/A return filenameTextField.getText();
0N/A } else {
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A public void setFileName(String filename) {
0N/A if(filenameTextField != null) {
0N/A filenameTextField.setText(filename);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Property to remember whether a directory is currently selected in the UI.
0N/A * This is normally called by the UI on a selection event.
0N/A *
0N/A * @param directorySelected if a directory is currently selected.
0N/A * @since 1.4
0N/A */
0N/A protected void setDirectorySelected(boolean directorySelected) {
0N/A super.setDirectorySelected(directorySelected);
0N/A JFileChooser chooser = getFileChooser();
0N/A if(directorySelected) {
0N/A approveButton.setText(directoryOpenButtonText);
0N/A approveButton.setToolTipText(directoryOpenButtonToolTipText);
0N/A approveButton.setMnemonic(directoryOpenButtonMnemonic);
0N/A } else {
0N/A approveButton.setText(getApproveButtonText(chooser));
0N/A approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
0N/A approveButton.setMnemonic(getApproveButtonMnemonic(chooser));
0N/A }
0N/A }
0N/A
0N/A public String getDirectoryName() {
0N/A // PENDING(jeff) - get the name from the directory combobox
0N/A return null;
0N/A }
0N/A
0N/A public void setDirectoryName(String dirname) {
0N/A // PENDING(jeff) - set the name in the directory combobox
0N/A }
0N/A
0N/A protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) {
0N/A return new DirectoryComboBoxRenderer();
0N/A }
0N/A
1639N/A private static JButton createToolButton(Action a, Icon defaultIcon, String toolTipText, String accessibleName) {
1639N/A final JButton result = new JButton(a);
1639N/A
1639N/A result.setText(null);
1639N/A result.setIcon(defaultIcon);
1639N/A result.setToolTipText(toolTipText);
1639N/A result.setRequestFocusEnabled(false);
1639N/A result.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, accessibleName);
1639N/A result.putClientProperty(WindowsLookAndFeel.HI_RES_DISABLED_ICON_CLIENT_KEY, Boolean.TRUE);
1639N/A result.setAlignmentX(JComponent.LEFT_ALIGNMENT);
1639N/A result.setAlignmentY(JComponent.CENTER_ALIGNMENT);
1639N/A result.setMargin(shrinkwrap);
1639N/A result.setFocusPainted(false);
1639N/A
1639N/A result.setModel(new DefaultButtonModel() {
1639N/A public void setPressed(boolean b) {
1639N/A // Forbid keyboard actions if the button is not in rollover state
1639N/A if (!b || isRollover()) {
1639N/A super.setPressed(b);
1639N/A }
1639N/A }
1639N/A
1639N/A public void setRollover(boolean b) {
1639N/A if (b && !isRollover()) {
1639N/A // Reset other buttons
1639N/A for (Component component : result.getParent().getComponents()) {
1639N/A if (component instanceof JButton && component != result) {
1639N/A ((JButton) component).getModel().setRollover(false);
1639N/A }
1639N/A }
1639N/A }
1639N/A
1639N/A super.setRollover(b);
1639N/A }
1639N/A
1639N/A public void setSelected(boolean b) {
1639N/A super.setSelected(b);
1639N/A
1639N/A if (b) {
1639N/A stateMask |= PRESSED | ARMED;
1639N/A } else {
1639N/A stateMask &= ~(PRESSED | ARMED);
1639N/A }
1639N/A }
1639N/A });
1639N/A
1639N/A result.addFocusListener(new FocusAdapter() {
1639N/A public void focusGained(FocusEvent e) {
1639N/A result.getModel().setRollover(true);
1639N/A }
1639N/A
1639N/A public void focusLost(FocusEvent e) {
1639N/A result.getModel().setRollover(false);
1639N/A }
1639N/A });
1639N/A
1639N/A return result;
1639N/A }
1639N/A
0N/A //
0N/A // Renderer for DirectoryComboBox
0N/A //
0N/A class DirectoryComboBoxRenderer extends DefaultListCellRenderer {
0N/A IndentIcon ii = new IndentIcon();
0N/A public Component getListCellRendererComponent(JList list, Object value,
0N/A int index, boolean isSelected,
0N/A boolean cellHasFocus) {
0N/A
0N/A super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
0N/A
0N/A if (value == null) {
0N/A setText("");
0N/A return this;
0N/A }
0N/A File directory = (File)value;
0N/A setText(getFileChooser().getName(directory));
0N/A Icon icon = getFileChooser().getIcon(directory);
0N/A ii.icon = icon;
0N/A ii.depth = directoryComboBoxModel.getDepth(index);
0N/A setIcon(ii);
0N/A
0N/A return this;
0N/A }
0N/A }
0N/A
0N/A final static int space = 10;
0N/A class IndentIcon implements Icon {
0N/A
0N/A Icon icon = null;
0N/A int depth = 0;
0N/A
0N/A public void paintIcon(Component c, Graphics g, int x, int y) {
0N/A if (c.getComponentOrientation().isLeftToRight()) {
0N/A icon.paintIcon(c, g, x+depth*space, y);
0N/A } else {
0N/A icon.paintIcon(c, g, x, y);
0N/A }
0N/A }
0N/A
0N/A public int getIconWidth() {
0N/A return icon.getIconWidth() + depth*space;
0N/A }
0N/A
0N/A public int getIconHeight() {
0N/A return icon.getIconHeight();
0N/A }
0N/A
0N/A }
0N/A
0N/A //
0N/A // DataModel for DirectoryComboxbox
0N/A //
0N/A protected DirectoryComboBoxModel createDirectoryComboBoxModel(JFileChooser fc) {
0N/A return new DirectoryComboBoxModel();
0N/A }
0N/A
0N/A /**
0N/A * Data model for a type-face selection combo-box.
0N/A */
0N/A protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel {
614N/A Vector<File> directories = new Vector<File>();
0N/A int[] depths = null;
0N/A File selectedDirectory = null;
0N/A JFileChooser chooser = getFileChooser();
0N/A FileSystemView fsv = chooser.getFileSystemView();
0N/A
0N/A public DirectoryComboBoxModel() {
0N/A // Add the current directory to the model, and make it the
0N/A // selectedDirectory
0N/A File dir = getFileChooser().getCurrentDirectory();
0N/A if(dir != null) {
0N/A addItem(dir);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Adds the directory to the model and sets it to be selected,
0N/A * additionally clears out the previous selected directory and
0N/A * the paths leading up to it, if any.
0N/A */
0N/A private void addItem(File directory) {
0N/A
0N/A if(directory == null) {
0N/A return;
0N/A }
0N/A
825N/A boolean useShellFolder = FilePane.usesShellFolder(chooser);
825N/A
0N/A directories.clear();
0N/A
0N/A File[] baseFolders;
0N/A if (useShellFolder) {
1085N/A baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() {
1085N/A public File[] run() {
1085N/A return (File[]) ShellFolder.get("fileChooserComboBoxFolders");
1085N/A }
1085N/A });
0N/A } else {
0N/A baseFolders = fsv.getRoots();
0N/A }
0N/A directories.addAll(Arrays.asList(baseFolders));
0N/A
0N/A // Get the canonical (full) path. This has the side
0N/A // benefit of removing extraneous chars from the path,
0N/A // for example /foo/bar/ becomes /foo/bar
614N/A File canonical;
0N/A try {
0N/A canonical = directory.getCanonicalFile();
0N/A } catch (IOException e) {
0N/A // Maybe drive is not ready. Can't abort here.
0N/A canonical = directory;
0N/A }
0N/A
0N/A // create File instances of each directory leading up to the top
0N/A try {
0N/A File sf = useShellFolder ? ShellFolder.getShellFolder(canonical)
0N/A : canonical;
0N/A File f = sf;
614N/A Vector<File> path = new Vector<File>(10);
0N/A do {
0N/A path.addElement(f);
0N/A } while ((f = f.getParentFile()) != null);
0N/A
0N/A int pathCount = path.size();
0N/A // Insert chain at appropriate place in vector
0N/A for (int i = 0; i < pathCount; i++) {
614N/A f = path.get(i);
0N/A if (directories.contains(f)) {
0N/A int topIndex = directories.indexOf(f);
0N/A for (int j = i-1; j >= 0; j--) {
0N/A directories.insertElementAt(path.get(j), topIndex+i-j);
0N/A }
0N/A break;
0N/A }
0N/A }
0N/A calculateDepths();
0N/A setSelectedItem(sf);
0N/A } catch (FileNotFoundException ex) {
0N/A calculateDepths();
0N/A }
0N/A }
0N/A
0N/A private void calculateDepths() {
0N/A depths = new int[directories.size()];
0N/A for (int i = 0; i < depths.length; i++) {
614N/A File dir = directories.get(i);
0N/A File parent = dir.getParentFile();
0N/A depths[i] = 0;
0N/A if (parent != null) {
0N/A for (int j = i-1; j >= 0; j--) {
614N/A if (parent.equals(directories.get(j))) {
0N/A depths[i] = depths[j] + 1;
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A public int getDepth(int i) {
0N/A return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0;
0N/A }
0N/A
0N/A public void setSelectedItem(Object selectedDirectory) {
0N/A this.selectedDirectory = (File)selectedDirectory;
0N/A fireContentsChanged(this, -1, -1);
0N/A }
0N/A
0N/A public Object getSelectedItem() {
0N/A return selectedDirectory;
0N/A }
0N/A
0N/A public int getSize() {
0N/A return directories.size();
0N/A }
0N/A
0N/A public Object getElementAt(int index) {
0N/A return directories.elementAt(index);
0N/A }
0N/A }
0N/A
0N/A //
0N/A // Renderer for Types ComboBox
0N/A //
0N/A protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
0N/A return new FilterComboBoxRenderer();
0N/A }
0N/A
0N/A /**
0N/A * Render different type sizes and styles.
0N/A */
0N/A public class FilterComboBoxRenderer extends DefaultListCellRenderer {
0N/A public Component getListCellRendererComponent(JList list,
0N/A Object value, int index, boolean isSelected,
0N/A boolean cellHasFocus) {
0N/A
0N/A super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
0N/A
0N/A if (value != null && value instanceof FileFilter) {
0N/A setText(((FileFilter)value).getDescription());
0N/A }
0N/A
0N/A return this;
0N/A }
0N/A }
0N/A
0N/A //
0N/A // DataModel for Types Comboxbox
0N/A //
0N/A protected FilterComboBoxModel createFilterComboBoxModel() {
0N/A return new FilterComboBoxModel();
0N/A }
0N/A
0N/A /**
0N/A * Data model for a type-face selection combo-box.
0N/A */
0N/A protected class FilterComboBoxModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener {
0N/A protected FileFilter[] filters;
0N/A protected FilterComboBoxModel() {
0N/A super();
0N/A filters = getFileChooser().getChoosableFileFilters();
0N/A }
0N/A
0N/A public void propertyChange(PropertyChangeEvent e) {
0N/A String prop = e.getPropertyName();
0N/A if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
0N/A filters = (FileFilter[]) e.getNewValue();
0N/A fireContentsChanged(this, -1, -1);
0N/A } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
0N/A fireContentsChanged(this, -1, -1);
0N/A }
0N/A }
0N/A
0N/A public void setSelectedItem(Object filter) {
0N/A if(filter != null) {
0N/A getFileChooser().setFileFilter((FileFilter) filter);
0N/A fireContentsChanged(this, -1, -1);
0N/A }
0N/A }
0N/A
0N/A public Object getSelectedItem() {
0N/A // Ensure that the current filter is in the list.
0N/A // NOTE: we shouldnt' have to do this, since JFileChooser adds
0N/A // the filter to the choosable filters list when the filter
0N/A // is set. Lets be paranoid just in case someone overrides
0N/A // setFileFilter in JFileChooser.
0N/A FileFilter currentFilter = getFileChooser().getFileFilter();
0N/A boolean found = false;
0N/A if(currentFilter != null) {
614N/A for (FileFilter filter : filters) {
614N/A if (filter == currentFilter) {
0N/A found = true;
0N/A }
0N/A }
0N/A if(found == false) {
0N/A getFileChooser().addChoosableFileFilter(currentFilter);
0N/A }
0N/A }
0N/A return getFileChooser().getFileFilter();
0N/A }
0N/A
0N/A public int getSize() {
0N/A if(filters != null) {
0N/A return filters.length;
0N/A } else {
0N/A return 0;
0N/A }
0N/A }
0N/A
0N/A public Object getElementAt(int index) {
0N/A if(index > getSize() - 1) {
0N/A // This shouldn't happen. Try to recover gracefully.
0N/A return getFileChooser().getFileFilter();
0N/A }
0N/A if(filters != null) {
0N/A return filters[index];
0N/A } else {
0N/A return null;
0N/A }
0N/A }
0N/A }
0N/A
0N/A public void valueChanged(ListSelectionEvent e) {
0N/A JFileChooser fc = getFileChooser();
0N/A File f = fc.getSelectedFile();
0N/A if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
0N/A setFileName(fileNameString(f));
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Acts when DirectoryComboBox has changed the selected item.
0N/A */
0N/A protected class DirectoryComboBoxAction implements ActionListener {
0N/A
0N/A
0N/A
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A File f = (File)directoryComboBox.getSelectedItem();
0N/A getFileChooser().setCurrentDirectory(f);
0N/A }
0N/A }
0N/A
0N/A protected JButton getApproveButton(JFileChooser fc) {
0N/A return approveButton;
0N/A }
0N/A
0N/A public FileView getFileView(JFileChooser fc) {
0N/A return fileView;
0N/A }
0N/A
0N/A // ***********************
0N/A // * FileView operations *
0N/A // ***********************
0N/A protected class WindowsFileView extends BasicFileView {
0N/A /* FileView type descriptions */
0N/A
0N/A public Icon getIcon(File f) {
0N/A Icon icon = getCachedIcon(f);
0N/A if (icon != null) {
0N/A return icon;
0N/A }
0N/A if (f != null) {
0N/A icon = getFileChooser().getFileSystemView().getSystemIcon(f);
0N/A }
0N/A if (icon == null) {
0N/A icon = super.getIcon(f);
0N/A }
0N/A cacheIcon(f, icon);
0N/A return icon;
0N/A }
0N/A }
0N/A}