GenericDialog wasCanceled() method problem

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

GenericDialog wasCanceled() method problem

lechristophe
Hi,  

I'm using the stock generic dialog example (found in the GenericDialog class Javadoc) that I tried to adapt as a javascript :

importPackage (Packages.java.lang);
gd = new GenericDialog("New Image");
gd.addStringField("Title: ", "example");
gd.addNumericField("Width: ", 512, 0);
gd.addNumericField("Height: ", 512, 0);
gd.showDialog();
if (gd.wasCanceled()) return;
title = gd.getNextString();
imwidth = gd.getNextNumber();
imheight = gd.getNextNumber();
IJ.newImage(title, "8-bit", imwidth, imheight, 1);


However I get an error with the gd.wasCanceled() method with an error saying:
org.mozilla.javascript.EvaluatorException: la valeur renvoyée est incorrecte
which translates to something like "incorrect returned value".

Any clue on what happens here? I'm running IJ 1.46d in Fiji.

Christophe
Reply | Threaded
Open this post in threaded view
|

Re: GenericDialog wasCanceled() method problem

jchanson
Christophe -
        I tried the script Generic Dialog example and ran into the same
thing.  It gets hung up on the "return" command.  When it's not inside a
function that returns a value, the return command is invalid.  I was able
to get it to work by taking out the return:
if (!gd.wasCanceled()) {
        title = gd.getNextString();
        imwidth = gd.getNextNumber();
        imheight = gd.getNextNumber();
        IJ.newImage(title, "8-bit", imwidth, imheight, 1);
}

Jeff