com.pietschy.command.file
Class RecentFileList

java.lang.Object
  extended by com.pietschy.command.Command
      extended by com.pietschy.command.group.CommandGroup
          extended by com.pietschy.command.file.RecentFileList
All Implemented Interfaces:
Bindable, Identifiable

public class RecentFileList
extends CommandGroup

Provides a group for selecting from a list of recently used files. A RecentFileListModel must be specified to provide the file list and an ActionCommandExecutor specified to perform the open operation. The file to be opened is passed to the executor as the named parameter AbstractFileOpenCommand.FILE_TO_OPEN.

As a convenience the AbstractFileOpenCommand automatically checks for this parameter and invokes performOpen(File[]) directly with out displaying the chooser. This allows you to use an existing file open command as the executor with no additional coding.

The class also includes a command for clearing the list. The text for the clear command is configured from the clearText property of the group. If the property isn't defined, the value Clear will be used. The clear command is hidden by default, to make it visible simply call getClearCommand().setVisible(true);

Version:
$Revision: 1.13 $
Author:
andrewp
See Also:
DefaultRecentFileListModel

Field Summary
 
Fields inherited from class com.pietschy.command.Command
internalLog, PROPERTY_ENABLED, PROPERTY_VISIBLE
 
Constructor Summary
RecentFileList(RecentFileListModel model)
          Creates a new anonymous instance with the specified RecentFileListModel.
RecentFileList(RecentFileListModel model, ActionCommandExecutor openExecutor)
          Creates a new anonymous instance with the specified RecentFileListModel and open executor.
RecentFileList(java.lang.String id, RecentFileListModel model)
          Creates a new instance with the specified id and RecentFileListModel.
RecentFileList(java.lang.String id, RecentFileListModel model, ActionCommandExecutor openExecutor)
          Creates a new instrance with the specified id, RecentFileListModel and open executor.
 
Method Summary
 void clear()
          Clears the model backing this instance.
 void clearExcludedFiles()
          Clears the current list of excluded files.
protected  javax.swing.KeyStroke getAcceleratorForIndex(int index)
          Returns the accelerator to use for the file at the specified index.
 int getAcceleratorModifiers()
          Gets the modifiers that are used to create the accelerators.
 ActionCommand getClearCommand()
          Gets the ActionCommand that clears the files from the group.
protected  com.pietschy.command.file.RecentFileList.OpenCommand getCommandFor(java.io.File file)
          Gets the command that opens the specified file.
 int getDisplaySize()
          Gets the number of files the group will display at any one time.
 java.io.File[] getExcludedFiles()
          Gets the file that is currently excluded from the list or null if all the files are included.
 RecentFileListModel getModel()
          Gets this commands data model.
protected  void initialise()
          Initialises the command internals.
(package private)  void installAccelerator(Face face, int index)
          Installs an accelerator for the specified index on the specified face.
 boolean isAccelerated()
          Checks if the list will have accelerator for each entry.
 boolean isIncludeNonExistentFiles()
          Checks if the group should include files for which File.exists() returns false.
 void setAccelerated(boolean accelerated)
          Configures the group to installFace accelerators for the list.
 void setAcceleratorModifiers(int acceleratorModifiers)
          Sets the modifiers that are used to create the accelerators.
 void setDisplaySize(int displaySize)
          Configures the number of files to display in the group.
 void setExcludedFile(java.io.File excludedFile)
          Sets the file to exclude from the list.
 void setExcludedFiles(java.util.Collection<java.io.File> excludedFiles)
          Sets the file to exclude from the list.
 void setExcludedFiles(java.io.File[] excludedFiles)
          Sets the file to exclude from the list.
 void setIncludeNonExistentFiles(boolean includeNonExistentFiles)
          Configures if the group should include files for which File.exists() returns false.
 void setModel(RecentFileListModel model)
          Sets the model for this command to use.
 void setOpenExecutor(ActionCommandExecutor openExecutor)
          Sets the open executor that this command will use to perform the file open operation.
 
Methods inherited from class com.pietschy.command.group.CommandGroup
addGroupListener, bindToContainer, createButton, createButton, createMemberManager, createMenuBar, createMenuBar, createMenuBar, createMenuBar, createMenuItem, createMenuItem, createPopupMenu, createPopupMenu, createPopupMenu, createToolBar, createToolBar, createToolBar, createToolBar, getBuilder, getExpansionPointBuilder, getMemberCount, getMemberListSpec, getMemberManager, getPopupContext, isAllowableMember, memberIterator, rebuildMembersFromSpec, removeGroupListener, setMemberListSpec, unbindFromContainer, visit, visitMembers
 
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, createComponent, createMenuItem, createMenuItem, createMenuItem, detach, doButtonAttachments, doButtonDetachments, 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
 

Constructor Detail

RecentFileList

public RecentFileList(RecentFileListModel model)
Creates a new anonymous instance with the specified RecentFileListModel.


RecentFileList

public RecentFileList(RecentFileListModel model,
                      ActionCommandExecutor openExecutor)
Creates a new anonymous instance with the specified RecentFileListModel and open executor.


RecentFileList

public RecentFileList(java.lang.String id,
                      RecentFileListModel model)
Creates a new instance with the specified id and RecentFileListModel.


