NOTICE! This is a static HTML version of a legacy ImageJ Trac ticket.

The ImageJ project now uses GitHub Issues for issue tracking.

Please file all new issues there.

Ticket #150 (closed enhancement: fixed)

Opened 2010-08-16T11:05:59-05:00

Last modified 2010-08-23T10:26:14-05:00

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 2010-08-23T10:26:14-05:00 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.