org.pietschy.command.file
Class AbstractRecentFileGroup

java.lang.Object
  extended by org.pietschy.command.Command
      extended by org.pietschy.command.CommandGroup
          extended by org.pietschy.command.file.AbstractRecentFileGroup
All Implemented Interfaces:
java.util.EventListener, CommandManagerListener
Direct Known Subclasses:
RecentFileGroup

public abstract class AbstractRecentFileGroup
extends CommandGroup

Provides a custom group implementation that manages a list of recently used files. Subclasses must override openFile(java.io.File) and implement the required behaviour.

The group also includes a command for clearing the list. The text for the clear command is configured from the clear-text 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);

The methods store(java.util.prefs.Preferences) and load(java.util.prefs.Preferences) are also provided to allow easy persistence of the groups file list.

Version:
$Revision: 1.13 $
Author:
andrewp

Field Summary
 
Fields inherited from class org.pietschy.command.CommandGroup
memberList
 
Fields inherited from class org.pietschy.command.Command
internalLog, listenerList, pcs
 
Constructor Summary
  AbstractRecentFileGroup(CommandManager commandManager)
          Creates a new anonymous group.
  AbstractRecentFileGroup(CommandManager commandManager, java.lang.String id)
          Creates a new group with the specified id.
protected AbstractRecentFileGroup(java.lang.String id)
          Constructs a new group with the specified Id that is bound to the default command manager.
 
Method Summary
 void add(java.io.File file)
          Adds a file to the list.
 void addAll(java.io.File[] files)
          Adds all the specified files to the list.
protected  javax.swing.KeyStroke getAcceleratorForIndex(int 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  org.pietschy.command.file.AbstractRecentFileGroup.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[] getExcludedFile()
          Gets the file that is currently excluded from the list or null if all the files are included.
 java.io.File[] getFiles()
          Gets all files in the group.
 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 load(java.util.prefs.Preferences prefs)
          Loads the groups file list from the specified preference node.
abstract  void openFile(java.io.File file)
          Called to open the selected file.
 void refresh()
           
 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.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 store(java.util.prefs.Preferences prefs)
          Stores the groups file list to the specified preference node.
 
Methods inherited from class org.pietschy.command.CommandGroup
acceptVisitor, add, add, addGlue, addGlue, addGroupListener, addInline, addInline, addSeparator, addSeparator, bindMembers, bindMembers, commandRegistered, contains, createButton, createButton, createMenuBar, createMenuBar, createMenuBar, createMenuBar, createMenuItem, createPopupMenu, createPopupMenu, createToolBar, createToolBar, createToolBar, createToolBar, fireMembersChanged, getMemberCount, getMemberFactory, getMemberList, isAllowableMember, isInlineMember, isMember, rebuildAllPopups, remove, remove, removeGroupListener, reset, reset, visit, visitChildren
 
Methods inherited from class org.pietschy.command.Command
addFace, addHoverListener, addNewFace, addNotify, addPropertyChangeListener, addPropertyChangeListener, attach, buttonIterator, configureButtonAppearance, configureButtonAppearances, configureButtonAppearances, configureButtonStates, createButton, createButton, createButton, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractRecentFileGroup

public AbstractRecentFileGroup(CommandManager commandManager)
Creates a new anonymous group.

Parameters:
commandManager - the CommandManager to which the group will belong.

AbstractRecentFileGroup

protected AbstractRecentFileGroup(java.lang.String id)
Constructs a new group with the specified Id that is bound to the default command manager.

Parameters:
id - the id of the group.
See Also:
CommandManager.defaultInstance()

AbstractRecentFileGroup

public AbstractRecentFileGroup(CommandManager commandManager,
                               java.lang.String id)
Creates a new group with the specified id.

Parameters:
id - the commands id.
commandManager - the CommandManager to which the group will belong.
Method Detail

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.

getExcludedFile

public java.io.File[] getExcludedFile()
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.

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.

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.

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.

add

public void add(java.io.File file)
Adds a file to the list. The file will be added to the start of the list (in the most recent position). If the file is already in the list it will be moved to the start.

Parameters:
file - the file to add to the list.

addAll

public void addAll(java.io.File[] files)
Adds all the specified files to the list. The files are added to the start of the list such that file[0] will be the first entry and files[files.length - 1] will proceed any existing files. If any file is already in the list it will be moved to the new position.

Parameters:
files - the files to add to the list.

getFiles

public java.io.File[] getFiles()
Gets all files in the group. The number of files may exceed the number displayed by the group.

Returns:
all the files in the group.
See Also:
setDisplaySize(int)

getCommandFor

protected org.pietschy.command.file.AbstractRecentFileGroup.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.

openFile

public abstract void openFile(java.io.File file)
Called to open the selected file. Subclasses must implement this method to provide the file open behaviour.

Parameters:
file - the file to be opened.

store

public void store(java.util.prefs.Preferences prefs)
           throws java.util.prefs.BackingStoreException
Stores the groups file list to the specified preference node.

Parameters:
prefs - the preference node in which to save the groups file list.
Throws:
java.util.prefs.BackingStoreException - if the store operation fails.
See Also:
load(java.util.prefs.Preferences)

load

public void load(java.util.prefs.Preferences prefs)
Loads the groups file list from the specified preference node.

Parameters:
prefs - the preference node in which to retrieve the groups file list.
See Also:
store(java.util.prefs.Preferences)

refresh

public void refresh()

getAcceleratorForIndex

protected javax.swing.KeyStroke getAcceleratorForIndex(int index)