Beispiel #1
1
 /**
  * Computes the perimeter point on this shape, lying on the line from a given source point in the
  * direction of a target point. If the source and target point coincide, the point to the east of
  * the source point is returned.
  *
  * @param bounds bounds of the shape
  * @param px x-coordinate of source point;
  * @param py y-coordinate of source point;
  * @param q target point
  */
 Point2D getPerimeterPoint(Rectangle2D bounds, double px, double py, Point2D q) {
   // distances from source point to left, right, top and bottom edge
   double dxRight = bounds.getMaxX() - px;
   double dxLeft = px - bounds.getMinX();
   double dyBottom = bounds.getMaxY() - py;
   double dyTop = py - bounds.getMinY();
   // angles from source point to upper left, upper right, bottom left, bottom right corner
   double urPhi = Math.atan2(-dyTop, dxRight);
   double ulPhi = Math.atan2(-dyTop, -dxLeft);
   double brPhi = Math.atan2(dyBottom, dxRight);
   double blPhi = Math.atan2(dyBottom, -dxLeft);
   // compute angle from source to nextPoint
   double dx = q.getX() - px; // Compute Angle
   double dy = q.getY() - py;
   double alpha = Math.atan2(dy, dx);
   double x, y;
   double pi = Math.PI;
   if (alpha < ulPhi || alpha > blPhi) { // Left edge
     x = px - dxLeft;
     y = py - dxLeft * Math.tan(alpha);
   } else if (alpha < urPhi) { // Top Edge
     y = py - dyTop;
     x = px - dyTop * Math.tan(pi / 2 - alpha);
   } else if (alpha < brPhi) { // Right Edge
     x = px + dxRight;
     y = py + dxRight * Math.tan(alpha);
   } else { // Bottom Edge
     y = py + dyBottom;
     x = px + dyBottom * Math.tan(pi / 2 - alpha);
   }
   return new Point2D.Double(x, y);
 }
 @Override
 public void drawItem(
     Graphics2D g2,
     CategoryItemRendererState state,
     Rectangle2D dataArea,
     CategoryPlot plot,
     CategoryAxis domainAxis,
     ValueAxis rangeAxis,
     CategoryDataset dataset,
     int row,
     int column,
     int pass) {
   drawItemInternal(
       g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass);
   //            System.out.println(String.format("row %s, column %s, pass %s", row, column,
   // pass));
   if ((pass == 0) && (row == 1) && (column == 3)) {
     // Workaround: because the dataArea sits on the the Axis the 0% gridline gets drawn
     // over the category axis making it gray. To fix this as we draw another black line
     // to restore the black axis.
     g2.setColor(Color.black);
     g2.setStroke(new BasicStroke(2));
     g2.drawLine(
         (int) dataArea.getMinX(),
         (int) dataArea.getMaxY(),
         (int) dataArea.getMaxX(),
         (int) dataArea.getMaxY());
     g2.drawLine(
         (int) dataArea.getMinX(),
         (int) dataArea.getMinY(),
         (int) dataArea.getMinX(),
         (int) dataArea.getMaxY());
   }
 }
  @Override
  public void draw(
      Graphics2D g2,
      XYPlot plot,
      Rectangle2D dataArea,
      ValueAxis domainAxis,
      ValueAxis rangeAxis,
      int rendererIndex,
      PlotRenderingInfo info) {

    Rectangle2D box = chartPanel.getScreenDataArea();
    float sx = (float) plot.getDomainAxis().valueToJava2D(x, box, plot.getDomainAxisEdge());
    float maxXLim = (float) box.getWidth() - g2.getFontMetrics().stringWidth(text);
    if (sx > maxXLim) {
      sx = maxXLim;
    }
    if (sx < box.getMinX()) {
      sx = (float) box.getMinX();
    }

    float sy =
        (float)
            plot.getRangeAxis()
                .valueToJava2D(y, chartPanel.getScreenDataArea(), plot.getRangeAxisEdge());
    g2.setTransform(new AffineTransform());
    g2.setColor(color);
    g2.setFont(font);
    g2.drawString(text, sx, sy);
  }
