using GenericDialog and the toolbar at the same time

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

using GenericDialog and the toolbar at the same time

Ignacio Arganda Carreras
Dear all,

I am trying to create a new toolbar when calling to my plugin, which is
based on GenericDialog. I managed to change the buttons and appearance
of the toolbar but as soon as i call the plugin and the dialog is shown,
the toolbar gets disabled. It gets enable again as soon as i press OK or
Cancel but i need it to be enable when the dialog is there... Any idea?

Thanks a lot!

ignacio

--
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
Reply | Threaded
Open this post in threaded view
|

Re: using GenericDialog and the toolbar at the same time

Marcel
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
Reply | Threaded
Open this post in threaded view
|

Re: using GenericDialog and the toolbar at the same time

Ignacio Arganda Carreras
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