public final class SettingsManager
extends java.lang.Object
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.
| Constructor and Description |
|---|
SettingsManager() |
| Modifier and Type | Method and Description |
|---|---|
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 <T> T |
get(java.lang.String key)
Returns Object value.
|
static <T extends DefaultValue> |
get(java.lang.String key,
java.lang.Class<T> defaultValueClass)
Returns typed value.
|
static <T extends DefaultValue> |
get(java.lang.String group,
java.lang.String key,
java.lang.Class<T> defaultValueClass)
Returns typed value.
|
static <T> T |
get(java.lang.String group,
java.lang.String key,
T defaultValue)
Returns typed value.
|
static <T> T |
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 <T extends DefaultValue> |
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 |
getGroupFilePath(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 <T> T |
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 |
isLoggingEnabled()
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 |
isSaveLoggingEnabled()
Returns whether settings save log is enabled or not.
|
static boolean |
isSaveOnChange()
Returns whether should save settings right after any changes made or not.
|
static void |
loadComponentSettings(javax.swing.JComponent component)
Loads saved settings into the component if it is registered.
|
static void |
registerComponent(javax.swing.JComponent component,
SettingsProcessor settingsProcessor)
Registers component for settings auto-save.
|
static void |
registerComponent(javax.swing.JComponent component,
java.lang.String key)
Registers component for settings auto-save.
|
static void |
registerComponent(javax.swing.JComponent component,
java.lang.String key,
boolean loadInitialSettings,
boolean applySettingsChanges)
Registers component for settings auto-save.
|
static <T extends DefaultValue> |
registerComponent(javax.swing.JComponent component,
java.lang.String key,
java.lang.Class<T> defaultValueClass)
Registers component for settings auto-save.
|
static <T extends DefaultValue> |
registerComponent(javax.swing.JComponent component,
java.lang.String key,
java.lang.Class<T> defaultValueClass,
boolean loadInitialSettings,
boolean applySettingsChanges)
Registers component for settings auto-save.
|
static void |
registerComponent(javax.swing.JComponent component,
java.lang.String key,
java.lang.Object defaultValue)
Registers component for settings auto-save.
|
static void |
registerComponent(javax.swing.JComponent component,
java.lang.String key,
java.lang.Object defaultValue,
boolean loadInitialSettings,
boolean applySettingsChanges)
Registers component for settings auto-save.
|
static void |
registerComponent(javax.swing.JComponent component,
java.lang.String group,
java.lang.String key)
Registers component for settings auto-save.
|
static <T extends DefaultValue> |
registerComponent(javax.swing.JComponent component,
java.lang.String group,
java.lang.String key,
java.lang.Class<T> defaultValueClass)
Registers component for settings auto-save.
|
static <T extends DefaultValue> |
registerComponent(javax.swing.JComponent 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(javax.swing.JComponent component,
java.lang.String group,
java.lang.String key,
java.lang.Object defaultValue)
Registers component for settings auto-save.
|
static void |
registerComponent(javax.swing.JComponent component,
java.lang.String group,
java.lang.String key,
java.lang.Object defaultValue,
boolean loadInitialSettings,
boolean applySettingsChanges)
Registers component for settings auto-save.
|
static <T extends SettingsProcessor> |
registerSettingsProcessor(java.lang.Class<? extends javax.swing.JComponent> 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 |
resetDefaultGroup()
Resets all settings within the default settings group.
|
static void |
resetGroup(java.lang.String group)
Resets all settings within the specified settings group.
|
static <T> T |
resetValue(java.lang.String key)
Resets settings under the key within the default settings group.
|
static <T> T |
resetValue(java.lang.String group,
java.lang.String key)
Resets settings under the key within the specified settings group.
|
static void |
saveComponentSettings(javax.swing.JComponent 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 <T> T |
set(java.lang.String group,
java.lang.String key,
T object)
Sets value for the specified settings group and key.
|
static <T> T |
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 |
setGroupFilePath(java.lang.String group,
java.lang.String dir)
Sets custom directory where settings group file will be saved.
|
static void |
setLoggingEnabled(boolean loggingEnabled)
Sets whether should display settings load and save error messages or not.
|
static void |
setSaveDefaultValues(boolean saveDefaultValues)
Sets whether should save provided default value in "get" calls or not.
|
static void |
setSaveLoggingEnabled(boolean enabled)
Sets whether settings save log is enabled 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(javax.swing.JComponent component)
Unregisters component from settings auto-save.
|
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(javax.swing.JComponent component,
java.lang.String key)
Also registered component will be: - listened for settings changes to save them when requested - automatically updated with any loaded settings for that key if requested - automatically updated with any changes made in its settings if requested
component - component to registerkey - component settings keypublic static <T extends DefaultValue> void registerComponent(javax.swing.JComponent component, java.lang.String key, java.lang.Class<T> defaultValueClass)
Also registered component will be: - listened for settings changes to save them when requested - automatically updated with any loaded settings for that key if requested - automatically updated with any changes made in its settings if requested
T - default value typecomponent - component to registerkey - component settings keydefaultValueClass - component default value classDefaultValuepublic static void registerComponent(javax.swing.JComponent component,
java.lang.String key,
java.lang.Object defaultValue)
Also registered component will be: - listened for settings changes to save them when requested - automatically updated with any loaded settings for that key if requested - automatically updated with any changes made in its settings if requested
component - component to registerkey - component settings keydefaultValue - component default valuepublic static void registerComponent(javax.swing.JComponent component,
java.lang.String group,
java.lang.String key)
Also registered component will be: - listened for settings changes to save them when requested - automatically updated with any loaded settings for that key if requested - automatically updated with any changes made in its settings if requested
component - component to registergroup - component settings groupkey - component settings keypublic static <T extends DefaultValue> void registerComponent(javax.swing.JComponent component, java.lang.String group, java.lang.String key, java.lang.Class<T> defaultValueClass)
Also registered component will be: - listened for settings changes to save them when requested - automatically updated with any loaded settings for that key if requested - automatically updated with any changes made in its settings if requested
T - default value typecomponent - component to registergroup - component settings groupkey - component settings keydefaultValueClass - component default value classDefaultValuepublic static void registerComponent(javax.swing.JComponent component,
java.lang.String group,
java.lang.String key,
java.lang.Object defaultValue)
Also registered component will be: - listened for settings changes to save them when requested - automatically updated with any loaded settings for that key if requested - automatically updated with any changes made in its settings if requested
component - component to registergroup - component settings groupkey - component settings keydefaultValue - component default valuepublic static void registerComponent(javax.swing.JComponent component,
java.lang.String key,
boolean loadInitialSettings,
boolean applySettingsChanges)
Also registered component will be: - listened for settings changes to save them when requested - automatically updated with any loaded settings for that key if requested - automatically updated with any changes made in its settings if requested
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(javax.swing.JComponent component, java.lang.String key, java.lang.Class<T> defaultValueClass, boolean loadInitialSettings, boolean applySettingsChanges)
Also registered component will be: - listened for settings changes to save them when requested - automatically updated with any loaded settings for that key if requested - automatically updated with any changes made in its settings if requested
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 notDefaultValuepublic static void registerComponent(javax.swing.JComponent component,
java.lang.String key,
java.lang.Object defaultValue,
boolean loadInitialSettings,
boolean applySettingsChanges)
Also registered component will be: - listened for settings changes to save them when requested - automatically updated with any loaded settings for that key if requested - automatically updated with any changes made in its settings if requested
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(javax.swing.JComponent component, java.lang.String group, java.lang.String key, java.lang.Class<T> defaultValueClass, boolean loadInitialSettings, boolean applySettingsChanges)
Also registered component will be: - listened for settings changes to save them when requested - automatically updated with any loaded settings for that key if requested - automatically updated with any changes made in its settings if requested
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 notDefaultValuepublic static void registerComponent(javax.swing.JComponent component,
java.lang.String group,
java.lang.String key,
java.lang.Object defaultValue,
boolean loadInitialSettings,
boolean applySettingsChanges)
Also registered component will be: - listened for settings changes to save them when requested - automatically updated with any loaded settings for that key if requested - automatically updated with any changes made in its settings if requested
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(javax.swing.JComponent component,
SettingsProcessor settingsProcessor)
Also registered component will be: - listened for settings changes to save them when requested - automatically updated with any loaded settings for that key if requested - automatically updated with any changes made in its settings if requested
component - component to registersettingsProcessor - component settings processorpublic static void unregisterComponent(javax.swing.JComponent component)
component - component to unregisterpublic static void loadComponentSettings(javax.swing.JComponent component)
component - component registered for settings auto-savepublic static void saveComponentSettings(javax.swing.JComponent component)
component - component registered for settings auto-savepublic static <T extends SettingsProcessor> void registerSettingsProcessor(java.lang.Class<? extends javax.swing.JComponent> 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 keypublic static java.lang.Boolean getBoolean(java.lang.String group,
java.lang.String key)
group - settings groupkey - settings keypublic static java.lang.String getString(java.lang.String key)
key - settings keypublic static java.lang.String getString(java.lang.String group,
java.lang.String key)
group - settings groupkey - settings keypublic static java.lang.Integer getInteger(java.lang.String key)
key - settings keypublic static java.lang.Integer getInteger(java.lang.String group,
java.lang.String key)
group - settings groupkey - settings keypublic static java.lang.Long getLong(java.lang.String key)
key - settings keypublic static java.lang.Long getLong(java.lang.String group,
java.lang.String key)
group - settings groupkey - settings keypublic static java.lang.Float getFloat(java.lang.String key)
key - settings keypublic static java.lang.Float getFloat(java.lang.String group,
java.lang.String key)
group - settings groupkey - settings keypublic static java.lang.Double getDouble(java.lang.String key)
key - settings keypublic static java.lang.Double getDouble(java.lang.String group,
java.lang.String key)
group - settings groupkey - settings keypublic static java.awt.Dimension getDimension(java.lang.String key)
key - settings keypublic static java.awt.Dimension getDimension(java.lang.String group,
java.lang.String key)
group - settings groupkey - settings keypublic static java.awt.Point getPoint(java.lang.String key)
key - settings keypublic static java.awt.Point getPoint(java.lang.String group,
java.lang.String key)
group - settings groupkey - settings keypublic static java.awt.Color getColor(java.lang.String key)
key - settings keypublic static java.awt.Color getColor(java.lang.String group,
java.lang.String key)
group - settings groupkey - settings keypublic static java.awt.Rectangle getRectangle(java.lang.String key)
key - settings keypublic static java.awt.Rectangle getRectangle(java.lang.String group,
java.lang.String key)
group - settings groupkey - settings keypublic static java.awt.Insets getInsets(java.lang.String key)
key - settings keypublic static java.awt.Insets getInsets(java.lang.String group,
java.lang.String key)
group - settings groupkey - settings keypublic static <T> T get(java.lang.String key)
key - settings keypublic static <T extends DefaultValue> T get(java.lang.String key, java.lang.Class<T> defaultValueClass)
T - default value typekey - settings keydefaultValueClass - default value classpublic static <T> T get(java.lang.String key,
T defaultValue)
T - default value typekey - settings keydefaultValue - default valuepublic 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 classpublic static <T> T get(java.lang.String group,
java.lang.String key,
T defaultValue)
T - default value typegroup - settings groupkey - settings keydefaultValue - default valuepublic static <T extends DefaultValue> T getDefaultValue(java.lang.Class<T> defaultValueClass)
T - default value typedefaultValueClass - default value classpublic static <T> T set(java.lang.String key,
T object)
T - new value typekey - settings keyobject - new valuepublic static <T> T set(java.lang.String group,
java.lang.String key,
T object)
T - new value typegroup - settings groupkey - settings keyobject - new valuepublic static void resetDefaultGroup()
public static void resetGroup(java.lang.String group)
group - settings grouppublic static <T> T resetValue(java.lang.String key)
T - value typekey - settings key to resetpublic static <T> T resetValue(java.lang.String group,
java.lang.String key)
T - value typegroup - settings groupkey - settings key to resetpublic static SettingsGroup getSettingsGroup(java.lang.String group)
group - settings group namepublic 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 namepublic static java.lang.Object getSettings(java.lang.String fileName)
fileName - settings file namepublic static <T> T getSettings(java.lang.String fileName,
T defaultValue)
T - default value typefileName - settings file namedefaultValue - default value classpublic 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 namepublic 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 setGroupFilePath(java.lang.String group,
java.lang.String dir)
group - settings group namedir - settings group file directorypublic static java.lang.String getGroupFilePath(java.lang.String group)
group - settings group namepublic 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 isLoggingEnabled()
public static void setLoggingEnabled(boolean loggingEnabled)
loggingEnabled - whether should display settings load and save error messages or notpublic static boolean isSaveLoggingEnabled()
public static void setSaveLoggingEnabled(boolean enabled)
enabled - whether settings save log is enabled 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