Beispiel #4
0
  /** {@inheritDoc} */
  @Override
  @TestMethod("testEmptyReaction")
  public IRenderingElement generate(IReaction reaction, RendererModel model) {
    if (!model.getParameter(ShowReactionBoxes.class).getValue()) return null;
    double separation =
        model.getParameter(BondLength.class).getValue()
            / model.getParameter(Scale.class).getValue();
    Rectangle2D totalBounds = BoundsCalculator.calculateBounds(reaction);
    if (totalBounds == null) return null;

    ElementGroup diagram = new ElementGroup();
    Color foregroundColor =
        model.getParameter(BasicSceneGenerator.ForegroundColor.class).getValue();
    diagram.add(
        new RectangleElement(
            totalBounds.getMinX() - separation,
            totalBounds.getMinY() - separation,
            totalBounds.getMaxX() + separation,
            totalBounds.getMaxY() + separation,
            foregroundColor));
    if (reaction.getID() != null) {
      diagram.add(
          new TextElement(
              (totalBounds.getMinX() + totalBounds.getMaxX()) / 2,
              totalBounds.getMinY() - separation,
              reaction.getID(),
              foregroundColor));
    }
    return diagram;
  }
 /** @param rectangle */
 public void setClipPolygon(Rectangle2D rectangle) {
   PolygonSimple poly = new PolygonSimple();
   poly.add(rectangle.getMinX(), rectangle.getMinY());
   poly.add(rectangle.getMaxX(), rectangle.getMinY());
   poly.add(rectangle.getMaxX(), rectangle.getMaxY());
   poly.add(rectangle.getMinX(), rectangle.getMaxY());
   setClipPolygon(poly);
 }
Beispiel #6
0
  private void paintFirms(Graphics2D g2d) {

    Rectangle2D rec = new Rectangle2D.Double();
    ArrayList<Firm> firms = SleepStoneTest.firms;

    Stroke normalStroke = new BasicStroke();
    Stroke boldStroke = new BasicStroke(4f);

    g2d.setStroke(boldStroke);
    for (Firm x : firms) {
      rec.setRect(firmsPlace.get(x));
      FirmStatus status = x.getStatus();

      g2d.setColor(Color.black);

      g2d.drawString(x.getFirmName(), Math.round(rec.getMinX()), Math.round(rec.getMaxY() + 15d));

      g2d.drawString(
          Integer.toString(x.getWorkers().size()),
          Math.round(rec.getMinX()),
          Math.round(rec.getMinY() - 15d));
      // g2d.setColor(Color.RED);
      g2d.drawImage(
          firmIcon.getImage(),
          (int) rec.getX(),
          (int) rec.getY(),
          (int) rec.getWidth(),
          (int) rec.getHeight(),
          FirmStatus.getStatusColor(status),
          null);

      // draw the jobs done indicator
      if (status == FirmStatus.PRODUCING) {
        g2d.setColor(Color.black);
        g2d.setStroke(boldStroke);
        Rectangle jobsIndicator =
            new Rectangle(
                (int) rec.getMaxX() + 5,
                (int) rec.getMinY(),
                (int) (firmSpacing / 2d),
                (int) rec.getHeight());
        g2d.draw(jobsIndicator);
        float jobsToDo = x.getJobsToDo();
        float jobsDone = x.getJobsDone().availablePermits();
        float percentComplete = jobsDone / jobsToDo;
        g2d.setColor(Color.BLUE);
        jobsIndicator.setBounds(
            (int) rec.getMaxX() + 5,
            (int) rec.getMinY(),
            (int) (firmSpacing / 2d),
            (int) (((float) (rec.getHeight())) * percentComplete));
        g2d.fill(jobsIndicator);
        g2d.setStroke(normalStroke);
      }
      // index++;
    }
  }
  public VoronoiCore(Rectangle2D rectangle) {
    PolygonSimple poly = new PolygonSimple(4);
    poly.add(rectangle.getMinX(), rectangle.getMinY());
    poly.add(rectangle.getMinX() + rectangle.getWidth(), rectangle.getMinY());
    poly.add(
        rectangle.getMinX() + rectangle.getWidth(), rectangle.getMinY() + rectangle.getHeight());
    poly.add(rectangle.getMinX(), rectangle.getMinY() + rectangle.getHeight());

    this.clipPolygon = poly;
    init();
    diagram.setClipPoly(poly);
  }
  /**
   * @param x x coordinate in PDF units
   * @param y y coordinate in PDF units
   * @param centre if true, centre this location in the viewport, otherwise cause it to be displayed
   *     at the top left of the viewport.
   */
  private void ensureVisible(PDFPage page, double x, double y, boolean centre) {
    PDFPage oldPage = view.getPage();
    Collection<PagePanel> oldPagePanels = view.getPagePanels();
    view.setPage(page, false);
    Rectangle pageRect = view.getPageRectangle(page);

    if (pageRect != null) {
      Rectangle2D crop = PagePanel.getFullPageView(page);
      int xoffset = pageRect.x, yoffset = pageRect.y;
      if (x > crop.getMinX()) { // Also confirms !NaN
        xoffset += pointsToPixels((float) (Math.min(crop.getMaxX(), x) - crop.getMinX()));
      }
      if (y < crop.getMaxY()) { // Also confirms !NaN
        yoffset += pointsToPixels((float) (crop.getHeight() - Math.max(0, y - crop.getMinY())));
      }

      JScrollBar hsb = scrollPane.getHorizontalScrollBar();
      JScrollBar vsb = scrollPane.getVerticalScrollBar();
      if (centre) {
        xoffset -= hsb.getVisibleAmount() / 2;
        yoffset -= vsb.getVisibleAmount() / 2;
      }
      if (getPagePanel() != null && getPagePanel().getClip() != null) {
        hsb.setValue(xoffset); // Don't want to smooth scroll if we're clipping
        vsb.setValue(yoffset); // the page rectangles.
      } else {
        smoothScroll(xoffset, yoffset, hsb, vsb);
      }
    }
    if (page != oldPage) {
      DocumentPanel docpanel = getDocumentPanel();
      if (docpanel != null) {
        DocumentPanelEvent dpe = DocumentPanelEvent.createPageChanged(docpanel);
        dpe.setPreviousPage(oldPage);
        docpanel.raiseDocumentPanelEvent(dpe);
      }
      Collection<PagePanel> newPagePanels = view.getPagePanels();
      for (Iterator<PagePanel> i = oldPagePanels.iterator(); i.hasNext(); ) {
        PagePanel oldPagePanel = i.next();
        if (!newPagePanels.contains(oldPagePanel)) {
          oldPagePanel.raisePagePanelEvent(PagePanelEvent.createPageHidden(oldPagePanel, oldPage));
        }
      }
      for (Iterator<PagePanel> i = newPagePanels.iterator(); i.hasNext(); ) {
        PagePanel newPagePanel = i.next();
        if (!oldPagePanels.contains(newPagePanel)) {
          newPagePanel.raisePagePanelEvent(PagePanelEvent.createPageVisible(newPagePanel, page));
        }
      }
    }
  }
