1 /* BasicFileChooserUI.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax.swing.plaf.basic;
40 import java.awt.Window;
41 import java.awt.event.ActionEvent;
42 import java.awt.event.MouseAdapter;
43 import java.awt.event.MouseEvent;
44 import java.awt.event.MouseListener;
45 import java.beans.PropertyChangeEvent;
46 import java.beans.PropertyChangeListener;
48 import java.io.IOException;
49 import java.util.ArrayList;
50 import java.util.Hashtable;
52 import javax.swing.AbstractAction;
53 import javax.swing.Action;
54 import javax.swing.Icon;
55 import javax.swing.JButton;
56 import javax.swing.JComponent;
57 import javax.swing.JDialog;
58 import javax.swing.JFileChooser;
59 import javax.swing.JList;
60 import javax.swing.JPanel;
61 import javax.swing.JTextField;
62 import javax.swing.SwingUtilities;
63 import javax.swing.UIDefaults;
64 import javax.swing.UIManager;
65 import javax.swing.event.ListSelectionEvent;
66 import javax.swing.event.ListSelectionListener;
67 import javax.swing.filechooser.FileFilter;
68 import javax.swing.filechooser.FileSystemView;
69 import javax.swing.filechooser.FileView;
70 import javax.swing.plaf.ComponentUI;
71 import javax.swing.plaf.FileChooserUI;
72 import javax.swing.plaf.metal.MetalIconFactory;
76 * A UI delegate for the {@link JFileChooser} component under the
77 * {@link BasicLookAndFeel}.
79 public class BasicFileChooserUI extends FileChooserUI
82 * A file filter that accepts all files.
84 protected class AcceptAllFileFilter extends FileFilter
87 * Creates a new instance.
89 public AcceptAllFileFilter()
91 // Nothing to do here.
95 * Returns <code>true</code> always, as all files are accepted by this
100 * @return Always <code>true</code>.
102 public boolean accept(File f)
108 * Returns a description for this filter.
110 * @return A description for the file filter.
112 public String getDescription()
114 return acceptAllFileFilterText;
119 * Handles a user action to approve the dialog selection.
121 * @see BasicFileChooserUI#getApproveSelectionAction()
123 protected class ApproveSelectionAction extends AbstractAction
126 * Creates a new ApproveSelectionAction object.
128 protected ApproveSelectionAction()
130 super("approveSelection");
134 * Sets the current selection and closes the dialog.
136 * @param e the action event.
138 public void actionPerformed(ActionEvent e)
141 if (parentPath != null)
142 obj = new String(parentPath + getFileName());
144 obj = filechooser.getSelectedFile();
147 File f = filechooser.getFileSystemView().createFileObject(obj.toString());
148 File currSelected = filechooser.getSelectedFile();
149 if (filechooser.isTraversable(f))
151 filechooser.setCurrentDirectory(currSelected);
152 filechooser.rescanCurrentDirectory();
156 filechooser.approveSelection();
162 File f = new File(filechooser.getCurrentDirectory(), getFileName());
163 if ( selectedDir != null )
165 if (filechooser.isTraversable(f))
167 filechooser.setCurrentDirectory(f);
168 filechooser.rescanCurrentDirectory();
172 filechooser.setSelectedFile(f);
173 filechooser.approveSelection();
181 * Provides presentation information about files and directories.
183 protected class BasicFileView extends FileView
185 /** Storage for cached icons. */
186 protected Hashtable<File, Icon> iconCache = new Hashtable<File, Icon>();
189 * Creates a new instance.
191 public BasicFileView()
193 // Nothing to do here.
197 * Adds an icon to the cache, associating it with the given file/directory.
199 * @param f the file/directory.
202 public void cacheIcon(File f, Icon i)
208 * Clears the icon cache.
210 public void clearIconCache()
216 * Retrieves the icon associated with the specified file/directory, if
219 * @param f the file/directory.
221 * @return The cached icon (or <code>null</code>).
223 public Icon getCachedIcon(File f)
225 return (Icon) iconCache.get(f);
229 * Returns a description of the given file/directory. In this
230 * implementation, the description is the same as the name returned by
231 * {@link #getName(File)}.
233 * @param f the file/directory.
235 * @return A description of the given file/directory.
237 public String getDescription(File f)
243 * Returns an icon appropriate for the given file or directory.
245 * @param f the file/directory.
249 public Icon getIcon(File f)
251 Icon val = getCachedIcon(f);
254 if (filechooser.isTraversable(f))
263 * Returns the name for the given file/directory.
265 * @param f the file/directory.
267 * @return The name of the file/directory.
269 public String getName(File f)
274 JFileChooser c = getFileChooser();
275 FileSystemView v = c.getFileSystemView();
276 name = v.getSystemDisplayName(f);
282 * Returns a localised description for the type of file/directory.
284 * @param f the file/directory.
286 * @return A type description for the given file/directory.
288 public String getTypeDescription(File f)
290 if (filechooser.isTraversable(f))
297 * Returns {@link Boolean#TRUE} if the given file/directory is hidden,
298 * and {@link Boolean#FALSE} otherwise.
300 * @param f the file/directory.
302 * @return {@link Boolean#TRUE} or {@link Boolean#FALSE}.
304 public Boolean isHidden(File f)
306 return Boolean.valueOf(filechooser.getFileSystemView().isHiddenFile(f));
311 * Handles an action to cancel the file chooser.
313 * @see BasicFileChooserUI#getCancelSelectionAction()
315 protected class CancelSelectionAction extends AbstractAction
318 * Creates a new <code>CancelSelectionAction</code> object.
320 protected CancelSelectionAction()
326 * Cancels the selection and closes the dialog.
328 * @param e the action event (ignored).
330 public void actionPerformed(ActionEvent e)
332 filechooser.setSelectedFile(null);
333 filechooser.setSelectedFiles(null);
334 filechooser.cancelSelection();
340 * An action to handle changes to the parent directory (for example, via
341 * a click on the "up folder" button).
343 * @see BasicFileChooserUI#getChangeToParentDirectoryAction()
345 protected class ChangeToParentDirectoryAction extends AbstractAction
348 * Creates a new <code>ChangeToParentDirectoryAction</code> object.
350 protected ChangeToParentDirectoryAction()
356 * Handles the action event.
358 * @param e the action event.
360 public void actionPerformed(ActionEvent e)
362 filechooser.changeToParentDirectory();
363 filechooser.revalidate();
364 filechooser.repaint();
369 * A mouse listener that handles double-click events.
371 * @see BasicFileChooserUI#createDoubleClickListener(JFileChooser, JList)
373 protected class DoubleClickListener extends MouseAdapter
377 private Object lastSelected;
383 * Creates a new DoubleClickListener object.
385 * @param list DOCUMENT ME!
387 public DoubleClickListener(JList list)
390 lastSelected = list.getSelectedValue();
391 setDirectorySelected(false);
395 * Handles a mouse click event.
397 * @param e the event.
399 public void mouseClicked(MouseEvent e)
401 Object p = list.getSelectedValue();
404 FileSystemView fsv = filechooser.getFileSystemView();
405 if (e.getClickCount() >= 2 && lastSelected != null &&
406 p.toString().equals(lastSelected.toString()))
408 File f = fsv.createFileObject(lastSelected.toString());
409 if (filechooser.isTraversable(f))
411 filechooser.setCurrentDirectory(f);
412 filechooser.rescanCurrentDirectory();
416 filechooser.setSelectedFile(f);
417 filechooser.approveSelection();
423 String path = p.toString();
424 File f = fsv.createFileObject(path);
425 filechooser.setSelectedFile(f);
427 if (filechooser.isMultiSelectionEnabled())
429 int[] inds = list.getSelectedIndices();
430 File[] allFiles = new File[inds.length];
431 for (int i = 0; i < inds.length; i++)
432 allFiles[i] = (File) list.getModel().getElementAt(inds[i]);
433 filechooser.setSelectedFiles(allFiles);
436 if (filechooser.isTraversable(f))
438 setDirectorySelected(true);
443 setDirectorySelected(false);
447 parentPath = f.getParent();
450 setFileName(f.getName());
451 else if (filechooser.getFileSelectionMode() !=
452 JFileChooser.FILES_ONLY)
458 * Handles a mouse entered event (NOT IMPLEMENTED).
460 * @param e the mouse event.
462 public void mouseEntered(MouseEvent e)
469 * An action that changes the file chooser to display the user's home
472 * @see BasicFileChooserUI#getGoHomeAction()
474 protected class GoHomeAction extends AbstractAction
477 * Creates a new <code>GoHomeAction</code> object.
479 protected GoHomeAction()
485 * Sets the directory to the user's home directory, and repaints the
486 * file chooser component.
488 * @param e the action event (ignored).
490 public void actionPerformed(ActionEvent e)
492 filechooser.setCurrentDirectory(filechooser.getFileSystemView()
493 .getHomeDirectory());
494 filechooser.revalidate();
495 filechooser.repaint();
500 * An action that handles the creation of a new folder/directory.
502 * @see BasicFileChooserUI#getNewFolderAction()
504 protected class NewFolderAction extends AbstractAction
507 * Creates a new <code>NewFolderAction</code> object.
509 protected NewFolderAction()
515 * Handles the event by creating a new folder.
517 * @param e the action event (ignored).
519 public void actionPerformed(ActionEvent e)
523 filechooser.getFileSystemView().createNewFolder(filechooser
524 .getCurrentDirectory());
526 catch (IOException ioe)
530 filechooser.rescanCurrentDirectory();
531 filechooser.repaint();
536 * A listener for selection events in the file list.
538 * @see BasicFileChooserUI#createListSelectionListener(JFileChooser)
540 protected class SelectionListener implements ListSelectionListener
543 * Creates a new <code>SelectionListener</code> object.
545 protected SelectionListener()
547 // Nothing to do here.
551 * Sets the JFileChooser to the selected file on an update
553 * @param e DOCUMENT ME!
555 public void valueChanged(ListSelectionEvent e)
557 JList list = (JList) e.getSource();
558 Object f = list.getSelectedValue();
561 File file = filechooser.getFileSystemView().createFileObject(f.toString());
562 if (! filechooser.isTraversable(file))
565 filechooser.setSelectedFile(file);
570 filechooser.setSelectedFile(null);
578 * @see BasicFileChooserUI#getUpdateAction()
580 protected class UpdateAction extends AbstractAction
583 * Creates a new UpdateAction object.
585 protected UpdateAction()
591 * NOT YET IMPLEMENTED.
593 * @param e the action event.
595 public void actionPerformed(ActionEvent e)
597 // FIXME: implement this
601 /** The localised mnemonic for the cancel button. */
602 protected int cancelButtonMnemonic;
604 /** The localised text for the cancel button. */
605 protected String cancelButtonText;
607 /** The localised tool tip text for the cancel button. */
608 protected String cancelButtonToolTipText;
610 /** An icon representing a computer. */
611 protected Icon computerIcon;
613 /** An icon for the "details view" button. */
614 protected Icon detailsViewIcon;
616 /** An icon representing a directory. */
617 protected Icon directoryIcon;
619 /** The localised Mnemonic for the open button. */
620 protected int directoryOpenButtonMnemonic;
622 /** The localised text for the open button. */
623 protected String directoryOpenButtonText;
625 /** The localised tool tip text for the open button. */
626 protected String directoryOpenButtonToolTipText;
628 /** An icon representing a file. */
629 protected Icon fileIcon;
631 /** An icon representing a floppy drive. */
632 protected Icon floppyDriveIcon;
634 /** An icon representing a hard drive. */
635 protected Icon hardDriveIcon;
637 /** The localised mnemonic for the "help" button. */
638 protected int helpButtonMnemonic;
640 /** The localised text for the "help" button. */
641 protected String helpButtonText;
643 /** The localised tool tip text for the help button. */
644 protected String helpButtonToolTipText;
646 /** An icon representing the user's home folder. */
647 protected Icon homeFolderIcon;
649 /** An icon for the "list view" button. */
650 protected Icon listViewIcon;
652 /** An icon for the "new folder" button. */
653 protected Icon newFolderIcon = directoryIcon;
655 /** The localised mnemonic for the "open" button. */
656 protected int openButtonMnemonic;
658 /** The localised text for the "open" button. */
659 protected String openButtonText;
661 /** The localised tool tip text for the "open" button. */
662 protected String openButtonToolTipText;
664 /** The localised mnemonic for the "save" button. */
665 protected int saveButtonMnemonic;
667 /** The localised text for the "save" button. */
668 protected String saveButtonText;
670 /** The localised tool tip text for the save button. */
671 protected String saveButtonToolTipText;
673 /** The localised mnemonic for the "update" button. */
674 protected int updateButtonMnemonic;
676 /** The localised text for the "update" button. */
677 protected String updateButtonText;
679 /** The localised tool tip text for the "update" button. */
680 protected String updateButtonToolTipText;
682 /** An icon for the "up folder" button. */
683 protected Icon upFolderIcon;
685 // -- begin private, but package local since used in inner classes --
687 /** The file chooser component represented by this UI delegate. */
688 JFileChooser filechooser;
690 /** The model for the directory list. */
691 BasicDirectoryModel model;
693 /** The file filter for all files. */
694 FileFilter acceptAll = new AcceptAllFileFilter();
696 /** The default file view. */
697 FileView fv = new BasicFileView();
699 /** The accept (open/save) button. */
702 /** An optional accessory panel. */
703 JPanel accessoryPanel = new JPanel();
705 /** A property change listener. */
706 PropertyChangeListener propertyChangeListener;
708 /** The text describing the filter for "all files". */
709 String acceptAllFileFilterText;
711 /** The text describing a directory type. */
714 /** The text describing a file type. */
717 /** Is a directory selected? */
720 /** The current directory. */
723 // FIXME: describe what is contained in the bottom panel
724 /** The bottom panel. */
727 /** The close panel. */
730 /** Text box that displays file name */
733 /** Current parent path */
737 * The action for the 'approve' button.
738 * @see #getApproveSelectionAction()
740 private ApproveSelectionAction approveSelectionAction;
743 * The action for the 'cancel' button.
744 * @see #getCancelSelectionAction()
746 private CancelSelectionAction cancelSelectionAction;
749 * The action for the 'go home' control button.
750 * @see #getGoHomeAction()
752 private GoHomeAction goHomeAction;
755 * The action for the 'up folder' control button.
756 * @see #getChangeToParentDirectoryAction()
758 private ChangeToParentDirectoryAction changeToParentDirectoryAction;
761 * The action for the 'new folder' control button.
762 * @see #getNewFolderAction()
764 private NewFolderAction newFolderAction;
767 * The action for ???. // FIXME: what is this?
768 * @see #getUpdateAction()
770 private UpdateAction updateAction;
773 * When in FILES_ONLY, mode a directory cannot be selected, so
774 * we save a reference to any it here. This is used to enter
775 * the directory on "Open" when in that mode.
777 private File selectedDir;
786 Window owner = SwingUtilities.windowForComponent(filechooser);
787 if (owner instanceof JDialog)
788 ((JDialog) owner).dispose();
792 * Creates a new <code>BasicFileChooserUI</code> object.
794 * @param b the file chooser component.
796 public BasicFileChooserUI(JFileChooser b)
801 * Returns a UI delegate for the given component.
803 * @param c the component (should be a {@link JFileChooser}).
805 * @return A new UI delegate.
807 public static ComponentUI createUI(JComponent c)
809 return new BasicFileChooserUI((JFileChooser) c);
813 * Installs the UI for the specified component.
815 * @param c the component (should be a {@link JFileChooser}).
817 public void installUI(JComponent c)
819 if (c instanceof JFileChooser)
821 JFileChooser fc = (JFileChooser) c;
822 this.filechooser = fc;
823 fc.resetChoosableFileFilters();
827 installComponents(fc);
828 installListeners(fc);
830 File path = filechooser.getCurrentDirectory();
832 parentPath = path.getParent();
837 * Uninstalls this UI from the given component.
839 * @param c the component (should be a {@link JFileChooser}).
841 public void uninstallUI(JComponent c)
844 uninstallListeners(filechooser);
845 uninstallComponents(filechooser);
846 uninstallDefaults(filechooser);
850 // FIXME: Indent the entries in the combobox
851 // Made this method package private to access it from within inner classes
852 // with better performance
855 ArrayList parentFiles = new ArrayList();
856 File parent = filechooser.getCurrentDirectory();
858 parent = filechooser.getFileSystemView().getDefaultDirectory();
859 while (parent != null)
861 String name = parent.getName();
863 name = parent.getAbsolutePath();
865 parentFiles.add(parentFiles.size(), name);
866 parent = parent.getParentFile();
869 if (parentFiles.size() == 0)
875 * Creates and install the subcomponents for the file chooser.
877 * @param fc the file chooser.
879 public void installComponents(JFileChooser fc)
884 * Uninstalls the components from the file chooser.
886 * @param fc the file chooser.
888 public void uninstallComponents(JFileChooser fc)
893 * Installs the listeners required by this UI delegate.
895 * @param fc the file chooser.
897 protected void installListeners(JFileChooser fc)
899 propertyChangeListener = createPropertyChangeListener(filechooser);
900 if (propertyChangeListener != null)
901 filechooser.addPropertyChangeListener(propertyChangeListener);
902 fc.addPropertyChangeListener(getModel());
906 * Uninstalls the listeners previously installed by this UI delegate.
908 * @param fc the file chooser.
910 protected void uninstallListeners(JFileChooser fc)
912 if (propertyChangeListener != null)
914 filechooser.removePropertyChangeListener(propertyChangeListener);
915 propertyChangeListener = null;
917 fc.removePropertyChangeListener(getModel());
921 * Installs the defaults for this UI delegate.
923 * @param fc the file chooser.
925 protected void installDefaults(JFileChooser fc)
932 * Uninstalls the defaults previously added by this UI delegate.
934 * @param fc the file chooser.
936 protected void uninstallDefaults(JFileChooser fc)
938 uninstallStrings(fc);
943 * Installs the icons for this UI delegate.
945 * @param fc the file chooser (ignored).
947 protected void installIcons(JFileChooser fc)
949 UIDefaults defaults = UIManager.getLookAndFeelDefaults();
950 computerIcon = MetalIconFactory.getTreeComputerIcon();
951 detailsViewIcon = defaults.getIcon("FileChooser.detailsViewIcon");
952 directoryIcon = new MetalIconFactory.TreeFolderIcon();
953 fileIcon = new MetalIconFactory.TreeLeafIcon();
954 floppyDriveIcon = MetalIconFactory.getTreeFloppyDriveIcon();
955 hardDriveIcon = MetalIconFactory.getTreeHardDriveIcon();
956 homeFolderIcon = defaults.getIcon("FileChooser.homeFolderIcon");
957 listViewIcon = defaults.getIcon("FileChooser.listViewIcon");
958 newFolderIcon = defaults.getIcon("FileChooser.newFolderIcon");
959 upFolderIcon = defaults.getIcon("FileChooser.upFolderIcon");
963 * Uninstalls the icons previously added by this UI delegate.
965 * @param fc the file chooser.
967 protected void uninstallIcons(JFileChooser fc)
970 detailsViewIcon = null;
971 directoryIcon = null;
973 floppyDriveIcon = null;
974 hardDriveIcon = null;
975 homeFolderIcon = null;
977 newFolderIcon = null;
982 * Installs the strings used by this UI delegate.
984 * @param fc the file chooser.
986 protected void installStrings(JFileChooser fc)
988 UIDefaults defaults = UIManager.getLookAndFeelDefaults();
990 dirDescText = defaults.getString("FileChooser.directoryDescriptionText");
991 fileDescText = defaults.getString("FileChooser.fileDescriptionText");
993 acceptAllFileFilterText = defaults.getString("FileChooser.acceptAllFileFilterText");
994 cancelButtonText = "Cancel";
995 cancelButtonToolTipText = "Abort file chooser dialog";
996 cancelButtonMnemonic = new Integer((String) UIManager.get("FileChooser.cancelButtonMnemonic")).intValue();
998 directoryOpenButtonText = "Open";
999 directoryOpenButtonToolTipText = "Open selected directory";
1000 directoryOpenButtonMnemonic
1001 = new Integer((String) UIManager.get("FileChooser.directoryOpenButtonMnemonic")).intValue();
1003 helpButtonText = "Help";
1004 helpButtonToolTipText = "FileChooser help";
1005 helpButtonMnemonic = new Integer((String) UIManager.get("FileChooser.helpButtonMnemonic")).intValue();
1007 openButtonText = "Open";
1008 openButtonToolTipText = "Open selected file";
1009 openButtonMnemonic = new Integer((String) UIManager.get("FileChooser.openButtonMnemonic")).intValue();
1011 saveButtonText = "Save";
1012 saveButtonToolTipText = "Save selected file";
1013 saveButtonMnemonic = new Integer((String) UIManager.get("FileChooser.saveButtonMnemonic")).intValue();
1015 updateButtonText = "Update";
1016 updateButtonToolTipText = "Update directory listing";
1017 updateButtonMnemonic = new Integer((String) UIManager.get("FileChooser.updateButtonMnemonic")).intValue();
1021 * Uninstalls the strings previously added by this UI delegate.
1023 * @param fc the file chooser.
1025 protected void uninstallStrings(JFileChooser fc)
1027 acceptAllFileFilterText = null;
1029 fileDescText = null;
1031 cancelButtonText = null;
1032 cancelButtonToolTipText = null;
1034 directoryOpenButtonText = null;
1035 directoryOpenButtonToolTipText = null;
1037 helpButtonText = null;
1038 helpButtonToolTipText = null;
1040 openButtonText = null;
1041 openButtonToolTipText = null;
1043 saveButtonText = null;
1044 saveButtonToolTipText = null;
1046 updateButtonText = null;
1047 updateButtonToolTipText = null;
1051 * Creates a new directory model.
1053 protected void createModel()
1055 model = new BasicDirectoryModel(filechooser);
1059 * Returns the directory model.
1061 * @return The directory model.
1063 public BasicDirectoryModel getModel()
1069 * Creates a listener to handle changes to the properties of the given
1070 * file chooser component.
1072 * @param fc the file chooser component.
1074 * @return A new listener.
1076 public PropertyChangeListener createPropertyChangeListener(JFileChooser fc)
1078 // The RI returns null here, so do we.
1083 * Returns the current file name.
1085 * @return The current file name.
1087 public String getFileName()
1089 return entry.getText();
1093 * Returns the current directory name.
1095 * @return The directory name.
1097 * @see #setDirectoryName(String)
1099 public String getDirectoryName()
1101 // XXX: I don't see a case where the thing returns something non-null..
1106 * Sets the file name.
1108 * @param filename the file name.
1110 * @see #getFileName()
1112 public void setFileName(String filename)
1114 // FIXME: it might be the case that this method provides an access
1115 // point for the JTextField (or whatever) a subclass is using...
1116 //this.filename = filename;
1120 * Sets the directory name (NOT IMPLEMENTED).
1122 * @param dirname the directory name.
1124 * @see #getDirectoryName()
1126 public void setDirectoryName(String dirname)
1132 * Rescans the current directory.
1134 * @param fc the file chooser.
1136 public void rescanCurrentDirectory(JFileChooser fc)
1138 getModel().validateFileCache();
1142 * NOT YET IMPLEMENTED.
1144 * @param fc the file chooser.
1145 * @param f the file.
1147 public void ensureFileIsVisible(JFileChooser fc, File f)
1149 // XXX: Not sure what this does.
1153 * Returns the {@link JFileChooser} component that this UI delegate
1156 * @return The component represented by this UI delegate.
1158 public JFileChooser getFileChooser()
1164 * Returns the optional accessory panel.
1166 * @return The optional accessory panel.
1168 public JPanel getAccessoryPanel()
1170 return accessoryPanel;
1174 * Returns the approve (open or save) button for the dialog.
1176 * @param fc the file chooser.
1178 * @return The button.
1180 protected JButton getApproveButton(JFileChooser fc)
1186 * Returns the tool tip text for the approve (open/save) button. This first
1187 * checks the file chooser to see if a value has been explicitly set - if
1188 * not, a default value appropriate for the type of file chooser is
1191 * @param fc the file chooser.
1193 * @return The tool tip text.
1195 public String getApproveButtonToolTipText(JFileChooser fc)
1197 if (fc.getApproveButtonToolTipText() != null)
1198 return fc.getApproveButtonToolTipText();
1199 else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG)
1200 return saveButtonToolTipText;
1202 return openButtonToolTipText;
1206 * Clears the icon cache.
1208 public void clearIconCache()
1210 if (fv instanceof BasicFileView)
1211 ((BasicFileView) fv).clearIconCache();
1215 * Creates a new listener to handle selections in the file list.
1217 * @param fc the file chooser component.
1219 * @return A new instance of {@link SelectionListener}.
1221 public ListSelectionListener createListSelectionListener(JFileChooser fc)
1223 return new SelectionListener();
1227 * Creates a new listener to handle double-click events.
1229 * @param fc the file chooser component.
1230 * @param list the list.
1232 * @return A new instance of {@link DoubleClickListener}.
1234 protected MouseListener createDoubleClickListener(JFileChooser fc, JList list)
1236 return new DoubleClickListener(list);
1240 * Returns <code>true</code> if a directory is selected, and
1241 * <code>false</code> otherwise.
1243 * @return A boolean.
1245 protected boolean isDirectorySelected()
1251 * Sets the flag that indicates whether the current directory is selected.
1253 * @param selected the new flag value.
1255 protected void setDirectorySelected(boolean selected)
1257 dirSelected = selected;
1261 * Returns the current directory.
1263 * @return The current directory.
1265 protected File getDirectory()
1271 * Sets the current directory.
1273 * @param f the directory.
1275 protected void setDirectory(File f)
1281 * Returns the "accept all" file filter.
1283 * @param fc the file chooser component.
1285 * @return The "accept all" file filter.
1287 public FileFilter getAcceptAllFileFilter(JFileChooser fc)
1293 * Returns the default file view (NOT the file view from the file chooser,
1296 * @param fc the file chooser component.
1298 * @return The file view.
1300 * @see JFileChooser#getFileView()
1302 public FileView getFileView(JFileChooser fc)
1308 * Returns the dialog title.
1310 * @param fc the file chooser (<code>null</code> not permitted).
1312 * @return The dialog title.
1314 * @see JFileChooser#getDialogTitle()
1316 public String getDialogTitle(JFileChooser fc)
1318 String result = fc.getDialogTitle();
1320 result = getApproveButtonText(fc);
1325 * Returns the approve button mnemonic.
1327 * @param fc the file chooser (<code>null</code> not permitted).
1329 * @return The approve button mnemonic.
1331 * @see JFileChooser#getApproveButtonMnemonic()
1333 public int getApproveButtonMnemonic(JFileChooser fc)
1335 if (fc.getApproveButtonMnemonic() != 0)
1336 return fc.getApproveButtonMnemonic();
1337 else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG)
1338 return saveButtonMnemonic;
1340 return openButtonMnemonic;
1344 * Returns the approve button text.
1346 * @param fc the file chooser (<code>null</code> not permitted).
1348 * @return The approve button text.
1350 * @see JFileChooser#getApproveButtonText()
1352 public String getApproveButtonText(JFileChooser fc)
1354 String result = fc.getApproveButtonText();
1357 if (fc.getDialogType() == JFileChooser.SAVE_DIALOG)
1358 result = saveButtonText;
1360 result = openButtonText;
1366 * Creates and returns a new action that will be used with the "new folder"
1369 * @return A new instance of {@link NewFolderAction}.
1371 public Action getNewFolderAction()
1373 if (newFolderAction == null)
1374 newFolderAction = new NewFolderAction();
1375 return newFolderAction;
1379 * Creates and returns a new action that will be used with the "home folder"
1382 * @return A new instance of {@link GoHomeAction}.
1384 public Action getGoHomeAction()
1386 if (goHomeAction == null)
1387 goHomeAction = new GoHomeAction();
1388 return goHomeAction;
1392 * Returns the action that handles events for the "up folder" control button.
1394 * @return An instance of {@link ChangeToParentDirectoryAction}.
1396 public Action getChangeToParentDirectoryAction()
1398 if (changeToParentDirectoryAction == null)
1399 changeToParentDirectoryAction = new ChangeToParentDirectoryAction();
1400 return changeToParentDirectoryAction;
1404 * Returns the action that handles events for the "approve" button.
1406 * @return An instance of {@link ApproveSelectionAction}.
1408 public Action getApproveSelectionAction()
1410 if (approveSelectionAction == null)
1411 approveSelectionAction = new ApproveSelectionAction();
1412 return approveSelectionAction;
1416 * Returns the action that handles events for the "cancel" button.
1418 * @return An instance of {@link CancelSelectionAction}.
1420 public Action getCancelSelectionAction()
1422 if (cancelSelectionAction == null)
1423 cancelSelectionAction = new CancelSelectionAction();
1424 return cancelSelectionAction;
1428 * Returns the update action (an instance of {@link UpdateAction}).
1430 * @return An action.
1432 public Action getUpdateAction()
1434 if (updateAction == null)
1435 updateAction = new UpdateAction();
1436 return updateAction;