Ejemplo n.º 1
0
 private void setIndicators() {
   if (ellipseIndicator == null) ellipseIndicator = new Ellipse2D.Double();
   if (arcIndicator == null) arcIndicator = new Arc2D.Double();
   ellipseIndicator.setFrame(angle.x, angle.y, angle.width, angle.height);
   arcIndicator.setArc(
       angle.x, angle.y, angle.width, angle.height, angle.start, angle.extent, Arc2D.PIE);
 }
Ejemplo n.º 2
0
 public Arc2D evaluate(Arc2D v0, Arc2D v1, float fraction) {
   double x = v0.getX() + ((v1.getX() - v0.getX()) * fraction);
   double y = v0.getY() + ((v1.getY() - v0.getY()) * fraction);
   double w = v0.getWidth() + ((v1.getWidth() - v0.getWidth()) * fraction);
   double h = v0.getHeight() + ((v1.getHeight() - v0.getHeight()) * fraction);
   double start = v0.getAngleStart() + ((v1.getAngleStart() - v0.getAngleStart()) * fraction);
   double extent = v0.getAngleExtent() + ((v1.getAngleExtent() - v0.getAngleExtent()) * fraction);
   Arc2D value = (Arc2D) v0.clone();
   value.setArc(x, y, w, h, start, extent, v0.getArcType());
   return value;
 }
Ejemplo n.º 3
0
 public boolean contains(double x, double y) {
   setArc();
   double narrow = Math.abs(angle.extent) * 0.2;
   if (arc == null) arc = new Arc2D.Double();
   arc.setArc(
       atom3.rx - 0.5 * angle.width,
       atom3.ry - 0.5 * angle.height,
       angle.width,
       angle.height,
       angle.extent > 0 ? angle.start + narrow : angle.start - narrow,
       angle.extent > 0 ? angle.extent - narrow - narrow : angle.extent + narrow + narrow,
       Arc2D.PIE);
   return arc.contains(x, y);
 }
Ejemplo n.º 4
0
  /**
   * Draws the scale on the dial plot.
   *
   * @param g2 the graphics target (<code>null</code> not permitted).
   * @param plot the dial plot (<code>null</code> not permitted).
   * @param frame the reference frame that is used to construct the geometry of the plot (<code>null
   *     </code> not permitted).
   * @param view the visible part of the plot (<code>null</code> not permitted).
   */
  public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Rectangle2D arcRect =
        DialPlot.rectangleByRadius(frame, this.getTickRadius(), this.getTickRadius());
    Rectangle2D arcRectMajor =
        DialPlot.rectangleByRadius(
            frame,
            this.getTickRadius() - this.getMajorTickLength(),
            this.getTickRadius() - this.getMajorTickLength());
    Rectangle2D arcRectMinor = arcRect;
    if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) {
      arcRectMinor =
          DialPlot.rectangleByRadius(
              frame,
              this.getTickRadius() - this.getMinorTickLength(),
              this.getTickRadius() - this.getMinorTickLength());
    }
    Rectangle2D arcRectForLabels =
        DialPlot.rectangleByRadius(
            frame,
            this.getTickRadius() - this.getTickLabelOffset(),
            this.getTickRadius() - this.getTickLabelOffset());

    boolean firstLabel = true;

    Arc2D arc = new Arc2D.Double();
    Line2D workingLine = new Line2D.Double();
    Stroke arcStroke = new BasicStroke(0.75f);

    for (double v = this.getLowerBound();
        v <= this.getUpperBound();
        v += this.getMajorTickIncrement()) {
      arc.setArc(arcRect, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
      g2.setPaint(this.getMajorTickPaint());
      g2.setStroke(arcStroke);
      g2.draw(arc);

      Point2D pt0 = arc.getEndPoint();
      arc.setArc(
          arcRectMajor, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
      Point2D pt1 = arc.getEndPoint();
      g2.setPaint(this.getMajorTickPaint());
      g2.setStroke(this.getMajorTickStroke());
      workingLine.setLine(pt0, pt1);
      g2.draw(workingLine);
      arc.setArc(
          arcRectForLabels,
          this.getStartAngle(),
          valueToAngle(v) - this.getStartAngle(),
          Arc2D.OPEN);
      Point2D pt2 = arc.getEndPoint();

      if (this.getTickLabelsVisible()) {
        if (!firstLabel || this.getFirstTickLabelVisible()) {
          g2.setFont(this.getTickLabelFont());
          TextUtilities.drawAlignedString(
              this.getTickLabelFormatter().format(v),
              g2,
              (float) pt2.getX(),
              (float) pt2.getY(),
              TextAnchor.CENTER);
        }
      }
      firstLabel = false;

      // now do the minor tick marks
      if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) {
        double minorTickIncrement = this.getMajorTickIncrement() / (this.getMinorTickCount() + 1);
        for (int i = 0; i < this.getMinorTickCount(); i++) {
          double vv = v + ((i + 1) * minorTickIncrement);
          if (vv >= this.getUpperBound()) {
            break;
          }
          double angle = valueToAngle(vv);

          arc.setArc(arcRect, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN);
          pt0 = arc.getEndPoint();
          arc.setArc(arcRectMinor, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN);
          Point2D pt3 = arc.getEndPoint();
          g2.setStroke(this.getMinorTickStroke());
          g2.setPaint(this.getMinorTickPaint());
          workingLine.setLine(pt0, pt3);
          g2.draw(workingLine);
        }
      }
    }
  }