org.pietschy.command.file

Class AbstractRecentFileGroup

Implemented Interfaces:
CommandManagerListener, EventListener
Known Direct 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(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(String id)
Constructs a new group with the specified Id that is bound to the default command manager.
AbstractRecentFileGroup(CommandManager commandManager)
Creates a new anonymous group.
AbstractRecentFileGroup(CommandManager commandManager, String id)
Creates a new group with the specified id.

Method Summary

void
add(File file)
Adds a file to the list.
void
addAll(File[] files)
Adds all the specified files to the list.
protected 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(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.
File[]
getExcludedFile()
Gets the file that is currently excluded from the list or null if all the files are included.
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 java.io.File.exists() returns false.
void
load(Preferences prefs)
Loads the groups file list from the specified preference node.
abstract void
openFile(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(File excludedFile)
Sets the file to exclude from the list.
void
setExcludedFiles(File[] excludedFiles)
Sets the file to exclude from the list.
void
setIncludeNonExistentFiles(boolean includeNonExistentFiles)
Configures if the group should include files for which java.io.File.exists() returns false.
void
store(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, 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

AbstractRecentFileGroup

protected AbstractRecentFileGroup(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.

AbstractRecentFileGroup

public AbstractRecentFileGroup(CommandManager commandManager)
Creates a new anonymous group.
Parameters:
commandManager - the CommandManager to which the group will belong.

AbstractRecentFileGroup

public AbstractRecentFileGroup(CommandManager commandManager,
                               String id)
Creates a new group with the specified id.
Parameters:
commandManager - the CommandManager to which the group will belong.
id - the commands id.

Method Details

add

public void add(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(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.

getAcceleratorForIndex

protected KeyStroke getAcceleratorForIndex(int index)

getAcceleratorModifiers

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

getClearCommand

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

getCommandFor

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

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

getExcludedFile

public 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.

getFiles

public 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.

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.

isIncludeNonExistentFiles

public boolean isIncludeNonExistentFiles()
Checks if the group should include files for which java.io.File.exists() returns false. The default value is false.
Returns:
true if the group is including non existant files, false otherwise.

load

public void load(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)

openFile

public abstract void openFile(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.

refresh

public void refresh()

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.

setAcceleratorModifiers

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

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.

setExcludedFile

public void setExcludedFile(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(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.

setIncludeNonExistentFiles

public void setIncludeNonExistentFiles(boolean includeNonExistentFiles)
Configures if the group should include files for which java.io.File.exists() returns false. The default value is false.
Parameters:
includeNonExistentFiles - true if the group is to include non existant files, false otherwise.

store

public void store(Preferences prefs)
            throws BackingStoreException
Stores the groups file list to the specified preference node.
Parameters:
prefs - the preference node in which to save the groups file list.
See Also:
load(java.util.prefs.Preferences)