Class ClearableFileChooser

java.lang.Object
org.bzdev.swing.ClearableFileChooser

public class ClearableFileChooser extends Object
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 Details

    • APPROVE_OPTION

      public static final int APPROVE_OPTION
      Return value if approve (yes, ok) is chosen.
      See Also:
    • CANCEL_OPTION

      public static final int CANCEL_OPTION
      Return value if cancel is chosen.
      See Also:
    • CLEAR_OPTION

      public static final int CLEAR_OPTION
      Return value if clear is chosen.
      See Also:
    • ERROR_OPTION

      public static final int ERROR_OPTION
      Return value if an error occurred.
      See Also:
  • Constructor Details

    • ClearableFileChooser

      public ClearableFileChooser(File cdir, boolean allowNewFiles)
      Constructor.
      Parameters:
      cdir - the working directory; null for the current working directory
      allowNewFiles - true if new files (not yet existing) can be provided; false otherwise
    • ClearableFileChooser

      public ClearableFileChooser(File cdir, FileSystemView fsv, boolean allowNewFiles)
      Constructor providing a file system view.
      Parameters:
      cdir - the working directory; null for the current working directory
      fsv - a file system view
      allowNewFiles - true if new files (not yet existing) can be provided; false otherwise
  • Method Details

    • getSelectedFile

      public File getSelectedFile()
      Returns the selected file. This can be set either by the programmer via setSelectedFile 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

      public void setSelectedFile(File f)
      Sets the selected file. This can be set either by the programmer via setSelectedFile 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

      public void setFileFilter(FileFilter filter)
      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

      public FileFilter getFileFilter()
      Returns the currently selected file filter.
      Returns:
      the current file filter.
    • addChoosableFileFilter

      public void addChoosableFileFilter(FileFilter filter)
      Adds a filter to the list of user choosable file filters. For information on setting the file selection mode, see setFileSelectionMode(int).
      Parameters:
      filter - the file filter
    • removeChoosableFileFilter

      public boolean removeChoosableFileFilter(FileFilter filter)
      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, or JFileChooser.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, or JFileChooser.FILES_AND_DIRECTORIES
    • getDialogTitle

      public String getDialogTitle()
      Gets the string that goes in the dialog's title bar.
      Returns:
      the title
      See Also:
    • setDialogTitle

      public void setDialogTitle(String dialogTitle)
      Sets the string that goes in the dialog's title bar.
      Parameters:
      dialogTitle - the new String for the title bar
      See Also:
    • getApproveButtonText

      public String getApproveButtonText()
      Get the text for the Approve button.
      Returns:
      the text
    • getClearButtonText

      public String getClearButtonText()
      Get the text for the Clear button.
      Returns:
      the text
    • getCancelButtonText

      public String getCancelButtonText()
      Get the text for the Cancel button.
      Returns:
      the text
    • setApproveButtonText

      public void setApproveButtonText(String text)
      Set the text for the Approve button.
      Parameters:
      text - the text; null for a default
    • setClearButtonText

      public void setClearButtonText(String text)
      Set the text for the Clear button.
      Parameters:
      text - the text; null for a default
    • setCancelButtonText

      public void setCancelButtonText(String text)
      Set the text for the Cancel button.
      Parameters:
      text - the text; null for a default
    • getApproveButtonTooltip

      public String getApproveButtonTooltip()
      Get the tooltip for the Approve button.
      Returns:
      the text
    • getClearButtonTooltip

      public String getClearButtonTooltip()
      Get the tooltip for the Clear button.
      Returns:
      the text
    • getCancelButtonTooltip

      public String getCancelButtonTooltip()
      Get the tooltip for the Cancel button.
      Returns:
      the text
    • setApproveButtonTooltip

      public void setApproveButtonTooltip(String text)
      Set the tooltip for the Approve button.
      Parameters:
      text - the text; null for a default
    • setClearButtonTooltip

      public void setClearButtonTooltip(String text)
      Set the tooltip for the Clear button.
      Parameters:
      text - the text; null for a default
    • setCancelButtonTooltip

      public void setCancelButtonTooltip(String text)
      Set the tooltip for the Cancel button.
      Parameters:
      text - the text; null for a default
    • showDialog

      public int showDialog(Component parent)
      Show a file-chooser dialog. The exit status for the dialog is either
      Parameters:
      parent - the component on which the dialog may be centered
      Returns:
      the dialog's exit status