RecentFileList

public RecentFileList(java.lang.String id,
                      RecentFileListModel model,
                      ActionCommandExecutor openExecutor)
Creates a new instrance with the specified id, RecentFileListModel and open executor.

Method Detail

initialise

protected void initialise()
Initialises the command internals.


getModel

public RecentFileListModel getModel()
Gets this commands data model.

Returns:
this commands data model.

setModel

public void setModel(RecentFileListModel model)
Sets the model for this command to use.

Parameters:
model - the model to use.
See Also:
DefaultRecentFileListModel

setOpenExecutor

public void setOpenExecutor(ActionCommandExecutor openExecutor)
Sets the open executor that this command will use to perform the file open operation. The actual file to open will be passed as a parameter to the execute method using the key AbstractFileOpenCommand.FILE_TO_OPEN.

Instances of AbstractFileOpenCommand automatically check for this parameter and bypass the opening of the file chooser.

Parameters:
openExecutor - the ActionCommandExecutor that will handle the file open operation.

getClearCommand

public ActionCommand getClearCommand()
Gets the ActionCommand that clears the files from the group.

Returns:
the ActionCommand that clears the files from the group.

getDisplaySize

public int getDisplaySize()
Gets the number of files the group will display at any one time.

Returns:
the number of files the group will display at any one time

setDisplaySize

public void setDisplaySize(int displaySize)
Configures the number of files to display in the group.

Parameters:
displaySize - the number of files to display in the group.

isIncludeNonExistentFiles

public boolean isIncludeNonExistentFiles()
Checks if the group should include files for which File.exists() returns false. The default value is false.

Returns:
true if the group is including non existant files, false otherwise.

setIncludeNonExistentFiles

public void setIncludeNonExistentFiles(boolean includeNonExistentFiles)
Configures if the group should include files for which File.exists() returns false. The default value is false.

Parameters:
includeNonExistentFiles - true if the group is to include non existant files, false otherwise.

getExcludedFiles

public java.io.File[] getExcludedFiles()
Gets the file that is currently excluded from the list or null if all the files are included.

Returns:
the file that is currently excluded from the list or null if all the files are included.
See Also:
setExcludedFile(File), setExcludedFiles(File[]), clearExcludedFiles()

setExcludedFile

public void setExcludedFile(java.io.File excludedFile)
Sets the file to exclude from the list. This typically used to exclude the file currently being edited by the application. If set to null, all files will be included in the list.

Parameters:
excludedFile - the file to exclude from the list, or null.
See Also:
setExcludedFiles(File[]), clearExcludedFiles()

setExcludedFiles

public void setExcludedFiles(java.io.File[] excludedFiles)
Sets the file to exclude from the list. This typically used to exclude the file currently being edited by the application. If set to null, all files will be included in the list.

Parameters:
excludedFiles - the file to exclude from the list, or null.
See Also:
setExcludedFile(File), clearExcludedFiles()

setExcludedFiles

public void setExcludedFiles(java.util.Collection<java.io.File> excludedFiles)
Sets the file to exclude from the list. This typically used to exclude the file currently being edited by the application. If set to null, all files will be included in the list.

Parameters:
excludedFiles - the file to exclude from the list, or null.
See Also:
setExcludedFile(File), clearExcludedFiles()

clearExcludedFiles

public void clearExcludedFiles()
Clears the current list of excluded files.

See Also:
setExcludedFile(File), setExcludedFiles(File[])

clear

public void clear()
Clears the model backing this instance. This is equivalent to calling getModel().clear.


isAccelerated

public boolean isAccelerated()
Checks if the list will have accelerator for each entry.

Returns:
true if the list will have accelerator for each entry, false otherwise.

setAccelerated

public void setAccelerated(boolean accelerated)
Configures the group to installFace accelerators for the list.

Parameters:
accelerated - true to display accelerators, false to ommit them.
See Also:
setAcceleratorModifiers(int)

getAcceleratorModifiers

public int getAcceleratorModifiers()
Gets the modifiers that are used to create the accelerators. This defaults to Toolkit.getMenuShortcutKeyMask().

Returns:
the modifiers that are used to create the accelerators.

setAcceleratorModifiers

public void setAcceleratorModifiers(int acceleratorModifiers)
Sets the modifiers that are used to create the accelerators. This defaults to Toolkit.getMenuShortcutKeyMask().

Parameters:
acceleratorModifiers - the modifiers that are used to create the accelerators.

getCommandFor

protected com.pietschy.command.file.RecentFileList.OpenCommand getCommandFor(java.io.File file)
Gets the command that opens the specified file.

Parameters:
file - the file of interest.
Returns:
the command that will open the specified file, or null if the file isn't in the list.

installAccelerator

void installAccelerator(Face face,
                        int index)
Installs an accelerator for the specified index on the specified face.

Parameters:
face - the face to configure.
index - the index of the file in the list.

getAcceleratorForIndex

protected javax.swing.KeyStroke getAcceleratorForIndex(int index)
Returns the accelerator to use for the file at the specified index. May return null.

Parameters:
index - the file index (starting at 0).
Returns:
the accelerator to use for the specified index, or null if there is no accelerator.


Copyright © 2006 - 2007 Andrew Pietsch