Package adams.gui.core
Class StringFavorites
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.gui.core.StringFavorites
-
- All Implemented Interfaces:
CloneHandler<StringFavorites>
,LoggingSupporter
,SizeOfHandler
,Serializable
,Comparable
public class StringFavorites extends LoggingObject implements Comparable, CloneHandler<StringFavorites>
A helper class for managing simple favorites.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StringFavorites.StringFavorite
Container class for a favorite setup.static class
StringFavorites.StringFavoriteSelectionEvent
Event that gets sent when a favorite gets selected.static interface
StringFavorites.StringFavoriteSelectionListener
Interface for classes that listen to selections of favorites.
-
Field Summary
Fields Modifier and Type Field Description static String
FILENAME
the filename of the props file.protected boolean
m_AutoSave
whether to save the properties whenever a change happened.protected boolean
m_Modified
whether the favorites were modified.protected Properties
m_Properties
the properties.protected static StringFavorites
m_Singleton
the singleton.protected Properties
m_TempProperties
the temporary favorites.static String
SEPARATOR
the separator between classname and favorite name.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description StringFavorites()
Initializes the favorites with immediate saving enabled.StringFavorites(boolean autoSave)
Initializes the favorites.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addFavorite(Properties props, Class cls, String data, String name)
Adds a favorite for a class.void
addFavorite(Class cls, String data, String name)
Adds a favorite for a class.protected void
addFavoritesMenuItems(boolean temp, Object menu, Class cls, String current, StringFavorites.StringFavoriteSelectionListener listener)
Adds menu items with the favorites (permanent or temporary) to the menu.void
addFavoritesMenuItems(Object menu, Class cls, String current, StringFavorites.StringFavoriteSelectionListener listener)
Adds a menu item with the favorites to the menu.void
addFavoritesSubMenu(Object menu, Class cls, String current, StringFavorites.StringFavoriteSelectionListener listener)
Adds a menu item with the favorites submenu to the popup menu.protected void
addMenuItem(Object menu, JMenuItem menuitem)
Adds the menuitem to the menu.protected void
addSeparator(Object menu)
Adds a separator to the menu.void
addTempFavorite(Class cls, String data, String name)
Adds a temporary favorite for a class.void
clear()
Removes all favorites.int
compareTo(Object o)
Compares this object with the specified object for order.protected String
createKey(Class cls)
Generates a properties key prefix for the class.protected String
createKey(Class cls, String name)
Generates a properties key for the class/name.boolean
equals(Object obj)
Indicates whether some other object is "equal to" this one.protected String
fixName(String name)
Fixes the name by replacing all "|" with "/".StringFavorites
getClone()
Returns a copy of itself.StringFavorites.StringFavorite
getFavorite(Class cls, String name)
Returns the named favorite for the specified class.protected List<StringFavorites.StringFavorite>
getFavorites(Properties props, Class cls)
Returns the favorites for the specified class.List<StringFavorites.StringFavorite>
getFavorites(Class cls)
Returns the favorites for the specified class.String
getFilename()
Returns the filename the favorites will be saved as.Properties
getProperties()
Returns the properties of the favorites.static StringFavorites
getSingleton()
Returns the singleton (and initializes it, if necessary).List<String>
getSuperclasses()
Returns all the current superclasses.StringFavorites.StringFavorite
getTempFavorite(Class cls, String name)
Returns the named temporary favorite for the specified class.List<StringFavorites.StringFavorite>
getTempFavorites(Class cls)
Returns the temporary favorites for the specified class.protected Properties
getTempProperties()
Returns the properties of the temp favorites.boolean
isAutoSave()
Returns whether the favorites get immediately saved whenever modified.boolean
isModified()
Returns whether the favorites are modified.protected void
load()
Loads the favorites.protected void
promptRemoval(boolean temp, Class cls, String name)
Prompts the user whether to remove the favorite.static void
reload()
Reloads the system-wide favorites.void
removeFavorite(Class cls, String name)
Removes a favorite for a class.void
removeFavorites(Class cls)
Removes the favorites for the specified class.void
removeFavorites(String classname)
Removes the favorites for the specified class.void
removeTempFavorite(Class cls, String name)
Removes a temporary favorite for a class.void
setAutoSave(boolean value)
Sets auto save to on or off.void
setModified(boolean value)
Sets the modified state.void
setProperties(Properties value)
Sets the properties containing the favorites to use.boolean
updateFavorites()
Updates the favorites, i.e., stores the properties on disk.-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
FILENAME
public static final String FILENAME
the filename of the props file.- See Also:
- Constant Field Values
-
SEPARATOR
public static final String SEPARATOR
the separator between classname and favorite name.- See Also:
- Constant Field Values
-
m_Properties
protected Properties m_Properties
the properties.
-
m_TempProperties
protected Properties m_TempProperties
the temporary favorites.
-
m_Modified
protected boolean m_Modified
whether the favorites were modified.
-
m_AutoSave
protected boolean m_AutoSave
whether to save the properties whenever a change happened.
-
m_Singleton
protected static StringFavorites m_Singleton
the singleton.
-
-
Method Detail
-
setAutoSave
public void setAutoSave(boolean value)
Sets auto save to on or off.- Parameters:
value
- if true then auto save is on
-
isAutoSave
public boolean isAutoSave()
Returns whether the favorites get immediately saved whenever modified.- Returns:
- true if auto-save is on
-
setModified
public void setModified(boolean value)
Sets the modified state.- Parameters:
value
- the modified state
-
isModified
public boolean isModified()
Returns whether the favorites are modified.- Returns:
- true if modified
-
setProperties
public void setProperties(Properties value)
Sets the properties containing the favorites to use.- Parameters:
value
- the properties to use
-
getProperties
public Properties getProperties()
Returns the properties of the favorites.- Returns:
- the properties
-
getTempProperties
protected Properties getTempProperties()
Returns the properties of the temp favorites.- Returns:
- the properties
-
load
protected void load()
Loads the favorites.
-
clear
public void clear()
Removes all favorites.
-
getFavorites
protected List<StringFavorites.StringFavorite> getFavorites(Properties props, Class cls)
Returns the favorites for the specified class.- Parameters:
props
- the properties to extract the favorites fromcls
- the class to get the favorites for- Returns:
- the favorites
-
getFavorites
public List<StringFavorites.StringFavorite> getFavorites(Class cls)
Returns the favorites for the specified class.- Parameters:
cls
- the class to get the favorites for- Returns:
- the favorites
-
getTempFavorites
public List<StringFavorites.StringFavorite> getTempFavorites(Class cls)
Returns the temporary favorites for the specified class.- Parameters:
cls
- the class to get the favorites for- Returns:
- the favorites
-
getSuperclasses
public List<String> getSuperclasses()
Returns all the current superclasses.- Returns:
- the classnames of the superclasses
-
fixName
protected String fixName(String name)
Fixes the name by replacing all "|" with "/".- Parameters:
name
- the name to fix- Returns:
- the fixed name
-
createKey
protected String createKey(Class cls)
Generates a properties key prefix for the class.- Parameters:
cls
- the class to generate the key for- Returns:
- the key
-
createKey
protected String createKey(Class cls, String name)
Generates a properties key for the class/name.- Parameters:
cls
- the class to generate the key forname
- the name to generete the key for- Returns:
- the key
-
getFavorite
public StringFavorites.StringFavorite getFavorite(Class cls, String name)
Returns the named favorite for the specified class.- Parameters:
cls
- the class to get the favorite forname
- the name of the favorite- Returns:
- the favorite, null if not available
-
getTempFavorite
public StringFavorites.StringFavorite getTempFavorite(Class cls, String name)
Returns the named temporary favorite for the specified class.- Parameters:
cls
- the class to get the favorite forname
- the name of the favorite- Returns:
- the favorite, null if not available
-
addFavorite
protected void addFavorite(Properties props, Class cls, String data, String name)
Adds a favorite for a class.- Parameters:
cls
- the class to add the favorite fordata
- the favoritename
- the name of the favorite
-
addFavorite
public void addFavorite(Class cls, String data, String name)
Adds a favorite for a class.- Parameters:
cls
- the class to add the favorite fordata
- the favoritename
- the name of the favorite
-
addTempFavorite
public void addTempFavorite(Class cls, String data, String name)
Adds a temporary favorite for a class.- Parameters:
cls
- the class to add the favorite fordata
- the favoritename
- the name of the favorite
-
removeFavorites
public void removeFavorites(String classname)
Removes the favorites for the specified class.- Parameters:
classname
- the class to remove the favorites for
-
removeFavorites
public void removeFavorites(Class cls)
Removes the favorites for the specified class.- Parameters:
cls
- the class to remove the favorites for
-
removeFavorite
public void removeFavorite(Class cls, String name)
Removes a favorite for a class.- Parameters:
cls
- the class to remove the favorite forname
- the name of the favorite
-
removeTempFavorite
public void removeTempFavorite(Class cls, String name)
Removes a temporary favorite for a class.- Parameters:
cls
- the class to remove the favorite forname
- the name of the favorite
-
getFilename
public String getFilename()
Returns the filename the favorites will be saved as.- Returns:
- the filename
-
updateFavorites
public boolean updateFavorites()
Updates the favorites, i.e., stores the properties on disk.- Returns:
- true if successfully saved
-
addMenuItem
protected void addMenuItem(Object menu, JMenuItem menuitem)
Adds the menuitem to the menu.- Parameters:
menu
- the JMenu or JPopupMenu to add tomenuitem
- the item to add
-
addSeparator
protected void addSeparator(Object menu)
Adds a separator to the menu.- Parameters:
menu
- the JMenu or JPopupMenu to add to
-
promptRemoval
protected void promptRemoval(boolean temp, Class cls, String name)
Prompts the user whether to remove the favorite.- Parameters:
temp
- temporary or permanent favoritescls
- the class of the favoritename
- the name of the favorite
-
addFavoritesMenuItems
protected void addFavoritesMenuItems(boolean temp, Object menu, Class cls, String current, StringFavorites.StringFavoriteSelectionListener listener)
Adds menu items with the favorites (permanent or temporary) to the menu.- Parameters:
menu
- the menu (JMenu/JPopupMenu) to add the favorites tocls
- the class the favorites are forcurrent
- the current data associated with the favoritelistener
- the listener to attach to the menu items' ActionListener
-
addFavoritesMenuItems
public void addFavoritesMenuItems(Object menu, Class cls, String current, StringFavorites.StringFavoriteSelectionListener listener)
Adds a menu item with the favorites to the menu.- Parameters:
menu
- the menu (JMenu/JPopupMenu) to add the favorites tocls
- the class the favorites are forcurrent
- the current data associated with the favoritelistener
- the listener to attach to the menu items' ActionListener
-
addFavoritesSubMenu
public void addFavoritesSubMenu(Object menu, Class cls, String current, StringFavorites.StringFavoriteSelectionListener listener)
Adds a menu item with the favorites submenu to the popup menu.- Parameters:
menu
- the menu (JMenu/JPopMenu) to add the favorites tocls
- the class the favorites are forcurrent
- the current data associated with the favoritelistener
- the listener to attach to the menu items' ActionListener
-
getClone
public StringFavorites getClone()
Returns a copy of itself.- Specified by:
getClone
in interfaceCloneHandler<StringFavorites>
- Returns:
- the copy
-
compareTo
public int compareTo(Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.- Specified by:
compareTo
in interfaceComparable
- Parameters:
o
- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
- Throws:
ClassCastException
- if the specified object's type prevents it from being compared to this object.
-
equals
public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.
-
getSingleton
public static StringFavorites getSingleton()
Returns the singleton (and initializes it, if necessary).- Returns:
- the singleton
-
reload
public static void reload()
Reloads the system-wide favorites.
-
-