Package jmri.util.prefs
Class JmriPreferencesProvider
java.lang.Object
jmri.util.prefs.JmriPreferencesProvider
Provides instances of
Preferences backed by a
JMRI-specific storage implementation based on a Properties file.
There are two Properties files per Profile and
NodeIdentity, both stored in the directory
profile:profile:
profile.propertiespreferences that are shared across multiple nodes for a single profile. An example of such a preference would be the Railroad Name preference.<node-identity>/profile.propertiespreferences that are specific to the profile running on a specific host (<node-identity> is the identity returned byNodeIdentity.storageIdentity()). An example of such a preference would be a file location.
Non-profile specific configuration that applies to all profiles is stored in
the file settings:preferences/preferences.properties.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringfindCNBForClass(Class<?> cls) Returns the name of the package for the class in a format that is treated as a single token.static StringfindCNBForPackage(Package pkg) Returns the name of the package in a format that is treated as a single token.(package private) static JmriPreferencesProviderfindProvider(File path, boolean shared) Get the JmriPreferencesProvider for the specified profile path.static PreferencesgetPreferences(File path, Class<?> clazz, boolean shared) Get thePreferencesfor the specified class in the specified path.(package private) PreferencesgetPreferences(Class<?> clazz) Get thePreferencesfor the specified class.(package private) PreferencesgetPreferences(Package pkg) Get thePreferencesfor the specified package.(package private) PreferencesgetPreferences(String pkg) Get thePreferencesfor the specified package.static PreferencesgetPreferences(Profile project, Class<?> clazz, boolean shared) Get thePreferencesfor the specified class in the specified profile.static PreferencesgetPreferences(Profile project, Package pkg, boolean shared) Get thePreferencesfor the specified package in the specified profile.static PreferencesgetPreferences(Profile project, String pkg, boolean shared) Get thePreferencesfor the specified package in the specified profile.(package private) Fileprotected booleanbooleanReturn true if the properties file had not been written for a JMRIProfilebefore this instance of JMRI was launched.protected voidsetBackedUp(boolean backedUp)
-
Constructor Details
-
JmriPreferencesProvider
JmriPreferencesProvider(@CheckForNull File path, boolean shared)
-
-
Method Details
-
findProvider
Get the JmriPreferencesProvider for the specified profile path.- Parameters:
path- The root path of aProfile. This is most frequently the path returned byProfile.getPath().shared- True if the preferences apply to the profile at path regardless of host. If false, the preferences only apply to this computer.- Returns:
- The shared or private JmriPreferencesProvider for the project at path.
-
getPreferences
@Nonnull public static Preferences getPreferences(@CheckForNull Profile project, @CheckForNull Class<?> clazz, boolean shared) Get thePreferencesfor the specified class in the specified profile.- Parameters:
project- The profile. This is most often the profile returned by theProfileManager.getActiveProfile()method of the ProfileManager returned byProfileManager.getDefault(). If null, preferences apply to all profiles on the computer and the value of shared is ignored.clazz- The class requesting preferences. Note that the preferences returned are for the package containing the class.shared- True if the preferences apply to this profile regardless of host. If false, the preferences only apply to this computer. Ignored if the value of project is null.- Returns:
- The shared or private Preferences node for the package containing clazz for project.
-
getPreferences
@Nonnull public static Preferences getPreferences(@CheckForNull Profile project, @CheckForNull Package pkg, boolean shared) Get thePreferencesfor the specified package in the specified profile.- Parameters:
project- The profile. This is most often the profile returned by theProfileManager.getActiveProfile()method of the ProfileManager returned byProfileManager.getDefault(). If null, preferences apply to all profiles on the computer and the value of shared is ignored.pkg- The package requesting preferences.shared- True if the preferences apply to this profile regardless of host. If false, the preferences only apply to this computer. Ignored if the value of project is null.- Returns:
- The shared or private Preferences node for the package for project.
-
getPreferences
@Nonnull public static Preferences getPreferences(@CheckForNull Profile project, @CheckForNull String pkg, boolean shared) Get thePreferencesfor the specified package in the specified profile.Use of
getPreferences(Profile, Class, boolean)orgetPreferences(Profile, Package, boolean)is preferred and recommended unless reading preferences for a non-existent package or class.- Parameters:
project- The profile. This is most often the profile returned by theProfileManager.getActiveProfile()method of the ProfileManager returned byProfileManager.getDefault(). If null, preferences apply to all profiles on the computer and the value of shared is ignored.pkg- The package requesting preferences.shared- True if the preferences apply to this profile regardless of host. If false, the preferences only apply to this computer. Ignored if the value of project is null.- Returns:
- The shared or private Preferences node for the package.
-
getPreferences
public static Preferences getPreferences(@CheckForNull File path, @CheckForNull Class<?> clazz, boolean shared) Get thePreferencesfor the specified class in the specified path.Use of
getPreferences(jmri.profile.Profile, java.lang.Class, boolean)is preferred and recommended unless being used to during the construction of a Profile object.- Parameters:
path- The path to a profile. This is most often the result ofProfile.getPath()for a given Profile. If null, preferences apply to all profiles on the computer and the value of shared is ignored.clazz- The class requesting preferences. Note that the preferences returned are for the package containing the class.shared- True if the preferences apply to this profile regardless of host. If false, the preferences only apply to this computer. Ignored if the value of path is null.- Returns:
- The shared or private Preferences node for the package containing clazz for project.
-
getPreferences
Get thePreferencesfor the specified package.- Parameters:
pkg- The package requesting preferences.- Returns:
- The shared or private Preferences node for the package.
-
getPreferences
Get thePreferencesfor the specified class.- Parameters:
clazz- The class requesting preferences. Note that the preferences returned are for the package containing the class.- Returns:
- The shared or private Preferences node for the package containing clazz.
-
getPreferences
Get thePreferencesfor the specified package.- Parameters:
pkg- The package for which preferences are needed.- Returns:
- The shared or private Preferences node for the package.
-
isFirstUse
Return true if the properties file had not been written for a JMRIProfilebefore this instance of JMRI was launched. Note that the first use of a node-specific setting can be different than the first use of a multi-node setting.- Returns:
- true if new or newly migrated profile, false otherwise
-
findCNBForClass
Returns the name of the package for the class in a format that is treated as a single token.- Parameters:
cls- The class for which a sanitized package name is needed- Returns:
- A sanitized package name
-
findCNBForPackage
Returns the name of the package in a format that is treated as a single token.- Parameters:
pkg- The package for which a sanitized name is needed- Returns:
- A sanitized package name
-
getPreferencesFile
-
isBackedUp
- Returns:
- the backedUp
-
setBackedUp
- Parameters:
backedUp- the backedUp to set
-