Beispiel #9
0
 /**
  * Returns the polygon surrounding the specified rectangle. Code lifted from ArcGridDataSource
  * (temporary).
  */
 public static Polygon getPolygon(final Rectangle2D rect, final int srid) {
   final PrecisionModel pm = new PrecisionModel();
   final GeometryFactory gf = new GeometryFactory(pm, srid);
   final Coordinate[] coord =
       new Coordinate[] {
         new Coordinate(rect.getMinX(), rect.getMinY()),
         new Coordinate(rect.getMaxX(), rect.getMinY()),
         new Coordinate(rect.getMaxX(), rect.getMaxY()),
         new Coordinate(rect.getMinX(), rect.getMaxY()),
         new Coordinate(rect.getMinX(), rect.getMinY())
       };
   final LinearRing ring = gf.createLinearRing(coord);
   return new Polygon(ring, null, gf);
 }
Beispiel #10
0
  @Override
  public Rectangle2D getBoundingBoxInLocalSpace() {
    Rectangle2D bb = getContentsBoundingBox();

    // Increase bb by the label height (to include the latter into the bb)
    if (labelBB != null) {
      bb.add(bb.getMinX(), bb.getMinY() - labelBB.getHeight());
    }
    // Increase bb by the encoding height (to include the latter into the bb)
    if (encodingBB != null) {
      bb.add(bb.getMinX(), bb.getMaxY() + encodingBB.getHeight());
    }

    return bb;
  }
Beispiel #11
0
  private Rectangle2D getContentsBoundingBox() {
    Rectangle2D bb = null;

    for (VisualVertex v : Hierarchy.getChildrenOfType(this, VisualVertex.class)) {
      bb = BoundingBoxHelper.union(bb, v.getBoundingBox());
    }
    for (VisualVariable v : Hierarchy.getChildrenOfType(this, VisualVariable.class)) {
      bb = BoundingBoxHelper.union(bb, v.getBoundingBox());
    }
    for (VisualArc a : Hierarchy.getChildrenOfType(this, VisualArc.class)) {
      bb = BoundingBoxHelper.union(bb, a.getLabelBoundingBox());
    }
    if (bb == null) bb = contentsBB;
    else {
      bb.setRect(
          bb.getMinX() - frameDepth,
          bb.getMinY() - frameDepth,
          bb.getWidth() + 2.0 * frameDepth,
          bb.getHeight() + 2.0 * frameDepth);
    }

    if (bb == null) bb = new Rectangle2D.Double(0, 0, 1, 1);

    contentsBB = (Rectangle2D) bb.clone();

    return bb;
  }
