With the help of Johannes we finally found a solution: extending
GenericDialog so it is non-modal.
Here you are an example:
---- NonblockingGenericDialog.java ---------
import ij.IJ;
import ij.gui.GenericDialog;
import ij.Macro;
import java.awt.event.ActionEvent;
public class NonblockingGenericDialog extends GenericDialog {
public NonblockingGenericDialog(String title) {
super(title, null);
setModal(false);
}
public synchronized void showDialog()
{
super.showDialog();
if (Macro.getOptions() != null)
return;
try {
wait();
} catch (InterruptedException e) {
IJ.error("Dialog " + getTitle() + " was interrupted.");
}
}
public synchronized void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
if (wasOKed() || wasCanceled())
notify();
}
}
----------- Test_Dialog.java -----------
import ij.IJ;
import ij.plugin.PlugIn;
public class Test_Dialog implements PlugIn {
public void run(String arg) {
NonblockingGenericDialog gd =
new NonblockingGenericDialog("Hello, Ignacio!");
gd.addCheckbox("A toggle", false);
gd.showDialog();
if (gd.wasCanceled()) {
IJ.write("was canceled");
return;
}
boolean toggle = gd.getNextBoolean();
IJ.write("Toggle is " + (toggle ? "" : "not ") + "on!");
}
}
Bio7 wrote:
> Since java 1.6 you can change the modality type of Dialogs.
> GenericDialog is a subclass of java.awt.Dialog
>
> yourGenericDialog.setModalityType(Dialog.ModalityType.MODELESS);
>
>
http://www.java-tips.org/java-se-tips/javax.swing/dialog-modality.html>
> If that doesn't work for you it is better to construct your own Plugin
> Frame.
>
> With kind regards
>
> M.Austenfeld
>
--
Ignacio Arganda-Carreras
Escuela Politécnica Superior
Laboratorio B-408 Phone: (+34) 91 497 2260
Universidad Autónoma de Madrid
Ctra. de Colmenar Viejo, Km. 15
Madrid 28049, Spain
E-mail:
[hidden email]
Website:
http://www.ii.uam.es/~iarganda