Login  Register

GenericDialog issue

Posted by Dimiter Prodanov on Jun 19, 2006; 3:43pm
URL: http://imagej.273.s1.nabble.com/GenericDialog-issue-tp3702457.html

Dear All,

I am sending a procedure that causes  ArrayIndexOutOfBoundsException  in
the getNextNumber() method. I wander what is the reason. According to me,
there should not be such behavior. Or is it a bug in ImageJ?

Any suggestions?

best regards

Dimiter


     private boolean showDialog() {
                 if (imp==null)
                         return true;
                 int width = imp.getWidth();
                 int height = imp.getHeight();
                 Calibration cal = imp.getCalibration();
                 int places;
                 if (cal.scaled()) {
                         pixelWidth = cal.pixelWidth;
                         pixelHeight = cal.pixelHeight;
                         units = cal.getUnits();
                         places = 2;
                 } else {
                         pixelWidth = 1.0;
                         pixelHeight = 1.0;
                         units = "pixels";
                         places = 0;
                 }
                 if (areaPerPoint==0.0)
                         areaPerPoint =
(width*cal.pixelWidth*height*cal.pixelHeight)/81.0; // default to 9x9 grid
                 lineWidth = Line.getWidth();
                 /*              ImageWindow win = imp.getWindow();
                 double mag = win!=null?win.getCanvas().getMagnification():1.0;
                 int scale = (int)(1.0/mag);
                 if (lineWidth<scale)
                         lineWidth = scale;*/
                 try {


                 GenericDialog gd = new GenericDialog("Grid...");
                 gd.setAlwaysOnTop(false);

                 gd.addChoice("Grid Type:", types, type);
                 gd.showDialog();
         if (gd.wasCanceled())
                         return false;
         option=gd.getNextChoiceIndex();
         type=types[option];
                 IJ.log(" "+ type);
                 //type = gd.getNextChoice();
                 gd.setVisible(false);
                 //gd=null;
                 gd.dispose();

                 GenericDialog gd2 = new GenericDialog("Grid continued ...");
         gd2.addNumericField("Area per Point:",
areaPerPoint, places, 6, units+"^2");
                 gd2.addNumericField("Line width:", lineWidth, 0, 6, "pixels");
                 gd2.addCheckbox("Random Offset", randomOffset);
         //        gd.addNumericField("ratio:", ratio, 0);
         if (type=="Boxes") {

             gd2.addNumericField("ratio:", ratio, 0);
        }

         gd2.showDialog();
         if (gd2.wasCanceled())
                         return false;

                 areaPerPoint = gd2.getNextNumber();
                 IJ.log("APP: "+ areaPerPoint);
                 Line.setWidth((int)gd2.getNextNumber());
                 lineWidth = Line.getWidth();
                 IJ.log("line width "+ lineWidth);
                 randomOffset = gd2.getNextBoolean();
                 IJ.log("random "+ randomOffset);
                 ratio=(int)gd2.getNextNumber();
                 IJ.log("ratio "+ ratio);
                 }
                 catch (ArrayIndexOutOfBoundsException  aiobe) {
                         IJ.log("ArrayIndexOutOfBoundsException");
                 }
                 double tileSize = Math.sqrt(areaPerPoint);
                 tileWidth = tileSize/pixelWidth;
                 tileHeight = tileSize/pixelHeight;
                 if (randomOffset) {
                         xstart = (int)(random.nextDouble()*tileWidth);
                         ystart = (int)(random.nextDouble()*tileHeight);
                 } else {
                         xstart = (int)(tileWidth/2.0+0.5);
                         ystart = (int)(tileHeight/2.0+0.5);
                 }
                 linesV = (int)((width-xstart)/tileWidth)+1;
                 linesH = (int)((height-ystart)/tileHeight)+1;
                 return true;
         }



_______________________________________________________________________
Dr Dimiter Prodanov, MD, Ph.D.

Neural Engineering Rehabilitation Laboratory
(Laboratoire de Génie de la Réhabilitation Neurale)
Département de Physiologie et Pharmacologie
Université catholique de Louvain
Avenue Hippocrate, 54
POBox UCL-5446 / B-1200 Bruxelles -Belgique-
Phone: 00-322-764 5596
Fax: 00-322-764 9422

http://www.md.ucl.ac.be/gren