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:
-
Field Summary
Fields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList
-
Constructor Summary
ConstructorsConstructorDescriptionFileNameCellEditor
(boolean allowNewFiles) Constructor.FileNameCellEditor
(String title, boolean allowNewFiles) Constructor specifying a title. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
addChoosableFileFilter
(FileFilter filter) Adds a filter to the list of user choosable file filters.Gets the string that goes in the dialog's title bar.Returns the currently selected file filter.int
Returns the current file-selection mode.getTableCellEditorComponent
(JTable table, Object value, boolean isSelected, int row, int column) getTreeCellEditorComponent
(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) 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
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.Methods inherited from class javax.swing.AbstractCellEditor
addCellEditorListener, cancelCellEditing, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, isCellEditable, removeCellEditorListener, shouldSelectCell, stopCellEditing
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.swing.CellEditor
addCellEditorListener, cancelCellEditing, isCellEditable, removeCellEditorListener, shouldSelectCell, stopCellEditing
-
Constructor Details
-
FileNameCellEditor
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
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 to add
-
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:
-
actionPerformed
- Specified by:
actionPerformed
in interfaceActionListener
-
getCellEditorValue
- Specified by:
getCellEditorValue
in interfaceCellEditor
-
getTableCellEditorComponent
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) - Specified by:
getTableCellEditorComponent
in interfaceTableCellEditor
-
getTreeCellEditorComponent
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) - Specified by:
getTreeCellEditorComponent
in interfaceTreeCellEditor
-