Beispiel #12
0
  /**
   * Draws the needle.
   *
   * @param g2 the graphics device.
   * @param plotArea the plot area.
   * @param rotate the rotation point.
   * @param angle the angle.
   */
  @Override
  protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {

    Area shape;
    GeneralPath pointer = new GeneralPath();

    int minY = (int) (plotArea.getMinY());
    // int maxX = (int) (plotArea.getMaxX());
    int maxY = (int) (plotArea.getMaxY());
    int midX = (int) (plotArea.getMinX() + (plotArea.getWidth() / 2));
    // int midY = (int) (plotArea.getMinY() + (plotArea.getHeight() / 2));
    int lenX = (int) (plotArea.getWidth() / 10);
    if (lenX < 2) {
      lenX = 2;
    }

    pointer.moveTo(midX - lenX, maxY - lenX);
    pointer.lineTo(midX + lenX, maxY - lenX);
    pointer.lineTo(midX, minY + lenX);
    pointer.closePath();

    lenX = 4 * lenX;
    Ellipse2D circle = new Ellipse2D.Double(midX - lenX / 2, plotArea.getMaxY() - lenX, lenX, lenX);

    shape = new Area(circle);
    shape.add(new Area(pointer));
    if ((rotate != null) && (angle != 0)) {
      /// we have rotation
      getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
      shape.transform(getTransform());
    }

    defaultDisplay(g2, shape);
  }
 public void visit(PointSet p) {
   // Following code should only be activated if we have listeners installed to update
   // the bounding box when it goes out of date.
   if (checkForBoundingBox(p)) return;
   Object domain = p.getGeometryAttributes(GeometryUtility.HEIGHT_FIELD_SHAPE);
   if (domain != null && domain instanceof Rectangle2D) {
     Rectangle2D box = (Rectangle2D) domain;
     double[][] data = p.getVertexAttributes(Attribute.COORDINATES).toDoubleArrayArray(null);
     double[][] zbnds = new double[2][1];
     Rn.calculateBounds(zbnds, data);
     double[][] xyzbnds = new double[2][3];
     xyzbnds[0][0] = box.getMinX();
     xyzbnds[1][0] = box.getMaxX();
     xyzbnds[0][1] = box.getMinY();
     xyzbnds[1][1] = box.getMaxY();
     xyzbnds[0][2] = zbnds[0][0];
     xyzbnds[1][2] = zbnds[1][0];
     if (Double.isNaN(xyzbnds[0][0])) throw new IllegalStateException("Nan");
     Rectangle3D box3 = new Rectangle3D(xyzbnds);
     unionBox(box3);
     return;
   }
   DataList vv = p.getVertexAttributes(Attribute.COORDINATES);
   if (vv == null) {
     // signal error
     return;
   }
   unionVectors(vv);
 }
  /**
   * Draws a grid line against the range axis.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param axis the value axis.
   * @param dataArea the area for plotting data (not yet adjusted for any 3D effect).
   * @param value the value at which the grid line should be drawn.
   */
  public void drawRangeGridline(
      Graphics2D g2, CategoryPlot plot, ValueAxis axis, Rectangle2D dataArea, double value) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
      return;
    }

    PlotOrientation orientation = plot.getOrientation();
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    Line2D line = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
      line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
    } else if (orientation == PlotOrientation.VERTICAL) {
      line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
    }

    Paint paint = plot.getRangeGridlinePaint();
    if (paint == null) {
      paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;
    }
    g2.setPaint(paint);

    Stroke stroke = plot.getRangeGridlineStroke();
    if (stroke == null) {
      stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
    }
    g2.setStroke(stroke);

    g2.draw(line);
  }
  /**
   * Draws a grid line against the domain axis.
   *
   * <p>Note that this default implementation assumes that the horizontal axis is the domain axis.
   * If this is not the case, you will need to override this method.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param dataArea the area for plotting data (not yet adjusted for any 3D effect).
   * @param value the Java2D value at which the grid line should be drawn.
   */
  public void drawDomainGridline(
      Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, double value) {

    Line2D line = null;
    PlotOrientation orientation = plot.getOrientation();

    if (orientation == PlotOrientation.HORIZONTAL) {
      line = new Line2D.Double(dataArea.getMinX(), value, dataArea.getMaxX(), value);
    } else if (orientation == PlotOrientation.VERTICAL) {
      line = new Line2D.Double(value, dataArea.getMinY(), value, dataArea.getMaxY());
    }

    Paint paint = plot.getDomainGridlinePaint();
    if (paint == null) {
      paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;
    }
    g2.setPaint(paint);

    Stroke stroke = plot.getDomainGridlineStroke();
    if (stroke == null) {
      stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
    }
    g2.setStroke(stroke);

    g2.draw(line);
  }
  /**
   * Converts a data value to a coordinate in Java2D space, assuming that the axis runs along one
   * edge of the specified plotArea. Note that it is possible for the coordinate to fall outside the
   * plotArea.
   *
   * @param value the data value.
   * @param plotArea the area for plotting the data.
   * @param edge the axis location.
   * @return The Java2D coordinate.
   */
  @Override
  public double valueToJava2D(double value, Rectangle2D plotArea, RectangleEdge edge) {

    Range range = getRange();
    double axisMin = switchedLog10(range.getLowerBound());
    double axisMax = switchedLog10(range.getUpperBound());

    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
      min = plotArea.getMinX();
      max = plotArea.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
      min = plotArea.getMaxY();
      max = plotArea.getMinY();
    }

    value = switchedLog10(value);

    if (isInverted()) {
      return max - (((value - axisMin) / (axisMax - axisMin)) * (max - min));
    } else {
      return min + (((value - axisMin) / (axisMax - axisMin)) * (max - min));
    }
  }
  /**
   * Draws a grid line against the domain axis.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param dataArea the area for plotting data (not yet adjusted for any 3D effect).
   * @param value the Java2D value at which the grid line should be drawn.
   */
  public void drawDomainGridline(
      Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, double value) {

    Line2D line1 = null;
    Line2D line2 = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
      double y0 = value;
      double y1 = value - getYOffset();
      double x0 = dataArea.getMinX();
      double x1 = x0 + getXOffset();
      double x2 = dataArea.getMaxX();
      line1 = new Line2D.Double(x0, y0, x1, y1);
      line2 = new Line2D.Double(x1, y1, x2, y1);
    } else if (orientation == PlotOrientation.VERTICAL) {
      double x0 = value;
      double x1 = value + getXOffset();
      double y0 = dataArea.getMaxY();
      double y1 = y0 - getYOffset();
      double y2 = dataArea.getMinY();
      line1 = new Line2D.Double(x0, y0, x1, y1);
      line2 = new Line2D.Double(x1, y1, x1, y2);
    }
    Paint paint = plot.getDomainGridlinePaint();
    Stroke stroke = plot.getDomainGridlineStroke();
    g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT);
    g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_STROKE);
    g2.draw(line1);
    g2.draw(line2);
  }
