Package adams.gui.goe
Class Favorites
- java.lang.Object
-
- adams.gui.goe.Favorites
-
- All Implemented Interfaces:
CloneHandler<Favorites>
,Comparable
public class Favorites extends Object implements Comparable, CloneHandler<Favorites>
A helper class for managing the GOE favorites.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
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.static String
SEPARATOR
the separator between classname and favorite name.static String
TEMPORARY
for storing a temporary favorite.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFavorite(Class cls, Object obj, String name)
Adds a favorite for a class.void
clear()
Removes all favorites.int
compareTo(Object o)
Compares this object with the specified object for order.void
customizePopupMenu(JPopupMenu menu, Class cls, Object current, Favorites.FavoriteSelectionListener listener)
Adds a menu item with the favorites to the popup menu.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, String name)
Returns the named favorite for the specified class.List<Favorites.Favorite>
getFavorites(Class cls)
Returns the favorites for the specified class.List<Favorites.Favorite>
getFavorites(String classname)
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.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.static void
reload()
Reloads the system-wide favorites.void
removeFavorite(Class cls, String name)
Removes a favorite for a class.void
removeFavorite(String classname, 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.protected boolean
removeTemporaryFavorites()
Removes all the temporary favorites from the properties.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.
-
-
-
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
-
TEMPORARY
public static final String TEMPORARY
for storing a temporary favorite.- See Also:
- Constant Field Values
-
m_Properties
protected Properties m_Properties
the properties.
-
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
-
load
protected void load()
Loads the favorites.
-
clear
public void clear()
Removes all favorites.
-
getFavorites
public List<Favorites.Favorite> getFavorites(String classname)
Returns the favorites for the specified class.- Parameters:
classname
- the class to get the favorites for- 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- 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
-
getFavorite
public Favorites.Favorite 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
-
addFavorite
public void addFavorite(Class cls, Object obj, String name)
Adds a favorite for a class.- Parameters:
cls
- the class to add the favorite forobj
- 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(String classname, String name)
Removes a favorite for a class.- Parameters:
classname
- the class to remove the favorite forname
- the name of the favorite
-
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
-
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
-
customizePopupMenu
public void customizePopupMenu(JPopupMenu menu, Class cls, Object current, Favorites.FavoriteSelectionListener listener)
Adds a menu item with the favorites to the popup menu.- Parameters:
menu
- the menu 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.
-
removeTemporaryFavorites
protected boolean removeTemporaryFavorites()
Removes all the temporary favorites from the properties.- Returns:
- true if modified
-
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.
-
-