java.lang.Object
org.bzdev.swing.ClearableFileChooser
File chooser that can distiguish between canceling the dialog and
indicating that no file is provided.
This class is used to implement FileNameCellEditor
. For this
dialog,
- The "Accept" button will set the call's value to the selected file.
- The "Clear" button will remove the value from cell.
- The "Cancel" button will leave the value in the cell unchanged.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Return value if approve (yes, ok) is chosen.static final int
Return value if cancel is chosen.static final int
Return value if clear is chosen.static final int
Return value if an error occurred. -
Constructor Summary
ConstructorsConstructorDescriptionClearableFileChooser
(File cdir, boolean allowNewFiles) Constructor.ClearableFileChooser
(File cdir, FileSystemView fsv, boolean allowNewFiles) Constructor providing a file system view. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChoosableFileFilter
(FileFilter filter) Adds a filter to the list of user choosable file filters.Get the text for the Approve button.Get the tooltip for the Approve button.Get the text for the Cancel button.Get the tooltip for the Cancel button.Get the text for the Clear button.Get the tooltip for the Clear button.Gets the string that goes in the dialog's title bar.Returns the currently selected file filter.int
Returns the current file-selection mode.Returns the selected file.boolean
Returns whether the AcceptAll FileFilter is used.boolean
removeChoosableFileFilter
(FileFilter filter) Removes a filter from the list of user choosable file filters.void
Resets the choosable file filter list to its starting state.void
setAcceptAllFileFilterUsed
(boolean b) Determines whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.void
setApproveButtonText
(String text) Set the text for the Approve button.void
Set the tooltip for the Approve button.void
setCancelButtonText
(String text) Set the text for the Cancel button.void
setCancelButtonTooltip
(String text) Set the tooltip for the Cancel button.void
setClearButtonText
(String text) Set the text for the Clear button.void
setClearButtonTooltip
(String text) Set the tooltip for the Clear button.void
setDialogTitle
(String dialogTitle) Sets the string that goes in the dialog's title bar.void
setFileFilter
(FileFilter filter) Sets the current file filter.void
setFileSelectionMode
(int mode) Sets the JFileChooser to allow the user to just select files, just select directories, or select both files and directories.void
Sets the selected file.int
showDialog
(Component parent) Show a file-chooser dialog.
-
Field Details
-
APPROVE_OPTION
public static final int APPROVE_OPTIONReturn value if approve (yes, ok) is chosen.- See Also:
-
CANCEL_OPTION
public static final int CANCEL_OPTIONReturn value if cancel is chosen.- See Also:
-
CLEAR_OPTION
public static final int CLEAR_OPTIONReturn value if clear is chosen.- See Also:
-
ERROR_OPTION
public static final int ERROR_OPTIONReturn value if an error occurred.- See Also:
-
-
Constructor Details
-
ClearableFileChooser
Constructor.- Parameters:
cdir
- the working directory; null for the current working directoryallowNewFiles
- true if new files (not yet existing) can be provided; false otherwise
-
ClearableFileChooser
Constructor providing a file system view.- Parameters:
cdir
- the working directory; null for the current working directoryfsv
- a file system viewallowNewFiles
- true if new files (not yet existing) can be provided; false otherwise
-
-
Method Details
-
getSelectedFile
Returns the selected file. This can be set either by the programmer viasetSelectedFile
or by a user action, such as either typing the filename into the UI or selecting the file from a list in the UI.- Returns:
- the selected file
- See Also:
-
setSelectedFile
Sets the selected file. This can be set either by the programmer viasetSelectedFile
or by a user action, such as either typing the filename into the UI or selecting the file from a list in the UI.- Parameters:
f
- the file- See Also:
-
setFileFilter
Sets the current file filter. The file filter is used by the file chooser to filter out files from the user's view.- Parameters:
filter
- the file filter
-
getFileFilter
Returns the currently selected file filter.- Returns:
- the current file filter.
-
addChoosableFileFilter
Adds a filter to the list of user choosable file filters. For information on setting the file selection mode, seesetFileSelectionMode(int)
.- Parameters:
filter
- the file filter
-
removeChoosableFileFilter
Removes a filter from the list of user choosable file filters.- Parameters:
filter
- the file filter to remove- Returns:
- true if the file filter was removed; false otherwise.
-
resetChoosableFileFilters
public void resetChoosableFileFilters()Resets the choosable file filter list to its starting state. Normally, this removes all added file filters while leaving the AcceptAll file filter. -
isAcceptAllFileFilterUsed
public boolean isAcceptAllFileFilterUsed()Returns whether the AcceptAll FileFilter is used.- Returns:
- true if the AcceptAll FileFilter is used; false otherwise
-
setAcceptAllFileFilterUsed
public void setAcceptAllFileFilterUsed(boolean b) Determines whether the AcceptAll FileFilter is used as an available choice in the choosable filter list. If the argument is false, the AcceptAll file filter is removed from the list of available file filters. If true, the AcceptAll file filter will become the actively used file filter.- Parameters:
b
- true if the AcceptAll FileFilter will be used; false otherwise
-
setFileSelectionMode
public void setFileSelectionMode(int mode) Sets the JFileChooser to allow the user to just select files, just select directories, or select both files and directories. The default is JFilesChooser.FILES_ONLY.- Parameters:
mode
- the type of files to be displayed:JFileChooser.FILES_ONLY
,JFileChooser.DIRECTORIES_ONLY
, orJFileChooser.FILES_AND_DIRECTORIES
- Throws:
IllegalArgumentException
- &emdash; if mode is an illegal file-selection mode
-
getFileSelectionMode
public int getFileSelectionMode()Returns the current file-selection mode. The default is JFilesChooser.FILES_ONLY.- Returns:
- the type of files to be displayed:
JFileChooser.FILES_ONLY
,JFileChooser.DIRECTORIES_ONLY
, orJFileChooser.FILES_AND_DIRECTORIES
-
getDialogTitle
Gets the string that goes in the dialog's title bar.- Returns:
- the title
- See Also:
-
setDialogTitle
Sets the string that goes in the dialog's title bar.- Parameters:
dialogTitle
- the newString
for the title bar- See Also:
-
getApproveButtonText
Get the text for the Approve button.- Returns:
- the text
-
getClearButtonText
Get the text for the Clear button.- Returns:
- the text
-
getCancelButtonText
Get the text for the Cancel button.- Returns:
- the text
-
setApproveButtonText
Set the text for the Approve button.- Parameters:
text
- the text; null for a default
-
setClearButtonText
Set the text for the Clear button.- Parameters:
text
- the text; null for a default
-
setCancelButtonText
Set the text for the Cancel button.- Parameters:
text
- the text; null for a default
-
getApproveButtonTooltip
Get the tooltip for the Approve button.- Returns:
- the text
-
getClearButtonTooltip
Get the tooltip for the Clear button.- Returns:
- the text
-
getCancelButtonTooltip
Get the tooltip for the Cancel button.- Returns:
- the text
-
setApproveButtonTooltip
Set the tooltip for the Approve button.- Parameters:
text
- the text; null for a default
-
setClearButtonTooltip
Set the tooltip for the Clear button.- Parameters:
text
- the text; null for a default
-
setCancelButtonTooltip
Set the tooltip for the Cancel button.- Parameters:
text
- the text; null for a default
-
showDialog
Show a file-chooser dialog. The exit status for the dialog is either-
APPROVE_OPTION
. This is the same asJFileChooser.APPROVE_OPTION
. -
CANCEL_OPTION
. This is the same asJFileChooser.CANCEL_OPTION
. -
ERROR_OPTION
. This is the same asJFileChooser.ERROR_OPTION
. -
CLEAR_OPTION
. The value is 2.
- Parameters:
parent
- the component on which the dialog may be centered- Returns:
- the dialog's exit status
-
-