示例#1
0
  public void updateLine() {
    PBounds sourceBounds = source.getBounds();
    PBounds targetBounds = target.getBounds();
    double x1, y1, x2, y2;

    if (Math.abs(sourceBounds.getCenterX() - targetBounds.getCenterX()) < 1.0) {
      // source and target on the same vertical position
      x1 = x2 = sourceBounds.getCenterX();
      y1 = sourceBounds.getMaxY();
      y2 = targetBounds.getMinY();
      y2 -= STROKE_ARROW.getLineWidth();

      if (y1 > y2) {
        y1 = sourceBounds.getMinY();
        y2 = targetBounds.getMaxY();
        y2 += STROKE_ARROW.getLineWidth();
      }
    } else {
      // source and target in different vertical positions
      x1 = sourceBounds.getMaxX();
      y1 = sourceBounds.getCenterY();
      x2 = targetBounds.getMinX();
      y2 = targetBounds.getCenterY();
      x2 -= STROKE_ARROW.getLineWidth();

      if (x1 > x2) {
        x1 = sourceBounds.getMinX();
        x2 = targetBounds.getMaxX();
        x2 += STROKE_ARROW.getLineWidth();
      }

      // move the ends a bit if we are not in the same vertical position
      int ydi = (int) Math.round((y2 - y1) / (MmfNode.HEIGHT + MmfNode.PADDING_HEIGHT));
      double yd = (ydi < 0 ? -1 : 1) * END_DELTA[Math.min(Math.abs(ydi), END_DELTA.length - 1)];
      y1 += yd;
      y2 -= yd;
    }

    line = new Line2D.Double(x1, y1, x2, y2);
    arrowHead = getArrowHead((int) x1, (int) y1, (int) x2, (int) y2);

    Rectangle bounds = line.getBounds();
    bounds.add(arrowHead.getBounds());
    setBounds(bounds);
  }
