Login  Register

Re: Macros: change Dialog checkbox state without clicking it?

Posted by ctrueden on Sep 14, 2017; 7:59pm
URL: http://imagej.273.s1.nabble.com/Macros-change-Dialog-checkbox-state-without-clicking-it-tp5019373p5019374.html

Hi Bill,

The SciJava framework of ImageJ2 offers that feature, via parameter
callbacks. In Java, if you declare parameters such as:

@Parameter(label = "x", callback = "xChanged")
private float x;

@Parameter(label = "2x", callback = "twoXChanged")
private float twoX;

And then write the methods:

/** Executed whenever the {@link #x} parameter changes. */
private void xChanged() {
twoX = x * 2;
}

/** Executed whenever the {@link #twoX} parameter changes. */
private void twoXChanged() {
x = twoX / 2;
}

Then whenever the x or 2x field is changed, the callback code is executed
adjusting the other value accordingly, and the dialog box will refresh
automatically.

This code and more can be seen in the WidgetDemo example [1].

Unfortunately, the callback attribute of parameters is not yet implemented
for script languages [2]. There is an open issue for it [3]. The good news
is: upon reading your question and thinking about this issue some more, I
have an idea for how to implement it [4].

Regards,
Curtis

[1]
https://github.com/imagej/tutorials/blob/9880387c96d6b6399c016f755707878f33812fc1/maven-projects/widget-demo/src/main/java/WidgetDemo.java
[2] https://imagej.net/Script_Parameters
[3] https://github.com/scijava/scijava-common/issues/200
[4]
https://github.com/scijava/scijava-common/issues/200#issuecomment-329591887

--
Curtis Rueden
LOCI software architect - https://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden
Did you know ImageJ has a forum? http://forum.imagej.net/


On Thu, Sep 14, 2017 at 1:59 PM, Bill Christens-Barry <[hidden email]>
wrote:

> In a macro, I would like to create a Dialog in which changing the checked
> states of some "control" checkboxes would change the state of other
> "dependent" checkboxes. I envision that whenever a control checkbox is
> checked or unchecked, some logic would decide which of the dependent
> checkboxes should have their state changed and those changes would
> immediately be made. The Dialog would remain active for further interaction.
>
> In order to programmatically alter the state of checkboxes, I suppose
> there would need to be a way to refer to previously created checkboxes (~
> Dialog.getState(checkbox)) and a command for changing them (~
> Dialog.setState(checkbox, state)). I haven't found any way to do either in
> the macro language.
>
> Is what I describe currently possible using the ImageJ macro language or
> other scripting language?
>
> Thanks.
>
> Bill Christens-Barry
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html