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
.PropertyChangeListener
;
47 import java
.io
.IOException
;
48 import java
.util
.ArrayList
;
49 import java
.util
.Hashtable
;
51 import javax
.swing
.AbstractAction
;
52 import javax
.swing
.Action
;
53 import javax
.swing
.Icon
;
54 import javax
.swing
.JButton
;
55 import javax
.swing
.JComponent
;
56 import javax
.swing
.JDialog
;
57 import javax
.swing
.JFileChooser
;
58 import javax
.swing
.JList
;
59 import javax
.swing
.JPanel
;
60 import javax
.swing
.JTextField
;
61 import javax
.swing
.SwingUtilities
;
62 import javax
.swing
.UIDefaults
;
63 import javax
.swing
.UIManager
;
64 import javax
.swing
.event
.ListSelectionEvent
;
65 import javax
.swing
.event
.ListSelectionListener
;
66 import javax
.swing
.filechooser
.FileFilter
;
67 import javax
.swing
.filechooser
.FileSystemView
;
68 import javax
.swing
.filechooser
.FileView
;
69 import javax
.swing
.plaf
.ComponentUI
;
70 import javax
.swing
.plaf
.FileChooserUI
;
71 import javax
.swing
.plaf
.metal
.MetalIconFactory
;
75 * A UI delegate for the {@link JFileChooser} component under the
76 * {@link BasicLookAndFeel}.
78 public class BasicFileChooserUI
extends FileChooserUI
81 * A file filter that accepts all files.
83 protected class AcceptAllFileFilter
extends FileFilter
86 * Creates a new instance.
88 public AcceptAllFileFilter()
90 // Nothing to do here.
94 * Returns <code>true</code> always, as all files are accepted by this
99 * @return Always <code>true</code>.
101 public boolean accept(File f
)
107 * Returns a description for this filter.
109 * @return A description for the file filter.
111 public String
getDescription()
113 return acceptAllFileFilterText
;
118 * Handles a user action to approve the dialog selection.
120 * @see BasicFileChooserUI#getApproveSelectionAction()
122 protected class ApproveSelectionAction
extends AbstractAction
125 * Creates a new ApproveSelectionAction object.
127 protected ApproveSelectionAction()
129 super("approveSelection");
133 * Sets the current selection and closes the dialog.
135 * @param e the action event.
137 public void actionPerformed(ActionEvent e
)
140 if (parentPath
!= null)
141 obj
= new String(parentPath
+ getFileName());
143 obj
= filechooser
.getSelectedFile();
146 File f
= filechooser
.getFileSystemView().createFileObject(obj
.toString());
147 File currSelected
= filechooser
.getSelectedFile();
148 if (filechooser
.isTraversable(f
))
150 filechooser
.setCurrentDirectory(currSelected
);
151 filechooser
.rescanCurrentDirectory();
155 filechooser
.approveSelection();
161 File f
= new File(filechooser
.getCurrentDirectory(), getFileName());
162 if ( selectedDir
!= null )
164 if (filechooser
.isTraversable(f
))
166 filechooser
.setCurrentDirectory(f
);
167 filechooser
.rescanCurrentDirectory();
171 filechooser
.setSelectedFile(f
);
172 filechooser
.approveSelection();
180 * Provides presentation information about files and directories.
182 protected class BasicFileView
extends FileView
184 /** Storage for cached icons. */
185 protected Hashtable
<File
, Icon
> iconCache
= new Hashtable
<File
, Icon
>();
188 * Creates a new instance.
190 public BasicFileView()
192 // Nothing to do here.
196 * Adds an icon to the cache, associating it with the given file/directory.
198 * @param f the file/directory.
201 public void cacheIcon(File f
, Icon i
)
207 * Clears the icon cache.
209 public void clearIconCache()
215 * Retrieves the icon associated with the specified file/directory, if
218 * @param f the file/directory.
220 * @return The cached icon (or <code>null</code>).
222 public Icon
getCachedIcon(File f
)
224 return (Icon
) iconCache
.get(f
);
228 * Returns a description of the given file/directory. In this
229 * implementation, the description is the same as the name returned by
230 * {@link #getName(File)}.
232 * @param f the file/directory.
234 * @return A description of the given file/directory.
236 public String
getDescription(File f
)
242 * Returns an icon appropriate for the given file or directory.
244 * @param f the file/directory.
248 public Icon
getIcon(File f
)
250 Icon val
= getCachedIcon(f
);
253 if (filechooser
.isTraversable(f
))
262 * Returns the name for the given file/directory.
264 * @param f the file/directory.
266 * @return The name of the file/directory.
268 public String
getName(File f
)
273 JFileChooser c
= getFileChooser();
274 FileSystemView v
= c
.getFileSystemView();
275 name
= v
.getSystemDisplayName(f
);
281 * Returns a localised description for the type of file/directory.
283 * @param f the file/directory.
285 * @return A type description for the given file/directory.
287 public String
getTypeDescription(File f
)
289 if (filechooser
.isTraversable(f
))
296 * Returns {@link Boolean#TRUE} if the given file/directory is hidden,
297 * and {@link Boolean#FALSE} otherwise.
299 * @param f the file/directory.
301 * @return {@link Boolean#TRUE} or {@link Boolean#FALSE}.
303 public Boolean
isHidden(File f
)
305 return Boolean
.valueOf(filechooser
.getFileSystemView().isHiddenFile(f
));
310 * Handles an action to cancel the file chooser.
312 * @see BasicFileChooserUI#getCancelSelectionAction()
314 protected class CancelSelectionAction
extends AbstractAction
317 * Creates a new <code>CancelSelectionAction</code> object.
319 protected CancelSelectionAction()
325 * Cancels the selection and closes the dialog.
327 * @param e the action event (ignored).
329 public void actionPerformed(ActionEvent e
)
331 filechooser
.setSelectedFile(null);
332 filechooser
.setSelectedFiles(null);
333 filechooser
.cancelSelection();
339 * An action to handle changes to the parent directory (for example, via
340 * a click on the "up folder" button).
342 * @see BasicFileChooserUI#getChangeToParentDirectoryAction()
344 protected class ChangeToParentDirectoryAction
extends AbstractAction
347 * Creates a new <code>ChangeToParentDirectoryAction</code> object.
349 protected ChangeToParentDirectoryAction()
355 * Handles the action event.
357 * @param e the action event.
359 public void actionPerformed(ActionEvent e
)
361 filechooser
.changeToParentDirectory();
362 filechooser
.revalidate();
363 filechooser
.repaint();
368 * A mouse listener that handles double-click events.
370 * @see BasicFileChooserUI#createDoubleClickListener(JFileChooser, JList)
372 protected class DoubleClickListener
extends MouseAdapter
376 private Object lastSelected
;
382 * Creates a new DoubleClickListener object.
384 * @param list DOCUMENT ME!
386 public DoubleClickListener(JList list
)
389 lastSelected
= list
.getSelectedValue();
390 setDirectorySelected(false);
394 * Handles a mouse click event.
396 * @param e the event.
398 public void mouseClicked(MouseEvent e
)
400 Object p
= list
.getSelectedValue();
403 FileSystemView fsv
= filechooser
.getFileSystemView();
404 if (e
.getClickCount() >= 2 && lastSelected
!= null &&
405 p
.toString().equals(lastSelected
.toString()))
407 File f
= fsv
.createFileObject(lastSelected
.toString());
408 if (filechooser
.isTraversable(f
))
410 filechooser
.setCurrentDirectory(f
);
411 filechooser
.rescanCurrentDirectory();
415 filechooser
.setSelectedFile(f
);
416 filechooser
.approveSelection();
422 String path
= p
.toString();
423 File f
= fsv
.createFileObject(path
);
424 filechooser
.setSelectedFile(f
);
426 if (filechooser
.isMultiSelectionEnabled())
428 int[] inds
= list
.getSelectedIndices();
429 File
[] allFiles
= new File
[inds
.length
];
430 for (int i
= 0; i
< inds
.length
; i
++)
431 allFiles
[i
] = (File
) list
.getModel().getElementAt(inds
[i
]);
432 filechooser
.setSelectedFiles(allFiles
);
435 if (filechooser
.isTraversable(f
))
437 setDirectorySelected(true);
442 setDirectorySelected(false);
446 parentPath
= f
.getParent();
449 setFileName(f
.getName());
450 else if (filechooser
.getFileSelectionMode() !=
451 JFileChooser
.FILES_ONLY
)
457 * Handles a mouse entered event (NOT IMPLEMENTED).
459 * @param e the mouse event.
461 public void mouseEntered(MouseEvent e
)
468 * An action that changes the file chooser to display the user's home
471 * @see BasicFileChooserUI#getGoHomeAction()
473 protected class GoHomeAction
extends AbstractAction
476 * Creates a new <code>GoHomeAction</code> object.
478 protected GoHomeAction()
484 * Sets the directory to the user's home directory, and repaints the
485 * file chooser component.
487 * @param e the action event (ignored).
489 public void actionPerformed(ActionEvent e
)
491 filechooser
.setCurrentDirectory(filechooser
.getFileSystemView()
492 .getHomeDirectory());
493 filechooser
.revalidate();
494 filechooser
.repaint();
499 * An action that handles the creation of a new folder/directory.
501 * @see BasicFileChooserUI#getNewFolderAction()
503 protected class NewFolderAction
extends AbstractAction
506 * Creates a new <code>NewFolderAction</code> object.
508 protected NewFolderAction()
514 * Handles the event by creating a new folder.
516 * @param e the action event (ignored).
518 public void actionPerformed(ActionEvent e
)
522 filechooser
.getFileSystemView().createNewFolder(filechooser
523 .getCurrentDirectory());
525 catch (IOException ioe
)
529 filechooser
.rescanCurrentDirectory();
530 filechooser
.repaint();
535 * A listener for selection events in the file list.
537 * @see BasicFileChooserUI#createListSelectionListener(JFileChooser)
539 protected class SelectionListener
implements ListSelectionListener
542 * Creates a new <code>SelectionListener</code> object.
544 protected SelectionListener()
546 // Nothing to do here.
550 * Sets the JFileChooser to the selected file on an update
552 * @param e DOCUMENT ME!
554 public void valueChanged(ListSelectionEvent e
)
556 JList list
= (JList
) e
.getSource();
557 Object f
= list
.getSelectedValue();
560 File file
= filechooser
.getFileSystemView().createFileObject(f
.toString());
561 if (! filechooser
.isTraversable(file
))
564 filechooser
.setSelectedFile(file
);
569 filechooser
.setSelectedFile(null);
577 * @see BasicFileChooserUI#getUpdateAction()
579 protected class UpdateAction
extends AbstractAction
582 * Creates a new UpdateAction object.
584 protected UpdateAction()
590 * NOT YET IMPLEMENTED.
592 * @param e the action event.
594 public void actionPerformed(ActionEvent e
)
596 // FIXME: implement this
600 /** The localised mnemonic for the cancel button. */
601 protected int cancelButtonMnemonic
;
603 /** The localised text for the cancel button. */
604 protected String cancelButtonText
;
606 /** The localised tool tip text for the cancel button. */
607 protected String cancelButtonToolTipText
;
609 /** An icon representing a computer. */
610 protected Icon computerIcon
;
612 /** An icon for the "details view" button. */
613 protected Icon detailsViewIcon
;
615 /** An icon representing a directory. */
616 protected Icon directoryIcon
;
618 /** The localised Mnemonic for the open button. */
619 protected int directoryOpenButtonMnemonic
;
621 /** The localised text for the open button. */
622 protected String directoryOpenButtonText
;
624 /** The localised tool tip text for the open button. */
625 protected String directoryOpenButtonToolTipText
;
627 /** An icon representing a file. */
628 protected Icon fileIcon
;
630 /** An icon representing a floppy drive. */
631 protected Icon floppyDriveIcon
;
633 /** An icon representing a hard drive. */
634 protected Icon hardDriveIcon
;
636 /** The localised mnemonic for the "help" button. */
637 protected int helpButtonMnemonic
;
639 /** The localised text for the "help" button. */
640 protected String helpButtonText
;
642 /** The localised tool tip text for the help button. */
643 protected String helpButtonToolTipText
;
645 /** An icon representing the user's home folder. */
646 protected Icon homeFolderIcon
;
648 /** An icon for the "list view" button. */
649 protected Icon listViewIcon
;
651 /** An icon for the "new folder" button. */
652 protected Icon newFolderIcon
= directoryIcon
;
654 /** The localised mnemonic for the "open" button. */
655 protected int openButtonMnemonic
;
657 /** The localised text for the "open" button. */
658 protected String openButtonText
;
660 /** The localised tool tip text for the "open" button. */
661 protected String openButtonToolTipText
;
663 /** The localised mnemonic for the "save" button. */
664 protected int saveButtonMnemonic
;
666 /** The localised text for the "save" button. */
667 protected String saveButtonText
;
669 /** The localised tool tip text for the save button. */
670 protected String saveButtonToolTipText
;
672 /** The localised mnemonic for the "update" button. */
673 protected int updateButtonMnemonic
;
675 /** The localised text for the "update" button. */
676 protected String updateButtonText
;
678 /** The localised tool tip text for the "update" button. */
679 protected String updateButtonToolTipText
;
681 /** An icon for the "up folder" button. */
682 protected Icon upFolderIcon
;
684 // -- begin private, but package local since used in inner classes --
686 /** The file chooser component represented by this UI delegate. */
687 JFileChooser filechooser
;
689 /** The model for the directory list. */
690 BasicDirectoryModel model
;
692 /** The file filter for all files. */
693 FileFilter acceptAll
= new AcceptAllFileFilter();
695 /** The default file view. */
696 FileView fv
= new BasicFileView();
698 /** The accept (open/save) button. */
701 /** An optional accessory panel. */
702 JPanel accessoryPanel
= new JPanel();
704 /** A property change listener. */
705 PropertyChangeListener propertyChangeListener
;
707 /** The text describing the filter for "all files". */
708 String acceptAllFileFilterText
;
710 /** The text describing a directory type. */
713 /** The text describing a file type. */
716 /** Is a directory selected? */
719 /** The current directory. */
722 // FIXME: describe what is contained in the bottom panel
723 /** The bottom panel. */
726 /** The close panel. */
729 /** Text box that displays file name */
732 /** Current parent path */
736 * The action for the 'approve' button.
737 * @see #getApproveSelectionAction()
739 private ApproveSelectionAction approveSelectionAction
;
742 * The action for the 'cancel' button.
743 * @see #getCancelSelectionAction()
745 private CancelSelectionAction cancelSelectionAction
;
748 * The action for the 'go home' control button.
749 * @see #getGoHomeAction()
751 private GoHomeAction goHomeAction
;
754 * The action for the 'up folder' control button.
755 * @see #getChangeToParentDirectoryAction()
757 private ChangeToParentDirectoryAction changeToParentDirectoryAction
;
760 * The action for the 'new folder' control button.
761 * @see #getNewFolderAction()
763 private NewFolderAction newFolderAction
;
766 * The action for ???. // FIXME: what is this?
767 * @see #getUpdateAction()
769 private UpdateAction updateAction
;
772 * When in FILES_ONLY, mode a directory cannot be selected, so
773 * we save a reference to any it here. This is used to enter
774 * the directory on "Open" when in that mode.
776 private File selectedDir
;
785 Window owner
= SwingUtilities
.windowForComponent(filechooser
);
786 if (owner
instanceof JDialog
)
787 ((JDialog
) owner
).dispose();
791 * Creates a new <code>BasicFileChooserUI</code> object.
793 * @param b the file chooser component.
795 public BasicFileChooserUI(JFileChooser b
)
800 * Returns a UI delegate for the given component.
802 * @param c the component (should be a {@link JFileChooser}).
804 * @return A new UI delegate.
806 public static ComponentUI
createUI(JComponent c
)
808 return new BasicFileChooserUI((JFileChooser
) c
);
812 * Installs the UI for the specified component.
814 * @param c the component (should be a {@link JFileChooser}).
816 public void installUI(JComponent c
)
818 if (c
instanceof JFileChooser
)
820 JFileChooser fc
= (JFileChooser
) c
;
821 this.filechooser
= fc
;
822 fc
.resetChoosableFileFilters();
826 installComponents(fc
);
827 installListeners(fc
);
829 File path
= filechooser
.getCurrentDirectory();
831 parentPath
= path
.getParent();
836 * Uninstalls this UI from the given component.
838 * @param c the component (should be a {@link JFileChooser}).
840 public void uninstallUI(JComponent c
)
843 uninstallListeners(filechooser
);
844 uninstallComponents(filechooser
);
845 uninstallDefaults(filechooser
);
849 // FIXME: Indent the entries in the combobox
850 // Made this method package private to access it from within inner classes
851 // with better performance
854 ArrayList parentFiles
= new ArrayList();
855 File parent
= filechooser
.getCurrentDirectory();
857 parent
= filechooser
.getFileSystemView().getDefaultDirectory();
858 while (parent
!= null)
860 String name
= parent
.getName();
862 name
= parent
.getAbsolutePath();
864 parentFiles
.add(parentFiles
.size(), name
);
865 parent
= parent
.getParentFile();
868 if (parentFiles
.size() == 0)
874 * Creates and install the subcomponents for the file chooser.
876 * @param fc the file chooser.
878 public void installComponents(JFileChooser fc
)
883 * Uninstalls the components from the file chooser.
885 * @param fc the file chooser.
887 public void uninstallComponents(JFileChooser fc
)
892 * Installs the listeners required by this UI delegate.
894 * @param fc the file chooser.
896 protected void installListeners(JFileChooser fc
)
898 propertyChangeListener
= createPropertyChangeListener(filechooser
);
899 if (propertyChangeListener
!= null)
900 filechooser
.addPropertyChangeListener(propertyChangeListener
);
901 fc
.addPropertyChangeListener(getModel());
905 * Uninstalls the listeners previously installed by this UI delegate.
907 * @param fc the file chooser.
909 protected void uninstallListeners(JFileChooser fc
)
911 if (propertyChangeListener
!= null)
913 filechooser
.removePropertyChangeListener(propertyChangeListener
);
914 propertyChangeListener
= null;
916 fc
.removePropertyChangeListener(getModel());
920 * Installs the defaults for this UI delegate.
922 * @param fc the file chooser.
924 protected void installDefaults(JFileChooser fc
)
931 * Uninstalls the defaults previously added by this UI delegate.
933 * @param fc the file chooser.
935 protected void uninstallDefaults(JFileChooser fc
)
937 uninstallStrings(fc
);
942 * Installs the icons for this UI delegate.
944 * @param fc the file chooser (ignored).
946 protected void installIcons(JFileChooser fc
)
948 UIDefaults defaults
= UIManager
.getLookAndFeelDefaults();
949 computerIcon
= MetalIconFactory
.getTreeComputerIcon();
950 detailsViewIcon
= defaults
.getIcon("FileChooser.detailsViewIcon");
951 directoryIcon
= new MetalIconFactory
.TreeFolderIcon();
952 fileIcon
= new MetalIconFactory
.TreeLeafIcon();
953 floppyDriveIcon
= MetalIconFactory
.getTreeFloppyDriveIcon();
954 hardDriveIcon
= MetalIconFactory
.getTreeHardDriveIcon();
955 homeFolderIcon
= defaults
.getIcon("FileChooser.homeFolderIcon");
956 listViewIcon
= defaults
.getIcon("FileChooser.listViewIcon");
957 newFolderIcon
= defaults
.getIcon("FileChooser.newFolderIcon");
958 upFolderIcon
= defaults
.getIcon("FileChooser.upFolderIcon");
962 * Uninstalls the icons previously added by this UI delegate.
964 * @param fc the file chooser.
966 protected void uninstallIcons(JFileChooser fc
)
969 detailsViewIcon
= null;
970 directoryIcon
= null;
972 floppyDriveIcon
= null;
973 hardDriveIcon
= null;
974 homeFolderIcon
= null;
976 newFolderIcon
= null;
981 * Installs the strings used by this UI delegate.
983 * @param fc the file chooser.
985 protected void installStrings(JFileChooser fc
)
987 UIDefaults defaults
= UIManager
.getLookAndFeelDefaults();
989 dirDescText
= defaults
.getString("FileChooser.directoryDescriptionText");
990 fileDescText
= defaults
.getString("FileChooser.fileDescriptionText");
992 acceptAllFileFilterText
= defaults
.getString("FileChooser.acceptAllFileFilterText");
993 cancelButtonText
= "Cancel";
994 cancelButtonToolTipText
= "Abort file chooser dialog";
995 cancelButtonMnemonic
= new Integer((String
) UIManager
.get("FileChooser.cancelButtonMnemonic")).intValue();
997 directoryOpenButtonText
= "Open";
998 directoryOpenButtonToolTipText
= "Open selected directory";
999 directoryOpenButtonMnemonic
1000 = new Integer((String
) UIManager
.get("FileChooser.directoryOpenButtonMnemonic")).intValue();
1002 helpButtonText
= "Help";
1003 helpButtonToolTipText
= "FileChooser help";
1004 helpButtonMnemonic
= new Integer((String
) UIManager
.get("FileChooser.helpButtonMnemonic")).intValue();
1006 openButtonText
= "Open";
1007 openButtonToolTipText
= "Open selected file";
1008 openButtonMnemonic
= new Integer((String
) UIManager
.get("FileChooser.openButtonMnemonic")).intValue();
1010 saveButtonText
= "Save";
1011 saveButtonToolTipText
= "Save selected file";
1012 saveButtonMnemonic
= new Integer((String
) UIManager
.get("FileChooser.saveButtonMnemonic")).intValue();
1014 updateButtonText
= "Update";
1015 updateButtonToolTipText
= "Update directory listing";
1016 updateButtonMnemonic
= new Integer((String
) UIManager
.get("FileChooser.updateButtonMnemonic")).intValue();
1020 * Uninstalls the strings previously added by this UI delegate.
1022 * @param fc the file chooser.
1024 protected void uninstallStrings(JFileChooser fc
)
1026 acceptAllFileFilterText
= null;
1028 fileDescText
= null;
1030 cancelButtonText
= null;
1031 cancelButtonToolTipText
= null;
1033 directoryOpenButtonText
= null;
1034 directoryOpenButtonToolTipText
= null;
1036 helpButtonText
= null;
1037 helpButtonToolTipText
= null;
1039 openButtonText
= null;
1040 openButtonToolTipText
= null;
1042 saveButtonText
= null;
1043 saveButtonToolTipText
= null;
1045 updateButtonText
= null;
1046 updateButtonToolTipText
= null;
1050 * Creates a new directory model.
1052 protected void createModel()
1054 model
= new BasicDirectoryModel(filechooser
);
1058 * Returns the directory model.
1060 * @return The directory model.
1062 public BasicDirectoryModel
getModel()
1068 * Creates a listener to handle changes to the properties of the given
1069 * file chooser component.
1071 * @param fc the file chooser component.
1073 * @return A new listener.
1075 public PropertyChangeListener
createPropertyChangeListener(JFileChooser fc
)
1077 // The RI returns null here, so do we.
1082 * Returns the current file name.
1084 * @return The current file name.
1086 public String
getFileName()
1088 return entry
.getText();
1092 * Returns the current directory name.
1094 * @return The directory name.
1096 * @see #setDirectoryName(String)
1098 public String
getDirectoryName()
1100 // XXX: I don't see a case where the thing returns something non-null..
1105 * Sets the file name.
1107 * @param filename the file name.
1109 * @see #getFileName()
1111 public void setFileName(String filename
)
1113 // FIXME: it might be the case that this method provides an access
1114 // point for the JTextField (or whatever) a subclass is using...
1115 //this.filename = filename;
1119 * Sets the directory name (NOT IMPLEMENTED).
1121 * @param dirname the directory name.
1123 * @see #getDirectoryName()
1125 public void setDirectoryName(String dirname
)
1131 * Rescans the current directory.
1133 * @param fc the file chooser.
1135 public void rescanCurrentDirectory(JFileChooser fc
)
1137 getModel().validateFileCache();
1141 * NOT YET IMPLEMENTED.
1143 * @param fc the file chooser.
1144 * @param f the file.
1146 public void ensureFileIsVisible(JFileChooser fc
, File f
)
1148 // XXX: Not sure what this does.
1152 * Returns the {@link JFileChooser} component that this UI delegate
1155 * @return The component represented by this UI delegate.
1157 public JFileChooser
getFileChooser()
1163 * Returns the optional accessory panel.
1165 * @return The optional accessory panel.
1167 public JPanel
getAccessoryPanel()
1169 return accessoryPanel
;
1173 * Returns the approve (open or save) button for the dialog.
1175 * @param fc the file chooser.
1177 * @return The button.
1179 protected JButton
getApproveButton(JFileChooser fc
)
1185 * Returns the tool tip text for the approve (open/save) button. This first
1186 * checks the file chooser to see if a value has been explicitly set - if
1187 * not, a default value appropriate for the type of file chooser is
1190 * @param fc the file chooser.
1192 * @return The tool tip text.
1194 public String
getApproveButtonToolTipText(JFileChooser fc
)
1196 if (fc
.getApproveButtonToolTipText() != null)
1197 return fc
.getApproveButtonToolTipText();
1198 else if (fc
.getDialogType() == JFileChooser
.SAVE_DIALOG
)
1199 return saveButtonToolTipText
;
1201 return openButtonToolTipText
;
1205 * Clears the icon cache.
1207 public void clearIconCache()
1209 if (fv
instanceof BasicFileView
)
1210 ((BasicFileView
) fv
).clearIconCache();
1214 * Creates a new listener to handle selections in the file list.
1216 * @param fc the file chooser component.
1218 * @return A new instance of {@link SelectionListener}.
1220 public ListSelectionListener
createListSelectionListener(JFileChooser fc
)
1222 return new SelectionListener();
1226 * Creates a new listener to handle double-click events.
1228 * @param fc the file chooser component.
1229 * @param list the list.
1231 * @return A new instance of {@link DoubleClickListener}.
1233 protected MouseListener
createDoubleClickListener(JFileChooser fc
, JList list
)
1235 return new DoubleClickListener(list
);
1239 * Returns <code>true</code> if a directory is selected, and
1240 * <code>false</code> otherwise.
1242 * @return A boolean.
1244 protected boolean isDirectorySelected()
1250 * Sets the flag that indicates whether the current directory is selected.
1252 * @param selected the new flag value.
1254 protected void setDirectorySelected(boolean selected
)
1256 dirSelected
= selected
;
1260 * Returns the current directory.
1262 * @return The current directory.
1264 protected File
getDirectory()
1270 * Sets the current directory.
1272 * @param f the directory.
1274 protected void setDirectory(File f
)
1280 * Returns the "accept all" file filter.
1282 * @param fc the file chooser component.
1284 * @return The "accept all" file filter.
1286 public FileFilter
getAcceptAllFileFilter(JFileChooser fc
)
1292 * Returns the default file view (NOT the file view from the file chooser,
1295 * @param fc the file chooser component.
1297 * @return The file view.
1299 * @see JFileChooser#getFileView()
1301 public FileView
getFileView(JFileChooser fc
)
1307 * Returns the dialog title.
1309 * @param fc the file chooser (<code>null</code> not permitted).
1311 * @return The dialog title.
1313 * @see JFileChooser#getDialogTitle()
1315 public String
getDialogTitle(JFileChooser fc
)
1317 String result
= fc
.getDialogTitle();
1319 result
= getApproveButtonText(fc
);
1324 * Returns the approve button mnemonic.
1326 * @param fc the file chooser (<code>null</code> not permitted).
1328 * @return The approve button mnemonic.
1330 * @see JFileChooser#getApproveButtonMnemonic()
1332 public int getApproveButtonMnemonic(JFileChooser fc
)
1334 if (fc
.getApproveButtonMnemonic() != 0)
1335 return fc
.getApproveButtonMnemonic();
1336 else if (fc
.getDialogType() == JFileChooser
.SAVE_DIALOG
)
1337 return saveButtonMnemonic
;
1339 return openButtonMnemonic
;
1343 * Returns the approve button text.
1345 * @param fc the file chooser (<code>null</code> not permitted).
1347 * @return The approve button text.
1349 * @see JFileChooser#getApproveButtonText()
1351 public String
getApproveButtonText(JFileChooser fc
)
1353 String result
= fc
.getApproveButtonText();
1356 if (fc
.getDialogType() == JFileChooser
.SAVE_DIALOG
)
1357 result
= saveButtonText
;
1359 result
= openButtonText
;
1365 * Creates and returns a new action that will be used with the "new folder"
1368 * @return A new instance of {@link NewFolderAction}.
1370 public Action
getNewFolderAction()
1372 if (newFolderAction
== null)
1373 newFolderAction
= new NewFolderAction();
1374 return newFolderAction
;
1378 * Creates and returns a new action that will be used with the "home folder"
1381 * @return A new instance of {@link GoHomeAction}.
1383 public Action
getGoHomeAction()
1385 if (goHomeAction
== null)
1386 goHomeAction
= new GoHomeAction();
1387 return goHomeAction
;
1391 * Returns the action that handles events for the "up folder" control button.
1393 * @return An instance of {@link ChangeToParentDirectoryAction}.
1395 public Action
getChangeToParentDirectoryAction()
1397 if (changeToParentDirectoryAction
== null)
1398 changeToParentDirectoryAction
= new ChangeToParentDirectoryAction();
1399 return changeToParentDirectoryAction
;
1403 * Returns the action that handles events for the "approve" button.
1405 * @return An instance of {@link ApproveSelectionAction}.
1407 public Action
getApproveSelectionAction()
1409 if (approveSelectionAction
== null)
1410 approveSelectionAction
= new ApproveSelectionAction();
1411 return approveSelectionAction
;
1415 * Returns the action that handles events for the "cancel" button.
1417 * @return An instance of {@link CancelSelectionAction}.
1419 public Action
getCancelSelectionAction()
1421 if (cancelSelectionAction
== null)
1422 cancelSelectionAction
= new CancelSelectionAction();
1423 return cancelSelectionAction
;
1427 * Returns the update action (an instance of {@link UpdateAction}).
1429 * @return An action.
1431 public Action
getUpdateAction()
1433 if (updateAction
== null)
1434 updateAction
= new UpdateAction();
1435 return updateAction
;