The TLcyPersistentPreferencesAddOn makes the user preferences of Lucy persistent. Typical preferences are the size and location of the Lucy window and the workspace that is loaded when the application starts. You can retrieve the Lucy user preferences using ILcyLucyEnv.getPreferencesManager().getUserPreferences(). When the add-on is plugged in, it reads the preferences from the persistent store. For properties that are not available in the persistent store, the properties in the property file defined in the configuration file of the TLcyPersistentPreferencesAddOn, default_preferences.cfg, are used as a fallback. This means that the preference settings for the first run of the application on some system can be configured in that configuration file. When Lucy exits, the preferences are written to the persistent store again. Every user in a system will have its own set of user preferences. The com.luciad.lucy.TLcyPreferencesManager.getUserPreferences() object is stored using the Java 1.4 java.util.prefs.Preferences API, which imposes the following restrictions:

  • Maximum key length of 80 characters (hierarchical keys have 80 characters per level)

  • Maximum value length of 8192 characters

The persistent store that is used to store the preferences depends on the platform. On windows platforms, these settings are saved in the registry under HKEY_CURRENT_USER/Software/JavaSoft/Prefs/com/luciad/lucy. On other platforms, these settings are saved in a file in the directory .java in the users home folder.

Note that in the java.util.prefs.Preferences API hierarchical keys are split by a slash (/), but for consistency with other applications of the Properties object within Lucy, we have chosen to use a dot (.) as the separator. Therefore, dots and slashes are swapped before the keys are stored in the java.util.prefs.Preferences API.

For convenience, these methods allow you to manipulate the persistent store:

  • clearUserPreferences() clears all user preferences for the current user.

  • encodeUserPreferences() encodes the user preferences (com.luciad.lucy. TLcyPreferencesManager.getUserPreferences()) to the persistent store. This method is automatically invoked when Lucy exits.

  • decodeUserPreferences() decodes the user preferences from the persistent store into com.luciad.lucy.TLcyPreferencesManager.getUserPreferences(). This method is automatically invoked when the add-on is plugged.

If a custom application is built on top of Lucy, it could be useful to prevent the standard Lucy application from interacting with the preferences of the custom application. Therefore, a prefix is used to store all preferences. This prefix can be configured by modifying the property TLcyPersistentPreferencesAddOn.storagePrefix in the configuration file of the TLcyPersistentPreferencesAddOn.

If needed, this add-on can be replaced by a custom add-on that makes the preferences persistent using some other mechanism. For example, you could write an add-on that saves the preferences to a server or database.