Package adams.gui.goe
Class Favorites
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.gui.goe.Favorites
-
- All Implemented Interfaces:
CloneHandler<Favorites>
,LoggingSupporter
,SizeOfHandler
,Serializable
,Comparable
public class Favorites extends LoggingObject implements Comparable, CloneHandler<Favorites>
A helper class for managing the GOE 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
Favorites.Favorite
Container class for a favorite setup.static class
Favorites.FavoriteSelectionEvent
Event that gets sent when a favorite gets selected.static interface
Favorites.FavoriteSelectionListener
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 Favorites
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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addFavorite(Properties props, Class cls, boolean array, Object obj, String name)
Adds a favorite for a class.void
addFavorite(Class cls, boolean array, Object obj, String name)
Adds a favorite for a class.void
addFavorite(Class cls, Object obj, String name)
Adds a favorite for a class.protected void
addFavoritesMenuItems(boolean temp, Object menu, Class cls, Object current, Favorites.FavoriteSelectionListener listener)
Adds menu items with the favorites (permanent or temporary) to the menu.void
addFavoritesMenuItems(Object menu, Class cls, Object current, Favorites.FavoriteSelectionListener listener)
Adds a menu item with the favorites to the menu.void
addFavoritesSubMenu(Object menu, Class cls, Object current, Favorites.FavoriteSelectionListener 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, boolean array, Object obj, String name)
Adds a temporary favorite for a class.void
addTempFavorite(Class cls, Object obj, 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 Class
createFavoritesClass(Class cls, boolean array)
Creates the class for the favorite.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 "/".Favorites
getClone()
Returns a copy of itself.Favorites.Favorite
getFavorite(Class cls, boolean array, String name)
Returns the named favorite for the specified class.protected List<Favorites.Favorite>
getFavorites(Properties props, Class cls)
Returns the favorites for the specified class.List<Favorites.Favorite>
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 Favorites
getSingleton()
Returns the singleton (and initializes it, if necessary).List<String>
getSuperclasses()
Returns all the current superclasses.Favorites.Favorite
getTempFavorite(Class cls, boolean array, String name)
Returns the named temporary favorite for the specified class.List<Favorites.Favorite>
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, boolean array, String name)
Removes a favorite for a class.void
removeFavorite(Class cls, String name)
Removes a favorite for a class (array or not).void
removeFavorites(Class cls, boolean array)
Removes the favorites for the specified class.void
removeFavorites(String classname)
Removes the favorites for the specified class.void
removeTempFavorite(Class cls, boolean array, String name)
Removes a temporary favorite for a class.void
removeTempFavorite(Class cls, String name)
Removes a temporary favorite for a class (array or not).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 Favorites 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 autosave 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<Favorites.Favorite> 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, can be array classes as well- Returns:
- the favorites
-
getFavorites
public List<Favorites.Favorite> getFavorites(Class cls)
Returns the favorites for the specified class.- Parameters:
cls
- the class to get the favorites for, can be array classes as well- Returns:
- the favorites
-
getTempFavorites
public List<Favorites.Favorite> getTempFavorites(Class cls)
Returns the temporary favorites for the specified class.- Parameters:
cls
- the class to get the favorites for, can be array classes as well- 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
-
createFavoritesClass
protected Class createFavoritesClass(Class cls, boolean array)
Creates the class for the favorite.- Parameters:
cls
- the base classarray
- whether for an array- Returns:
- the favorites class
-
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 Favorites.Favorite getFavorite(Class cls, boolean array, String name)
Returns the named favorite for the specified class.- Parameters:
cls
- the class to get the favorite forarray
- whether for an arrayname
- the name of the favorite- Returns:
- the favorite, null if not available
-
getTempFavorite
public Favorites.Favorite getTempFavorite(Class cls, boolean array, String name)
Returns the named temporary favorite for the specified class.- Parameters:
cls
- the class to get the favorite forarray
- whether for an arrayname
- the name of the favorite- Returns:
- the favorite, null if not available
-
addFavorite
public void addFavorite(Class cls, Object obj, String name)
Adds a favorite for a class.- Parameters:
cls
- the class to add the favorite for (array or not)obj
- the favoritename
- the name of the favorite
-
addTempFavorite
public void addTempFavorite(Class cls, Object obj, String name)
Adds a temporary favorite for a class.- Parameters:
cls
- the class to add the favorite for (array or not)obj
- the favoritename
- the name of the favorite
-
addFavorite
protected void addFavorite(Properties props, Class cls, boolean array, Object obj, String name)
Adds a favorite for a class.- Parameters:
cls
- the class to add the favorite for, component type for arraysarray
- whether for an arrayobj
- the favoritename
- the name of the favorite
-
addFavorite
public void addFavorite(Class cls, boolean array, Object obj, String name)
Adds a favorite for a class.- Parameters:
cls
- the class to add the favorite for, component type for arraysarray
- whether for an arrayobj
- the favoritename
- the name of the favorite
-
addTempFavorite
public void addTempFavorite(Class cls, boolean array, Object obj, String name)
Adds a temporary favorite for a class.- Parameters:
cls
- the class to add the favorite for, component type for arraysarray
- whether for an arrayobj
- 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, use [] suffix for arrays
-
removeFavorites
public void removeFavorites(Class cls, boolean array)
Removes the favorites for the specified class.- Parameters:
cls
- the class to remove the favorites forarray
- whether for an array
-
removeFavorite
public void removeFavorite(Class cls, String name)
Removes a favorite for a class (array or not).- 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 (array or not).- Parameters:
cls
- the class to remove the favorite forname
- the name of the favorite
-
removeFavorite
public void removeFavorite(Class cls, boolean array, String name)
Removes a favorite for a class.- Parameters:
cls
- the class to remove the favorite forarray
- whether an array or notname
- the name of the favorite
-
removeTempFavorite
public void removeTempFavorite(Class cls, boolean array, String name)
Removes a temporary favorite for a class.- Parameters:
cls
- the class to remove the favorite forarray
- whether an array or notname
- 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 favorite (array or not)name
- the name of the favorite
-
addFavoritesMenuItems
protected void addFavoritesMenuItems(boolean temp, Object menu, Class cls, Object current, Favorites.FavoriteSelectionListener 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 for, can be array class as wellcurrent
- the current objectlistener
- the listener to attach to the menu items' ActionListener
-
addFavoritesMenuItems
public void addFavoritesMenuItems(Object menu, Class cls, Object current, Favorites.FavoriteSelectionListener 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 for, can be array class as wellcurrent
- the current objectlistener
- the listener to attach to the menu items' ActionListener
-
addFavoritesSubMenu
public void addFavoritesSubMenu(Object menu, Class cls, Object current, Favorites.FavoriteSelectionListener 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 objectlistener
- the listener to attach to the menu items' ActionListener
-
getClone
public Favorites getClone()
Returns a copy of itself.- Specified by:
getClone
in interfaceCloneHandler<Favorites>
- 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 Favorites getSingleton()
Returns the singleton (and initializes it, if necessary).- Returns:
- the singleton
-
reload
public static void reload()
Reloads the system-wide favorites.
-
-