com.pietschy.command.file
Class AbstractFileCommand

java.lang.Object
  extended by com.pietschy.command.Command
      extended by com.pietschy.command.ActionCommand
          extended by com.pietschy.command.file.AbstractFileCommand
All Implemented Interfaces:
ActionCommandExecutor, Bindable, Identifiable
Direct Known Subclasses:
AbstractFileOpenCommand, AbstractSaveAsCommand

public abstract class AbstractFileCommand
extends ActionCommand

Base implementation of file commands. It provides the common JFileChooser functionality. Subclasses must override showChooserDialog(javax.swing.JFileChooser, java.awt.Component) and performFileAction(java.io.File[], javax.swing.JFileChooser, java.awt.Component) to provide appropriate functionality.

Version:
$Revision: 1.6 $
Author:
andrewp

Field Summary
 
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
AbstractFileCommand(javax.swing.filechooser.FileFilter[] filters)
          Creates a new anonymous AbstractFileCommand with the specified file filters.
AbstractFileCommand(java.lang.String id, javax.swing.filechooser.FileFilter[] filters)
          Creates a new instance with the specified id and file filters.
 
Method Summary
protected  boolean beforeProceeding(java.awt.Component centerOn)
          This is method can be overridden to prevent the action from proceeding.
protected  java.awt.Component getComponentToCenterOn()
          Provides the component on which to center the chooser.
 javax.swing.filechooser.FileFilter getDefaultFileFilter()
          Gets the default FileFilter that will be selected in the chooser if isRememberLastFilter() is false.
protected  void handleCancel(javax.swing.JFileChooser chooser, java.awt.Component centerOn)
          This method is invoked if the user cancels the file chooser dialog.
protected  void handleError(javax.swing.JFileChooser chooser, java.awt.Component centerOn)
          This method is invoked if the showChooserDialog(javax.swing.JFileChooser, java.awt.Component) 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 JFileChooser.setAcceptAllFileFilterUsed(boolean).
 boolean isRememberLastFilter()
          Checks if the last FileFilter used by the user will be remembered.
protected abstract  void performFileAction(java.io.File[] files, javax.swing.JFileChooser chooser, java.awt.Component centerOn)
          This method is invoked if the showChooserDialog(javax.swing.JFileChooser, java.awt.Component) returns JFileChooser.APPROVE_OPTION.
