Dialog Box with several buttons

Hi everyone,

Is it possible to create a Dialog box with several specifics buttons?

I would like to create a dialog box in which I propose to enter a threshold value. With a “Update” button, the user would see the result in a other windows (without out closing the dialogbox). If he is not satisfied by the result, he would have just to change the value, click on “Update” again to check if the result is good. And if it is good, we would click on “OK” button to select the threshold value and do the threshold for real.

Thanks for your answer

Fabien

Just find the beginning of a solution here:
http://imagej.1557.x6.nabble.com/Additional-button-in-display-function-td3684417.html

I have to understand now how it works. Any help would be appreciated.

Thanks

Dear @Fabien,

Could you elaborate a bit more how complex your UI will be in the end?

I would suggest to use Script Parameters with callback functions. You can take a look at the JavaDoc for the @Parameter annotation as well as the sources to get more information.

I have a not-at-all polished ImageJ plugin on GitHub that is Interactive (so that the dialog doesn’t block the UI) and updates whenever a @Parameter is changed:

Best,
Stefan

1 Like

Hi Stefan,

Thanks for your answer. And sorry for the delay.

Finally, as it was quite difficult for me, I finally use a easier way (for me), with a succession of Dialog windows in which :

  1. I proposed to select the threshold value with a slider (first windows)
  2. show the result thanks to ROI manager
  3. I proposed to confirm the value with a second dialog windows with a yes or no check box. If no, the macro go back to step 1. If yes, the macro continues.

Regards

Fabien

1 Like

Hi @Fabien
I’m quite new for the ImageJ Macro system. I’m really interested on how you coded your dialog box system.
Is it possible to send the part of code you did for this?

  1. I proposed to select the threshold value with a slider (first windows)
  2. show the result thanks to ROI manager
  3. I proposed to confirm the value with a second dialog windows with a yes or no check box. If no, the macro go back to step 1. If yes, the macro continues.

Thanks you very much!

Nils

Hi Nils

You can find below, a part of my code. Some comment and functions name are in French as it is my native language. I add some quick english comment to help you

Hope it will be enough clear to help you,

Regards

Fabien

[...]
tester_autres_threshold_checkbox_value=true;
conserver_threshold_max_checkbox_value=false;
conserver_threshold_min_checkbox_value=false;
[...]
while (tester_autres_threshold_checkbox_value==true){ //check //if the user ask to test other threshold value or not (boolean value), cf function dialog_conserver_threshold_min
		while (conserver_threshold_max_checkbox_value==false){ // in my case, I check all threshold value, between a min threshold value to a max threshold value
			dialog_box_choix_threshold_maximale(threshold_max);
			generation_interface(threshold_max); // function to prepare the result (not display here)
			fermeture_images(); //function to close all image (not display here)
			preparation_interface(); // function to produce the result on the image (not display here)
			waitForUser("Merci de verifier si l'interface vous convient, avant de cliquer sur OK puis de repondre a la prochaine fenetre. \nCliquer sur la fenetre de la photo pour activer cette fenetre puis utiliser Ctrl+Maj+E pour afficher l'interface en jaune.\nCtrl+Maj+A permet de la deselectionner."); // windows to explain to the user if the result is OK for him. If yes he will check Yes in the next window. If not, he wil select No.
			dialog_conserver_threshold_max(threshold_max);
		}
		run("Select None");
		while (conserver_threshold_min_checkbox_value==false){
			dialog_box_choix_threshold_minimale(threshold_min);
			generation_interface(threshold_min);
			fermeture_images();
			preparation_interface();
			waitForUser("Merci de verifier si l'interface vous convient, avant de cliquer sur OK puis de repondre a la prochaine fenetre. \nCliquer sur la fenetre de la photo pour activer cette fenetre puis utiliser Ctrl+Maj+E pour afficher l'interface en jaune.\nCtrl+Maj+A permet de la deselectionner.");
			dialog_conserver_threshold_min(threshold_min);
			run("Select None");
		}
	}

[...]

function dialog_box_choix_threshold_maximale(value){ // dialog box with slider for max value.
	label="Merci de selectionner la valeur de threshold maximale a tester.\nPlus la valeur rentree est grande, plus l'interface sera vers le bas de l'image.";
	Dialog.create("Threshold maximal");
	Dialog.addMessage(label);
	Dialog.addSlider("Saturation :",0,100,value);
	Dialog.show();
	threshold_max = Dialog.getNumber(); //keep the value selected by the user in a variable.
}

function dialog_box_choix_threshold_minimale(value){ // dialog box with slider for min value.
	label="Merci de selectionner la valeur de threshold minimale a tester.\nPlus la valeur rentree est petite, plus l'interface sera vers le haut de l'image.\nToutes les interfaces entre les deux threshold seront tracees par pas de 1%.";
	Dialog.create("Threshold minimal");
	Dialog.addMessage(label);
	Dialog.addSlider("Saturation :",0,100,value);
	Dialog.show();
	threshold_min = Dialog.getNumber();
}

function dialog_conserver_threshold_max(threshold) { // windows to confirm if the maximum value is OK
	//setBatchMode(false);
	label="Merci de confirmer si vous voulez conserver cette interface (max) dans \nle ROI manager afin de comparer plusieurs interfaces entre elles";
	Dialog.create("Interface a conserver?");
	Dialog.addMessage(label);
	Dialog.addCheckbox("Oui?",false);
	Dialog.show();
	conserver_threshold_max_checkbox_value = Dialog.getCheckbox(); // depending on this boolean value, the second while loop will be canceled or not.
	if (conserver_threshold_max_checkbox_value==false){
		run("Select None");
		selectImage(interface_interm_ID); 	//à commenter?
		close();							//à commenter?
	} else {
		selectImage(AOI_ID);
		run("Restore Selection");
		run("Add to Manager");
		nb_roi=roiManager("count");
		roiManager("select",nb_roi-1);
		roiManager("Rename", threshold+"% (Max)");
	}
	//setBatchMode(true);
}

function dialog_conserver_threshold_min(threshold) { // dialog box to ask if the min threshold value is OK
	//setBatchMode(false);
	label="Merci de confirmer si vous voulez conserver cette interface (min) dans \nle ROI manager afin de comparer plusieurs interfaces entre elles";
	Dialog.create("Interface a conserver?");
	Dialog.addMessage(label);
	Dialog.addCheckbox("Oui?",false);
	Dialog.show();
	conserver_threshold_min_checkbox_value = Dialog.getCheckbox();
	if (conserver_threshold_min_checkbox_value==false){ // the user doesn't wnat to keep this min value, so the selection is canceled.
		run("Select None");
		selectImage(interface_interm_ID);	//à commenter?
		close();							//à commenter?
	} else { 
		selectImage(AOI_ID);
		run("Restore Selection");
		run("Add to Manager");
		nb_roi=roiManager("count");
		roiManager("select",nb_roi-1);
		roiManager("Rename", threshold+"% (Min)");
		tester_autres_threshold_checkbox_value=false; // modification of the boolean value to stop the while loop.
	}
	//setBatchMode(true);
}

function tester_autres_threshold(){ // windows to confirm if the user want to test other threshold values.
	label="Merci d'indiquer si vous souhaitez tester d'autres threshold";
	Dialog.create("Tester d'autres threshold?");
	Dialog.addMessage(label);
	Dialog.addCheckbox("Oui?",true);
	Dialog.show();
	tester_autres_threshold_checkbox_value = Dialog.getCheckbox(); // modification of the boolean value to stop the while loop.
	run("Select None");
}