Package adams.gui.core
Class RecentFilesHandler<M>
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.gui.core.AbstractRecentItemsHandler<M,File>
-
- adams.gui.core.RecentFilesHandler<M>
-
- All Implemented Interfaces:
LoggingSupporter
,SizeOfHandler
,Serializable
public class RecentFilesHandler<M> extends AbstractRecentItemsHandler<M,File>
A class that handles a list of recent files. Reads/writes them from/to a props file in the application's home directory.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
AbstractEnvironment.getHome()
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected int
m_MinNumParentDirs
the minimum number of parent directories to use.static String
RECENTFILES_COUNT
the property for storing the number of recent files.static String
RECENTFILES_PREFIX
the property prefix for a recent file.-
Fields inherited from class adams.gui.core.AbstractRecentItemsHandler
m_AddShortcuts, m_IgnoreChanges, m_Listeners, m_MaxCount, m_Menu, m_PropertiesFile, m_PropertyPrefix, m_RecentItems
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description RecentFilesHandler(String propsFile, int maxCount, M menu)
Initializes the handler.RecentFilesHandler(String propsFile, String propPrefix, int maxCount, M menu)
Initializes the handler.RecentFilesHandler(String propsFile, M menu)
Initializes the handler with a maximum of 5 items.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
check(File item)
Checks the item after obtaining from the props file.protected String
createMenuItemText(int index, File item)
Generates the text for the menuitem.protected int
determineMinimumNumberOfParentDirs()
Determines the minimum number of parent directories that need to be included in the filename to make the filenames in the menu distinguishable.protected File
fromString(String s)
Turns the string obtained from the props into an object again.protected String
getCountKey()
Returns the key to use for the counts in the props file.protected String
getItemPrefix()
Returns the key prefix to use for the items in the props file.protected void
preUpdateMenu()
Hook method which gets executed just before updating the menu.protected String
toString(File obj)
Turns an object into a string for storing in the props.-
Methods inherited from class adams.gui.core.AbstractRecentItemsHandler
addRecentItem, addRecentItemListener, doUpdateMenu, expand, getAddShortcuts, getMaxCount, getMenu, getPropertiesFile, getPropertyPrefix, getRecentItems, loadProps, notifyRecentItemListenersOfAdd, notifyRecentItemListenersOfSelect, postUpdateMenu, readProps, removeAll, removeRecentItem, removeRecentItemListener, setAddShortcuts, size, updateMenu, writeProps
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
RECENTFILES_COUNT
public static final String RECENTFILES_COUNT
the property for storing the number of recent files.- See Also:
- Constant Field Values
-
RECENTFILES_PREFIX
public static final String RECENTFILES_PREFIX
the property prefix for a recent file.- See Also:
- Constant Field Values
-
m_MinNumParentDirs
protected int m_MinNumParentDirs
the minimum number of parent directories to use.
-
-
Constructor Detail
-
RecentFilesHandler
public RecentFilesHandler(String propsFile, M menu)
Initializes the handler with a maximum of 5 items.- Parameters:
propsFile
- the props file to store the files inmenu
- the menu to add the recent files as subitems to
-
RecentFilesHandler
public RecentFilesHandler(String propsFile, int maxCount, M menu)
Initializes the handler.- Parameters:
propsFile
- the props file to store the files inmaxCount
- the maximum number of files to keep in menumenu
- the menu to add the recent files as subitems to
-
RecentFilesHandler
public RecentFilesHandler(String propsFile, String propPrefix, int maxCount, M menu)
Initializes the handler.- Parameters:
propsFile
- the props file to store the files inpropPrefix
- the properties prefix, use null to ignoremaxCount
- the maximum number of files to keep in menumenu
- the menu to add the recent files as subitems to
-
-
Method Detail
-
check
protected boolean check(File item)
Checks the item after obtaining from the props file.
File must exist.- Overrides:
check
in classAbstractRecentItemsHandler<M,File>
- Parameters:
item
- the item to check- Returns:
- true if checks passed
-
determineMinimumNumberOfParentDirs
protected int determineMinimumNumberOfParentDirs()
Determines the minimum number of parent directories that need to be included in the filename to make the filenames in the menu distinguishable.- Returns:
- the minimum number of parent directories, -1 means full path
-
getCountKey
protected String getCountKey()
Returns the key to use for the counts in the props file.- Specified by:
getCountKey
in classAbstractRecentItemsHandler<M,File>
- Returns:
- the key
-
getItemPrefix
protected String getItemPrefix()
Returns the key prefix to use for the items in the props file.- Specified by:
getItemPrefix
in classAbstractRecentItemsHandler<M,File>
- Returns:
- the prefix
-
toString
protected String toString(File obj)
Turns an object into a string for storing in the props.- Specified by:
toString
in classAbstractRecentItemsHandler<M,File>
- Parameters:
obj
- the object to convert- Returns:
- the string representation
-
fromString
protected File fromString(String s)
Turns the string obtained from the props into an object again.- Specified by:
fromString
in classAbstractRecentItemsHandler<M,File>
- Parameters:
s
- the string representation- Returns:
- the parsed object
-
preUpdateMenu
protected void preUpdateMenu()
Hook method which gets executed just before updating the menu.- Overrides:
preUpdateMenu
in classAbstractRecentItemsHandler<M,File>
-
createMenuItemText
protected String createMenuItemText(int index, File item)
Generates the text for the menuitem.- Specified by:
createMenuItemText
in classAbstractRecentItemsHandler<M,File>
- Parameters:
index
- the index of the itemitem
- the item itself- Returns:
- the generated text
-
-