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();
164 * Provides presentation information about files and directories.
166 protected class BasicFileView
extends FileView
168 /** Storage for cached icons. */
169 protected Hashtable iconCache
= new Hashtable();
172 * Creates a new instance.
174 public BasicFileView()
176 // Nothing to do here.
180 * Adds an icon to the cache, associating it with the given file/directory.
182 * @param f the file/directory.
185 public void cacheIcon(File f
, Icon i
)
191 * Clears the icon cache.
193 public void clearIconCache()
199 * Retrieves the icon associated with the specified file/directory, if
202 * @param f the file/directory.
204 * @return The cached icon (or <code>null</code>).
206 public Icon
getCachedIcon(File f
)
208 return (Icon
) iconCache
.get(f
);
212 * Returns a description of the given file/directory. In this
213 * implementation, the description is the same as the name returned by
214 * {@link #getName(File)}.
216 * @param f the file/directory.
218 * @return A description of the given file/directory.
220 public String
getDescription(File f
)
226 * Returns an icon appropriate for the given file or directory.
228 * @param f the file/directory.
232 public Icon
getIcon(File f
)
234 Icon val
= getCachedIcon(f
);
237 if (filechooser
.isTraversable(f
))
246 * Returns the name for the given file/directory.
248 * @param f the file/directory.
250 * @return The name of the file/directory.
252 public String
getName(File f
)
258 * Returns a localised description for the type of file/directory.
260 * @param f the file/directory.
262 * @return A type description for the given file/directory.
264 public String
getTypeDescription(File f
)
266 if (filechooser
.isTraversable(f
))
273 * Returns {@link Boolean#TRUE} if the given file/directory is hidden,
274 * and {@link Boolean#FALSE} otherwise.
276 * @param f the file/directory.
278 * @return {@link Boolean#TRUE} or {@link Boolean#FALSE}.
280 public Boolean
isHidden(File f
)
282 return Boolean
.valueOf(filechooser
.getFileSystemView().isHiddenFile(f
));
287 * Handles an action to cancel the file chooser.
289 * @see BasicFileChooserUI#getCancelSelectionAction()
291 protected class CancelSelectionAction
extends AbstractAction
294 * Creates a new <code>CancelSelectionAction</code> object.
296 protected CancelSelectionAction()
302 * Cancels the selection and closes the dialog.
304 * @param e the action event (ignored).
306 public void actionPerformed(ActionEvent e
)
308 filechooser
.setSelectedFile(null);
309 filechooser
.setSelectedFiles(null);
310 filechooser
.cancelSelection();
316 * An action to handle changes to the parent directory (for example, via
317 * a click on the "up folder" button).
319 * @see BasicFileChooserUI#getChangeToParentDirectoryAction()
321 protected class ChangeToParentDirectoryAction
extends AbstractAction
324 * Creates a new <code>ChangeToParentDirectoryAction</code> object.
326 protected ChangeToParentDirectoryAction()
332 * Handles the action event.
334 * @param e the action event.
336 public void actionPerformed(ActionEvent e
)
338 filechooser
.changeToParentDirectory();
339 filechooser
.revalidate();
340 filechooser
.repaint();
345 * A mouse listener that handles double-click events.
347 * @see BasicFileChooserUI#createDoubleClickListener(JFileChooser, JList)
349 protected class DoubleClickListener
extends MouseAdapter
353 private Object lastSelected
= null;
356 private JList list
= null;
359 * Creates a new DoubleClickListener object.
361 * @param list DOCUMENT ME!
363 public DoubleClickListener(JList list
)
366 lastSelected
= list
.getSelectedValue();
367 setDirectorySelected(false);
371 * Handles a mouse click event.
373 * @param e the event.
375 public void mouseClicked(MouseEvent e
)
377 Object p
= list
.getSelectedValue();
380 FileSystemView fsv
= filechooser
.getFileSystemView();
381 if (e
.getClickCount() >= 2 && lastSelected
!= null &&
382 p
.toString().equals(lastSelected
.toString()))
384 File f
= fsv
.createFileObject(lastSelected
.toString());
385 if (filechooser
.isTraversable(f
))
387 filechooser
.setCurrentDirectory(f
);
388 filechooser
.rescanCurrentDirectory();
392 filechooser
.setSelectedFile(f
);
393 filechooser
.approveSelection();
399 String path
= p
.toString();
400 File f
= fsv
.createFileObject(path
);
401 filechooser
.setSelectedFile(f
);
403 if (filechooser
.isMultiSelectionEnabled())
405 int[] inds
= list
.getSelectedIndices();
406 File
[] allFiles
= new File
[inds
.length
];
407 for (int i
= 0; i
< inds
.length
; i
++)
408 allFiles
[i
] = (File
) list
.getModel().getElementAt(inds
[i
]);
409 filechooser
.setSelectedFiles(allFiles
);
412 if (filechooser
.isTraversable(f
))
414 setDirectorySelected(true);
419 setDirectorySelected(false);
423 parentPath
= path
.substring(0, path
.lastIndexOf("/") + 1);
425 setFileName(path
.substring(path
.lastIndexOf("/") + 1));
426 else if (filechooser
.getFileSelectionMode() ==
427 JFileChooser
.DIRECTORIES_ONLY
)
433 * Handles a mouse entered event (NOT IMPLEMENTED).
435 * @param e the mouse event.
437 public void mouseEntered(MouseEvent e
)
444 * An action that changes the file chooser to display the user's home
447 * @see BasicFileChooserUI#getGoHomeAction()
449 protected class GoHomeAction
extends AbstractAction
452 * Creates a new <code>GoHomeAction</code> object.
454 protected GoHomeAction()
460 * Sets the directory to the user's home directory, and repaints the
461 * file chooser component.
463 * @param e the action event (ignored).
465 public void actionPerformed(ActionEvent e
)
467 filechooser
.setCurrentDirectory(filechooser
.getFileSystemView()
468 .getHomeDirectory());
469 filechooser
.revalidate();
470 filechooser
.repaint();
475 * An action that handles the creation of a new folder/directory.
477 * @see BasicFileChooserUI#getNewFolderAction()
479 protected class NewFolderAction
extends AbstractAction
482 * Creates a new <code>NewFolderAction</code> object.
484 protected NewFolderAction()
490 * Handles the event by creating a new folder.
492 * @param e the action event (ignored).
494 public void actionPerformed(ActionEvent e
)
498 filechooser
.getFileSystemView().createNewFolder(filechooser
499 .getCurrentDirectory());
501 catch (IOException ioe
)
505 filechooser
.rescanCurrentDirectory();
506 filechooser
.repaint();
511 * A listener for selection events in the file list.
513 * @see BasicFileChooserUI#createListSelectionListener(JFileChooser)
515 protected class SelectionListener
implements ListSelectionListener
518 * Creates a new <code>SelectionListener</code> object.
520 protected SelectionListener()
522 // Nothing to do here.
528 * @param e DOCUMENT ME!
530 public void valueChanged(ListSelectionEvent e
)
532 JList list
= (JList
) e
.getSource();
533 Object f
= list
.getSelectedValue();
536 File file
= filechooser
.getFileSystemView().createFileObject(f
.toString());
537 if (! filechooser
.isTraversable(file
))
538 filechooser
.setSelectedFile(file
);
540 filechooser
.setSelectedFile(null);
547 * @see BasicFileChooserUI#getUpdateAction()
549 protected class UpdateAction
extends AbstractAction
552 * Creates a new UpdateAction object.
554 protected UpdateAction()
560 * NOT YET IMPLEMENTED.
562 * @param e the action event.
564 public void actionPerformed(ActionEvent e
)
566 // FIXME: implement this
570 /** The localised mnemonic for the cancel button. */
571 protected int cancelButtonMnemonic
;
573 /** The localised text for the cancel button. */
574 protected String cancelButtonText
;
576 /** The localised tool tip text for the cancel button. */
577 protected String cancelButtonToolTipText
;
579 /** An icon representing a computer. */
580 protected Icon computerIcon
;
582 /** An icon for the "details view" button. */
583 protected Icon detailsViewIcon
;
585 /** An icon representing a directory. */
586 protected Icon directoryIcon
;
588 /** The localised Mnemonic for the open button. */
589 protected int directoryOpenButtonMnemonic
;
591 /** The localised text for the open button. */
592 protected String directoryOpenButtonText
;
594 /** The localised tool tip text for the open button. */
595 protected String directoryOpenButtonToolTipText
;
597 /** An icon representing a file. */
598 protected Icon fileIcon
;
600 /** An icon representing a floppy drive. */
601 protected Icon floppyDriveIcon
;
603 /** An icon representing a hard drive. */
604 protected Icon hardDriveIcon
;
606 /** The localised mnemonic for the "help" button. */
607 protected int helpButtonMnemonic
;
609 /** The localised text for the "help" button. */
610 protected String helpButtonText
;
612 /** The localised tool tip text for the help button. */
613 protected String helpButtonToolTipText
;
615 /** An icon representing the user's home folder. */
616 protected Icon homeFolderIcon
;
618 /** An icon for the "list view" button. */
619 protected Icon listViewIcon
;
621 /** An icon for the "new folder" button. */
622 protected Icon newFolderIcon
= directoryIcon
;
624 /** The localised mnemonic for the "open" button. */
625 protected int openButtonMnemonic
;
627 /** The localised text for the "open" button. */
628 protected String openButtonText
;
630 /** The localised tool tip text for the "open" button. */
631 protected String openButtonToolTipText
;
633 /** The localised mnemonic for the "save" button. */
634 protected int saveButtonMnemonic
;
636 /** The localised text for the "save" button. */
637 protected String saveButtonText
;
639 /** The localised tool tip text for the save button. */
640 protected String saveButtonToolTipText
;
642 /** The localised mnemonic for the "update" button. */
643 protected int updateButtonMnemonic
;
645 /** The localised text for the "update" button. */
646 protected String updateButtonText
;
648 /** The localised tool tip text for the "update" button. */
649 protected String updateButtonToolTipText
;
651 /** An icon for the "up folder" button. */
652 protected Icon upFolderIcon
;
654 // -- begin private, but package local since used in inner classes --
656 /** The file chooser component represented by this UI delegate. */
657 JFileChooser filechooser
;
659 /** The model for the directory list. */
660 BasicDirectoryModel model
;
662 /** The file filter for all files. */
663 FileFilter acceptAll
= new AcceptAllFileFilter();
665 /** The default file view. */
666 FileView fv
= new BasicFileView();
668 /** The accept (open/save) button. */
671 /** An optional accessory panel. */
672 JPanel accessoryPanel
= new JPanel();
674 /** A property change listener. */
675 PropertyChangeListener propertyChangeListener
;
677 /** The text describing the filter for "all files". */
678 String acceptAllFileFilterText
;
680 /** The text describing a directory type. */
683 /** The text describing a file type. */
686 /** Is a directory selected? */
687 boolean dirSelected
= false;
689 /** The current directory. */
692 // FIXME: describe what is contained in the bottom panel
693 /** The bottom panel. */
696 /** The close panel. */
699 /** Text box that displays file name */
702 /** Current parent path */
706 * The action for the 'approve' button.
707 * @see #getApproveSelectionAction()
709 private ApproveSelectionAction approveSelectionAction
;
712 * The action for the 'cancel' button.
713 * @see #getCancelSelectionAction()
715 private CancelSelectionAction cancelSelectionAction
;
718 * The action for the 'go home' control button.
719 * @see #getGoHomeAction()
721 private GoHomeAction goHomeAction
;
724 * The action for the 'up folder' control button.
725 * @see #getChangeToParentDirectoryAction()
727 private ChangeToParentDirectoryAction changeToParentDirectoryAction
;
730 * The action for the 'new folder' control button.
731 * @see #getNewFolderAction()
733 private NewFolderAction newFolderAction
;
736 * The action for ???. // FIXME: what is this?
737 * @see #getUpdateAction()
739 private UpdateAction updateAction
;
748 Window owner
= SwingUtilities
.windowForComponent(filechooser
);
749 if (owner
instanceof JDialog
)
750 ((JDialog
) owner
).dispose();
754 * Creates a new <code>BasicFileChooserUI</code> object.
756 * @param b the file chooser component.
758 public BasicFileChooserUI(JFileChooser b
)
763 * Returns a UI delegate for the given component.
765 * @param c the component (should be a {@link JFileChooser}).
767 * @return A new UI delegate.
769 public static ComponentUI
createUI(JComponent c
)
771 return new BasicFileChooserUI((JFileChooser
) c
);
775 * Installs the UI for the specified component.
777 * @param c the component (should be a {@link JFileChooser}).
779 public void installUI(JComponent c
)
781 if (c
instanceof JFileChooser
)
783 JFileChooser fc
= (JFileChooser
) c
;
784 this.filechooser
= fc
;
785 fc
.resetChoosableFileFilters();
789 installComponents(fc
);
790 installListeners(fc
);
792 Object path
= filechooser
.getCurrentDirectory();
794 parentPath
= path
.toString().substring(path
.toString().lastIndexOf("/"));
799 * Uninstalls this UI from the given component.
801 * @param c the component (should be a {@link JFileChooser}).
803 public void uninstallUI(JComponent c
)
806 uninstallListeners(filechooser
);
807 uninstallComponents(filechooser
);
808 uninstallDefaults(filechooser
);
812 // FIXME: Indent the entries in the combobox
813 // Made this method package private to access it from within inner classes
814 // with better performance
817 ArrayList parentFiles
= new ArrayList();
818 File parent
= filechooser
.getCurrentDirectory();
820 parent
= filechooser
.getFileSystemView().getDefaultDirectory();
821 while (parent
!= null)
823 String name
= parent
.getName();
825 name
= parent
.getAbsolutePath();
827 parentFiles
.add(parentFiles
.size(), name
);
828 parent
= parent
.getParentFile();
831 if (parentFiles
.size() == 0)
837 * Creates and install the subcomponents for the file chooser.
839 * @param fc the file chooser.
841 public void installComponents(JFileChooser fc
)
846 * Uninstalls the components from the file chooser.
848 * @param fc the file chooser.
850 public void uninstallComponents(JFileChooser fc
)
855 * Installs the listeners required by this UI delegate.
857 * @param fc the file chooser.
859 protected void installListeners(JFileChooser fc
)
861 propertyChangeListener
= createPropertyChangeListener(filechooser
);
862 filechooser
.addPropertyChangeListener(propertyChangeListener
);
866 * Uninstalls the listeners previously installed by this UI delegate.
868 * @param fc the file chooser.
870 protected void uninstallListeners(JFileChooser fc
)
872 filechooser
.removePropertyChangeListener(propertyChangeListener
);
873 propertyChangeListener
= null;
877 * Installs the defaults for this UI delegate.
879 * @param fc the file chooser.
881 protected void installDefaults(JFileChooser fc
)
888 * Uninstalls the defaults previously added by this UI delegate.
890 * @param fc the file chooser.
892 protected void uninstallDefaults(JFileChooser fc
)
894 uninstallStrings(fc
);
899 * Installs the icons for this UI delegate.
901 * @param fc the file chooser (ignored).
903 protected void installIcons(JFileChooser fc
)
905 UIDefaults defaults
= UIManager
.getLookAndFeelDefaults();
906 computerIcon
= MetalIconFactory
.getTreeComputerIcon();
907 detailsViewIcon
= defaults
.getIcon("FileChooser.detailsViewIcon");
908 directoryIcon
= new MetalIconFactory
.TreeFolderIcon();
909 fileIcon
= new MetalIconFactory
.TreeLeafIcon();
910 floppyDriveIcon
= MetalIconFactory
.getTreeFloppyDriveIcon();
911 hardDriveIcon
= MetalIconFactory
.getTreeHardDriveIcon();
912 homeFolderIcon
= defaults
.getIcon("FileChooser.homeFolderIcon");
913 listViewIcon
= defaults
.getIcon("FileChooser.listViewIcon");
914 newFolderIcon
= defaults
.getIcon("FileChooser.newFolderIcon");
915 upFolderIcon
= defaults
.getIcon("FileChooser.upFolderIcon");
919 * Uninstalls the icons previously added by this UI delegate.
921 * @param fc the file chooser.
923 protected void uninstallIcons(JFileChooser fc
)
926 detailsViewIcon
= null;
927 directoryIcon
= null;
929 floppyDriveIcon
= null;
930 hardDriveIcon
= null;
931 homeFolderIcon
= null;
933 newFolderIcon
= null;
938 * Installs the strings used by this UI delegate.
940 * @param fc the file chooser.
942 protected void installStrings(JFileChooser fc
)
944 UIDefaults defaults
= UIManager
.getLookAndFeelDefaults();
946 dirDescText
= defaults
.getString("FileChooser.directoryDescriptionText");
947 fileDescText
= defaults
.getString("FileChooser.fileDescriptionText");
949 acceptAllFileFilterText
= defaults
.getString("FileChooser.acceptAllFileFilterText");
950 cancelButtonText
= "Cancel";
951 cancelButtonToolTipText
= "Abort file chooser dialog";
952 cancelButtonMnemonic
= new Integer((String
) UIManager
.get("FileChooser.cancelButtonMnemonic")).intValue();
954 directoryOpenButtonText
= "Open";
955 directoryOpenButtonToolTipText
= "Open selected directory";
956 directoryOpenButtonMnemonic
957 = new Integer((String
) UIManager
.get("FileChooser.directoryOpenButtonMnemonic")).intValue();
959 helpButtonText
= "Help";
960 helpButtonToolTipText
= "FileChooser help";
961 helpButtonMnemonic
= new Integer((String
) UIManager
.get("FileChooser.helpButtonMnemonic")).intValue();
963 openButtonText
= "Open";
964 openButtonToolTipText
= "Open selected file";
965 openButtonMnemonic
= new Integer((String
) UIManager
.get("FileChooser.openButtonMnemonic")).intValue();
967 saveButtonText
= "Save";
968 saveButtonToolTipText
= "Save selected file";
969 saveButtonMnemonic
= new Integer((String
) UIManager
.get("FileChooser.saveButtonMnemonic")).intValue();
971 updateButtonText
= "Update";
972 updateButtonToolTipText
= "Update directory listing";
973 updateButtonMnemonic
= new Integer((String
) UIManager
.get("FileChooser.updateButtonMnemonic")).intValue();
977 * Uninstalls the strings previously added by this UI delegate.
979 * @param fc the file chooser.
981 protected void uninstallStrings(JFileChooser fc
)
983 acceptAllFileFilterText
= null;
987 cancelButtonText
= null;
988 cancelButtonToolTipText
= null;
990 directoryOpenButtonText
= null;
991 directoryOpenButtonToolTipText
= null;
993 helpButtonText
= null;
994 helpButtonToolTipText
= null;
996 openButtonText
= null;
997 openButtonToolTipText
= null;
999 saveButtonText
= null;
1000 saveButtonToolTipText
= null;
1002 updateButtonText
= null;
1003 updateButtonToolTipText
= null;
1007 * Creates a new directory model.
1009 protected void createModel()
1011 model
= new BasicDirectoryModel(filechooser
);
1015 * Returns the directory model.
1017 * @return The directory model.
1019 public BasicDirectoryModel
getModel()
1025 * Creates a listener to handle changes to the properties of the given
1026 * file chooser component.
1028 * @param fc the file chooser component.
1030 * @return A new listener.
1032 public PropertyChangeListener
createPropertyChangeListener(JFileChooser fc
)
1034 return new PropertyChangeListener()
1036 public void propertyChange(PropertyChangeEvent e
)
1043 * Returns the current file name.
1045 * @return The current file name.
1047 public String
getFileName()
1049 // FIXME: I'm thinking that this method just provides access to the
1050 // text value in the JTextField component...but not sure yet
1051 return null; //filename;
1055 * Returns the current directory name.
1057 * @return The directory name.
1059 * @see #setDirectoryName(String)
1061 public String
getDirectoryName()
1063 // XXX: I don't see a case where the thing returns something non-null..
1068 * Sets the file name.
1070 * @param filename the file name.
1072 * @see #getFileName()
1074 public void setFileName(String filename
)
1076 // FIXME: it might be the case that this method provides an access
1077 // point for the JTextField (or whatever) a subclass is using...
1078 //this.filename = filename;
1082 * Sets the directory name (NOT IMPLEMENTED).
1084 * @param dirname the directory name.
1086 * @see #getDirectoryName()
1088 public void setDirectoryName(String dirname
)
1094 * Rescans the current directory.
1096 * @param fc the file chooser.
1098 public void rescanCurrentDirectory(JFileChooser fc
)
1100 getModel().validateFileCache();
1104 * NOT YET IMPLEMENTED.
1106 * @param fc the file chooser.
1107 * @param f the file.
1109 public void ensureFileIsVisible(JFileChooser fc
, File f
)
1111 // XXX: Not sure what this does.
1115 * Returns the {@link JFileChooser} component that this UI delegate
1118 * @return The component represented by this UI delegate.
1120 public JFileChooser
getFileChooser()
1126 * Returns the optional accessory panel.
1128 * @return The optional accessory panel.
1130 public JPanel
getAccessoryPanel()
1132 return accessoryPanel
;
1136 * Returns the approve (open or save) button for the dialog.
1138 * @param fc the file chooser.
1140 * @return The button.
1142 protected JButton
getApproveButton(JFileChooser fc
)
1148 * Returns the tool tip text for the approve (open/save) button. This first
1149 * checks the file chooser to see if a value has been explicitly set - if
1150 * not, a default value appropriate for the type of file chooser is
1153 * @param fc the file chooser.
1155 * @return The tool tip text.
1157 public String
getApproveButtonToolTipText(JFileChooser fc
)
1159 if (fc
.getApproveButtonToolTipText() != null)
1160 return fc
.getApproveButtonToolTipText();
1161 else if (fc
.getDialogType() == JFileChooser
.SAVE_DIALOG
)
1162 return saveButtonToolTipText
;
1164 return openButtonToolTipText
;
1168 * Clears the icon cache.
1170 public void clearIconCache()
1172 if (fv
instanceof BasicFileView
)
1173 ((BasicFileView
) fv
).clearIconCache();
1177 * Creates a new listener to handle selections in the file list.
1179 * @param fc the file chooser component.
1181 * @return A new instance of {@link SelectionListener}.
1183 public ListSelectionListener
createListSelectionListener(JFileChooser fc
)
1185 return new SelectionListener();
1189 * Creates a new listener to handle double-click events.
1191 * @param fc the file chooser component.
1192 * @param list the list.
1194 * @return A new instance of {@link DoubleClickListener}.
1196 protected MouseListener
createDoubleClickListener(JFileChooser fc
, JList list
)
1198 return new DoubleClickListener(list
);
1202 * Returns <code>true</code> if a directory is selected, and
1203 * <code>false</code> otherwise.
1205 * @return A boolean.
1207 protected boolean isDirectorySelected()
1213 * Sets the flag that indicates whether the current directory is selected.
1215 * @param selected the new flag value.
1217 protected void setDirectorySelected(boolean selected
)
1219 dirSelected
= selected
;
1223 * Returns the current directory.
1225 * @return The current directory.
1227 protected File
getDirectory()
1233 * Sets the current directory.
1235 * @param f the directory.
1237 protected void setDirectory(File f
)
1243 * Returns the "accept all" file filter.
1245 * @param fc the file chooser component.
1247 * @return The "accept all" file filter.
1249 public FileFilter
getAcceptAllFileFilter(JFileChooser fc
)
1255 * Returns the default file view (NOT the file view from the file chooser,
1258 * @param fc the file chooser component.
1260 * @return The file view.
1262 * @see JFileChooser#getFileView()
1264 public FileView
getFileView(JFileChooser fc
)
1270 * Returns the dialog title.
1272 * @param fc the file chooser (<code>null</code> not permitted).
1274 * @return The dialog title.
1276 * @see JFileChooser#getDialogTitle()
1278 public String
getDialogTitle(JFileChooser fc
)
1280 String result
= fc
.getDialogTitle();
1282 result
= getApproveButtonText(fc
);
1287 * Returns the approve button mnemonic.
1289 * @param fc the file chooser (<code>null</code> not permitted).
1291 * @return The approve button mnemonic.
1293 * @see JFileChooser#getApproveButtonMnemonic()
1295 public int getApproveButtonMnemonic(JFileChooser fc
)
1297 if (fc
.getApproveButtonMnemonic() != 0)
1298 return fc
.getApproveButtonMnemonic();
1299 else if (fc
.getDialogType() == JFileChooser
.SAVE_DIALOG
)
1300 return saveButtonMnemonic
;
1302 return openButtonMnemonic
;
1306 * Returns the approve button text.
1308 * @param fc the file chooser (<code>null</code> not permitted).
1310 * @return The approve button text.
1312 * @see JFileChooser#getApproveButtonText()
1314 public String
getApproveButtonText(JFileChooser fc
)
1316 String result
= fc
.getApproveButtonText();
1319 if (fc
.getDialogType() == JFileChooser
.SAVE_DIALOG
)
1320 result
= saveButtonText
;
1322 result
= openButtonText
;
1328 * Creates and returns a new action that will be used with the "new folder"
1331 * @return A new instance of {@link NewFolderAction}.
1333 public Action
getNewFolderAction()
1335 if (newFolderAction
== null)
1336 newFolderAction
= new NewFolderAction();
1337 return newFolderAction
;
1341 * Creates and returns a new action that will be used with the "home folder"
1344 * @return A new instance of {@link GoHomeAction}.
1346 public Action
getGoHomeAction()
1348 if (goHomeAction
== null)
1349 goHomeAction
= new GoHomeAction();
1350 return goHomeAction
;
1354 * Returns the action that handles events for the "up folder" control button.
1356 * @return An instance of {@link ChangeToParentDirectoryAction}.
1358 public Action
getChangeToParentDirectoryAction()
1360 if (changeToParentDirectoryAction
== null)
1361 changeToParentDirectoryAction
= new ChangeToParentDirectoryAction();
1362 return changeToParentDirectoryAction
;
1366 * Returns the action that handles events for the "approve" button.
1368 * @return An instance of {@link ApproveSelectionAction}.
1370 public Action
getApproveSelectionAction()
1372 if (approveSelectionAction
== null)
1373 approveSelectionAction
= new ApproveSelectionAction();
1374 return approveSelectionAction
;
1378 * Returns the action that handles events for the "cancel" button.
1380 * @return An instance of {@link CancelSelectionAction}.
1382 public Action
getCancelSelectionAction()
1384 if (cancelSelectionAction
== null)
1385 cancelSelectionAction
= new CancelSelectionAction();
1386 return cancelSelectionAction
;
1390 * Returns the update action (an instance of {@link UpdateAction}).
1392 * @return An action.
1394 public Action
getUpdateAction()
1396 if (updateAction
== null)
1397 updateAction
= new UpdateAction();
1398 return updateAction
;