示例#1
0
 /**
  * Draw the image containing the dataset pixels.
  *
  * @param panel the panel containing this data raster
  * @param g the graphics context upon which to draw
  */
 public void draw(DrawingPanel panel, Graphics g) {
   if (!visible) {
     return;
   }
   if (primaryDrawingPanel != panel) {
     return; // can only draw on one panel for now.
   }
   int xrange = panel.xToPix(xmax) - panel.xToPix(xmin);
   int yrange = panel.yToPix(ymin) - panel.yToPix(ymax);
   xrange = Math.min(xrange, panel.getWidth());
   yrange = Math.min(yrange, panel.getHeight());
   if ((xrange == 0) || (xrange == 0)) {
     return;
   }
   // render a new image if the scale or image size change
   if ((Math.abs(xrange) != image.getWidth())
       || // image size change
       (Math.abs(yrange) != image.getHeight())
       || ( // image size change
       xppu != primaryDrawingPanel.getXPixPerUnit())
       || ( // scale change
       yppu != primaryDrawingPanel.getYPixPerUnit())) {
     render();
   }
   double xmin = Math.max(primaryDrawingPanel.getXMin(), this.xmin);
   double ymax = Math.min(primaryDrawingPanel.getYMax(), this.ymax);
   if ((image != null) && (image.getWidth() > 1)) {
     g.drawImage(
         image, panel.xToPix(xmin), panel.yToPix(ymax), panel); // blast the image into the panel
   }
 }
 /**
  * Draws the rings for the polar plot.
  *
  * @param panel
  * @param g
  * @return double the ring separation used
  */
 public double drawRings(double rmax, DrawingPanel panel, Graphics g) {
   double dr = Math.max(this.dr, 1.0e-9);
   if (autospaceRings) {
     int exponent = (int) (Math.log(rmax) / LOG10);
     double decade = Math.pow(10, exponent - 1);
     dr = decade;
     while (rmax / dr > 5 * MAJOR_TIC) { // increase dr if we have more than 25 rings
       dr *= 2;
       if (dr / decade > 3.5 && dr / decade < 4.5) {
         dr = 5 * decade;
         decade *= 10;
       }
     }
   } else {
     int nrings = (int) (rmax / dr);
     while (nrings > 10 * MAJOR_TIC) {
       dr *= 2;
       nrings = (int) (rmax / dr);
     }
   }
   int xcenter = panel.xToPix(0);
   int ycenter = panel.yToPix(0);
   int xrad = (int) (panel.getXPixPerUnit() * rmax);
   int yrad = (int) (panel.getYPixPerUnit() * rmax);
   if (interiorColor != null) {
     g.setColor(interiorColor);
     g.fillOval(xcenter - xrad, ycenter - yrad, 2 * xrad, 2 * yrad);
   }
   int counter = 0;
   for (double r = 0; r <= rmax; r += dr) {
     g.setColor(gridcolor);
     xrad = panel.xToPix(r) - xcenter;
     yrad = ycenter - panel.yToPix(r);
     if (counter % MAJOR_TIC == 0) {
       g.setColor(gridcolor.darker());
     }
     g.drawOval(xcenter - xrad, ycenter - yrad, 2 * xrad, 2 * yrad);
     counter++;
   }
   return dr;
 }