示例#2
0
 @Override
 public Rectangle getBounds() {
   return MainLine.getBounds();
 }
  /**
   * Draws the block representing the specified item.
   *
   * @param g2 the graphics device.
   * @param state the state.
   * @param dataArea the data area.
   * @param info the plot rendering info.
   * @param plot the plot.
   * @param domainAxis the x-axis.
   * @param rangeAxis the y-axis.
   * @param dataset the dataset.
   * @param series the series index.
   * @param item the item index.
   * @param crosshairState the crosshair state.
   * @param pass the pass index.
   */
  @Override
  public void drawItem(
      Graphics2D g2,
      XYItemRendererState state,
      Rectangle2D dataArea,
      PlotRenderingInfo info,
      XYPlot plot,
      ValueAxis domainAxis,
      ValueAxis rangeAxis,
      XYDataset dataset,
      int series,
      int item,
      CrosshairState crosshairState,
      int pass) {

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double dx = 0.0;
    double dy = 0.0;
    if (dataset instanceof VectorXYDataset) {
      dx = ((VectorXYDataset) dataset).getVectorXValue(series, item);
      dy = ((VectorXYDataset) dataset).getVectorYValue(series, item);
    }
    double xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + dx, dataArea, plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + dy, dataArea, plot.getRangeAxisEdge());
    Line2D line;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
      line = new Line2D.Double(yy0, xx0, yy1, xx1);
    } else {
      line = new Line2D.Double(xx0, yy0, xx1, yy1);
    }
    g2.setPaint(getItemPaint(series, item));
    g2.setStroke(getItemStroke(series, item));
    g2.draw(line);

    // calculate the arrow head and draw it...
    double dxx = (xx1 - xx0);
    double dyy = (yy1 - yy0);
    double bx = xx0 + (1.0 - this.baseLength) * dxx;
    double by = yy0 + (1.0 - this.baseLength) * dyy;

    double cx = xx0 + (1.0 - this.headLength) * dxx;
    double cy = yy0 + (1.0 - this.headLength) * dyy;

    double angle = 0.0;
    if (dxx != 0.0) {
      angle = Math.PI / 2.0 - Math.atan(dyy / dxx);
    }
    double deltaX = 2.0 * Math.cos(angle);
    double deltaY = 2.0 * Math.sin(angle);

    double leftx = cx + deltaX;
    double lefty = cy - deltaY;
    double rightx = cx - deltaX;
    double righty = cy + deltaY;

    GeneralPath p = new GeneralPath();
    if (orientation == PlotOrientation.VERTICAL) {
      p.moveTo((float) xx1, (float) yy1);
      p.lineTo((float) rightx, (float) righty);
      p.lineTo((float) bx, (float) by);
      p.lineTo((float) leftx, (float) lefty);
    } else { // orientation is HORIZONTAL
      p.moveTo((float) yy1, (float) xx1);
      p.lineTo((float) righty, (float) rightx);
      p.lineTo((float) by, (float) bx);
      p.lineTo((float) lefty, (float) leftx);
    }
    p.closePath();
    g2.draw(p);

    // setup for collecting optional entity info...
    EntityCollection entities = null;
    if (info != null) {
      entities = info.getOwner().getEntityCollection();
      if (entities != null) {
        addEntity(entities, line.getBounds(), dataset, series, item, 0.0, 0.0);
      }
    }
  }
  /**
   * Draws the visual representation of a single data item.
   *
   * @param g2 the graphics device.
   * @param state the renderer state.
   * @param dataArea the area within which the plot is being drawn.
   * @param info collects information about the drawing.
   * @param plot the plot (can be used to obtain standard color information etc).
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param dataset the dataset.
   * @param series the series index (zero-based).
   * @param item the item index (zero-based).
   * @param crosshairState crosshair information for the plot (<code>null</code> permitted).
   * @param pass the pass index (ignored here).
   */
  public void drawItem(
      Graphics2D g2,
      XYItemRendererState state,
      Rectangle2D dataArea,
      PlotRenderingInfo info,
      XYPlot plot,
      ValueAxis domainAxis,
      ValueAxis rangeAxis,
      XYDataset dataset,
      int series,
      int item,
      CrosshairState crosshairState,
      int pass) {

    // setup for collecting optional entity info...
    EntityCollection entities = null;
    if (info != null) {
      entities = info.getOwner().getEntityCollection();
    }

    IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

    double x = intervalDataset.getXValue(series, item);
    double yLow = intervalDataset.getStartYValue(series, item);
    double yHigh = intervalDataset.getEndYValue(series, item);

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
    double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
    double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);

    Paint p = getItemPaint(series, item);
    Stroke s = getItemStroke(series, item);

    Line2D line = null;
    Shape shape = getItemShape(series, item);
    Shape top = null;
    Shape bottom = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
      line = new Line2D.Double(yyLow, xx, yyHigh, xx);
      top = ShapeUtilities.createTranslatedShape(shape, yyHigh, xx);
      bottom = ShapeUtilities.createTranslatedShape(shape, yyLow, xx);
    } else if (orientation == PlotOrientation.VERTICAL) {
      line = new Line2D.Double(xx, yyLow, xx, yyHigh);
      top = ShapeUtilities.createTranslatedShape(shape, xx, yyHigh);
      bottom = ShapeUtilities.createTranslatedShape(shape, xx, yyLow);
    }
    g2.setPaint(p);
    g2.setStroke(s);
    g2.draw(line);

    g2.fill(top);
    g2.fill(bottom);

    // for item labels, we have a special case because there is the
    // possibility to draw (a) the regular item label near to just the
    // upper y-value, or (b) the regular item label near the upper y-value
    // PLUS an additional item label near the lower y-value.
    if (isItemLabelVisible(series, item)) {
      drawItemLabel(g2, orientation, dataset, series, item, xx, yyHigh, false);
      drawAdditionalItemLabel(g2, orientation, dataset, series, item, xx, yyLow);
    }

    // add an entity for the item...
    if (entities != null) {
      addEntity(entities, line.getBounds(), dataset, series, item, 0.0, 0.0);
    }
  }
示例#5
0
 public GRectangle getBounds() {
   return new org.geogebra.desktop.awt.GRectangleD(impl.getBounds());
 }