protected  javax.swing.JFileChooser prepareFileChooser()
          Gets the file choose the command will use.
 void setAcceptAllFileFilterUsed(boolean accept)
          Used to configure JFileChooser.setAcceptAllFileFilterUsed(boolean).
 void setDefaultFileFilter(javax.swing.filechooser.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.
 void setSelectedFile(java.io.File file)
          Sets the file to be selected when the chooser is displayed.
 void setSelectedFiles(java.io.File[] files)
          Sets the files to be selected when the chooser is displayed.
protected abstract  int showChooserDialog(javax.swing.JFileChooser chooser, java.awt.Component centerOn)
          Called to display the JFileChooser.
 
Methods inherited from class com.pietschy.command.ActionCommand
addActionCommandListener, addInterceptor, bindToContainer, createButton, createButton, createButton, createButton, createMenuItem, createMenuItem, createMenuItem, createMenuItem, doButtonAttachments, doButtonDetachments, execute, execute, getActionAdapter, getActionAdapter, getActionEvent, getInvoker, getInvokerWindow, getModifiers, getParameter, getParameter, getParameters, installShortCut, installShortCut, postExecute, preExecute, putParameter, putParameters, removeActionCommandListener, removeInterceptor, requestDefaultIn, unbindFromContainer, uninstallShortCut, uninstallShortCut
 
Methods inherited from class com.pietschy.command.Command
addContainerPropertyListener, addFace, addHoverListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, attach, bind, bind, bind, buttonIterator, configureAppearance, configureAppearances, configureButtonAppearances, configureButtonStates, configureButtonStates, createButton, createButton, createButton, createButton, createComponent, createMenuItem, createMenuItem, createMenuItem, createMenuItem, detach, faceExists, findBestFace, fireHoverEnded, fireHoverStarted, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlternativeFaceContexts, getButtonFactory, getButtonIn, getCommandContainer, getContainerProperty, getDefaultFace, getDefaultFace, getFace, getFace, getId, getMenuFactory, getProperty, getProperty, getPropertyNames, getToolbarFactory, isAnonymous, isAttachedTo, isBound, isEnabled, isVisible, loadConfiguration, notifyCommandContainerHierarchyChanged, putProperties, putProperty, rebind, removeContainerPropertyListener, removeHoverListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, requestFocusIn, setButtonFactory, setEnabled, setMenuFactory, setToolbarFactory, setVisible, toString, unbind, validateId
 
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
 

Constructor Detail

AbstractFileCommand

public AbstractFileCommand(javax.swing.filechooser.FileFilter[] filters)
Creates a new anonymous AbstractFileCommand with the specified file filters. If the filter list is empty then setAcceptAllFileFilterUsed(boolean) will be set to true

Parameters:
filters - the file filters to use.
Throws:
java.lang.NullPointerException - if filters is null

AbstractFileCommand

public AbstractFileCommand(java.lang.String id,
                           javax.swing.filechooser.FileFilter[] filters)
Creates a new instance with the specified id and file filters. If the filter list is empty then setAcceptAllFileFilterUsed(boolean) will be set to true.

Parameters:
filters - the file filters to use.
Throws:
java.lang.NullPointerException - if filters is null
Method Detail

handleExecute

protected void handleExecute()
Description copied from class: ActionCommand
Main entry point for command subclasses that must be implemented to provide command specific behaviour.

This method should never be called directly to invoke a command. All command invocation must be performed using the ActionCommand.execute() and ActionCommand.execute(Map) methods.

Specified by:
handleExecute in class ActionCommand

getComponentToCenterOn

protected java.awt.Component getComponentToCenterOn()
Provides the component on which to center the chooser. By default this method returns ActionCommand.getInvokerWindow().

Returns:
the window on which to center the chooser.

handleCancel

protected void handleCancel(javax.swing.JFileChooser chooser,
                            java.awt.Component centerOn)
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.
centerOn -

beforeProceeding

protected boolean beforeProceeding(java.awt.Component centerOn)
This is method can be overridden to prevent the action from proceeding. The default implementation simply returns true .

Parameters:
centerOn - the component that the chooser will be centered on.
Returns:
true to preceed with showing the chooser, false to cancel the action. The default implementation always returns true.

handleError

protected void handleError(javax.swing.JFileChooser chooser,
                           java.awt.Component centerOn)
This method is invoked if the showChooserDialog(javax.swing.JFileChooser, java.awt.Component) returns JFileChooser.ERROR_OPTION. The default implementation does nothing, subclasses can override to handle the error.

Parameters:
chooser - the JFileChooser that was displayed.
centerOn -

showChooserDialog

protected abstract int showChooserDialog(javax.swing.JFileChooser chooser,
                                         java.awt.Component 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(java.awt.Component, java.lang.String), JFileChooser.showOpenDialog(java.awt.Component) or JFileChooser.showSaveDialog(java.awt.Component).

performFileAction

protected abstract void performFileAction(java.io.File[] files,
                                          javax.swing.JFileChooser chooser,
                                          java.awt.Component centerOn)
This method is invoked if the showChooserDialog(javax.swing.JFileChooser, java.awt.Component) 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.
centerOn - the component to center the chooser on.

prepareFileChooser

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

Returns:
the commands JFileChooser.

setSelectedFile

public void setSelectedFile(java.io.File file)
Sets the file to be selected when the chooser is displayed.

Parameters:
file - the file to be selected when the chooser is displayed.

setSelectedFiles

public void setSelectedFiles(java.io.File[] files)
Sets the files to be selected when the chooser is displayed.

Parameters:
files - the files to be selected when the chooser is displayed.

getDefaultFileFilter

public javax.swing.filechooser.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.


setDefaultFileFilter

public void setDefaultFileFilter(javax.swing.filechooser.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.

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.

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.

isAcceptAllFileFilterUsed

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


setAcceptAllFileFilterUsed

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



Copyright © 2006 - 2007 Andrew Pietsch