Beispiel #18
0
  /**
   * Draws a grid line against the domain axis.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param dataArea the area for plotting data (not yet adjusted for any 3D effect).
   * @param value the Java2D value at which the grid line should be drawn.
   */
  @Override
  public void drawDomainGridline(
      Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, double value) {

    Line2D line1 = null;
    Line2D line2 = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
      double y0 = value;
      double y1 = value - getYOffset();
      double x0 = dataArea.getMinX();
      double x1 = x0 + getXOffset();
      double x2 = dataArea.getMaxX();
      line1 = new Line2D.Double(x0, y0, x1, y1);
      line2 = new Line2D.Double(x1, y1, x2, y1);
    } else if (orientation == PlotOrientation.VERTICAL) {
      double x0 = value;
      double x1 = value + getXOffset();
      double y0 = dataArea.getMaxY();
      double y1 = y0 - getYOffset();
      double y2 = dataArea.getMinY();
      line1 = new Line2D.Double(x0, y0, x1, y1);
      line2 = new Line2D.Double(x1, y1, x1, y2);
    }
    g2.setPaint(plot.getDomainGridlinePaint());
    g2.setStroke(plot.getDomainGridlineStroke());
    g2.draw(line1);
    g2.draw(line2);
  }
Beispiel #19
0
  public void testCropRectangle() throws Exception {
    final Envelope rasterEnvelope = geoRasterSrc.getMetadata().getEnvelope();
    geoRasterSrc.save(tmpData + "1.tif");
    final int buffer = (int) (rasterEnvelope.getWidth() / 2.3);
    final Rectangle2D cropRectangle =
        new Rectangle2D.Double(
            rasterEnvelope.getMinX() + buffer,
            rasterEnvelope.getMinY() + buffer,
            rasterEnvelope.getWidth() - 2 * buffer,
            rasterEnvelope.getHeight() - 2 * buffer);
    geoRasterDst = geoRasterSrc.doOperation(new Crop(cropRectangle));
    geoRasterDst.save(tmpData + "2.tif");

    assertTrue(geoRasterDst.getWidth() > 0);
    assertTrue(geoRasterDst.getHeight() > 0);

    final ImagePlus srcImagePlus = geoRasterSrc.getImagePlus();
    final ImagePlus dstImagePlus = geoRasterDst.getImagePlus();
    RasterMetadata dstMetadata = geoRasterDst.getMetadata();
    RasterMetadata srcMetadata = geoRasterSrc.getMetadata();
    assertTrue(dstMetadata.getEnvelope().getMinX() < cropRectangle.getMinX());
    assertTrue(dstMetadata.getEnvelope().getMinY() < cropRectangle.getMinY());
    assertTrue(dstMetadata.getEnvelope().getMaxX() > cropRectangle.getMaxX());
    assertTrue(dstMetadata.getEnvelope().getMaxY() > cropRectangle.getMaxY());
    assertTrue(dstMetadata.getEnvelope().getWidth() < srcMetadata.getEnvelope().getWidth());
    checkCrop(geoRasterDst.getMetadata().getEnvelope(), srcImagePlus, dstImagePlus);
  }
