org.pietschy.command.file

Class AbstractFileCommand

Implemented Interfaces:
ActionCommandExecutor
Known Direct Subclasses:
AbstractFileOpenCommand, AbstractSaveAsCommand

public abstract class AbstractFileCommand
extends ActionCommand

This is the base implementation of file commands. It provides the basic JFileChooser functionality. Subclass must override showChooserDialog(JFileChooser,Window) and performFileAction(File[],JFileChooser,Window).
Version:
$Revision: 1.6 $
Author:
andrewp

Field Summary

Fields inherited from class org.pietschy.command.ActionCommand

HINT_ACTION_EVENT, HINT_INVOKER, HINT_INVOKER_WINDOW, HINT_MODIFIERS

Fields inherited from class org.pietschy.command.Command

internalLog, listenerList, pcs

Constructor Summary

AbstractFileCommand(CommandManager manager, String id, FileFilter[] filters)
Creates a new AbstractFileCommand with the specified file filters.

Method Summary

protected void
afterExecute()
Deprecated. Use ActionCommandInterceptor instead.
protected void
beforeExecute()
Deprecated. Use ActionCommandInterceptor instead.
protected boolean
confirmProceed()
This is method can be overridden to prevent the action from proceeding.
FileFilter
getDefaultFileFilter()
Gets the default FileFilter that will be selected in the chooser if isRememberLastFilter() is false.
protected JFileChooser
getFileChooser()
Gets the file choose the command will use.
protected void
handleCancel(JFileChooser chooser, Window invokerWindow)
This method is invoked if the user cancels the file chooser dialog.
protected void
handleError(JFileChooser chooser, Window invoker)
This method is invoked if the showChooserDialog(JFileChooser,Window) returns JFileChooser.ERROR_OPTION.
protected void
handleExecute()
Main entry point for command subclasses that must be implemented to provide command specific behaviour.
boolean
isAcceptAllFileFilterUsed()
Used to configure javax.swing.JFileChooser.setAcceptAllFileFilterUsed(boolean).
boolean
isCenterOnInvoker()
Checks if this command will be centering the chooser on the invoker window.
boolean
isRememberLastFilter()
Checks if the last FileFilter used by the user will be remembered.
protected abstract void
performFileAction(File[] files, JFileChooser chooser, Window invoker)
This method is invoked if the showChooserDialog(JFileChooser,Window) returns JFileChooser.APPROVE_OPTION.
void
setAcceptAllFileFilterUsed(boolean accept)
Used to configure javax.swing.JFileChooser.setAcceptAllFileFilterUsed(boolean).
void
setCenterOnInvoker(boolean centerOnInvoker)
Configures if command will centre the chooser over the invoker or centre in the desktop.
void
setDefaultFileFilter(FileFilter defaultFileFilter)
Sets the default FileFilter that will be selected in the chooser if isRememberLastFilter() is false.
void
setRememberLastFilter(boolean rememberLastFilter)
Configures this command to remember the FileFilter last used by the user.
protected abstract int
showChooserDialog(JFileChooser chooser, Window centerOn)
Called to display the JFileChooser.

Methods inherited from class org.pietschy.command.ActionCommand

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

Methods inherited from class org.pietschy.command.Command

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

Constructor Details

AbstractFileCommand

public AbstractFileCommand(CommandManager manager,
                           String id,
                           FileFilter[] filters)
Creates a new AbstractFileCommand with the specified file filters. Filters must contain at least one instance of javax.swing.filechooser.FileFilter.
Parameters:
filters - the file filters to use.

Method Details

afterExecute

protected void afterExecute()

Deprecated. Use ActionCommandInterceptor instead.

Invoked after the command is executed.

beforeExecute

protected void beforeExecute()

Deprecated. Use ActionCommandInterceptor instead.

Invoked before the command is executed.

confirmProceed

protected boolean confirmProceed()
This is method can be overridden to prevent the action from proceeding. By default this method simply returns true.
Returns:
true to preceed with showing the chooser, false to cancel the action. This method always returns true.

