<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="background-color: transparent;">I've just started looking into to porting my existing ImageJ plugins to ImageJ2. I have hit a problem in that calls to functions like setDisplayRange seem not to take effect until my plugin returns.<span class="Apple-tab-span" style="white-space: pre; "> </span><span class="Apple-tab-span" style="white-space: pre; "> </span></span><div><span class="Apple-style-span" style="background-color: transparent;"><br></span></div><div><span class="Apple-style-span" style="background-color: transparent;">The following plugin lets me interactively adjust the image display range when run with ImageJ1 but with ImageJ2 there is no effect to the image until I close the plugIn dialog.<br></span><div><div><span class="Apple-style-span" style="background-color: transparent;"><br></span><div><span class="Apple-style-span" style="background-color: transparent;">I also note that the ImageJ2 Adjust->Brightness/Contrast (appears new) can update the image interactively, whereas the Adjust->WindowLevel (looks like existing ImageJ1 UI) does not work.</span></div><div><span class="Apple-style-span" style="background-color: transparent;"><br></span></div><div><span class="Apple-style-span" style="background-color: transparent;">Any help greatly appreciated!</span></div><div><span class="Apple-style-span" style="background-color: transparent;"><br></span></div><div><span class="Apple-style-span" style="background-color: transparent;">Example code below</span></div><div><br></div><div>//===========================================================================</div><div><br></div><div><br></div><div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #941c64">package</span> SmartCapture;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #941c64">import</span> java.awt.AWTEvent;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #941c64">import</span> ij.IJ;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #941c64">import</span> ij.ImagePlus;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #941c64">import</span> ij.gui.DialogListener;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #941c64">import</span> ij.gui.GenericDialog;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #941c64">import</span> ij.plugin.filter.ExtendedPlugInFilter;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #941c64">import</span> ij.plugin.filter.PlugInFilterRunner;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #941c64">import</span> ij.process.ImageProcessor;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: #941c64">public</span> <span style="color: #941c64">class</span> Test_IJ2 <span style="color: #941c64">implements</span> ExtendedPlugInFilter, DialogListener {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #941c64">private</span> <span style="color: #941c64">final</span> <span style="color: #941c64">static</span> String <span style="color: #0431c3">PLUGIN_NAME</span> = Test_IJ2.<span style="color: #941c64">class</span>.getSimpleName();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(76, 143, 117); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span><span style="color: #941c64">private</span><span style="color: #000000"> </span><span style="color: #941c64">static</span><span style="color: #000000"> </span><span style="color: #941c64">int</span><span style="color: #000000"> </span><span style="color: #0431c3">FLAGS</span><span style="color: #000000"> = </span>// bitwise or of the following flags:</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(76, 143, 117); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span><span style="color: #0431c3">DOES_8G</span><span style="color: #000000"> | </span><span style="color: #0431c3">KEEP_PREVIEW</span><span style="color: #000000">; </span>// When using preview, the preview image can be kept as a result</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>ImagePlus <span style="color: #0431c3">imp</span>;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(148, 28, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>private<span style="color: #000000"> </span>double<span style="color: #000000"> </span><span style="color: #0431c3">low</span><span style="color: #000000">;</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(148, 28, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>private<span style="color: #000000"> </span>double<span style="color: #000000"> </span><span style="color: #0431c3">high</span><span style="color: #000000">;</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #941c64">public</span> <span style="color: #941c64">int</span> setup(String arg, ImagePlus imp) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #941c64">if</span> (imp == <span style="color: #941c64">null</span>) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(58, 64, 244); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span>IJ.error(</span><span style="color: #0431c3">PLUGIN_NAME</span><span style="color: #000000">, </span>"No image.\nOpen or create an image first then run "</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(4, 49, 195); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span>+ </span>PLUGIN_NAME<span style="color: #000000">);</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(148, 28, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>return<span style="color: #000000"> </span><span style="color: #0431c3">DONE</span><span style="color: #000000">;</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #941c64">this</span>.<span style="color: #0431c3">imp</span> = imp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(148, 28, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>return<span style="color: #000000"> </span><span style="color: #0431c3">FLAGS</span><span style="color: #000000">;</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #941c64">public</span> <span style="color: #941c64">int</span> showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #941c64">assert</span> (imp != <span style="color: #941c64">null</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #941c64">if</span> (imp == <span style="color: #941c64">null</span>)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(148, 28, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>return<span style="color: #000000"> </span><span style="color: #0431c3">DONE</span><span style="color: #000000">;</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>GenericDialog gd = <span style="color: #941c64">new</span> GenericDialog(<span style="color: #0431c3">PLUGIN_NAME</span> + <span style="color: #3a40f4">"..."</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>gd.addMessage(imp.getTitle());</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>gd.addSlider(<span style="color: #3a40f4">"low"</span>, 0, 255, 0);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>gd.addSlider(<span style="color: #3a40f4">"high"</span>, 0, 255, 255);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>gd.addPreviewCheckbox(pfr, <span style="color: #3a40f4">" Preview"</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>gd.addDialogListener(<span style="color: #941c64">this</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(76, 143, 117); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span>gd.showDialog(); </span>// user input (or reading from macro) happens here</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #941c64">if</span> (gd.wasCanceled()) <span style="color: #4c8f75">// dialog </span><span style="text-decoration: underline ; color: #4c8f75">cancelled</span><span style="color: #4c8f75">?</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(148, 28, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>return<span style="color: #000000"> </span><span style="color: #0431c3">DONE</span><span style="color: #000000">;</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #941c64">return</span> IJ.setupDialog(imp, <span style="color: #0431c3">FLAGS</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #941c64">public</span> <span style="color: #941c64">boolean</span> dialogItemChanged(GenericDialog gd, AWTEvent e) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #0431c3">low</span> = gd.getNextNumber();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #0431c3">high</span> = gd.getNextNumber();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>IJ.log(String.format(<span style="color: #3a40f4">"low=%g high=%g\n"</span>, <span style="color: #0431c3">low</span>, <span style="color: #0431c3">high</span>));</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(148, 28, 100); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span>return<span style="color: #000000"> </span>true<span style="color: #000000">;</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #941c64">public</span> <span style="color: #941c64">void</span> run(ImageProcessor ip) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(58, 64, 244); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span>IJ.log(</span>"run called\n"<span style="color: #000000">);</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #0431c3">imp</span>.setDisplayRange(<span style="color: #0431c3">low</span>, <span style="color: #0431c3">high</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span><span style="color: #941c64">public</span> <span style="color: #941c64">void</span> setNPasses(<span style="color: #941c64">int</span> nPasses) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>IJ.log(String.format(<span style="color: #3a40f4">"setNPasses(%d)\n"</span>, nPasses));</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; ">}</div></div><div><br></div></div></div></div></div></body></html>