Beispiel #20
0
  /**
   * Draws the circle.
   *
   * @param g2 the graphics device.
   * @param area the area in which to draw.
   */
  public void draw(Graphics2D g2, Rectangle2D area) {
    Ellipse2D ellipse =
        new Ellipse2D.Double(
            area.getX(), area.getY(),
            area.getWidth(), area.getHeight());
    if (this.fillPaint != null) {
      g2.setPaint(this.fillPaint);
      g2.fill(ellipse);
    }
    if (this.outlinePaint != null && this.outlineStroke != null) {
      g2.setPaint(this.outlinePaint);
      g2.setStroke(this.outlineStroke);
      g2.draw(ellipse);
    }

    g2.setPaint(Color.black);
    g2.setStroke(new BasicStroke(1.0f));
    Line2D line1 =
        new Line2D.Double(
            area.getCenterX(), area.getMinY(),
            area.getCenterX(), area.getMaxY());
    Line2D line2 =
        new Line2D.Double(
            area.getMinX(), area.getCenterY(),
            area.getMaxX(), area.getCenterY());
    g2.draw(line1);
    g2.draw(line2);
  }
  /**
   * Converts a coordinate from Java 2D space to data space.
   *
   * @param java2DValue the coordinate in Java2D space.
   * @param dataArea the data area.
   * @param edge the edge.
   * @return The data value.
   */
  public double java2DToValue(double java2DValue, Rectangle2D dataArea, RectangleEdge edge) {
    Range range = getRange();

    double vmax = range.getUpperBound();
    double vp = getCycleBound();

    double jmin = 0.0;
    double jmax = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
      jmin = dataArea.getMinX();
      jmax = dataArea.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
      jmin = dataArea.getMaxY();
      jmax = dataArea.getMinY();
    }

    if (isInverted()) {
      double jbreak = jmax - (vmax - vp) * (jmax - jmin) / this.period;
      if (java2DValue >= jbreak) {
        return vp + (jmax - java2DValue) * this.period / (jmax - jmin);
      } else {
        return vp - (java2DValue - jmin) * this.period / (jmax - jmin);
      }
    } else {
      double jbreak = (vmax - vp) * (jmax - jmin) / this.period + jmin;
      if (java2DValue <= jbreak) {
        return vp + (java2DValue - jmin) * this.period / (jmax - jmin);
      } else {
        return vp - (jmax - java2DValue) * this.period / (jmax - jmin);
      }
    }
  }
 /**
  * Transforms a <code>GradientPaint</code> instance to fit the specified
  * <code>target</code> shape.
  * 
  * @param paint  the original paint (<code>null</code> not permitted).
  * @param target  the target shape (<code>null</code> not permitted).
  * 
  * @return The transformed paint.
  */
 public GradientPaint transform(final GradientPaint paint, 
                                final Shape target) {
     
     GradientPaint result = paint;
     final Rectangle2D bounds = target.getBounds2D();
     
     if (this.type.equals(GradientPaintTransformType.VERTICAL)) {
         result = new GradientPaint((float) bounds.getCenterX(), 
                 (float) bounds.getMinY(), paint.getColor1(), 
                 (float) bounds.getCenterX(), (float) bounds.getMaxY(), 
                 paint.getColor2());
     }
     else if (this.type.equals(GradientPaintTransformType.HORIZONTAL)) {
         result = new GradientPaint((float) bounds.getMinX(), 
                 (float) bounds.getCenterY(), paint.getColor1(), 
                 (float) bounds.getMaxX(), (float) bounds.getCenterY(), 
                 paint.getColor2());            
     }
     else if (this.type.equals(
             GradientPaintTransformType.CENTER_HORIZONTAL)) {
         result = new GradientPaint((float) bounds.getCenterX(), 
                 (float) bounds.getCenterY(), paint.getColor2(), 
                 (float) bounds.getMaxX(), (float) bounds.getCenterY(), 
                 paint.getColor1(), true);            
     }
     else if (this.type.equals(GradientPaintTransformType.CENTER_VERTICAL)) {
         result = new GradientPaint((float) bounds.getCenterX(), 
                 (float) bounds.getMinY(), paint.getColor1(), 
                 (float) bounds.getCenterX(), (float) bounds.getCenterY(), 
                 paint.getColor2(), true);            
     }
     
     return result;
 }
