Ticket #150 (closed enhancement: fixed)

Opened 9 years ago

Last modified 9 years ago

Saving of Preferences using LookupAPI

Reported by: gharris Owned by: gharris
Priority: major Milestone: biweekly-2010: Aug-09 to Aug-20
Component: Analysis Plugins Version:
Severity: major Keywords:
Cc: Blocked By:
Blocking:

Description

On Quiting ImageJ, ij.Prefs.savePreferences() calls a variety of classes in order to force them to save their preferences, like this:

IJ.getInstance().savePreferences(prefs);
Menus.savePreferences(prefs);
ParticleAnalyzer.savePreferences(prefs);
Analyzer.savePreferences(prefs);
ImportDialog.savePreferences(prefs);
PlotWindow.savePreferences(prefs);
NewImage.savePreferences(prefs);

This process can be dynamic by having this discover any classes that want to save their preferences on Quit. By creating an interface SavesPrefs, add the annotation @ServiceProvider(service = SavesPrefs.class) to the classes that implement SavesPrefs, and then using Lookup.getDefault().lookupAll(SavesPrefs.class) find all the ‘services’ and to invoke the savePrefs() method on each one.

Each of the classes in the list above was made to implement SavesPrefs.

NewImage is problematic because the no-args constructor calls openImage().

Change History

comment:1 Changed 9 years ago by gharris

  • Status changed from new to closed
  • Resolution set to fixed

This mechanism for dynamically invoking classes that implement a specific capability works nicely... I will incorporate it as necessary and useful, beyond the saving of preferences.

Note: See TracTickets for help on using tickets.