Esempio n. 1
0
  /** Overrides <code>Graphics.drawPolyline</code>. */
  public void drawPolyline(int xPoints[], int yPoints[], int nPoints) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Drawing polyline: "
                  + " nPoints: "
                  + nPoints
                  + " X's: "
                  + xPoints
                  + " Y's: "
                  + yPoints);
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawPolyline(xPoints, yPoints, nPoints);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.drawPolyline(xPoints, yPoints, nPoints);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawPolyline(xPoints, yPoints, nPoints);
  }
  /* draw a cubic spline */
  public void paint(Graphics g) {
    super.paint(g);
    if (pts.npoints >= 2) {
      Cubic[] X = calcNaturalCubic(pts.npoints - 1, pts.xpoints);
      Cubic[] Y = calcNaturalCubic(pts.npoints - 1, pts.ypoints);

      /* very crude technique - just break each segment up into steps lines */
      Polygon p = new Polygon();
      p.addPoint((int) Math.round(X[0].eval(0)), (int) Math.round(Y[0].eval(0)));
      for (int i = 0; i < X.length; i++) {
        for (int j = 1; j <= STEPS; j++) {
          float u = j / (float) STEPS;
          p.addPoint(Math.round(X[i].eval(u)), Math.round(Y[i].eval(u)));
        }
      }
      g.drawPolyline(p.xpoints, p.ypoints, p.npoints);
    }
  }
 @Override
 public void update(Graphics g) {
   Dimension dimension = getSize();
   if (gBuffer == null || dimension.width != dim.width || dimension.height != dim.height) {
     dim = dimension;
     imag = createImage(dimension.width, dimension.height);
     gBuffer = imag.getGraphics();
   }
   gBuffer.setColor(getBackground());
   gBuffer.fillRect(0, 0, dimension.width, dimension.height);
   gBuffer.setColor(Color.black);
   dibujaEjes(gBuffer);
   dibujaEjeAnimacion(gBuffer);
   dibujaAmbiente(gBuffer);
   muestraValores(gBuffer);
   gBuffer.fillOval(orgXX + 2 * cAncho, y1 - cAncho / 2, cAncho, cAncho);
   gBuffer.drawImage(
       this.imag2.getImage(), orgXX + 8 * cAncho, y1 - this.imag2.getIconHeight(), this);
   flechaVelocidad(gBuffer);
   flechaAceleracion(gBuffer);
   gBuffer.setColor(Color.black);
   gBuffer.drawPolyline(pol.xpoints, pol.ypoints, pol.npoints);
   g.drawImage(imag, 0, 0, null);
 }
Esempio n. 4
0
 @Override
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   g.drawPolyline(p.xpoints, p.ypoints, p.npoints);
 }
Esempio n. 5
0
 public void draw(Graphics g) {
   updatePolygon();
   Color color = strokeColor != null ? strokeColor : ROIColor;
   boolean hasHandles = xSpline != null || type == POLYGON || type == POLYLINE || type == ANGLE;
   boolean isActiveOverlayRoi = !overlay && isActiveOverlayRoi();
   if (isActiveOverlayRoi && !hasHandles) {
     if (color == Color.cyan) color = Color.magenta;
     else color = Color.cyan;
   }
   boolean fill = false;
   mag = getMagnification();
   if (fillColor != null && !isLine() && state != CONSTRUCTING) {
     color = fillColor;
     fill = true;
   }
   g.setColor(color);
   Graphics2D g2d = (Graphics2D) g;
   if (stroke != null && !isActiveOverlayRoi) g2d.setStroke(getScaledStroke());
   if (xSpline != null) {
     if (type == POLYLINE || type == FREELINE) {
       drawSpline(g, xSpline, ySpline, splinePoints, false, fill, isActiveOverlayRoi);
       if (wideLine && !overlay) {
         g2d.setStroke(onePixelWide);
         g.setColor(getColor());
         drawSpline(g, xSpline, ySpline, splinePoints, false, fill, isActiveOverlayRoi);
       }
     } else drawSpline(g, xSpline, ySpline, splinePoints, true, fill, isActiveOverlayRoi);
   } else {
     if (type == POLYLINE || type == FREELINE || type == ANGLE || state == CONSTRUCTING) {
       g.drawPolyline(xp2, yp2, nPoints);
       if (wideLine && !overlay) {
         g2d.setStroke(onePixelWide);
         g.setColor(getColor());
         g.drawPolyline(xp2, yp2, nPoints);
       }
     } else {
       if (fill) {
         if (isActiveOverlayRoi) {
           g.setColor(Color.cyan);
           g.drawPolygon(xp2, yp2, nPoints);
         } else g.fillPolygon(xp2, yp2, nPoints);
       } else g.drawPolygon(xp2, yp2, nPoints);
     }
     if (state == CONSTRUCTING && type != FREEROI && type != FREELINE) drawStartBox(g);
   }
   if (hasHandles && state != CONSTRUCTING && clipboard == null && !overlay) {
     int size2 = HANDLE_SIZE / 2;
     if (activeHandle > 0)
       drawHandle(g, xp2[activeHandle - 1] - size2, yp2[activeHandle - 1] - size2);
     if (activeHandle < nPoints - 1)
       drawHandle(g, xp2[activeHandle + 1] - size2, yp2[activeHandle + 1] - size2);
     handleColor = strokeColor != null ? strokeColor : ROIColor;
     drawHandle(g, xp2[0] - size2, yp2[0] - size2);
     handleColor = Color.white;
     for (int i = 1; i < nPoints; i++) drawHandle(g, xp2[i] - size2, yp2[i] - size2);
   }
   drawPreviousRoi(g);
   if (!(state == MOVING_HANDLE || state == CONSTRUCTING || state == NORMAL)) showStatus();
   if (updateFullWindow) {
     updateFullWindow = false;
     imp.draw();
   }
 }
Esempio n. 6
0
  /**
   * This method will draw the line.
   *
   * @param gc the graphics
   * @see #setLog
   */
  void paintLine(Graphics g) {
    double dvalue;
    int[] values = dataSet.getValues();
    // first decide the x scale factor;
    if ((dataSet == null) || (dataSet.getSize() < 1)) {
      return; // nothing to draw
    }

    // the maximum number of values we are every going to get
    int capacity = dataSet.getCapacity();

    // the available number of values at the moment
    int nr = dataSet.getSize();
    Rectangle space = g.getClipBounds();

    // pixel width of x values
    int width = space.width;
    int xscale = (int) (width / capacity);
    if (xscale < 1) {
      xscale = 1;
    }
    width = xscale * capacity;
    if (width > space.width) {
      width = space.width;
    }

    // pixel width of y values
    float yscale = (space.height) / (float) (dmax - dmin);

    // offset into array
    int xstart = 0;
    if (width < (nr * xscale)) {
      // we are lacking space
      xstart = nr - (int) (width / xscale);
    }

    // if needed reallocate some space
    int totx = nr - xstart + 1;
    if (xline.length < totx) {
      xline = new int[totx + 100];
      yline = new int[totx + 100];
    }

    // now workout where to put the first point so that
    // the last one ends up on the right hand edge
    int x = width - (int) ((nr - xstart - 1) * xscale);
    if (x < 0) {
      x = 0; // can't be negative
      System.out.println("negative start point in graph.");
    }

    int y;
    int ox = x;
    x += xscale;
    dvalue = values[xstart];
    if (doLog) {
      dvalue = log10(values[xstart]);
    }
    xstart++;
    int oy = space.height - (int) ((dvalue - dmin) * yscale);
    int pt = 0;
    for (int i = xstart; i < nr; i++) {
      dvalue = values[i];
      if (doLog) {
        dvalue = log10(values[i]);
      }
      y = space.height - (int) ((dvalue - dmin) * yscale);
      xline[pt] = x;
      yline[pt] = y;
      pt++;
      ox = x;
      oy = y;
      x += xscale;
    }
    g.drawPolyline(xline, yline, pt);
  }