Exemplo n.º 1
0
 /**
  * Returns the value from the specified dataset.
  *
  * @param datasetIndex the dataset index.
  * @return The data value.
  */
 public double getValue(int datasetIndex) {
   double result = Double.NaN;
   ValueDataset dataset = getDataset(datasetIndex);
   if (dataset != null) {
     Number n = dataset.getValue();
     if (n != null) {
       result = n.doubleValue();
     }
   }
   return result;
 }
Exemplo n.º 2
0
  /**
   * Sets a dataset for the plot.
   *
   * @param index the dataset index.
   * @param dataset the dataset (<code>null</code> permitted).
   */
  public void setDataset(int index, ValueDataset dataset) {

    ValueDataset existing = (ValueDataset) this.datasets.get(index);
    if (existing != null) {
      existing.removeChangeListener(this);
    }
    this.datasets.set(index, dataset);
    if (dataset != null) {
      dataset.addChangeListener(this);
    }

    // send a dataset change event to self...
    DatasetChangeEvent event = new DatasetChangeEvent(this, dataset);
    datasetChanged(event);
  }
Exemplo n.º 3
0
  /**
   * Sets the dataset for the plot, replacing the existing dataset if there is one, and triggers a
   * {@link PlotChangeEvent}.
   *
   * @param dataset the dataset (<code>null</code> permitted).
   * @see #getDataset()
   */
  public void setDataset(ValueDataset dataset) {

    // if there is an existing dataset, remove the plot from the list of
    // change listeners...
    ValueDataset existing = this.dataset;
    if (existing != null) {
      existing.removeChangeListener(this);
    }

    // set the new dataset, and register the chart as a change listener...
    this.dataset = dataset;
    if (dataset != null) {
      setDatasetGroup(dataset.getGroup());
      dataset.addChangeListener(this);
    }

    // send a dataset change event to self...
    DatasetChangeEvent event = new DatasetChangeEvent(this, dataset);
    datasetChanged(event);
  }
Exemplo n.º 4
0
  /**
   * Draws the plot on a Java 2D graphics device (such as the screen or a printer).
   *
   * @param g2 the graphics device.
   * @param area the area within which the plot should be drawn.
   * @param anchor the anchor point (<code>null</code> permitted).
   * @param parentState the state from the parent plot, if there is one.
   * @param info collects info about the drawing.
   */
  public void draw(
      Graphics2D g2,
      Rectangle2D area,
      Point2D anchor,
      PlotState parentState,
      PlotRenderingInfo info) {

    if (info != null) {
      info.setPlotArea(area);
    }

    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    area.setRect(area.getX() + 4, area.getY() + 4, area.getWidth() - 8, area.getHeight() - 8);

    // draw the background
    if (this.drawBorder) {
      drawBackground(g2, area);
    }

    // adjust the plot area by the interior spacing value
    double gapHorizontal = (2 * DEFAULT_BORDER_SIZE);
    double gapVertical = (2 * DEFAULT_BORDER_SIZE);
    double meterX = area.getX() + gapHorizontal / 2;
    double meterY = area.getY() + gapVertical / 2;
    double meterW = area.getWidth() - gapHorizontal;
    double meterH =
        area.getHeight()
            - gapVertical
            + ((this.meterAngle <= 180) && (this.shape != DialShape.CIRCLE)
                ? area.getHeight() / 1.25
                : 0);

    double min = Math.min(meterW, meterH) / 2;
    meterX = (meterX + meterX + meterW) / 2 - min;
    meterY = (meterY + meterY + meterH) / 2 - min;
    meterW = 2 * min;
    meterH = 2 * min;

    Rectangle2D meterArea = new Rectangle2D.Double(meterX, meterY, meterW, meterH);

    Rectangle2D.Double originalArea =
        new Rectangle2D.Double(
            meterArea.getX() - 4,
            meterArea.getY() - 4,
            meterArea.getWidth() + 8,
            meterArea.getHeight() + 8);

    double meterMiddleX = meterArea.getCenterX();
    double meterMiddleY = meterArea.getCenterY();

    // plot the data (unless the dataset is null)...
    ValueDataset data = getDataset();
    if (data != null) {
      double dataMin = this.range.getLowerBound();
      double dataMax = this.range.getUpperBound();

      Shape savedClip = g2.getClip();
      g2.clip(originalArea);
      Composite originalComposite = g2.getComposite();
      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));

      if (this.dialBackgroundPaint != null) {
        fillArc(g2, originalArea, dataMin, dataMax, this.dialBackgroundPaint, true);
      }
      drawTicks(g2, meterArea, dataMin, dataMax);
      drawArcForInterval(
          g2,
          meterArea,
          new MeterInterval("", this.range, this.dialOutlinePaint, new BasicStroke(1.0f), null));

      Iterator iterator = this.intervals.iterator();
      while (iterator.hasNext()) {
        MeterInterval interval = (MeterInterval) iterator.next();
        drawArcForInterval(g2, meterArea, interval);
      }

      Number n = data.getValue();
      if (n != null) {
        double value = n.doubleValue();
        drawValueLabel(g2, meterArea);

        if (this.range.contains(value)) {
          g2.setPaint(this.needlePaint);
          g2.setStroke(new BasicStroke(2.0f));

          double radius = (meterArea.getWidth() / 2) + DEFAULT_BORDER_SIZE + 15;
          double valueAngle = valueToAngle(value);
          double valueP1 = meterMiddleX + (radius * Math.cos(Math.PI * (valueAngle / 180)));
          double valueP2 = meterMiddleY - (radius * Math.sin(Math.PI * (valueAngle / 180)));

          Polygon arrow = new Polygon();
          if ((valueAngle > 135 && valueAngle < 225) || (valueAngle < 45 && valueAngle > -45)) {

            double valueP3 = (meterMiddleY - DEFAULT_CIRCLE_SIZE / 4);
            double valueP4 = (meterMiddleY + DEFAULT_CIRCLE_SIZE / 4);
            arrow.addPoint((int) meterMiddleX, (int) valueP3);
            arrow.addPoint((int) meterMiddleX, (int) valueP4);

          } else {
            arrow.addPoint((int) (meterMiddleX - DEFAULT_CIRCLE_SIZE / 4), (int) meterMiddleY);
            arrow.addPoint((int) (meterMiddleX + DEFAULT_CIRCLE_SIZE / 4), (int) meterMiddleY);
          }
          arrow.addPoint((int) valueP1, (int) valueP2);
          g2.fill(arrow);

          Ellipse2D circle =
              new Ellipse2D.Double(
                  meterMiddleX - DEFAULT_CIRCLE_SIZE / 2,
                  meterMiddleY - DEFAULT_CIRCLE_SIZE / 2,
                  DEFAULT_CIRCLE_SIZE,
                  DEFAULT_CIRCLE_SIZE);
          g2.fill(circle);
        }
      }

      g2.setClip(savedClip);
      g2.setComposite(originalComposite);
    }
    if (this.drawBorder) {
      drawOutline(g2, area);
    }
  }