Login  Register

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

Posted by Wayne Rasband-2 on Sep 15, 2017; 12:30am
URL: http://imagej.273.s1.nabble.com/Macros-change-Dialog-checkbox-state-without-clicking-it-tp5019373p5019375.html

> On Sep 14, 2017, at 2: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?

You can do this in JavaScript by using a DialogListener. Here is an example:
   
    listener = new DialogListener() {
        dialogItemChanged : function(gd, event) {
            state = gd.getNextBoolean();
            checkbox2.setState(state);
            return true;
        }
    };
    gd = new GenericDialog("DialogListener Demo");
    gd.addCheckbox("Checkbox 1", false);
    gd.addCheckbox("Checkbox 2", false);
    checkbox2 = gd.getCheckboxes().get(1);
    gd.addDialogListener(listener);
    gd.showDialog();

-wayne

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