Class JmriPreferencesProvider

java.lang.Object
jmri.util.prefs.JmriPreferencesProvider

public final class JmriPreferencesProvider extends Object
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.properties preferences 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.properties preferences that are specific to the profile running on a specific host (<node-identity> is the identity returned by NodeIdentity.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 Details

  • Method Details

    • findProvider

      Get the JmriPreferencesProvider for the specified profile path.
      Parameters:
      path - The root path of a Profile. This is most frequently the path returned by Profile.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 the Preferences for the specified class in the specified profile.
      Parameters:
      project - The profile. This is most often the profile returned by the ProfileManager.getActiveProfile() method of the ProfileManager returned by ProfileManager.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 the Preferences for the specified package in the specified profile.
      Parameters:
      project - The profile. This is most often the profile returned by the ProfileManager.getActiveProfile() method of the ProfileManager returned by ProfileManager.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 the Preferences for the specified package in the specified profile.

      Use of getPreferences(Profile, Class, boolean) or getPreferences(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 the ProfileManager.getActiveProfile() method of the ProfileManager returned by ProfileManager.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 the Preferences for 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 of Profile.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 the Preferences for the specified package.
      Parameters:
      pkg - The package requesting preferences.
      Returns:
      The shared or private Preferences node for the package.
    • getPreferences

      Get the Preferences for 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 the Preferences for the specified package.
      Parameters:
      pkg - The package for which preferences are needed.
      Returns:
      The shared or private Preferences node for the package.
    • isFirstUse

      public boolean isFirstUse()
      Return true if the properties file had not been written for a JMRI Profile before 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

      public static String findCNBForClass(@Nonnull Class<?> cls)
      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

      protected boolean isBackedUp()
      Returns:
      the backedUp
    • setBackedUp

      protected void setBackedUp(boolean backedUp)
      Parameters:
      backedUp - the backedUp to set