0N/A/*
3261N/A * Copyright (c) 2003, 2010, 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/Apackage sun.swing.plaf.synth;
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport java.beans.*;
0N/Aimport java.io.*;
0N/Aimport java.util.*;
1085N/Aimport java.security.AccessController;
1085N/Aimport java.security.PrivilegedAction;
0N/A
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.event.*;
0N/Aimport javax.swing.filechooser.*;
0N/Aimport javax.swing.filechooser.FileFilter;
0N/Aimport javax.swing.plaf.basic.*;
0N/Aimport javax.swing.plaf.synth.*;
1173N/Aimport javax.swing.plaf.ActionMapUIResource;
0N/A
0N/Aimport sun.awt.shell.ShellFolder;
0N/Aimport sun.swing.*;
0N/A
0N/A/**
0N/A * Synth FileChooserUI implementation.
0N/A * <p>
0N/A * Note that the classes in the com.sun.java.swing.plaf.synth
0N/A * package are not
0N/A * part of the core Java APIs. They are a part of Sun's JDK and JRE
0N/A * distributions. Although other licensees may choose to distribute
0N/A * these classes, developers cannot depend on their availability in
0N/A * non-Sun implementations. Additionally this API may change in
0N/A * incompatible ways between releases. While this class is public, it
0N/A * shoud be considered an implementation detail, and subject to change.
0N/A *
0N/A * @author Leif Samuelsson
0N/A * @author Jeff Dinkins
0N/A */
0N/Apublic class SynthFileChooserUIImpl extends SynthFileChooserUI {
0N/A private JLabel lookInLabel;
0N/A private JComboBox directoryComboBox;
0N/A private DirectoryComboBoxModel directoryComboBoxModel;
0N/A private Action directoryComboBoxAction = new DirectoryComboBoxAction();
0N/A
0N/A private FilterComboBoxModel filterComboBoxModel;
0N/A
0N/A private JTextField fileNameTextField;
0N/A
0N/A private FilePane filePane;
0N/A private JToggleButton listViewButton;
0N/A private JToggleButton detailsViewButton;
0N/A
0N/A private boolean readOnly;
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 hstrut5 = new Dimension(5, 1);
0N/A private static final Dimension vstrut5 = new Dimension(1, 5);
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 Dimension LIST_PREF_SIZE = new Dimension(405, 135);
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 homeFolderToolTipText = null;
0N/A private String homeFolderAccessibleName = null;
0N/A
0N/A private String newFolderToolTipText = null;
0N/A private String newFolderAccessibleName = null;
0N/A
0N/A private String listViewButtonToolTipText = null;
0N/A private String listViewButtonAccessibleName = null;
0N/A
0N/A private String detailsViewButtonToolTipText = null;
0N/A private String detailsViewButtonAccessibleName = null;
0N/A
0N/A private AlignedLabel fileNameLabel;
0N/A private final PropertyChangeListener modeListener = new PropertyChangeListener() {
0N/A public void propertyChange(PropertyChangeEvent event) {
0N/A if (fileNameLabel != null) {
0N/A populateFileNameLabel();
0N/A }
0N/A }
0N/A };
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 public SynthFileChooserUIImpl(JFileChooser b) {
0N/A super(b);
0N/A }
0N/A
0N/A
0N/A private class SynthFileChooserUIAccessor implements FilePane.FileChooserUIAccessor {
0N/A public JFileChooser getFileChooser() {
0N/A return SynthFileChooserUIImpl.this.getFileChooser();
0N/A }
0N/A
0N/A public BasicDirectoryModel getModel() {
0N/A return SynthFileChooserUIImpl.this.getModel();
0N/A }
0N/A
0N/A public JPanel createList() {
0N/A return null;
0N/A }
0N/A
0N/A public JPanel createDetailsView() {
0N/A return null;
0N/A }
0N/A
0N/A public boolean isDirectorySelected() {
0N/A return SynthFileChooserUIImpl.this.isDirectorySelected();
0N/A }
0N/A
0N/A public File getDirectory() {
0N/A return SynthFileChooserUIImpl.this.getDirectory();
0N/A }
0N/A
0N/A public Action getChangeToParentDirectoryAction() {
0N/A return SynthFileChooserUIImpl.this.getChangeToParentDirectoryAction();
0N/A }
0N/A
0N/A public Action getApproveSelectionAction() {
0N/A return SynthFileChooserUIImpl.this.getApproveSelectionAction();
0N/A }
0N/A
0N/A public Action getNewFolderAction() {
0N/A return SynthFileChooserUIImpl.this.getNewFolderAction();
0N/A }
0N/A
0N/A public MouseListener createDoubleClickListener(JList list) {
0N/A return SynthFileChooserUIImpl.this.createDoubleClickListener(getFileChooser(),
0N/A list);
0N/A }
0N/A
0N/A public ListSelectionListener createListSelectionListener() {
0N/A return SynthFileChooserUIImpl.this.createListSelectionListener(getFileChooser());
0N/A }
0N/A }
0N/A
0N/A protected void installDefaults(JFileChooser fc) {
0N/A super.installDefaults(fc);
0N/A readOnly = UIManager.getBoolean("FileChooser.readOnly");
0N/A }
0N/A
0N/A public void installComponents(JFileChooser fc) {
0N/A super.installComponents(fc);
0N/A
0N/A SynthContext context = getContext(fc, ENABLED);
0N/A
0N/A fc.setLayout(new BorderLayout(0, 11));
0N/A
0N/A // ********************************* //
0N/A // **** Construct the top panel **** //
0N/A // ********************************* //
0N/A
0N/A // Directory manipulation buttons
0N/A JPanel topPanel = new JPanel(new BorderLayout(11, 0));
0N/A JPanel topButtonPanel = new JPanel();
0N/A topButtonPanel.setLayout(new BoxLayout(topButtonPanel, BoxLayout.LINE_AXIS));
0N/A topPanel.add(topButtonPanel, BorderLayout.AFTER_LINE_ENDS);
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);
0N/A lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic);
0N/A topPanel.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS);
0N/A
0N/A // CurrentDir ComboBox
0N/A directoryComboBox = new JComboBox();
0N/A directoryComboBox.getAccessibleContext().setAccessibleDescription(lookInLabelText);
0N/A directoryComboBox.putClientProperty( "JComboBox.isTableCellEditor", Boolean.TRUE );
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.TOP_ALIGNMENT);
0N/A directoryComboBox.setMaximumRowCount(8);
0N/A topPanel.add(directoryComboBox, BorderLayout.CENTER);
0N/A
0N/A filePane = new FilePane(new SynthFileChooserUIAccessor());
0N/A fc.addPropertyChangeListener(filePane);
0N/A
0N/A // Add 'Go Up' to context menu, plus 'Go Home' if on Unix
0N/A JPopupMenu contextMenu = filePane.getComponentPopupMenu();
0N/A if (contextMenu != null) {
0N/A contextMenu.insert(getChangeToParentDirectoryAction(), 0);
0N/A if (File.separatorChar == '/') {
0N/A contextMenu.insert(getGoHomeAction(), 1);
0N/A }
0N/A }
0N/A
0N/A FileSystemView fsv = fc.getFileSystemView();
0N/A
0N/A // Up Button
0N/A JButton upFolderButton = new JButton(getChangeToParentDirectoryAction());
0N/A upFolderButton.setText(null);
0N/A upFolderButton.setIcon(upFolderIcon);
0N/A upFolderButton.setToolTipText(upFolderToolTipText);
0N/A upFolderButton.getAccessibleContext().setAccessibleName(upFolderAccessibleName);
0N/A upFolderButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
0N/A upFolderButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
0N/A upFolderButton.setMargin(shrinkwrap);
0N/A
0N/A topButtonPanel.add(upFolderButton);
0N/A topButtonPanel.add(Box.createRigidArea(hstrut5));
0N/A
0N/A // Home Button
0N/A File homeDir = fsv.getHomeDirectory();
0N/A String toolTipText = homeFolderToolTipText;
0N/A if (fsv.isRoot(homeDir)) {
0N/A toolTipText = getFileView(fc).getName(homeDir); // Probably "Desktop".
0N/A }
0N/A
0N/A JButton b = new JButton(homeFolderIcon);
0N/A b.setToolTipText(toolTipText);
0N/A b.getAccessibleContext().setAccessibleName(homeFolderAccessibleName);
0N/A b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
0N/A b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
0N/A b.setMargin(shrinkwrap);
0N/A
0N/A b.addActionListener(getGoHomeAction());
0N/A topButtonPanel.add(b);
0N/A topButtonPanel.add(Box.createRigidArea(hstrut5));
0N/A
0N/A // New Directory Button
0N/A if (!readOnly) {
0N/A b = new JButton(filePane.getNewFolderAction());
0N/A b.setText(null);
0N/A b.setIcon(newFolderIcon);
0N/A b.setToolTipText(newFolderToolTipText);
0N/A b.getAccessibleContext().setAccessibleName(newFolderAccessibleName);
0N/A b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
0N/A b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
0N/A b.setMargin(shrinkwrap);
1173N/A topButtonPanel.add(b);
1173N/A topButtonPanel.add(Box.createRigidArea(hstrut5));
0N/A }
0N/A
0N/A // View button group
0N/A ButtonGroup viewButtonGroup = new ButtonGroup();
0N/A
0N/A // List Button
0N/A listViewButton = new JToggleButton(listViewIcon);
0N/A listViewButton.setToolTipText(listViewButtonToolTipText);
0N/A listViewButton.getAccessibleContext().setAccessibleName(listViewButtonAccessibleName);
0N/A listViewButton.setSelected(true);
0N/A listViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
0N/A listViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
0N/A listViewButton.setMargin(shrinkwrap);
0N/A listViewButton.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_LIST));
0N/A topButtonPanel.add(listViewButton);
0N/A viewButtonGroup.add(listViewButton);
0N/A
0N/A // Details Button
0N/A detailsViewButton = new JToggleButton(detailsViewIcon);
0N/A detailsViewButton.setToolTipText(detailsViewButtonToolTipText);
0N/A detailsViewButton.getAccessibleContext().setAccessibleName(detailsViewButtonAccessibleName);
0N/A detailsViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
0N/A detailsViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT);
0N/A detailsViewButton.setMargin(shrinkwrap);
0N/A detailsViewButton.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS));
0N/A topButtonPanel.add(detailsViewButton);
0N/A viewButtonGroup.add(detailsViewButton);
0N/A
0N/A filePane.addPropertyChangeListener(new PropertyChangeListener() {
0N/A public void propertyChange(PropertyChangeEvent e) {
0N/A if ("viewType".equals(e.getPropertyName())) {
0N/A int viewType = filePane.getViewType();
0N/A switch (viewType) {
0N/A case FilePane.VIEWTYPE_LIST:
0N/A listViewButton.setSelected(true);
0N/A break;
0N/A case FilePane.VIEWTYPE_DETAILS:
0N/A detailsViewButton.setSelected(true);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A });
0N/A
0N/A // ************************************** //
0N/A // ******* Add the directory pane ******* //
0N/A // ************************************** //
0N/A fc.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 fc.add(filePane, BorderLayout.CENTER);
0N/A
0N/A
0N/A // ********************************** //
0N/A // **** Construct the bottom panel ** //
0N/A // ********************************** //
0N/A bottomPanel = new JPanel();
0N/A bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS));
0N/A fc.add(bottomPanel, BorderLayout.SOUTH);
0N/A
0N/A // FileName label and textfield
0N/A JPanel fileNamePanel = new JPanel();
0N/A fileNamePanel.setLayout(new BoxLayout(fileNamePanel, BoxLayout.LINE_AXIS));
0N/A bottomPanel.add(fileNamePanel);
0N/A bottomPanel.add(Box.createRigidArea(new Dimension(1, 5)));
0N/A
0N/A fileNameLabel = new AlignedLabel();
0N/A populateFileNameLabel();
0N/A fileNamePanel.add(fileNameLabel);
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 fileNamePanel.add(fileNameTextField);
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 if (fc.isMultiSelectionEnabled()) {
0N/A setFileName(fileNameString(fc.getSelectedFiles()));
0N/A } else {
0N/A setFileName(fileNameString(fc.getSelectedFile()));
0N/A }
0N/A
0N/A
0N/A // Filetype label and combobox
0N/A JPanel filesOfTypePanel = new JPanel();
0N/A filesOfTypePanel.setLayout(new BoxLayout(filesOfTypePanel, BoxLayout.LINE_AXIS));
0N/A bottomPanel.add(filesOfTypePanel);
0N/A
0N/A AlignedLabel filesOfTypeLabel = new AlignedLabel(filesOfTypeLabelText);
0N/A filesOfTypeLabel.setDisplayedMnemonic(filesOfTypeLabelMnemonic);
0N/A filesOfTypePanel.add(filesOfTypeLabel);
0N/A
0N/A filterComboBoxModel = createFilterComboBoxModel();
0N/A fc.addPropertyChangeListener(filterComboBoxModel);
0N/A filterComboBox = new JComboBox(filterComboBoxModel);
0N/A filterComboBox.getAccessibleContext().setAccessibleDescription(filesOfTypeLabelText);
0N/A filesOfTypeLabel.setLabelFor(filterComboBox);
0N/A filterComboBox.setRenderer(createFilterComboBoxRenderer());
0N/A filesOfTypePanel.add(filterComboBox);
0N/A
0N/A
0N/A // buttons
0N/A buttonPanel = new JPanel();
0N/A buttonPanel.setLayout(new ButtonAreaLayout());
0N/A
0N/A buttonPanel.add(getApproveButton(fc));
0N/A buttonPanel.add(getCancelButton(fc));
0N/A
0N/A if (fc.getControlButtonsAreShown()) {
0N/A addControlButtons();
0N/A }
0N/A
0N/A groupLabels(new AlignedLabel[] { fileNameLabel, filesOfTypeLabel });
0N/A }
0N/A
0N/A protected void installListeners(JFileChooser fc) {
0N/A super.installListeners(fc);
0N/A fc.addPropertyChangeListener(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY, modeListener);
0N/A }
0N/A
0N/A protected void uninstallListeners(JFileChooser fc) {
0N/A fc.removePropertyChangeListener(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY, modeListener);
0N/A super.uninstallListeners(fc);
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 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 public void uninstallUI(JComponent c) {
0N/A // Remove listeners
0N/A c.removePropertyChangeListener(filterComboBoxModel);
0N/A c.removePropertyChangeListener(filePane);
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 protected void installStrings(JFileChooser fc) {
0N/A super.installStrings(fc);
0N/A
0N/A Locale l = fc.getLocale();
0N/A
0N/A lookInLabelMnemonic = getMnemonic("FileChooser.lookInLabelMnemonic", l);
0N/A lookInLabelText = UIManager.getString("FileChooser.lookInLabelText", l);
0N/A saveInLabelText = UIManager.getString("FileChooser.saveInLabelText", l);
0N/A
0N/A fileNameLabelMnemonic = getMnemonic("FileChooser.fileNameLabelMnemonic", l);
0N/A fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText", l);
0N/A folderNameLabelMnemonic = getMnemonic("FileChooser.folderNameLabelMnemonic", l);
0N/A folderNameLabelText = UIManager.getString("FileChooser.folderNameLabelText", l);
0N/A
0N/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 homeFolderToolTipText = UIManager.getString("FileChooser.homeFolderToolTipText",l);
0N/A homeFolderAccessibleName = UIManager.getString("FileChooser.homeFolderAccessibleName",l);
0N/A
0N/A newFolderToolTipText = UIManager.getString("FileChooser.newFolderToolTipText",l);
0N/A newFolderAccessibleName = UIManager.getString("FileChooser.newFolderAccessibleName",l);
0N/A
0N/A listViewButtonToolTipText = UIManager.getString("FileChooser.listViewButtonToolTipText",l);
0N/A listViewButtonAccessibleName = UIManager.getString("FileChooser.listViewButtonAccessibleName",l);
0N/A
0N/A detailsViewButtonToolTipText = UIManager.getString("FileChooser.detailsViewButtonToolTipText",l);
0N/A detailsViewButtonAccessibleName = UIManager.getString("FileChooser.detailsViewButtonAccessibleName",l);
0N/A }
0N/A
0N/A private int getMnemonic(String key, Locale l) {
0N/A return SwingUtilities2.getUIDefaultsInt(key, l);
0N/A }
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
1173N/A @Override public void rescanCurrentDirectory(JFileChooser fc) {
1173N/A filePane.rescanCurrentDirectory();
1173N/A }
0N/A
0N/A protected void doSelectedFileChanged(PropertyChangeEvent e) {
0N/A super.doSelectedFileChanged(e);
0N/A
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 protected void doSelectedFilesChanged(PropertyChangeEvent e) {
0N/A super.doSelectedFilesChanged(e);
0N/A
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 protected void doDirectoryChanged(PropertyChangeEvent e) {
0N/A super.doDirectoryChanged(e);
0N/A
0N/A JFileChooser fc = getFileChooser();
0N/A FileSystemView fsv = fc.getFileSystemView();
0N/A File currentDirectory = fc.getCurrentDirectory();
0N/A
0N/A if (!readOnly && currentDirectory != null) {
0N/A getNewFolderAction().setEnabled(filePane.canWrite(currentDirectory));
0N/A }
0N/A
0N/A if (currentDirectory != null) {
0N/A JComponent cb = getDirectoryComboBox();
0N/A if (cb instanceof JComboBox) {
0N/A ComboBoxModel model = ((JComboBox)cb).getModel();
0N/A if (model instanceof DirectoryComboBoxModel) {
0N/A ((DirectoryComboBoxModel)model).addItem(currentDirectory);
0N/A }
0N/A }
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
0N/A protected void doFileSelectionModeChanged(PropertyChangeEvent e) {
0N/A super.doFileSelectionModeChanged(e);
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 protected 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 protected void doControlButtonsChanged(PropertyChangeEvent e) {
0N/A super.doControlButtonsChanged(e);
0N/A
0N/A if (getFileChooser().getControlButtonsAreShown()) {
0N/A addControlButtons();
0N/A } else {
0N/A removeControlButtons();
0N/A }
0N/A }
0N/A
0N/A protected void addControlButtons() {
0N/A if (bottomPanel != null) {
0N/A bottomPanel.add(buttonPanel);
0N/A }
0N/A }
0N/A
0N/A protected void removeControlButtons() {
0N/A if (bottomPanel != null) {
0N/A bottomPanel.remove(buttonPanel);
0N/A }
0N/A }
0N/A
0N/A
0N/A
0N/A
0N/A // *******************************************************
0N/A // ************ FileChooser UI PLAF methods **************
0N/A // *******************************************************
0N/A
1173N/A protected ActionMap createActionMap() {
1173N/A ActionMap map = new ActionMapUIResource();
1173N/A // add standard actions
1173N/A FilePane.addActionsToMap(map, filePane.getActions());
1173N/A // add synth only actions
1173N/A map.put("fileNameCompletion", getFileNameCompletionAction());
1173N/A return map;
1173N/A }
0N/A
0N/A // *****************************
0N/A // ***** Directory Actions *****
0N/A // *****************************
0N/A
0N/A protected JComponent getDirectoryComboBox() {
0N/A return directoryComboBox;
0N/A }
0N/A
0N/A protected Action getDirectoryComboBoxAction() {
0N/A return directoryComboBoxAction;
0N/A }
0N/A
0N/A protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) {
1173N/A return new DirectoryComboBoxRenderer(directoryComboBox.getRenderer());
0N/A }
0N/A
0N/A //
0N/A // Renderer for DirectoryComboBox
0N/A //
1173N/A // Synth has some odd behavior with regards to renderers. Renderers are styled
1173N/A // in a specific manner by the SynthComboBoxUI. If we extend DefaultListCellRenderer
1173N/A // here, then we get none of those benefits or behaviors, leading to poor
1173N/A // looking combo boxes.
1173N/A // So what we do here is delegate most jobs to the "real" or original renderer,
1173N/A // and simply monkey with the icon and text of the renderer.
1173N/A private class DirectoryComboBoxRenderer implements ListCellRenderer {
1173N/A private ListCellRenderer delegate;
0N/A IndentIcon ii = new IndentIcon();
0N/A
1173N/A private DirectoryComboBoxRenderer(ListCellRenderer delegate) {
1173N/A this.delegate = delegate;
1173N/A }
0N/A
1173N/A @Override
1173N/A public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
1173N/A Component c = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
1173N/A
1173N/A assert c instanceof JLabel;
1173N/A JLabel label = (JLabel)c;
0N/A if (value == null) {
1173N/A label.setText("");
1173N/A return label;
0N/A }
1173N/A File directory = (File) value;
1173N/A label.setText(getFileChooser().getName(directory));
0N/A Icon icon = getFileChooser().getIcon(directory);
0N/A ii.icon = icon;
0N/A ii.depth = directoryComboBoxModel.getDepth(index);
1173N/A label.setIcon(ii);
0N/A
1173N/A return label;
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 (icon != null) {
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
0N/A public int getIconWidth() {
0N/A return ((icon != null) ? icon.getIconWidth() : 0) + depth*space;
0N/A }
0N/A
0N/A public int getIconHeight() {
0N/A return (icon != null) ? icon.getIconHeight() : 0;
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 public 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 int oldSize = directories.size();
0N/A directories.clear();
0N/A if (oldSize > 0) {
0N/A fireIntervalRemoved(this, 0, oldSize);
0N/A }
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 {
2372N/A canonical = ShellFolder.getNormalizedFile(directory);
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 * Acts when DirectoryComboBox has changed the selected item.
0N/A */
0N/A protected class DirectoryComboBoxAction extends AbstractAction {
0N/A protected DirectoryComboBoxAction() {
0N/A super("DirectoryComboBoxAction");
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A directoryComboBox.hidePopup();
0N/A JComponent cb = getDirectoryComboBox();
0N/A if (cb instanceof JComboBox) {
0N/A File f = (File)((JComboBox)cb).getSelectedItem();
0N/A getFileChooser().setCurrentDirectory(f);
0N/A }
0N/A }
0N/A }
0N/A
0N/A //
0N/A // Renderer for Types ComboBox
0N/A //
0N/A protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
1173N/A return new FilterComboBoxRenderer(filterComboBox.getRenderer());
0N/A }
0N/A
0N/A /**
0N/A * Render different type sizes and styles.
0N/A */
1173N/A public class FilterComboBoxRenderer implements ListCellRenderer {
1173N/A private ListCellRenderer delegate;
1173N/A private FilterComboBoxRenderer(ListCellRenderer delegate) {
1173N/A this.delegate = delegate;
1173N/A }
0N/A
1173N/A public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
1173N/A Component c = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
0N/A
1173N/A String text = null;
0N/A if (value != null && value instanceof FileFilter) {
1173N/A text = ((FileFilter) value).getDescription();
0N/A }
0N/A
1173N/A //this should always be true, since SynthComboBoxUI's SynthComboBoxRenderer
1173N/A //extends JLabel
1173N/A assert c instanceof JLabel;
1173N/A if (text != null) {
1173N/A ((JLabel)c).setText(text);
1173N/A }
1173N/A return c;
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
0N/A
0N/A /**
0N/A * <code>ButtonAreaLayout</code> behaves in a similar manner to
0N/A * <code>FlowLayout</code>. It lays out all components from left to
0N/A * right, flushed right. The widths of all components will be set
0N/A * to the largest preferred size width.
0N/A */
0N/A private static class ButtonAreaLayout implements LayoutManager {
0N/A private int hGap = 5;
0N/A private int topMargin = 17;
0N/A
0N/A public void addLayoutComponent(String string, Component comp) {
0N/A }
0N/A
0N/A public void layoutContainer(Container container) {
0N/A Component[] children = container.getComponents();
0N/A
0N/A if (children != null && children.length > 0) {
0N/A int numChildren = children.length;
0N/A Dimension[] sizes = new Dimension[numChildren];
0N/A Insets insets = container.getInsets();
0N/A int yLocation = insets.top + topMargin;
0N/A int maxWidth = 0;
0N/A
0N/A for (int counter = 0; counter < numChildren; counter++) {
0N/A sizes[counter] = children[counter].getPreferredSize();
0N/A maxWidth = Math.max(maxWidth, sizes[counter].width);
0N/A }
0N/A int xLocation, xOffset;
0N/A if (container.getComponentOrientation().isLeftToRight()) {
0N/A xLocation = container.getSize().width - insets.left - maxWidth;
0N/A xOffset = hGap + maxWidth;
0N/A } else {
0N/A xLocation = insets.left;
0N/A xOffset = -(hGap + maxWidth);
0N/A }
0N/A for (int counter = numChildren - 1; counter >= 0; counter--) {
0N/A children[counter].setBounds(xLocation, yLocation,
0N/A maxWidth, sizes[counter].height);
0N/A xLocation -= xOffset;
0N/A }
0N/A }
0N/A }
0N/A
0N/A public Dimension minimumLayoutSize(Container c) {
0N/A if (c != null) {
0N/A Component[] children = c.getComponents();
0N/A
0N/A if (children != null && children.length > 0) {
0N/A int numChildren = children.length;
0N/A int height = 0;
0N/A Insets cInsets = c.getInsets();
0N/A int extraHeight = topMargin + cInsets.top + cInsets.bottom;
0N/A int extraWidth = cInsets.left + cInsets.right;
0N/A int maxWidth = 0;
0N/A
0N/A for (int counter = 0; counter < numChildren; counter++) {
0N/A Dimension aSize = children[counter].getPreferredSize();
0N/A height = Math.max(height, aSize.height);
0N/A maxWidth = Math.max(maxWidth, aSize.width);
0N/A }
0N/A return new Dimension(extraWidth + numChildren * maxWidth +
0N/A (numChildren - 1) * hGap,
0N/A extraHeight + height);
0N/A }
0N/A }
0N/A return new Dimension(0, 0);
0N/A }
0N/A
0N/A public Dimension preferredLayoutSize(Container c) {
0N/A return minimumLayoutSize(c);
0N/A }
0N/A
0N/A public void removeLayoutComponent(Component c) { }
0N/A }
0N/A
0N/A private static void groupLabels(AlignedLabel[] group) {
0N/A for (int i = 0; i < group.length; i++) {
0N/A group[i].group = group;
0N/A }
0N/A }
0N/A
0N/A private class AlignedLabel extends JLabel {
0N/A private AlignedLabel[] group;
0N/A private int maxWidth = 0;
0N/A
0N/A AlignedLabel() {
0N/A super();
0N/A setAlignmentX(JComponent.LEFT_ALIGNMENT);
0N/A }
0N/A
0N/A AlignedLabel(String text) {
0N/A super(text);
0N/A setAlignmentX(JComponent.LEFT_ALIGNMENT);
0N/A }
0N/A
0N/A public Dimension getPreferredSize() {
0N/A Dimension d = super.getPreferredSize();
0N/A // Align the width with all other labels in group.
0N/A return new Dimension(getMaxWidth() + 11, d.height);
0N/A }
0N/A
0N/A private int getMaxWidth() {
0N/A if (maxWidth == 0 && group != null) {
0N/A int max = 0;
0N/A for (int i = 0; i < group.length; i++) {
0N/A max = Math.max(group[i].getSuperPreferredWidth(), max);
0N/A }
0N/A for (int i = 0; i < group.length; i++) {
0N/A group[i].maxWidth = max;
0N/A }
0N/A }
0N/A return maxWidth;
0N/A }
0N/A
0N/A private int getSuperPreferredWidth() {
0N/A return super.getPreferredSize().width;
0N/A }
0N/A }
0N/A}