M
- the type of menu to useT
- the type of item to usepublic abstract class AbstractRecentItemsHandler<M,T> extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected boolean |
m_IgnoreChanges
whether to ignore changes temporarily.
|
protected HashSet<RecentItemListener<M,T>> |
m_Listeners
the event listeners.
|
protected int |
m_MaxCount
the maximum number of items to keep.
|
protected M |
m_Menu
the menu to add the items as sub-items to.
|
protected String |
m_PropertiesFile
the props file to use.
|
protected String |
m_PropertyPrefix
the prefix for the properties.
|
protected List<T> |
m_RecentItems
the items.
|
Constructor and Description |
---|
AbstractRecentItemsHandler(String propsFile,
int maxCount,
M menu)
Initializes the handler.
|
AbstractRecentItemsHandler(String propsFile,
M menu)
Initializes the handler with a maximum of 5 items.
|
AbstractRecentItemsHandler(String propsFile,
String propPrefix,
int maxCount,
M menu)
Initializes the handler.
|
Modifier and Type | Method and Description |
---|---|
void |
addRecentItem(T item)
Adds the item to the internal list.
|
void |
addRecentItemListener(RecentItemListener l)
Adds the listener to the internal list.
|
protected boolean |
check(T item)
Checks the item after obtaining from the props file.
|
protected abstract String |
createMenuItemText(int index,
T item)
Generates the text for the menuitem.
|
protected void |
doUpdateMenu()
Updates the menu.
|
protected String |
expand(String property)
Adds the prefix to the property name if provided.
|
protected abstract T |
fromString(String s)
Turns the string obtained from the props into an object again.
|
protected abstract String |
getCountKey()
Returns the key to use for the counts in the props file.
|
protected abstract String |
getItemPrefix()
Returns the key prefix to use for the items in the props file.
|
int |
getMaxCount()
Returns the maximum number of items to keep.
|
M |
getMenu()
Returns the menu to add the recent items as subitems to.
|
String |
getPropertiesFile()
Returns the props file used to store the recent items in.
|
String |
getPropertyPrefix()
Returns the prefix for the property names.
|
List<T> |
getRecentItems()
Returns the currently stored recent items.
|
protected Properties |
loadProps()
Loads the properties file from disk, if possible.
|
protected void |
notifyRecentItemListenersOfAdd(T item)
Notifies the listeners of a item that got added.
|
protected void |
notifyRecentItemListenersOfSelect(T item)
Notifies the listeners of a item that got selected.
|
protected void |
postUpdateMenu()
Hook method which gets executed just after the menu was updated.
|
protected void |
preUpdateMenu()
Hook method which gets executed just before the menu gets updated.
|
protected void |
readProps()
Reads the recent items from the props file.
|
void |
removeAll()
Removes all items from the internal list.
|
void |
removeRecentItem(T item)
Removes the item from the internal list, e.g., if it no longer exists on
disk.
|
void |
removeRecentItemListener(RecentItemListener l)
Removes the listener from the internal list.
|
int |
size()
Returns the number of recent items currently stored.
|
protected abstract String |
toString(T obj)
Turns an object into a string for storing in the props.
|
protected void |
updateMenu()
Updates the menu with the currently stored recent files.
|
protected void |
writeProps()
Writes the current recent items back to the props file.
|
protected String m_PropertiesFile
protected String m_PropertyPrefix
protected int m_MaxCount
protected M m_Menu
protected boolean m_IgnoreChanges
protected HashSet<RecentItemListener<M,T>> m_Listeners
public AbstractRecentItemsHandler(String propsFile, M menu)
propsFile
- the props file to store the items inmenu
- the menu to add the recent items as subitems topublic AbstractRecentItemsHandler(String propsFile, int maxCount, M menu)
propsFile
- the props file to store the items inmaxCount
- the maximum number of items to keep in menumenu
- the menu to add the recent items as subitems topublic AbstractRecentItemsHandler(String propsFile, String propPrefix, int maxCount, M menu)
propsFile
- the props file to store the items inpropPrefix
- the properties prefix, use null to ignoremaxCount
- the maximum number of items to keep in menumenu
- the menu to add the recent items as subitems topublic String getPropertiesFile()
public String getPropertyPrefix()
public int getMaxCount()
public M getMenu()
protected abstract String getCountKey()
protected abstract String getItemPrefix()
protected abstract String toString(T obj)
obj
- the object to convertprotected abstract T fromString(String s)
s
- the string representationprotected String expand(String property)
property
- the property to expandprotected Properties loadProps()
protected boolean check(T item)
item
- the item to checkprotected void readProps()
protected void writeProps()
protected void preUpdateMenu()
protected abstract String createMenuItemText(int index, T item)
index
- the index of the itemitem
- the item itselfprotected void doUpdateMenu()
protected void postUpdateMenu()
protected void updateMenu()
public void addRecentItem(T item)
item
- the item to add to the listpublic void removeRecentItem(T item)
item
- the item to remove from the listpublic void removeAll()
public List<T> getRecentItems()
public int size()
public void addRecentItemListener(RecentItemListener l)
l
- the listener to addpublic void removeRecentItemListener(RecentItemListener l)
l
- the listener to removeprotected void notifyRecentItemListenersOfAdd(T item)
item
- the affected itemprotected void notifyRecentItemListenersOfSelect(T item)
item
- the affected itemCopyright © 2017. All Rights Reserved.