How to add a preview option to a ImageJ dialog

Hi, I am trying to add a preview option to a imageJ dialog, is there a way to do this in imageJ language? This is what I have so far.

if (thres == 1) {
	Dialog.create("Subtraction");
Dialog.addSlider("how much do you want subtracted?", 0, 100, 0);
Dialog.addCheckbox("preview", 0)
Dialog.show();
numm = Dialog.getNumber();
prev = Dialog.getCheckbox();
run("Subtract...", "value="+numm);
//if (prev == 1) {
// this is the part I need help with
//}

Hi,

a long time I made a IJ macro for something like this. It was designed to let the parameters in a script be changed and for the results to be seen. The script had a checkbox call Preview. When Preview is check and the Ok button pressed the results would be drawn and dialog represented. When Preview as checked the window would close.

I had a function that presented dialog and extracted the settings. The variable preview (and the other script parameters) was globally defined with initial value true.

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function get_user_parameters(){
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    // Display the dialog
    Dialog.create("script name");
    // set the other parameters
    Dialog.addCheckBox("Preview",preview);
    Dialog.show();

    // Get the other parameters
    preview   = Dialog.getCheckbox();
}

In the main function of the script there is a loop that draws the window and redisplays the dialog.

get_user_parameters(" ");  \\ this get preview and the other parameters
while( preview ){
     do_processing();
     draw_results();
     get_user_parameters(" ");
}

I’m sure there’s a better way to do this.

Cheers,

Chris

2 Likes

Hi Chris,

Thank you! I modified this code a bit to better fit my program, but we used your general idea to create this working code!!

prev = 1

while( prev ){
Dialog.create("Subtraction");
	Dialog.addMessage("How much would you like to subtract from your image?")
Dialog.addSlider("how much?", 0, 100, 0);
Dialog.addCheckbox("preview", 1)
Dialog.show();
numm = Dialog.getNumber();
prev = Dialog.getCheckbox();
run("Subtract...", "value="+numm);

Dialog.create("Continue?");
Dialog.addMessage("Is this a good look?");
Dialog.addCheckbox("Yes", 0);
Dialog.addCheckbox("No", 0);
Dialog.show();
if (Dialog.getCheckbox()) {
	prev = 0;
}
if (Dialog.getCheckbox()) {
	run("Add...", "value="+numm);
}
}

Kind regards,
Soleille

1 Like