|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.pietschy.command.Command
com.pietschy.command.ActionCommand
com.pietschy.command.file.AbstractFileCommand
com.pietschy.command.file.AbstractSaveAsCommand
public abstract class AbstractSaveAsCommand
An abstract class that provides behaviour for the standard "save as" operation. On execution, the
command will display a JFileChooser and if successful performSave(java.io.File) will be
invoked.
ExtensionFileFilter, the command will also
ensure the extension of the file is correct.
If the selected file already exists the command will prompt the user to
confirm before performSave(java.io.File) is invoked. The message displayed to the user can be
configured by specifying the properties overwriteMessage and overwriteTitle.
The message parameter is passed throught a message format where paramter 0 is the file name returned
by File.getName(). If the parameters aren't defined then the following defaults are used.
overwriteTitle=Confirm file overwrite
overwriteMessage=File ''{0}'' already exists. Overwrite?
If you need greater control over the messages displayed you can overload getOverwriteTitle()
and/or getOverwriteMessage(File). You can also override confirmOverwrite(Component, File)
to completely control the user interaction.
| Field Summary | |
|---|---|
(package private) static java.lang.String |
DEFAULT_OVERWRITE_MESSAGE
|
(package private) static java.lang.String |
DEFAULT_OVERWRITE_TITLE
|
static java.lang.String |
OVERWRITE_MESSAGE_PROPERTY
|
static java.lang.String |
OVERWRITE_TITLE_PROPERTY
|
| Fields inherited from class com.pietschy.command.ActionCommand |
|---|
PARAMETER_ACTION_EVENT, PARAMETER_INVOKER, PARAMETER_INVOKER_WINDOW, PARAMETER_MODIFIERS |
| Fields inherited from class com.pietschy.command.Command |
|---|
internalLog, PROPERTY_ENABLED, PROPERTY_VISIBLE |
| Constructor Summary | |
|---|---|
AbstractSaveAsCommand()
Creates a new anonymous instance. |
|
AbstractSaveAsCommand(javax.swing.filechooser.FileFilter filter)
Creates a new anonymous instance with the specified FileFilter. |
|
AbstractSaveAsCommand(javax.swing.filechooser.FileFilter[] filters)
Creates new anonymous instance with the specified list of FileFilters. |
|
AbstractSaveAsCommand(java.lang.String id)
Creates a new instance. |
|
AbstractSaveAsCommand(java.lang.String id,
javax.swing.filechooser.FileFilter filter)
Creates a new instance with the specified FileFilter. |
|
AbstractSaveAsCommand(java.lang.String id,
javax.swing.filechooser.FileFilter[] filters)
Creates new instance with the specified id and list of FileFilters. |
|
| Method Summary | |
|---|---|
protected boolean |
confirmOverwrite(java.awt.Component centerOn,
java.io.File file)
This method is called to confirm the save if the selected file already exists. |
protected java.lang.String |
getOverwriteMessage(java.io.File file)
Gets the text to display in the dialog that confirms file overwrite. |
protected java.lang.String |
getOverwriteTitle()
Gets the title to display in the dialog that confirms file overwrite. |
protected void |
performFileAction(java.io.File[] selectedFiles,
javax.swing.JFileChooser chooser,
java.awt.Component centerOn)
This method verifies
the extension, checks if the file exists, confirms overwrite if it does
and invokes performSave(File). |
protected abstract void |
performSave(java.io.File file)
Called to perform the save operation. |
protected int |
showChooserDialog(javax.swing.JFileChooser chooser,
java.awt.Component invoker)
shows the standard save dialog. |
protected java.io.File |
verifyFileExtension(java.io.File file,
javax.swing.filechooser.FileFilter selectedFilter)
Invoked to verify the extension of the file selected by the user. |
| Methods inherited from class com.pietschy.command.file.AbstractFileCommand |
|---|
beforeProceeding, getComponentToCenterOn, getDefaultFileFilter, handleCancel, handleError, handleExecute, isAcceptAllFileFilterUsed, isRememberLastFilter, prepareFileChooser, setAcceptAllFileFilterUsed, setDefaultFileFilter, setRememberLastFilter, setSelectedFile, setSelectedFiles |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.pietschy.command.ActionCommandExecutor |
|---|
addPropertyChangeListener, addPropertyChangeListener, isEnabled, removePropertyChangeListener, removePropertyChangeListener |
| Methods inherited from interface com.pietschy.command.Identifiable |
|---|
getId |
| Field Detail |
|---|
public static final java.lang.String OVERWRITE_MESSAGE_PROPERTY
public static final java.lang.String OVERWRITE_TITLE_PROPERTY
static final java.lang.String DEFAULT_OVERWRITE_MESSAGE
static final java.lang.String DEFAULT_OVERWRITE_TITLE
| Constructor Detail |
|---|
public AbstractSaveAsCommand(java.lang.String id,
javax.swing.filechooser.FileFilter[] filters)
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.
public AbstractSaveAsCommand(java.lang.String id,
javax.swing.filechooser.FileFilter filter)
FileFilter.
id - the command id.filter - the filter to use.public AbstractSaveAsCommand(java.lang.String id)
id - the command id.public AbstractSaveAsCommand(javax.swing.filechooser.FileFilter[] filters)
FileFilters.
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.public AbstractSaveAsCommand(javax.swing.filechooser.FileFilter filter)
FileFilter.
filter - the filter to use.public AbstractSaveAsCommand()
| Method Detail |
|---|
protected int showChooserDialog(javax.swing.JFileChooser chooser,
java.awt.Component invoker)
showChooserDialog in class AbstractFileCommandchooser - the chooser to display
JFileChooser.showSaveDialog(Component).
protected void performFileAction(java.io.File[] selectedFiles,
javax.swing.JFileChooser chooser,
java.awt.Component centerOn)
verifies
the extension, checks if the file exists, confirms overwrite if it does
and invokes performSave(File).
performFileAction in class AbstractFileCommandselectedFiles - the file list from the chooser.chooser - the chooser that was used.centerOn - the component to center any subsequent window on.
protected java.io.File verifyFileExtension(java.io.File file,
javax.swing.filechooser.FileFilter selectedFilter)
FileFilter is an instance of
ExtensionFileFilter. If it is, it invokes
ExtensionFileFilter.checkAndAddExtension(java.io.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.
ExtensionFileFilter
protected boolean confirmOverwrite(java.awt.Component centerOn,
java.io.File file)
JOptionPane.showConfirmDialog(Component, Object)
with getOverwriteTitle() and getOverwriteMessage(File).
Subclasses can override for complete control over the confirmation process.
centerOn - the invoker window.file - the file that is to be overwritten.
true to overwrite the file, false to cancel the operation.protected java.lang.String getOverwriteTitle()
protected java.lang.String getOverwriteMessage(java.io.File file)
MessageFormat template.
The file name as per File.getName() is the first pararmeter.
If the property is undefined the template "File '$1' already exists. Overwrite?"
is used.
protected abstract void performSave(java.io.File file)
file - the file to save.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||