Listener for GenericDialog

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

Listener for GenericDialog

G. Esteban Fernandez
Hi everyone,

I started writing a plugin where I envision a GenericDialog with a slider
bar to control the size of an ROI, but I want the size to change in
real-time, not only after clicking 'OK'.  How can I implement a listener so
that the ROI changes size near-simultaneously as I move the GD slider?  I
tried gd.addDialogListener(this) but that caused the dialog to go way (on
ubuntu 12.04 LTS 64-bit).  Can someone point me to a code example please?
Maybe a GenericDialog is not the way to go?

Thanks,
Esteban

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Listener for GenericDialog

Walter O'Dell PhD
hello Esteban,

so GenericDialog is not really designed for real time, repeated interactions with the user.  I few years ago I made a GenericRecallableDialog class that I included as part of the template matching plug-in package to achieve this type of continuous interaction, but note that the GenericRecallableDialog class is itself not a normal plug in.  

I have since elaborated on the GenericRecallableDialog class.  I'm attaching here what I currently have.

(update, I guess I cannot attach .java files to emails sent to this list server, so I'll plan to send it to you directly.  And one to Wayne in case it may be useful to others).

This class provides sliders, buttons, checkboxes, choices -- pretty much everything that is available to be used with Java.  It also provides means to arrange them nicely on the screen.  

Unfortunately, I doubt that this will work for you nicely right out of the box.  I actually recompile all of imageJ from the source .java files rather than work solely through the plug-ins feature, so I have not tested how this version will work directly as a plug-in add-on.  It is possible to run the GenericRecallableDialog class through the plugins feature and plugins folder -- if you download the template matching plugin you will see how it installs that older version of the GenericRecallableDialog class into the plugins folder and that the template matching plugin is able to use it.

The bottom line is that continuous user interaction is possible with ImageJ, and this GenericRecallableDialog class achieves it nicely, but you may need a little effort to get it working on your end.

-Walter

On Apr 23, 2013, at 10:09 AM, G. Esteban Fernandez wrote:

> Hi everyone,
>
> I started writing a plugin where I envision a GenericDialog with a slider
> bar to control the size of an ROI, but I want the size to change in
> real-time, not only after clicking 'OK'.  How can I implement a listener so
> that the ROI changes size near-simultaneously as I move the GD slider?  I
> tried gd.addDialogListener(this) but that caused the dialog to go way (on
> ubuntu 12.04 LTS 64-bit).  Can someone point me to a code example please?
> Maybe a GenericDialog is not the way to go?
>
> Thanks,
> Esteban
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

Walter O'Dell, PhD
Assistant Professor
Dept. Radiation Oncology
McKnight Brain Inst. Rm LG-177
PO Box 100385
Shands Cancer Center, University of Florida
Gainesville, FL 32610
[hidden email]
352-273-9030
http://odell.radonc.med.ufl.edu
___________




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

4659_image001(02-20-19-05-36).png (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Listener for GenericDialog

G. Esteban Fernandez
In reply to this post by G. Esteban Fernandez
Turns out that my GenericDialog window is not going away when I add the
DialogListener, and the listener is working.  The dialog is, however,
reduced to a tiny window in the upper-left corner of the screen, even when
I use gd.centerDialog(true).  Any ideas how I can reset the GenericDialog
size/position in a different way or prevent the erroneous positioning in
the first place?

Thanks,
Esteban


On Tue, Apr 23, 2013 at 7:09 AM, G. Esteban Fernandez <
[hidden email]> wrote:

> Hi everyone,
>
> I started writing a plugin where I envision a GenericDialog with a slider
> bar to control the size of an ROI, but I want the size to change in
> real-time, not only after clicking 'OK'.  How can I implement a listener so
> that the ROI changes size near-simultaneously as I move the GD slider?  I
> tried gd.addDialogListener(this) but that caused the dialog to go way (on
> ubuntu 12.04 LTS 64-bit).  Can someone point me to a code example please?
> Maybe a GenericDialog is not the way to go?
>
> Thanks,
> Esteban
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Listener for GenericDialog

Jan Eglinger
In reply to this post by Walter O'Dell PhD
Dear Walter,

(for some reason my email client did not display any text in your
previous mail, it only showed an unrelated - and unnecessary - png file.
Since I assume it might be an issue with your Apple Mail, and others
might also have missed your words, I pasted the contents of your mail
from the message source below. Maybe you find the time to investigate
and fix the issue on your mailer's side...)

> I have since elaborated on the GenericRecallableDialog class.  I'm
> attaching here what I currently have.
> (update, I guess I cannot attach .java files to emails sent to this
> list server, so I'll plan to send it to you directly.  And one to
> Wayne in case it may be useful to others).

I would be great if you posted your java code in another way then, e.g.
  - as .txt file attached to your email
  - on http://pastebin.com/
  - on http://github.com/ with the advantage that others can directly
contribute.
In any case, I would love to learn from your work and am very interested
in looking at your GenericRecallableDialog code.

Cheers,
Jan


On 23.04.2013 4:48 PM, Walter O'Dell wrote:

so GenericDialog is not really designed for real time, repeated =
interactions with the user.  I few years ago I made a =
GenericRecallableDialog class that I included as part of the template =
matching plug-in package to achieve this type of continuous interaction, =
but note that the GenericRecallableDialog class is itself not a normal =
plug in. =20

I have since elaborated on the GenericRecallableDialog class.  I'm =
attaching here what I currently have.=20

(update, I guess I cannot attach .java files to emails sent to this list =
server, so I'll plan to send it to you directly.  And one to Wayne in =
case it may be useful to others).

This class provides sliders, buttons, checkboxes, choices -- pretty much =
everything that is available to be used with Java.  It also provides =
means to arrange them nicely on the screen. =20

Unfortunately, I doubt that this will work for you nicely right out of =
the box.  I actually recompile all of imageJ from the source .java files =
rather than work solely through the plug-ins feature, so I have not =
tested how this version will work directly as a plug-in add-on.  It is =
possible to run the GenericRecallableDialog class through the plugins =
feature and plugins folder -- if you download the template matching =
plugin you will see how it installs that older version of the =
GenericRecallableDialog class into the plugins folder and that the =
template matching plugin is able to use it.=20

The bottom line is that continuous user interaction is possible with =
ImageJ, and this GenericRecallableDialog class achieves it nicely, but =
you may need a little effort to get it working on your end.

-Walter

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Listener for GenericDialog

Yuekan Jiao-2
Hi

Another way that works is to extend GenericDialog and write the
textValueChanged as following:

public void textValueChanged(TextEvent e) {
      Scrollbar slider0 =(Scrollbar)(slider.elementAt(0));
      int slider0Value = slider0.getValue();
}

Cheers

Yuekan Jiao



On Tue, Apr 23, 2013 at 9:38 AM, Jan Eglinger <[hidden email]>wrote:

> Dear Walter,
>
> (for some reason my email client did not display any text in your
> previous mail, it only showed an unrelated - and unnecessary - png file.
> Since I assume it might be an issue with your Apple Mail, and others
> might also have missed your words, I pasted the contents of your mail
> from the message source below. Maybe you find the time to investigate
> and fix the issue on your mailer's side...)
>
> > I have since elaborated on the GenericRecallableDialog class.  I'm
> > attaching here what I currently have.
> > (update, I guess I cannot attach .java files to emails sent to this
> > list server, so I'll plan to send it to you directly.  And one to
> > Wayne in case it may be useful to others).
>
> I would be great if you posted your java code in another way then, e.g.
>   - as .txt file attached to your email
>   - on http://pastebin.com/
>   - on http://github.com/ with the advantage that others can directly
> contribute.
> In any case, I would love to learn from your work and am very interested
> in looking at your GenericRecallableDialog code.
>
> Cheers,
> Jan
>
>
> On 23.04.2013 4:48 PM, Walter O'Dell wrote:
>
> so GenericDialog is not really designed for real time, repeated =
> interactions with the user.  I few years ago I made a =
> GenericRecallableDialog class that I included as part of the template =
> matching plug-in package to achieve this type of continuous interaction, =
> but note that the GenericRecallableDialog class is itself not a normal =
> plug in. =20
>
> I have since elaborated on the GenericRecallableDialog class.  I'm =
> attaching here what I currently have.=20
>
> (update, I guess I cannot attach .java files to emails sent to this list =
> server, so I'll plan to send it to you directly.  And one to Wayne in =
> case it may be useful to others).
>
> This class provides sliders, buttons, checkboxes, choices -- pretty much =
> everything that is available to be used with Java.  It also provides =
> means to arrange them nicely on the screen. =20
>
> Unfortunately, I doubt that this will work for you nicely right out of =
> the box.  I actually recompile all of imageJ from the source .java files =
> rather than work solely through the plug-ins feature, so I have not =
> tested how this version will work directly as a plug-in add-on.  It is =
> possible to run the GenericRecallableDialog class through the plugins =
> feature and plugins folder -- if you download the template matching =
> plugin you will see how it installs that older version of the =
> GenericRecallableDialog class into the plugins folder and that the =
> template matching plugin is able to use it.=20
>
> The bottom line is that continuous user interaction is possible with =
> ImageJ, and this GenericRecallableDialog class achieves it nicely, but =
> you may need a little effort to get it working on your end.
>
> -Walter
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Listener for GenericDialog

Walter O'Dell PhD
In reply to this post by Jan Eglinger
hey Jan,

> might also have missed your words, I pasted the contents of your mail
> from the message source below.
thanks much

> I would be great if you posted your java code in another way then, e.g.
>  - as .txt file attached to your email
oh, perhaps that is a clever work-around.  I'll try that here by just adding .txt to the end of the .java file:


>  - on http://pastebin.com/
>  - on http://github.com/ with the advantage that others can directly
> contribute.
I'm not familiar with those. Does the ImageJ users group have a group account with either?

> (for some reason my email client did not display any text in your
> previous mail, it only showed an unrelated - and unnecessary - png file.
clearly you are an SEC or ACC rival to UF.

> Since I assume it might be an issue with your Apple Mail, and others
> Maybe you find the time to investigate
> and fix the issue on your mailer's side...)
the png is part of my email signature that is common for my university.  I removed the png from the signature on this email to eliminate that problem.
But I doubt that it is a problem on my end, but rather is some 'feature' of the list-server for ImageJ, probably along the lines of removing any images
for fear of transferring an email virus or such -- like the way it prevents one from including java files.

> In any case, I would love to learn from your work and am very interested
> in looking at your GenericRecallableDialog code.
>
> Cheers,
> Jan
thanks for the help,

Walter

>
> On 23.04.2013 4:48 PM, Walter O'Dell wrote:
>
> so GenericDialog is not really designed for real time, repeated =
> interactions with the user.  I few years ago I made a =
> GenericRecallableDialog class that I included as part of the template =
> matching plug-in package to achieve this type of continuous interaction, =
> but note that the GenericRecallableDialog class is itself not a normal =
> plug in. =20
>
> I have since elaborated on the GenericRecallableDialog class.  I'm =
> attaching here what I currently have.=20
>
> (update, I guess I cannot attach .java files to emails sent to this list =
> server, so I'll plan to send it to you directly.  And one to Wayne in =
> case it may be useful to others).
>
> This class provides sliders, buttons, checkboxes, choices -- pretty much =
> everything that is available to be used with Java.  It also provides =
> means to arrange them nicely on the screen. =20
>
> Unfortunately, I doubt that this will work for you nicely right out of =
> the box.  I actually recompile all of imageJ from the source .java files =
> rather than work solely through the plug-ins feature, so I have not =
> tested how this version will work directly as a plug-in add-on.  It is =
> possible to run the GenericRecallableDialog class through the plugins =
> feature and plugins folder -- if you download the template matching =
> plugin you will see how it installs that older version of the =
> GenericRecallableDialog class into the plugins folder and that the =
> template matching plugin is able to use it.=20
>
> The bottom line is that continuous user interaction is possible with =
> ImageJ, and this GenericRecallableDialog class achieves it nicely, but =
> you may need a little effort to get it working on your end.
>
> -Walter
>
>
>
>

Walter O'Dell, PhD
Assistant Professor
Dept. Radiation Oncology
McKnight Brain Inst. Rm LG-177
PO Box 100385
Shands Cancer Center, University of Florida
Gainesville, FL 32610
[hidden email]
352-273-9030
http://odell.radonc.med.ufl.edu




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

GenericRecallableDialog.java.txt (49K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Listener for GenericDialog

Michael Schmid
In reply to this post by G. Esteban Fernandez
Hi Esteban,

have a look at ij.plugin.SpecifyRoi.

You can use the same code, just replace the 'gd.addNumericField' with 'gd.addSlider'.

GenericDialogs with DialogListeners are definitely meant to work for preview, that's what the DialogListener interface was added for.

If your linux flavor + Java virtual machine has a problem with displaying sliders, you should see it also in other plugins that use sliders and preview such as the Options dialog of the Versatile Wand for a color image (with preview checked).

http://imagejdocu.tudor.lu/doku.php?id=plugin:segmentation:versatile_wand:start

Michael
________________________________________________________________
On Apr 23, 2013, at 16:09, G. Esteban Fernandez wrote:

> Hi everyone,
>
> I started writing a plugin where I envision a GenericDialog with a slider
> bar to control the size of an ROI, but I want the size to change in
> real-time, not only after clicking 'OK'.  How can I implement a listener so
> that the ROI changes size near-simultaneously as I move the GD slider?  I
> tried gd.addDialogListener(this) but that caused the dialog to go way (on
> ubuntu 12.04 LTS 64-bit).  Can someone point me to a code example please?
> Maybe a GenericDialog is not the way to go?
>
> Thanks,
> Esteban
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Fwd: Listener for GenericDialog

Walter O'Dell PhD
In reply to this post by Walter O'Dell PhD
another email that was received with no text but the attachment.  too funny.  so here is my last email but without the java.txt attachment so that the rest of the text appears.

Begin forwarded message:

> From: Walter O'Dell <[hidden email]>
> Date: April 23, 2013 12:51:14 PM EDT
> To: ImageJ Interest Group <[hidden email]>
> Subject: Re: Listener for GenericDialog
>
> hey Jan,
>
>> might also have missed your words, I pasted the contents of your mail
>> from the message source below.
> thanks much
>
>> I would be great if you posted your java code in another way then, e.g.
>>  - as .txt file attached to your email
> oh, perhaps that is a clever work-around.  I'll try that here by just adding .txt to the end of the .java file:
>
>
>>  - on http://pastebin.com/
>>  - on http://github.com/ with the advantage that others can directly
>> contribute.
> I'm not familiar with those. Does the ImageJ users group have a group account with either?
>
>> (for some reason my email client did not display any text in your
>> previous mail, it only showed an unrelated - and unnecessary - png file.
> clearly you are an SEC or ACC rival to UF.
>
>> Since I assume it might be an issue with your Apple Mail, and others
>> Maybe you find the time to investigate
>> and fix the issue on your mailer's side...)
> the png is part of my email signature that is common for my university.  I removed the png from the signature on this email to eliminate that problem.
> But I doubt that it is a problem on my end, but rather is some 'feature' of the list-server for ImageJ, probably along the lines of removing any images
> for fear of transferring an email virus or such -- like the way it prevents one from including java files.
>
>> In any case, I would love to learn from your work and am very interested
>> in looking at your GenericRecallableDialog code.
>>
>> Cheers,
>> Jan
> thanks for the help,
>
> Walter
>
>>
>> On 23.04.2013 4:48 PM, Walter O'Dell wrote:
>>
>> so GenericDialog is not really designed for real time, repeated =
>> interactions with the user.  I few years ago I made a =
>> GenericRecallableDialog class that I included as part of the template =
>> matching plug-in package to achieve this type of continuous interaction, =
>> but note that the GenericRecallableDialog class is itself not a normal =
>> plug in. =20
>>
>> I have since elaborated on the GenericRecallableDialog class.  I'm =
>> attaching here what I currently have.=20
>>
>> (update, I guess I cannot attach .java files to emails sent to this list =
>> server, so I'll plan to send it to you directly.  And one to Wayne in =
>> case it may be useful to others).
>>
>> This class provides sliders, buttons, checkboxes, choices -- pretty much =
>> everything that is available to be used with Java.  It also provides =
>> means to arrange them nicely on the screen. =20
>>
>> Unfortunately, I doubt that this will work for you nicely right out of =
>> the box.  I actually recompile all of imageJ from the source .java files =
>> rather than work solely through the plug-ins feature, so I have not =
>> tested how this version will work directly as a plug-in add-on.  It is =
>> possible to run the GenericRecallableDialog class through the plugins =
>> feature and plugins folder -- if you download the template matching =
>> plugin you will see how it installs that older version of the =
>> GenericRecallableDialog class into the plugins folder and that the =
>> template matching plugin is able to use it.=20
>>
>> The bottom line is that continuous user interaction is possible with =
>> ImageJ, and this GenericRecallableDialog class achieves it nicely, but =
>> you may need a little effort to get it working on your end.
>>
>> -Walter
>>
>
>

Walter O'Dell, PhD
Assistant Professor
Dept. Radiation Oncology
McKnight Brain Inst. Rm LG-177
PO Box 100385
Shands Cancer Center, University of Florida
Gainesville, FL 32610
[hidden email]
352-273-9030
http://odell.radonc.med.ufl.edu



--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Listener for GenericDialog

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by G. Esteban Fernandez
On Apr 23, 2013, at 10:09 AM, G. Esteban Fernandez wrote:

> Hi everyone,
>
> I started writing a plugin where I envision a GenericDialog with a slider
> bar to control the size of an ROI, but I want the size to change in
> real-time, not only after clicking 'OK'.  How can I implement a listener so
> that the ROI changes size near-simultaneously as I move the GD slider?  I
> tried gd.addDialogListener(this) but that caused the dialog to go way (on
> ubuntu 12.04 LTS 64-bit).  Can someone point me to a code example please?
> Maybe a GenericDialog is not the way to go?

You can do this with a GenericDialog. Here is an example plugin that displays a dialog with sliders that allow you to control, in real-time, the size and location of an ROI. It is based on the internal plugin than implements the Edit>Selection>Specify command.

-wayne


import ij.plugin.PlugIn;
import java.awt.*;
import java.util.Vector;
import ij.*;
import ij.gui.*;

public class Specify_ROI implements PlugIn, DialogListener {
    private double xRoi, yRoi, width, height;
    private boolean  oval;
    private boolean  centered;
    private Rectangle prevRoi;
    private boolean bAbort;
    private ImagePlus imp;

    public void run(String arg) {
        imp = IJ.getImage();
        Roi roi = imp.getRoi();
        if (roi!=null && roi.getBounds().equals(prevRoi))
            roi = null;
        if (roi!=null) {
            boolean rectOrOval = roi!=null
                && (roi.getType()==Roi.RECTANGLE||roi.getType()==Roi.OVAL);
            oval = rectOrOval && (roi.getType()==Roi.OVAL);
            Rectangle r = roi.getBounds();
            width = r.width;
            height = r.height;
            xRoi = r.x;
            yRoi = r.y;
        } else if (!validDialogValues()) {
            width = imp.getWidth()/2;
            height = imp.getHeight()/2;
            xRoi = width/2;
            yRoi = height/2;
        }
        if (centered) {
            xRoi += width/2.0;
            yRoi += height/2.0;
        }
        showDialog();
    }
   
    boolean validDialogValues() {
        if (width<1.5 || height<1.5)
            return false;
        if (xRoi>=imp.getWidth() || yRoi>=imp.getHeight())
            return false;
        return true;
    }

    void showDialog() {
        Roi roi = imp.getRoi();
        if (roi==null)
            drawRoi();
        int w = imp.getWidth();
        int h = imp.getHeight();
        GenericDialog gd = new GenericDialog("Specify ROI");
        gd.addSlider("X:", 0, w, xRoi);
        gd.addSlider("Y:", 0, h, yRoi);
        gd.addSlider("Width:", 0, w, width);
        gd.addSlider("Height:", 0, h, height);
        gd.addCheckbox("Oval", oval);
        gd.addCheckbox("Centered",centered);
        gd.addDialogListener(this);
        gd.showDialog();
        if (gd.wasCanceled()) {
             if (roi==null)
                imp.deleteRoi();
             else // restore initial ROI when cancelled
                imp.setRoi(roi);
        }
    }
   
    void drawRoi() {
        int iX = (int)xRoi;
        int iY = (int)yRoi;
        if (centered) {
            iX = (int)(xRoi - (width/2));
            iY = (int)(yRoi - (height/2));
        }
        int iWidth = (int)width;
        int iHeight = (int)height;
        Roi roi;
        if (oval)
            roi = new OvalRoi(iX, iY, iWidth, iHeight, imp);
        else
            roi = new Roi(iX, iY, iWidth, iHeight);
        imp.setRoi(roi);
        prevRoi = roi.getBounds();
    }
       
    public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
        xRoi = gd.getNextNumber();  
        yRoi = gd.getNextNumber();
        width = gd.getNextNumber();
        height = gd.getNextNumber();
        oval = gd.getNextBoolean();
        centered = gd.getNextBoolean();
        if (gd.invalidNumber())
            return false;
        else {
            drawRoi();
            return true;
        }
    }

}

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Listener for GenericDialog

G. Esteban Fernandez
Turns out I was using gd.show() instead of gd.showDialog() and that was
causing my errors in position/size of the GenericDialog.  Everything works
now; thanks everyone for your help.

-Esteban


On Tue, Apr 23, 2013 at 3:16 PM, Rasband, Wayne (NIH/NIMH) [E] <
[hidden email]> wrote:

> On Apr 23, 2013, at 10:09 AM, G. Esteban Fernandez wrote:
>
> > Hi everyone,
> >
> > I started writing a plugin where I envision a GenericDialog with a slider
> > bar to control the size of an ROI, but I want the size to change in
> > real-time, not only after clicking 'OK'.  How can I implement a listener
> so
> > that the ROI changes size near-simultaneously as I move the GD slider?  I
> > tried gd.addDialogListener(this) but that caused the dialog to go way (on
> > ubuntu 12.04 LTS 64-bit).  Can someone point me to a code example please?
> > Maybe a GenericDialog is not the way to go?
>
> You can do this with a GenericDialog. Here is an example plugin that
> displays a dialog with sliders that allow you to control, in real-time, the
> size and location of an ROI. It is based on the internal plugin than
> implements the Edit>Selection>Specify command.
>
> -wayne
>
>
> import ij.plugin.PlugIn;
> import java.awt.*;
> import java.util.Vector;
> import ij.*;
> import ij.gui.*;
>
> public class Specify_ROI implements PlugIn, DialogListener {
>     private double xRoi, yRoi, width, height;
>     private boolean  oval;
>     private boolean  centered;
>     private Rectangle prevRoi;
>     private boolean bAbort;
>     private ImagePlus imp;
>
>     public void run(String arg) {
>         imp = IJ.getImage();
>         Roi roi = imp.getRoi();
>         if (roi!=null && roi.getBounds().equals(prevRoi))
>             roi = null;
>         if (roi!=null) {
>             boolean rectOrOval = roi!=null
>                 && (roi.getType()==Roi.RECTANGLE||roi.getType()==Roi.OVAL);
>             oval = rectOrOval && (roi.getType()==Roi.OVAL);
>             Rectangle r = roi.getBounds();
>             width = r.width;
>             height = r.height;
>             xRoi = r.x;
>             yRoi = r.y;
>         } else if (!validDialogValues()) {
>             width = imp.getWidth()/2;
>             height = imp.getHeight()/2;
>             xRoi = width/2;
>             yRoi = height/2;
>         }
>         if (centered) {
>             xRoi += width/2.0;
>             yRoi += height/2.0;
>         }
>         showDialog();
>     }
>
>     boolean validDialogValues() {
>         if (width<1.5 || height<1.5)
>             return false;
>         if (xRoi>=imp.getWidth() || yRoi>=imp.getHeight())
>             return false;
>         return true;
>     }
>
>     void showDialog() {
>         Roi roi = imp.getRoi();
>         if (roi==null)
>             drawRoi();
>         int w = imp.getWidth();
>         int h = imp.getHeight();
>         GenericDialog gd = new GenericDialog("Specify ROI");
>         gd.addSlider("X:", 0, w, xRoi);
>         gd.addSlider("Y:", 0, h, yRoi);
>         gd.addSlider("Width:", 0, w, width);
>         gd.addSlider("Height:", 0, h, height);
>         gd.addCheckbox("Oval", oval);
>         gd.addCheckbox("Centered",centered);
>         gd.addDialogListener(this);
>         gd.showDialog();
>         if (gd.wasCanceled()) {
>              if (roi==null)
>                 imp.deleteRoi();
>              else // restore initial ROI when cancelled
>                 imp.setRoi(roi);
>         }
>     }
>
>     void drawRoi() {
>         int iX = (int)xRoi;
>         int iY = (int)yRoi;
>         if (centered) {
>             iX = (int)(xRoi - (width/2));
>             iY = (int)(yRoi - (height/2));
>         }
>         int iWidth = (int)width;
>         int iHeight = (int)height;
>         Roi roi;
>         if (oval)
>             roi = new OvalRoi(iX, iY, iWidth, iHeight, imp);
>         else
>             roi = new Roi(iX, iY, iWidth, iHeight);
>         imp.setRoi(roi);
>         prevRoi = roi.getBounds();
>     }
>
>     public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
>         xRoi = gd.getNextNumber();
>         yRoi = gd.getNextNumber();
>         width = gd.getNextNumber();
>         height = gd.getNextNumber();
>         oval = gd.getNextBoolean();
>         centered = gd.getNextBoolean();
>         if (gd.invalidNumber())
>             return false;
>         else {
>             drawRoi();
>             return true;
>         }
>     }
>
> }
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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