Posted by
Fred Damen on
URL: http://imagej.273.s1.nabble.com/Programatic-Java-zooming-issue-s-tp5024578p5024594.html
Greetings,
Thanks to the Zoom plugin suggestion and some free time to dig, it seems I
may be on to something, or may be just a WAG...
It seems as though the Java GUI proper classes do no fully initialize
their internals until the widget has reached a certain point in its being
brought to life, i.e., activated?. (I base this on a newly created but
not yet displayed Dialog not knowing its default Font...) The ImagePlus
show method waits upwards of 2 seconds, if a macro is running, for the
ImageWindow's windowActivated callback to be called. I suspect that this
is due to the ImageCanvas's internals may not be completely valid until
setActivated is called... nb, Java plugin(s) get no time buffer. The load
on my computer partially results from my inability to work on one thing at
a time, thus I have many many browser, etc windows open, resulting in a
noticeable delay in GUI interactions in general. Thus a more than 2 second
delay in a window opening would not be surprising. Whenever the
ImageWindow finally opens, it seems that ImagePlus will properly set its
activated variable to true, but alas this fact is not revealed outside of
ImagePlus and impeads my testing this hypothesis. Therefore when Zoom
queries the canvas size, etc, in an pre-activated window the eventual
results of the zoom are ...
If there is any validity to my guess, might I suggest:
a) Expose the activated state, i.e., isActivated ImagePlus method.
b) Zoom deals with a possibly not yet valid ImageCanavas.
c) ImagePlus show method with a magnification parameter
d) The notifyListeners(OPENED) call in ImagePlus show method moved to the
setActivated method.
Enjoy,
Fred
On Thu, April 1, 2021 2:53 am, Herbie wrote:
> Dear Fred,
>
> since long I successfully use
>
> if ( imp.getRoi() != null )
> new Zoom().run( "to" );
>
> and have never ever encountered any of the described effects.
>
> Regards
>
> Herbie
>
> ::::::::::::::::::::::::::::::::::::::::
> Am 01.04.21 um 0:09 schrieb Fred Damen:
>> Greetings,
>>
>> Resizing image windows thru the GUI seems to always work as expected.
>> Resizing the windows from within a Java plugin seem to work undesirably
>> about 40% of the time. The undesirable effects tend to be consistent,
>> e.g., the second,third, and fifth windows exhibit the same effect each
>> time the plugin is run. I suspect that the issue is some sort of a race
>> condition between ImageJ and Java/System GUI proper, as the symptoms
>> vary
>> somewhat with load and computer.
>>
>> The symptoms include:
>> Window has slightly wrong size and image appears to be the correct
>> magnification.
>> Window has correct size and the image is original size.
>>
>> Both these statements produce these results:
>> IJ.run("In [+]", "");
>> IJ.run("Set... ", "zoom=200");
>>
>> I have found that after show(ing) all the windows if I ...
>> Dimension ws = imps[0].getWindow().getSize();
>> for(ImagePlus imp : imps)
>> imp.getWindow().setSize(ws.width,ws.height);
>> for(ImagePlus imp : imps)
>> imp.getWindow().getCanvas().fitToWindow();
>> This seems to adjust the window and image sizes appropriately most of
>> the
>> time.
>>
>> Is there a recommended way to zoom a window programmatically that works
>> consistently and correctly like it does from Image>Zoom>... ?
>>
>> Thanks in advance,
>>
>> Fred
>>
>> --
>> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>>
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html