NOTICE! This is a static HTML version of a legacy Fiji BugZilla bug.

The Fiji project now uses GitHub Issues for issue tracking.

Please file all new issues there.

Bug 651 - Using IJ.run() in preview triggers premature macro recording
Using IJ.run() in preview triggers premature macro recording
Status: RESOLVED WONTFIX
Product: Fiji
Classification: Unclassified
Component: Other
unspecified
All All
: P5 normal
Assigned To: ImageJ Bugs Mailing List
Depends on:
Blocks:
 
Reported: 2013-08-14 05:02 CDT by Jan Eglinger
Modified: 2013-08-17 16:23 CDT
1 user (show)

See Also:


Attachments
Example plugin (ExtendedPlugInFilter) to reproduce the bug. (1.34 KB, text/plain)
2013-08-14 05:02 CDT, Jan Eglinger

Description Jan Eglinger 2013-08-14 05:02:19 CDT
Created attachment 116
Example plugin (ExtendedPlugInFilter) to reproduce the bug.

When using any IJ.run(imp, "...") command in the run method of an ExtendedPlugInFilter containing GenericDialog.addPreviewCheckbox(), the first activation of the preview checkbox triggers the command to be recorded in the macro recorder, without the parameters of the current dialog.

To reproduce, put the attached file as Bug_Report.java into ./plugins/ or any subfolder, start Fiji (or run 'Help>Refresh Menus'), start macro recording via 'Plugins>Macros>Record...', and start 'Bug Report'.

In the dialog asking for a number, a click on the preview checkbox triggers the premature recording:
  run("Bug Report");
while clicking on OK without using the preview triggers the correct recording:
  run("Bug Report", "number=1.00000");

Commenting out the last command 'IJ.run(imp, "Smooth", "");' leads to correct recording (only upon OK, not during preview).

(Using up-to-date Fiji/ImageJ 1.48a)
Comment 1 Wayne Rasband 2013-08-15 11:29:27 CDT
Plugins that implement the PlugInFilter or ExtendedPlugInFilter interfaces should not use IJ.run(). Either switch to the PlugIn interface or use direct API calls, such as ip.smooth().
Comment 2 Jan Eglinger 2013-08-16 02:18:05 CDT
Thanks, Wayne, for the clarification.

I was actually using ExtendedPlugInFilter because of its support for an options dialog and preview, that avoids a lot of repeated code.
Could you point me to some code example that uses the PlugIn interface and implements a preview, so that I can learn from that?

On the other side, it would be great to have an additional option in the macro (plugin) recorder that allows to record lower level API calls other than IJ.run(...). Is that feasible?

Best,
Jan
Comment 3 Wayne Rasband 2013-08-17 15:50:46 CDT
Here are four relatively simple plugins (three internal and one external) that implement ExtendedPlugInFilter and support Preview:

Rotator (Image>Transform>Rotate...)
http://imagej.nih.gov/ij/developer/source/ij/plugin/filter/Rotator.java.html

Translator (Image>Transform>Translate...)
http://imagej.nih.gov/ij/developer/source/ij/plugin/filter/Translator.java.html

UnsharpMask (Process>Filters>Unsharp Mask...)
http://imagej.nih.gov/ij/developer/source/ij/plugin/filter/UnsharpMask.java.html

Erode_Demo (external plugin)
http://imagej.nih.gov/ij/plugins/erode-demo.html

What I can easily do is update the Recorder so that is records the lower level API call as a comment. For example, the Process>Math>Set command would be recorded as:

   IJ.run(imp, "Set...", "value=25");
   //ip.set(25);

-wayne
Comment 4 Jan Eglinger 2013-08-17 16:07:04 CDT
Thanks for the reply.
Since you suggested to switch to the PlugIn interface instead of ExtendedPlugInFilter, I was wondering if there are examples using PlugIn while implementing a preview.
But I guess I'll rather stick with ExtendedPlugInFilter and try to avoid IJ.run in my case.

Your suggestion to record the lower level API call would be helpful in my opinion.

Thanks again for your help.
Jan
Comment 5 Wayne Rasband 2013-08-17 16:23:23 CDT
I do not know of any plugins that implement the PlugIn interface and have a Preview option. I would stick with ExtendedPlugInFilter and avoid IJ.run().