Beispiel #23
0
  private static Point2D intersectionPoint2D(
      Side side, Point2D p1, Point2D p2, Rectangle2D boundingBox) {

    if (side == Side.top) {
      final double topEdge = boundingBox.getMaxY();
      return new Point2D.Double(
          p1.getX() + (topEdge - p1.getY()) * (p2.getX() - p1.getX()) / (p2.getY() - p1.getY()),
          topEdge);
    } else if (side == Side.bottom) {
      final double bottomEdge = boundingBox.getMinY();
      return new Point2D.Double(
          p1.getX() + (bottomEdge - p1.getY()) * (p2.getX() - p1.getX()) / (p2.getY() - p1.getY()),
          bottomEdge);
    } else if (side == Side.right) {
      final double rightEdge = boundingBox.getMaxX();
      return new Point2D.Double(
          rightEdge,
          p1.getY() + (rightEdge - p1.getX()) * (p2.getY() - p1.getY()) / (p2.getX() - p1.getX()));
    } else if (side == Side.left) {
      final double leftEdge = boundingBox.getMinX();
      return new Point2D.Double(
          leftEdge,
          p1.getY() + (leftEdge - p1.getX()) * (p2.getY() - p1.getY()) / (p2.getX() - p1.getX()));
    }
    return null;
  }
Beispiel #24
0
    /**
     * Draws the needle.
     *
     * @param g2  the graphics device.
     * @param plotArea  the plot area.
     * @param rotate  the rotation point.
     * @param angle  the angle.
     */
    protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea,
                              Point2D rotate, double angle) {

        Arc2D shape = new Arc2D.Double(Arc2D.PIE);
        double radius = plotArea.getHeight();
        double halfX = plotArea.getWidth() / 2;
        double diameter = 2 * radius;

        shape.setFrame(plotArea.getMinX() + halfX - radius ,
                       plotArea.getMinY() - radius,
                       diameter, diameter);
        radius = Math.toDegrees(Math.asin(halfX / radius));
        shape.setAngleStart(270 - radius);
        shape.setAngleExtent(2 * radius);

        Area s = new Area(shape);

        if ((rotate != null) && (angle != 0)) {
            /// we have rotation houston, please spin me
            getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
            s.transform(getTransform());
        }

        defaultDisplay(g2, s);
    }
Beispiel #25
0
 private static boolean isInsideClip(Point2D p, Side side, Rectangle2D boundingBox) {
   if (side == Side.top) return (p.getY() <= boundingBox.getMaxY());
   else if (side == Side.bottom) return (p.getY() >= boundingBox.getMinY());
   else if (side == Side.left) return (p.getX() >= boundingBox.getMinX());
   else if (side == Side.right) return (p.getX() <= boundingBox.getMaxX());
   else throw new RuntimeException("Error in Polygon");
 }
Beispiel #26
0
 /**
  * This test demonstrates the read of the network's physical bounds.
  *
  * @throws IOException
  */
 @Test
 public void testGetBounds() throws IOException {
   Rectangle2D bounds = conn.getSimulationData().queryNetBoundaries().get();
   assertEquals(0.0, bounds.getMinX(), DELTA);
   assertEquals(0.0, bounds.getMinY(), DELTA);
   assertEquals(2500.0, bounds.getMaxX(), DELTA);
   assertEquals(500.0, bounds.getMaxY(), DELTA);
 }
 public void setPage(PDFPage page, double x, double y, double zoom) {
   if (page.getPDF() != pdf) {
     throw new IllegalArgumentException("Page is from a different PDF");
   }
   setZoom((float) zoom);
   Rectangle2D crop = PagePanel.getFullPageView(page);
   ensureVisible(page, crop.getMinX() + x, crop.getMaxY() - y, false);
 }