getDefaultFileFilter

public FileFilter getDefaultFileFilter()
Gets the default FileFilter that will be selected in the chooser if isRememberLastFilter() is false.

If not explicitly specified, this value will be the filter specified in the constructor, or the first filter if a list of filteres was specified.


getFileChooser

protected JFileChooser getFileChooser()
Gets the file choose the command will use. The chooser will be configured with the filters specified by the command.
Returns:
the commands javax.swing.JFileChooser.

handleCancel

protected void handleCancel(JFileChooser chooser,
                            Window invokerWindow)
This method is invoked if the user cancels the file chooser dialog. By default this method doesn nothing. Subclasses can override to perform some meaningful action.
Parameters:
chooser - the chooser that was cancelled.
invokerWindow - the window associated with the button or menu that invoked the command.

handleError

protected void handleError(JFileChooser chooser,
                           Window invoker)
This method is invoked if the showChooserDialog(JFileChooser,Window) returns JFileChooser.ERROR_OPTION. The default implementation does nothing, subclasses can override to handle the error.
Parameters:
chooser - the JFileChooser that was displayed.
invoker - the owner window.

handleExecute

protected final void handleExecute()
Overrides:
handleExecute in interface ActionCommand

isAcceptAllFileFilterUsed

public boolean isAcceptAllFileFilterUsed()
Used to configure javax.swing.JFileChooser.setAcceptAllFileFilterUsed(boolean).

isCenterOnInvoker

public boolean isCenterOnInvoker()
Checks if this command will be centering the chooser on the invoker window. If false, the command will invoke showChooserDialog(JFileChooser,Window) with a null window to center on.

This setting will only be honoured if subclasses implement showChooserDialog(JFileChooser,Window) to correctly utilize the centerOn parameter.

Returns:
true if the chooser will be centered on the invoker window, false to center on the desktop.

isRememberLastFilter

public boolean isRememberLastFilter()
Checks if the last FileFilter used by the user will be remembered.
Returns:
true if the command remebers the last FileFilter used by the user, false if default is always used.

performFileAction

protected abstract void performFileAction(File[] files,
                                          JFileChooser chooser,
                                          Window invoker)
This method is invoked if the showChooserDialog(JFileChooser,Window) returns JFileChooser.APPROVE_OPTION. Subclasses must override to perform the specific file operation.
Parameters:
files - the files that were selected in the JFileChooser
chooser - the JFileChooser that was displayed.
invoker - the owner window.

setAcceptAllFileFilterUsed

public void setAcceptAllFileFilterUsed(boolean accept)
Used to configure javax.swing.JFileChooser.setAcceptAllFileFilterUsed(boolean).

setCenterOnInvoker

public void setCenterOnInvoker(boolean centerOnInvoker)
Parameters:
centerOnInvoker - true to center the chooser on the invoker window, false to centre on the desktop.

setDefaultFileFilter

public void setDefaultFileFilter(FileFilter defaultFileFilter)
Sets the default FileFilter that will be selected in the chooser if isRememberLastFilter() is false.

If not explicitly specified, this value will be the filter specified in the constructor, or the first filter if a list of filteres was specified.

Parameters:
defaultFileFilter - the default file filter.

setRememberLastFilter

public void setRememberLastFilter(boolean rememberLastFilter)
Configures this command to remember the FileFilter last used by the user. This property defaults to false.
Parameters:
rememberLastFilter - true to remember the last FileFilter used, false to always used the default FileFilter.

showChooserDialog

protected abstract int showChooserDialog(JFileChooser chooser,
                                         Window centerOn)
Called to display the JFileChooser. Subclasses override to display an appropriate version of the chooser (such as an open or save dialog). This method must return the result of the JFileChooser show method. Eg.
protected int showChooserDialog(JFileChooser chooser, Window invoker)
{
   return chooser.showOpenDialog(invoker);
}
Parameters:
chooser - the chooser to display
Returns:
the result of JFileChooser.showDialog, JFileChooser.showOpenDialog or JFileChooser.showSaveDialog.