|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.alee.managers.settings.SettingsManager
public final class SettingsManager
This manager allows you to quickly and easily save any serializable data into settings files using simple XML format.
You can define settings group file name (they are equal to the SettingsGroup name and should be unique), its location on local or remote drive and each separate property key. Any amount of properties could be stored in each group. Also there are some additional manager settings that allows you to configure SettingsManager to work the way you want it to. The rest of the work is done by the SettingsManager - it decides where, when and how to save the settings files. Settings data aliasing (see XStream documentation and XmlUtils class) or SettingsGroup file location changes should be done before requesting any of the settings, preferably right at the application startup. Otherwise data might not be properly read and settings will appear empty.
ComponentSettingsManager
,
XmlUtils
Constructor Summary | |
---|---|
SettingsManager()
|
Method Summary | ||
---|---|---|
static void |
addSettingsListener(java.lang.String key,
SettingsListener listener)
Adds setting listener. |
|
static void |
addSettingsListener(java.lang.String group,
java.lang.String key,
SettingsListener listener)
Adds setting listener. |
|
static void |
disableSave()
Disables saving settings into files. |
|
static void |
enableSave()
Enables saving settings into files. |
|
static
|
get(java.lang.String key)
Returns Object value. |
|
static
|
get(java.lang.String key,
java.lang.Class<T> defaultValueClass)
Returns typed value. |
|
static
|
get(java.lang.String group,
java.lang.String key,
java.lang.Class<T> defaultValueClass)
Returns typed value. |
|
static
|
get(java.lang.String group,
java.lang.String key,
T defaultValue)
Returns typed value. |
|
static
|
get(java.lang.String key,
T defaultValue)
Returns typed value. |
|
static java.lang.String |
getBackupFilesExtension()
Returns backup files extension. |
|
static java.lang.Boolean |
getBoolean(java.lang.String key)
Returns Boolean value. |
|
static java.lang.Boolean |
getBoolean(java.lang.String group,
java.lang.String key)
Returns Boolean value. |
|
static java.awt.Color |
getColor(java.lang.String key)
Returns Color value. |
|
static java.awt.Color |
getColor(java.lang.String group,
java.lang.String key)
Returns Color value. |
|
static java.lang.String |
getDefaultSettingsDir()
Returns default settings directory. |
|
static java.lang.String |
getDefaultSettingsDirName()
Returns default settings directory name. |
|
static java.lang.String |
getDefaultSettingsGroup()
Returns default settings group name. |
|
static
|
getDefaultValue(java.lang.Class<T> defaultValueClass)
Returns default value for the specified class. |
|
static java.awt.Dimension |
getDimension(java.lang.String key)
Returns Dimension value. |
|
static java.awt.Dimension |
getDimension(java.lang.String group,
java.lang.String key)
Returns Dimension value. |
|
static java.lang.Double |
getDouble(java.lang.String key)
Returns Double value. |
|
static java.lang.Double |
getDouble(java.lang.String group,
java.lang.String key)
Returns Double value. |
|
static java.lang.Float |
getFloat(java.lang.String key)
Returns Float value. |
|
static java.lang.Float |
getFloat(java.lang.String group,
java.lang.String key)
Returns Float value. |
|
static java.lang.String |
getGroupFileLocation(java.lang.String group)
Returns directory where settings group file is saved. |
|
static java.awt.Insets |
getInsets(java.lang.String key)
Returns Insets value. |
|
static java.awt.Insets |
getInsets(java.lang.String group,
java.lang.String key)
Returns Insets value. |
|
static java.lang.Integer |
getInteger(java.lang.String key)
Returns Integer value. |
|
static java.lang.Integer |
getInteger(java.lang.String group,
java.lang.String key)
Returns Integer value. |
|
static java.util.List<SettingsGroup> |
getLoadedGroups()
Returns list of all loaded settings groups. |
|
static java.util.Map<java.lang.String,SettingsGroup> |
getLoadedGroupsMap()
Returns map of all loaded settings groups. |
|
static java.lang.Long |
getLong(java.lang.String key)
Returns Long value. |
|
static java.lang.Long |
getLong(java.lang.String group,
java.lang.String key)
Returns Long value. |
|
static java.awt.Point |
getPoint(java.lang.String key)
Returns Point value. |
|
static java.awt.Point |
getPoint(java.lang.String group,
java.lang.String key)
Returns Point value. |
|
static java.awt.Rectangle |
getRectangle(java.lang.String key)
Returns Rectangle value. |
|
static java.awt.Rectangle |
getRectangle(java.lang.String group,
java.lang.String key)
Returns Rectangle value. |
|
static long |
getSaveOnChangeDelay()
Returns save-on-change delay in milliseconds. |
|
static java.lang.Object |
getSettings(java.lang.String fileName)
Returns value read from the settings file. |
|
static
|
getSettings(java.lang.String fileName,
T defaultValue)
Returns value read from the settings file. |
|
static java.lang.String |
getSettingsFilesExtension()
Returns settings files extension. |
|
static SettingsGroup |
getSettingsGroup(java.lang.String group)
Returns settings group for the specified name. |
|
SettingsGroupState |
getSettingsGroupState(java.lang.String group)
Returns settings group state. |
|
static java.lang.String |
getString(java.lang.String key)
Returns String value. |
|
static java.lang.String |
getString(java.lang.String group,
java.lang.String key)
Returns String value. |
|
static void |
initialize()
Initializes SettingsManager. |
|
static boolean |
isAllowSave()
Returns whether should allow saving settings into files or not. |
|
static boolean |
isDisplayExceptions()
Returns whether should display settings load and save error messages or not. |
|
static boolean |
isSaveDefaultValues()
Sets whether should save provided default value in "get" calls or not. |
|
static boolean |
isSaveOnChange()
Returns whether should save settings right after any changes made or not. |
|
static void |
loadComponentSettings(java.awt.Component component)
Loads saved settings into the component if it is registered. |
|
static void |
registerComponent(java.awt.Component component,
SettingsProcessor settingsProcessor)
Registers component for settings auto-save. |
|
static void |
registerComponent(java.awt.Component component,
java.lang.String key)
Registers component for settings auto-save. |
|
static void |
registerComponent(java.awt.Component component,
java.lang.String key,
boolean loadInitialSettings,
boolean applySettingsChanges)
Registers component for settings auto-save. |
|
static
|
registerComponent(java.awt.Component component,
java.lang.String key,
java.lang.Class<T> defaultValueClass)
Registers component for settings auto-save. |
|
static
|
registerComponent(java.awt.Component component,
java.lang.String key,
java.lang.Class<T> defaultValueClass,
boolean loadInitialSettings,
boolean applySettingsChanges)
Registers component for settings auto-save. |
|
static void |
registerComponent(java.awt.Component component,
java.lang.String key,
java.lang.Object defaultValue)
Registers component for settings auto-save. |
|
static void |
registerComponent(java.awt.Component component,
java.lang.String key,
java.lang.Object defaultValue,
boolean loadInitialSettings,
boolean applySettingsChanges)
Registers component for settings auto-save. |
|
static void |
registerComponent(java.awt.Component component,
java.lang.String group,
java.lang.String key)
Registers component for settings auto-save. |
|
static
|
registerComponent(java.awt.Component component,
java.lang.String group,
java.lang.String key,
java.lang.Class<T> defaultValueClass)
Registers component for settings auto-save. |
|
static
|
registerComponent(java.awt.Component component,
java.lang.String group,
java.lang.String key,
java.lang.Class<T> defaultValueClass,
boolean loadInitialSettings,
boolean applySettingsChanges)
Registers component for settings auto-save. |
|
static void |
registerComponent(java.awt.Component component,
java.lang.String group,
java.lang.String key,
java.lang.Object defaultValue)
Registers component for settings auto-save. |
|
static void |
registerComponent(java.awt.Component component,
java.lang.String group,
java.lang.String key,
java.lang.Object defaultValue,
boolean loadInitialSettings,
boolean applySettingsChanges)
Registers component for settings auto-save. |
|
static
|
registerSettingsProcessor(java.lang.Class componentType,
java.lang.Class<T> settingsProcessor)
Registers specified settings processor class for the specified component type. |
|
static void |
removeSettingsListener(java.lang.String key,
SettingsListener listener)
Removes settings listener. |
|
static void |
removeSettingsListener(java.lang.String group,
java.lang.String key,
SettingsListener listener)
Removes settings listener. |
|
static void |
saveComponentSettings(java.awt.Component component)
Saves component settings. |
|
static void |
saveSettings()
Saves all settings groups and files. |
|
static void |
saveSettingsGroup(SettingsGroup settingsGroup)
Saves specified settings group. |
|
static void |
saveSettingsGroup(java.lang.String group)
Saves settings group with the specified name. |
|
static
|
set(java.lang.String group,
java.lang.String key,
T object)
Sets value for the specified settings group and key. |
|
static
|
set(java.lang.String key,
T object)
Sets value for the specified settings key. |
|
static void |
setAllowSave(boolean allowSave)
Sets whether should allow saving settings into files or not. |
|
static void |
setBackupFilesExtension(java.lang.String backupFilesExtension)
Sets backup files extension |
|
static void |
setDefaultSettingsDir(java.lang.String defaultSettingsDir)
Sets default settings directory. |
|
static void |
setDefaultSettingsDirName(java.lang.String defaultSettingsDir)
Sets default settings directory name. |
|
static void |
setDefaultSettingsGroup(java.lang.String defaultSettingsGroup)
Sets default settings group name. |
|
static void |
setDisplayExceptions(boolean displayExceptions)
Sets whether should display settings load and save error messages or not. |
|
static void |
setGroupFileLocation(java.lang.String group,
java.lang.String dir)
Sets custom directory where settings group file will be saved. |
|
static void |
setSaveDefaultValues(boolean saveDefaultValues)
Sets whether should save provided default value in "get" calls or not. |
|
static void |
setSaveOnChange(boolean saveOnChange)
Sets whether should save settings right after any changes made or not. |
|
static void |
setSaveOnChangeDelay(long saveOnChangeDelay)
Sets save-on-change delay in milliseconds. |
|
static void |
setSettings(java.lang.String fileName,
java.lang.Object settings)
Sets and saves value into settings file with the specified name. |
|
static void |
setSettingsFilesExtension(java.lang.String settingsFilesExtension)
Sets settings files extension |
|
static boolean |
settingsExists(java.lang.String fileName)
Returns whether settings file with the specified name exists or not. |
|
static void |
unregisterComponent(java.awt.Component component)
Unregisters component from settings auto-save. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SettingsManager()
Method Detail |
---|
public static void initialize()
public static java.util.List<SettingsGroup> getLoadedGroups()
public static java.util.Map<java.lang.String,SettingsGroup> getLoadedGroupsMap()
public static void registerComponent(java.awt.Component component, java.lang.String key)
component
- component to registerkey
- component settings keypublic static <T extends DefaultValue> void registerComponent(java.awt.Component component, java.lang.String key, java.lang.Class<T> defaultValueClass)
T
- default value typecomponent
- component to registerkey
- component settings keydefaultValueClass
- component default value classDefaultValue
public static void registerComponent(java.awt.Component component, java.lang.String key, java.lang.Object defaultValue)
component
- component to registerkey
- component settings keydefaultValue
- component default valuepublic static void registerComponent(java.awt.Component component, java.lang.String group, java.lang.String key)
component
- component to registergroup
- component settings groupkey
- component settings keypublic static <T extends DefaultValue> void registerComponent(java.awt.Component component, java.lang.String group, java.lang.String key, java.lang.Class<T> defaultValueClass)
T
- default value typecomponent
- component to registergroup
- component settings groupkey
- component settings keydefaultValueClass
- component default value classDefaultValue
public static void registerComponent(java.awt.Component component, java.lang.String group, java.lang.String key, java.lang.Object defaultValue)
component
- component to registergroup
- component settings groupkey
- component settings keydefaultValue
- component default valuepublic static void registerComponent(java.awt.Component component, java.lang.String key, boolean loadInitialSettings, boolean applySettingsChanges)
component
- component to registerkey
- component settings keyloadInitialSettings
- whether to load initial available settings into the component or notapplySettingsChanges
- whether to apply settings changes to the component or notpublic static <T extends DefaultValue> void registerComponent(java.awt.Component component, java.lang.String key, java.lang.Class<T> defaultValueClass, boolean loadInitialSettings, boolean applySettingsChanges)
T
- default value typecomponent
- component to registerkey
- component settings keydefaultValueClass
- component default value classloadInitialSettings
- whether to load initial available settings into the component or notapplySettingsChanges
- whether to apply settings changes to the component or notDefaultValue
public static void registerComponent(java.awt.Component component, java.lang.String key, java.lang.Object defaultValue, boolean loadInitialSettings, boolean applySettingsChanges)
component
- component to registerkey
- component settings keydefaultValue
- component default valueloadInitialSettings
- whether to load initial available settings into the component or notapplySettingsChanges
- whether to apply settings changes to the component or notpublic static <T extends DefaultValue> void registerComponent(java.awt.Component component, java.lang.String group, java.lang.String key, java.lang.Class<T> defaultValueClass, boolean loadInitialSettings, boolean applySettingsChanges)
T
- default value typecomponent
- component to registergroup
- component settings groupkey
- component settings keydefaultValueClass
- component default value classloadInitialSettings
- whether to load initial available settings into the component or notapplySettingsChanges
- whether to apply settings changes to the component or notDefaultValue
public static void registerComponent(java.awt.Component component, java.lang.String group, java.lang.String key, java.lang.Object defaultValue, boolean loadInitialSettings, boolean applySettingsChanges)
component
- component to registergroup
- component settings groupkey
- component settings keydefaultValue
- component default valueloadInitialSettings
- whether to load initial available settings into the component or notapplySettingsChanges
- whether to apply settings changes to the component or notpublic static void registerComponent(java.awt.Component component, SettingsProcessor settingsProcessor)
component
- component to registersettingsProcessor
- component settings processorpublic static void unregisterComponent(java.awt.Component component)
component
- component to unregisterpublic static void loadComponentSettings(java.awt.Component component)
component
- component registered for settings auto-savepublic static void saveComponentSettings(java.awt.Component component)
component
- component registered for settings auto-savepublic static <T extends SettingsProcessor> void registerSettingsProcessor(java.lang.Class componentType, java.lang.Class<T> settingsProcessor)
T
- settings processor typecomponentType
- component typesettingsProcessor
- settings processor classpublic static java.lang.Boolean getBoolean(java.lang.String key)
key
- settings key
public static java.lang.Boolean getBoolean(java.lang.String group, java.lang.String key)
group
- settings groupkey
- settings key
public static java.lang.String getString(java.lang.String key)
key
- settings key
public static java.lang.String getString(java.lang.String group, java.lang.String key)
group
- settings groupkey
- settings key
public static java.lang.Integer getInteger(java.lang.String key)
key
- settings key
public static java.lang.Integer getInteger(java.lang.String group, java.lang.String key)
group
- settings groupkey
- settings key
public static java.lang.Long getLong(java.lang.String key)
key
- settings key
public static java.lang.Long getLong(java.lang.String group, java.lang.String key)
group
- settings groupkey
- settings key
public static java.lang.Float getFloat(java.lang.String key)
key
- settings key
public static java.lang.Float getFloat(java.lang.String group, java.lang.String key)
group
- settings groupkey
- settings key
public static java.lang.Double getDouble(java.lang.String key)
key
- settings key
public static java.lang.Double getDouble(java.lang.String group, java.lang.String key)
group
- settings groupkey
- settings key
public static java.awt.Dimension getDimension(java.lang.String key)
key
- settings key
public static java.awt.Dimension getDimension(java.lang.String group, java.lang.String key)
group
- settings groupkey
- settings key
public static java.awt.Point getPoint(java.lang.String key)
key
- settings key
public static java.awt.Point getPoint(java.lang.String group, java.lang.String key)
group
- settings groupkey
- settings key
public static java.awt.Color getColor(java.lang.String key)
key
- settings key
public static java.awt.Color getColor(java.lang.String group, java.lang.String key)
group
- settings groupkey
- settings key
public static java.awt.Rectangle getRectangle(java.lang.String key)
key
- settings key
public static java.awt.Rectangle getRectangle(java.lang.String group, java.lang.String key)
group
- settings groupkey
- settings key
public static java.awt.Insets getInsets(java.lang.String key)
key
- settings key
public static java.awt.Insets getInsets(java.lang.String group, java.lang.String key)
group
- settings groupkey
- settings key
public static <T> T get(java.lang.String key)
key
- settings key
public static <T extends DefaultValue> T get(java.lang.String key, java.lang.Class<T> defaultValueClass)
T
- default value typekey
- settings keydefaultValueClass
- default value class
public static <T> T get(java.lang.String key, T defaultValue)
T
- default value typekey
- settings keydefaultValue
- default value
public static <T extends DefaultValue> T get(java.lang.String group, java.lang.String key, java.lang.Class<T> defaultValueClass)
T
- default value typegroup
- settings groupkey
- settings keydefaultValueClass
- default value class
public static <T> T get(java.lang.String group, java.lang.String key, T defaultValue)
T
- default value typegroup
- settings groupkey
- settings keydefaultValue
- default value
public static <T extends DefaultValue> T getDefaultValue(java.lang.Class<T> defaultValueClass)
T
- default value typedefaultValueClass
- default value class
public static <T> T set(java.lang.String key, T object)
T
- new value typekey
- settings keyobject
- new value
public static <T> T set(java.lang.String group, java.lang.String key, T object)
T
- new value typegroup
- settings groupkey
- settings keyobject
- new value
public static SettingsGroup getSettingsGroup(java.lang.String group)
group
- settings group name
public static void saveSettings()
public static void saveSettingsGroup(java.lang.String group)
group
- name of the settings group to savepublic static void saveSettingsGroup(SettingsGroup settingsGroup)
settingsGroup
- settings group to savepublic SettingsGroupState getSettingsGroupState(java.lang.String group)
group
- settings group name
public static java.lang.Object getSettings(java.lang.String fileName)
fileName
- settings file name
public static <T> T getSettings(java.lang.String fileName, T defaultValue)
T
- default value typefileName
- settings file namedefaultValue
- default value class
public static void setSettings(java.lang.String fileName, java.lang.Object settings)
fileName
- settings file namesettings
- valuepublic static boolean settingsExists(java.lang.String fileName)
fileName
- settings file name
public static java.lang.String getSettingsFilesExtension()
public static void setSettingsFilesExtension(java.lang.String settingsFilesExtension)
settingsFilesExtension
- new settings files extensionpublic static java.lang.String getBackupFilesExtension()
public static void setBackupFilesExtension(java.lang.String backupFilesExtension)
backupFilesExtension
- new backup files extensionpublic static java.lang.String getDefaultSettingsDir()
public static void setDefaultSettingsDir(java.lang.String defaultSettingsDir)
defaultSettingsDir
- new default settings directorypublic static java.lang.String getDefaultSettingsDirName()
public static void setDefaultSettingsDirName(java.lang.String defaultSettingsDir)
defaultSettingsDir
- new default settings directory namepublic static java.lang.String getDefaultSettingsGroup()
public static void setDefaultSettingsGroup(java.lang.String defaultSettingsGroup)
defaultSettingsGroup
- new default settings group namepublic static void setGroupFileLocation(java.lang.String group, java.lang.String dir)
group
- settings group namedir
- settings group file directorypublic static java.lang.String getGroupFileLocation(java.lang.String group)
group
- settings group name
public static boolean isSaveOnChange()
public static void setSaveOnChange(boolean saveOnChange)
saveOnChange
- whether should save settings right after any changes made or notpublic static boolean isSaveDefaultValues()
public static void setSaveDefaultValues(boolean saveDefaultValues)
saveDefaultValues
- whether should save provided default value in "get" calls or notpublic static long getSaveOnChangeDelay()
public static void setSaveOnChangeDelay(long saveOnChangeDelay)
saveOnChangeDelay
- new save-on-change delay in millisecondspublic static boolean isDisplayExceptions()
public static void setDisplayExceptions(boolean displayExceptions)
displayExceptions
- whether should display settings load and save error messages or notpublic static boolean isAllowSave()
public static void setAllowSave(boolean allowSave)
allowSave
- whether should allow saving settings into files or notpublic static void disableSave()
public static void enableSave()
public static void addSettingsListener(java.lang.String key, SettingsListener listener)
key
- settings key to listen tolistener
- settings listener to addpublic static void addSettingsListener(java.lang.String group, java.lang.String key, SettingsListener listener)
group
- settings group to listen tokey
- settings key to listen tolistener
- settings listener to addpublic static void removeSettingsListener(java.lang.String key, SettingsListener listener)
key
- listened settings keylistener
- settings listener to removepublic static void removeSettingsListener(java.lang.String group, java.lang.String key, SettingsListener listener)
group
- listened settings groupkey
- listened settings keylistener
- settings listener to remove
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |