Example #1
0
  /** Plots this graph on the specified canvas using the provided Graphics object. */
  public void plot(Component canvas, Graphics g) {
    try {
      g.setColor(this.color);

      int numPoints = this.getNumberOfPoints();
      Point oldp = null, newp;

      for (int i = 0; i < numPoints; i++, oldp = newp) {
        newp = this.getPoint(canvas, i);

        // draw accent circle around next point, if applicable
        if (accentPoints) g.drawOval(newp.x - 2, newp.y - 2, 4, 4);

        // draw line segment connecting previous point to next point, if
        // applicable (note: it's never applicable if this is the very
        // first point)
        if (i != 0 && connectPattern.isConnected(i)) g.drawLine(oldp.x, oldp.y, newp.x, newp.y);

        // highlight this point, if applicable
        if (i == this.getHighlightedPoint()) {
          g.drawOval(newp.x - 4, newp.y - 4, 8, 8);
          g.drawOval(newp.x - 5, newp.y - 5, 10, 10);
        }
      }
    } catch (IndexOutOfBoundsException ex) {
      // do nothing.  Due to threading issues, it's possible that the
      // data may suddenly change or even vanish in the middle of
      // plotting.  In this case, we abort, and trust that the
      // application will make sure plot gets called again once the
      // data is back in a consistent state.
    }
  }
Example #2
0
 /** Sets the ConnectPattern for this graph. */
 public void setConnectPattern(ConnectPattern cp) {
   if (!cp.equals(this.connectPattern)) {
     this.connectPattern = cp;
     this.setChanged(CONNECT_PATTERN_CHANGE);
   }
 }