Beispiel #28
0
  /**
   * Wraps a grid coverage into a Feature. Code lifted from ArcGridDataSource (temporary).
   *
   * @param reader the grid coverage reader.
   * @return a feature with the grid coverage envelope as the geometry and the grid coverage itself
   *     in the "grid" attribute.
   */
  @SuppressWarnings("unchecked")
  public static SimpleFeatureCollection wrapGridCoverageReader(
      final GridCoverage2DReader gridCoverageReader, GeneralParameterValue[] params)
      throws TransformException, FactoryRegistryException, SchemaException {

    // create surrounding polygon
    final PrecisionModel pm = new PrecisionModel();
    final GeometryFactory gf = new GeometryFactory(pm, 0);
    final Rectangle2D rect = gridCoverageReader.getOriginalEnvelope().toRectangle2D();
    final CoordinateReferenceSystem sourceCrs =
        CRS.getHorizontalCRS(gridCoverageReader.getCoordinateReferenceSystem());
    if (sourceCrs == null)
      throw new UnsupportedOperationException(
          Errors.format(
              ErrorKeys.CANT_SEPARATE_CRS_$1, gridCoverageReader.getCoordinateReferenceSystem()));

    final Coordinate[] coord = new Coordinate[5];
    coord[0] = new Coordinate(rect.getMinX(), rect.getMinY());
    coord[1] = new Coordinate(rect.getMaxX(), rect.getMinY());
    coord[2] = new Coordinate(rect.getMaxX(), rect.getMaxY());
    coord[3] = new Coordinate(rect.getMinX(), rect.getMaxY());
    coord[4] = new Coordinate(rect.getMinX(), rect.getMinY());

    // }
    final LinearRing ring = gf.createLinearRing(coord);
    final Polygon bounds = new Polygon(ring, null, gf);

    SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(getTypeFactory());
    ftb.setName("GridCoverage");
    ftb.add("geom", Polygon.class, sourceCrs);
    ftb.add("grid", GridCoverage2DReader.class);
    ftb.add("params", GeneralParameterValue[].class);
    SimpleFeatureType schema = ftb.buildFeatureType();

    // create the feature
    SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema, getFeatureFactory());
    fb.add(bounds);
    fb.add(gridCoverageReader);
    fb.add(params);
    SimpleFeature feature = fb.buildFeature(null);

    final DefaultFeatureCollection collection = new DefaultFeatureCollection();
    collection.add(feature);
    return collection;
  }
  /**
   * Create a VisAD UnionSet from a McIDAS Base Map file inputstream
   *
   * @param is input stream of mapfile
   * @param bbox lat/lon bounding box
   * @exception IOException if there was a problem reading the inputstream
   * @exception VisADException if an unexpected problem occurs.
   */
  public BaseMapAdapter(InputStream is, Rectangle2D bbox) throws IOException, VisADException {

    din = new DataInputStream(new BufferedInputStream(is));
    InitFile();
    if (bbox != null)
      setLatLonLimits(
          (float) bbox.getMinY(), (float) bbox.getMaxY(),
          (float) bbox.getMinX(), (float) bbox.getMaxX());
  }
Beispiel #30
0
  /**
   * Draws the annotation. This method is usually called by the {@link XYPlot} class, you shouldn't
   * need to call it directly.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param dataArea the data area.
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param rendererIndex the renderer index.
   * @param info the plot rendering info.
   */
  public void draw(
      Graphics2D g2,
      XYPlot plot,
      Rectangle2D dataArea,
      ValueAxis domainAxis,
      ValueAxis rangeAxis,
      int rendererIndex,
      PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge =
        Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge =
        Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);

    // compute transform matrix elements via sample points. Assume no
    // rotation or shear.
    Rectangle2D bounds = this.shape.getBounds2D();
    double x0 = bounds.getMinX();
    double x1 = bounds.getMaxX();
    double xx0 = domainAxis.valueToJava2D(x0, dataArea, domainEdge);
    double xx1 = domainAxis.valueToJava2D(x1, dataArea, domainEdge);
    double m00 = (xx1 - xx0) / (x1 - x0);
    double m02 = xx0 - x0 * m00;

    double y0 = bounds.getMaxY();
    double y1 = bounds.getMinY();
    double yy0 = rangeAxis.valueToJava2D(y0, dataArea, rangeEdge);
    double yy1 = rangeAxis.valueToJava2D(y1, dataArea, rangeEdge);
    double m11 = (yy1 - yy0) / (y1 - y0);
    double m12 = yy0 - m11 * y0;

    //  create transform & transform shape
    Shape s = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
      AffineTransform t1 = new AffineTransform(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
      AffineTransform t2 = new AffineTransform(m11, 0.0f, 0.0f, m00, m12, m02);
      s = t1.createTransformedShape(this.shape);
      s = t2.createTransformedShape(s);
    } else if (orientation == PlotOrientation.VERTICAL) {
      AffineTransform t = new AffineTransform(m00, 0, 0, m11, m02, m12);
      s = t.createTransformedShape(this.shape);
    }

    if (this.fillPaint != null) {
      g2.setPaint(this.fillPaint);
      g2.fill(s);
    }

    if (this.stroke != null && this.outlinePaint != null) {
      g2.setPaint(this.outlinePaint);
      g2.setStroke(this.stroke);
      g2.draw(s);
    }
    addEntity(info, s, rendererIndex, getToolTipText(), getURL());
  }