Package adams.gui.tools.previewbrowser
Class ContentHandlerFavorites
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.gui.tools.previewbrowser.ContentHandlerFavorites
-
- All Implemented Interfaces:
LoggingSupporter
,SizeOfHandler
,Serializable
public class ContentHandlerFavorites extends LoggingObject
Manages the 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
ContentHandlerFavorites.ContentHandlerFavorite
Encapsulates a single favorite.
-
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 List<ContentHandlerFavorites.ContentHandlerFavorite>
m_Favorites
the favorites.protected boolean
m_Modified
whether the favorites were modified.protected static ContentHandlerFavorites
m_Singleton
the singleton.static String
SEPARATOR
the separator between extension and name.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description ContentHandlerFavorites()
Initializes the favorites with immediate saving enabled.ContentHandlerFavorites(boolean autosave)
Initializes the favorites.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ContentHandlerFavorites.ContentHandlerFavorite
addFavorite(String ext, String name, ContentHandler handler)
Adds the favorite.void
clear()
Removes all favorites.void
customizeDropDownButton(BaseButtonWithDropDownMenu button, String ext, PreviewDisplay display)
Adds menu items for favorites to the dropdown button.List<String>
getExtensions()
Returns the list of extensions we have favorites for.List<ContentHandlerFavorites.ContentHandlerFavorite>
getFavorites(String ext)
Returns all the favorites for the specified extension.String
getFilename()
Returns the filename the favorites will be saved as.static ContentHandlerFavorites
getSingleton()
Returns the singleton (and initializes it, if necessary).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.ContentHandlerFavorites.ContentHandlerFavorite
removeFavorite(String name)
Removes the favorite with the specified name.void
removeFavorites(String ext)
Removes all the favorites for this extension.void
setAutoSave(boolean value)
Sets auto save to on or off.void
setModified(boolean value)
Sets the modified state.boolean
updateFavorite(String ext, String name, ContentHandler handler)
Updates the favorite.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 extension and name.- See Also:
- Constant Field Values
-
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_Favorites
protected List<ContentHandlerFavorites.ContentHandlerFavorite> m_Favorites
the favorites.
-
m_Singleton
protected static ContentHandlerFavorites m_Singleton
the singleton.
-
-
Constructor Detail
-
ContentHandlerFavorites
public ContentHandlerFavorites()
Initializes the favorites with immediate saving enabled.
-
ContentHandlerFavorites
public ContentHandlerFavorites(boolean autosave)
Initializes the favorites.- Parameters:
autosave
- whether to save the favorites immediately whenever modified
-
-
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
-
load
protected void load()
Loads the favorites.
-
clear
public void clear()
Removes all favorites.
-
getExtensions
public List<String> getExtensions()
Returns the list of extensions we have favorites for.- Returns:
- the list
-
getFavorites
public List<ContentHandlerFavorites.ContentHandlerFavorite> getFavorites(String ext)
Returns all the favorites for the specified extension.- Parameters:
ext
- the extension to get the favorites for- Returns:
- the favorites
-
addFavorite
public ContentHandlerFavorites.ContentHandlerFavorite addFavorite(String ext, String name, ContentHandler handler)
Adds the favorite.- Parameters:
ext
- the extension this favorite is forname
- the name of the favoritehandler
- the handler- Returns:
- the generated favorite
-
updateFavorite
public boolean updateFavorite(String ext, String name, ContentHandler handler)
Updates the favorite.- Parameters:
ext
- the extension this favorite is forname
- the name of the favoritehandler
- the handler- Returns:
- the generated favorite
-
removeFavorite
public ContentHandlerFavorites.ContentHandlerFavorite removeFavorite(String name)
Removes the favorite with the specified name.- Parameters:
name
- the name of the favorite to remove- Returns:
- the removed favorite, if any
-
removeFavorites
public void removeFavorites(String ext)
Removes all the favorites for this extension.- Parameters:
ext
- the extension to remove the favorites for
-
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
-
customizeDropDownButton
public void customizeDropDownButton(BaseButtonWithDropDownMenu button, String ext, PreviewDisplay display)
Adds menu items for favorites to the dropdown button.- Parameters:
button
- the button to add the favorites toext
- the extension of the current file, disables the button if null
-
getSingleton
public static ContentHandlerFavorites getSingleton()
Returns the singleton (and initializes it, if necessary).- Returns:
- the singleton
-
reload
public static void reload()
Reloads the system-wide favorites.
-
-