org.pietschy.command.file
Class AbstractSaveAsCommand
- ActionCommandExecutor
public abstract class AbstractSaveAsCommand
This command provides generic behaviour for the standard "save as" operation. On execution, the
command will display a
JFileChooser
and if successful
performSave(File)
will be
invoked. If the file selected by the user already exists the command will prompt the user to
confirm before
performSave(File)
is invoked. The message displayed to the user can be
configured by overriding
getFileExistsMessage(File)
and
AbstractSaveAsCommand
.
If the filters specified are instances of
ExtensionFileFilter
, the command will also
ensure the extension of the file is correct.
protected boolean | confirmOverwrite(Window invoker, File file) - This method is called to confirm the save if the selected file already exists.
|
protected String | getFileExistsMessage(File file) - Gets the text to display in the dialog that confirms file overwrite.
|
protected void | performFileAction(File[] selectedFiles, JFileChooser chooser, Window invoker)
|
protected abstract void | performSave(File file) - Called to perform the save operation.
|
protected int | showChooserDialog(JFileChooser chooser, Window invoker)
|
protected File | verifyFileExtension(File file, FileFilter selectedFilter) - Invoked to verify the extension of the file selected by the user.
|
afterExecute , beforeExecute , confirmProceed , getDefaultFileFilter , getFileChooser , handleCancel , handleError , handleExecute , isAcceptAllFileFilterUsed , isCenterOnInvoker , isRememberLastFilter , performFileAction , setAcceptAllFileFilterUsed , setCenterOnInvoker , setDefaultFileFilter , setRememberLastFilter , showChooserDialog |
addCommandListener , addInterceptor , areEqual , attach , configureButtonStates , detach , execute , execute , getActionAdapter , getActionAdapter , getActionCommand , getActionEvent , getHint , getHint , getHints , getInvoker , getInvokerWindow , getModifiers , handleExecute , installShortCut , installShortCut , postExecute , preExecute , putHint , putHints , removeCommandListener , removeInterceptor , requestDefautIn , setActionCommand , uninstallShortCut , uninstallShortCut |
addFace , addHoverListener , addNewFace , addNotify , addPropertyChangeListener , addPropertyChangeListener , attach , buttonIterator , configureButtonAppearance , configureButtonAppearances , configureButtonAppearances , configureButtonStates , createButton , createButton , createButton , createButton , createMenuItem , createMenuItem , createMenuItem , createMenuItem , detach , export , faceExists , fireHoverEnded , fireHoverStarted , getAccelerator , getAlternativeFaceNames , getButtonFactory , getButtonIn , getCommandManager , getDefaultFace , getDefaultFace , getDescription , getFace , getFace , getIcon , getId , getLongDescription , getMenuFactory , getMnemonic , getMnemonicIndex , getProperty , getProperty , getPropertyNames , getSelectedIcon , getText , getTextPosition , getToolbarFactory , initCommandManager , installFace , isAnonymous , isAttachedTo , isEnabled , isVisible , putProperty , removeHoverListener , removeNotify , removePropertyChangeListener , removePropertyChangeListener , requestFocusIn , setAccelerator , setButtonFactory , setDescription , setEnabled , setIcon , setLongDescription , setMenuFactory , setMnemonic , setMnemonicIndex , setSelectedIcon , setText , setTextPosition , setToolbarFactory , setVisible , toString |
AbstractSaveAsCommand
public AbstractSaveAsCommand(String id,
FileFilter filter)
Creates new instance with the specified id and FileFilter
. This command is
bound to the default command manager.
id
- the command id.filter
- the FileFilter
for the JFileChooser
to use. If it is an
instance of ExtensionFileFilter
the command will ensure the selected file has
the correct extension.
AbstractSaveAsCommand
public AbstractSaveAsCommand(String id,
FileFilter[] filters)
Creates new instance with the specified id and FileFilter
list. This command is
bound to the default command manager.
id
- the command id.filters
- the FileFilter
list for the JFileChooser
to use. If they are
instances of ExtensionFileFilter
the command will ensure the selected file has
the correct extension.
AbstractSaveAsCommand
public AbstractSaveAsCommand(CommandManager manager,
String id,
FileFilter filter)
Creates new instance with the specified id and FileFilter
.
id
- the commands id.filter
- the FileFilter
for the JFileChooser
to use. If it is an
instance of ExtensionFileFilter
the command will ensure the selected file has
the correct extension.
AbstractSaveAsCommand
public AbstractSaveAsCommand(CommandManager manager,
String id,
FileFilter[] filters)
Creates new instance with the specified id and FileFilters
.
id
- the commands id.filters
- the FileFilter
list for the JFileChooser
to use. If they are
instances of ExtensionFileFilter
the command will ensure the selected file has
the correct extension.
confirmOverwrite
protected boolean confirmOverwrite(Window invoker,
File file)
This method is called to confirm the save if the selected file already exists. By default
this method invokes
javax.swing.JOptionPane.showConfirmDialog(java.awt.Component, Object)
with
getFileExistsTitle()
and
getFileExistsMessage(java.io.File)
.
Subclasses can override for complete control over the confirmation process.
invoker
- the invoker window.file
- the file that is to be overwritten.
true
to overwrite the file, false
to cancel the operation.
getFileExistsMessage
protected String getFileExistsMessage(File file)
Gets the text to display in the dialog that confirms file overwrite. This defaults
to the string "File '" + file.getName() + "' already exists. Overwrite?"
- the string "File '" + file.getName() + "' already exists. Overwrite?".
performSave
protected abstract void performSave(File file)
Called to perform the save operation. Subclasses must implement this method to perform
the required save behaviour.
verifyFileExtension
protected File verifyFileExtension(File file,
FileFilter selectedFilter)
Invoked to verify the extension of the file selected by the user. This is provided to catch
the case where the user has typed the file name but has ommited the extension.
This implementation checks if the
FileFilter
is an instance of
ExtensionFileFilter
. If it is, it invokes
ExtensionFileFilter.checkAndAddExtension(File)
on the file, otherwise the file is returned
as is.
file
- the file the users has selected, that may or may not have an extension.selectedFilter
- the FileFilter
selected in the chooser.
- a filename with the correct extension.