| |
|
| javax.swing.JFileChooser org.tp23.gui.widget.DefaultingDirectoryChooser
DefaultingDirectoryChooser | public class DefaultingDirectoryChooser extends JFileChooser implements DirectoryChooser(Code) | | A file chooser that makes a better default if the default directory is not available.
Basically the default looks for the suggested directory and if it does not find it moves back
up the directories. If still nothing is found (for example it may get to My Computer
which you can not add file to) the home directory is selected, as in the default file chooser.
To use this class call new DefaultingDirectoryChooser(boolean) and immediately call
setDefaultDirectory(File) to determine the default. If you don't it behaves like the default JFileChooser
Also if you call setCurrentDirectory(File) it will behave like JFileChooser
This chooser has two modes CREATE_MODE and EXISTING_MODE.
In existing mode it is assumed the chooser is being used to identify an existing directory
the default directory should exist if not the directory shown will be the next existing parent.
In create mode it is
assumed that the last directory in the default directory is to be created and may not
exist yet. Therefor the default directory displayed is the parent (with suitable defaulting)
and the text box will contain the name of the last directory.
e.g. if default is C:\Program Files\MyApp C:\Program Files will be displayed and
MyApp will be shown in the text box (even if it does not exist yet) If C:\Program Files does not exist
C:\ will be shown as with existing mode.
Choosing select can lead to the creation of the file. It will not be automatically
created that is the responsibility of the client code.
This class uses FileSystemView and will only display folders that return true to fsv.isFileSystem()
This class also uses a bit of a hack by in CREATE_MODE it sets the selectables to files and directories
although only shows the directories this way a non-existing Directory can be chosen. This is the only way I can
get it to work on my Java version but I would not be supprised if it did not work on
other versions of the Java API. It also means that setFileSelectionMode() should
never be called by clients as it will break this hack.
N.B. createMode is incompatible with multiselect mode
author: Paul Hinds version: 1.0 |
CREATE_MODE | final public static boolean CREATE_MODE(Code) | | |
EXISTING_MODE | final public static boolean EXISTING_MODE(Code) | | |
DefaultingDirectoryChooser | public DefaultingDirectoryChooser(boolean createMode)(Code) | | |
initDefaultNameListener | public void initDefaultNameListener()(Code) | | |
setDefaultDirectory | public void setDefaultDirectory(File dir)(Code) | | Sets the default directory.
Parameters: dir - the current directory to point to |
|
|
|