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 #365 (closed task: fixed)

Opened 2011-03-13T22:27:24-05:00

Last modified 2011-09-12T15:01:13-05:00

Interoperability with legacy IJ_Prefs.txt

Reported by: curtis Owned by: bdezonia
Priority: major Milestone: imagej-2.0-alpha5
Component: Legacy Compatibility Version:
Severity: serious Keywords:
Cc: Blocked By:


ImageJ 1.x uses a file called IJ_Prefs.txt to record preferences and persisted fields. Some legacy plugins may rely on calls to ij.Prefs to read and write these preferences. We should decide if/how to intercept this behavior and make it compatible with the IJ2 persistence mechanism.

In particular, if a legacy plugin asks for the value of some option from one of the IJ1 options menus, it should reflect the relevant values from our updated IJ2 options plugins.

Change History

comment:1 Changed 2011-03-14T13:09:32-05:00 by bdezonia

TODO : find a testbed - find some option in IJ2 that when changed currently DOES NOT work correctly because it calls an IJ1 method that uses IJ1's preferences.

comment:2 Changed 2011-03-14T13:17:40-05:00 by bdezonia

This should work as a test bed:

ImageCalculator, float images, divide one image by another image that is all zero. IJ1 looks up a pref for the divide by zero value. IJ2 tracks this itself. If you set DBZ to something in IJ2 Edit Options it will not be applied when the above image calculation is done.

comment:3 Changed 2011-03-14T14:25:18-05:00 by bdezonia

Since I've replaced ImageCalculator the only way to test this with my test bed is to unblacklist the IJ1 ImageCalculator, set the DBZ value in IJ2 prefs, run IJ1 ImageCalculator as specified above, and see that IJ2 DBZ value actually used.

Another item to be added is Options events. Make each OptionsPlugin extend an abstract options plugin of some type. The abstract class has the single method run() which publishes an OptionChanged event (only if a setting actually changed or just everytime?).

ij-legacy layer subscribes to OptionChanged events and sets the corresponding IJ1 pref to keep them in sync.

comment:4 Changed 2011-06-28T16:27:08-05:00 by bdezonia

Some work completed on this ticket in c3110d966d0d8359060d8a0ace8714364fd30499. Added an OptionsPlugin base class whose run() method throws an OptionsChangedEvent. Changed all options plugins to inherit this behavior. Included new Rounded Rect Tool plugin.

Still need to do:

  • listen in legacy layer for OptionsChangedEvents. When fired, get current values from Prefs and set IJ1's relevant global settings or Prefs.

Since the legacy layer is being modified by someone else right now this can wait.

comment:5 Changed 2011-07-07T17:52:20-05:00 by bdezonia

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

Made code for setting IJ1 preferences (as much as feasible) when IJ2 options are changed. Present in cd09b8c05346c9ed7ada1d755a657c0cfbff0ce8.

Still TODO:

An initial call to OptionsSynchronizer::update() has to take place when the IJ2 Prefs are loaded from disk. Determine initialization order.

Some preferences cannot be synced with IJ1 and need IJ2 side effects to be implemented. Those are outlined as TODOs in OptionsSynchronizer. Each IJ2 Options dialog could do the side effects code as needed.

comment:6 Changed 2011-07-07T17:52:26-05:00 by bdezonia

  • Status changed from closed to reopened
  • Resolution fixed deleted

comment:7 Changed 2011-07-29T12:53:33-05:00 by bdezonia

Initial call to update() happens in LegacyService::initialize().

Have not determined how to set all IJ1 preferences from IJ2. Might need to use reflection on IJ1 plugins that contain the nonpublic settings.

Have not put hooks in the legacy layer that notices when an IJ1 setting is updated by an IJ1 command which then updates IJ2's settings.

comment:8 Changed 2011-07-29T12:53:51-05:00 by bdezonia

  • Milestone changed from imagej-2.0-beta1 to imagej-2.0-alpha5

comment:9 Changed 2011-07-29T14:34:31-05:00 by bdezonia


  • make sure IJ2 can set all IJ1 options fields (use ClassUtils methods such as setValue() and one Curtis hatched for getting a Field). Use these to set instance variables of IJ1 options classes as needed.
  • hook IJ1's Prefs.set() in the legacy layer and update the appropriate IJ2 option. Have a map that takes IJ1 pref key id strings and gets the IJ2 settings key. Set the value as specified.

comment:10 Changed 2011-08-12T16:19:13-05:00 by bdezonia

LegacyInjector now captures all getting and setting of ij.Prefs with methods to IJ2's Prefs. There is one batch of settings. Changes in IJ1 to settings should affect IJ2 values.

All that is left is to:

1) Make sure we are setting IJ1 options values from IJ2 (might need to use reflection)

2) Make sure we are using default values on IJ2 prefs get() calls so that the initial values are assigned correctly.

comment:11 Changed 2011-09-06T12:27:56-05:00 by bdezonia

Reflection comment

use ClassUtils.setValue() and ClassUtils.getField(class,fieldName)

comment:12 Changed 2011-09-12T15:01:13-05:00 by bdezonia

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

Much code changed by Curtis and Barry. Major commit in 0c803bfcb23b34910d2221e1e7192b5c0e6a2761. OptionsPlugins now manage initialization of fields from preferences falling back to compile time defaults.