Class FileNameCellEditor

java.lang.Object
javax.swing.AbstractCellEditor
org.bzdev.swing.FileNameCellEditor
All Implemented Interfaces:
ActionListener, Serializable, EventListener, CellEditor, TableCellEditor, TreeCellEditor

public class FileNameCellEditor extends AbstractCellEditor implements TableCellEditor, TreeCellEditor, ActionListener
Table cell editor for file names. The file name is stored in a table as text, but will be edited using a JFileChooser. An example of when this class might be used is when an instance of ConfigPropertyEditor includes entries providing file names and when one wants to use a file-chooser to pick appropriate files.

Relative file names are resolved relative to the current working directory in effect when the constructor of this class is called.

The code is based on an example in the Java swing tutorial.

See Also:
  • Constructor Details

    • FileNameCellEditor

      public FileNameCellEditor(String title, boolean allowNewFiles)
      Constructor specifying a title.
      Parameters:
      title - the title of dialog boxes that this class creates.
      allowNewFiles - true if new files (not yet existing) can be provided; false otherwise
    • FileNameCellEditor

      public FileNameCellEditor(boolean allowNewFiles)
      Constructor.
      Parameters:
      allowNewFiles - true if new files (not yet existing) can be provided; false otherwise
  • Method Details

    • 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 to add
    • 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:
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Specified by:
      actionPerformed in interface ActionListener
    • getCellEditorValue

      public Object getCellEditorValue()
      Specified by:
      getCellEditorValue in interface CellEditor
    • getTableCellEditorComponent

      public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
      Specified by:
      getTableCellEditorComponent in interface TableCellEditor
    • getTreeCellEditorComponent

      public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
      Specified by:
      getTreeCellEditorComponent in interface TreeCellEditor