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);
 }
Beispiel #2
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;
  }
 /**
  * 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 #4
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);
  }
Beispiel #6
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 #7
0
  /**
   * Draws a range marker.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param axis the value axis.
   * @param marker the marker.
   * @param dataArea the area for plotting data (not including 3D effect).
   */
  @Override
  public void drawRangeMarker(
      Graphics2D g2, CategoryPlot plot, ValueAxis axis, Marker marker, Rectangle2D dataArea) {

    Rectangle2D adjusted =
        new Rectangle2D.Double(
            dataArea.getX(),
            dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(),
            dataArea.getHeight() - getYOffset());

    if (marker instanceof ValueMarker) {
      ValueMarker vm = (ValueMarker) marker;
      double value = vm.getValue();
      Range range = axis.getRange();
      if (!range.contains(value)) {
        return;
      }

      GeneralPath path = null;
      PlotOrientation orientation = plot.getOrientation();
      if (orientation == PlotOrientation.HORIZONTAL) {
        float x = (float) axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
        float y = (float) adjusted.getMaxY();
        path = new GeneralPath();
        path.moveTo(x, y);
        path.lineTo((float) (x + getXOffset()), y - (float) getYOffset());
        path.lineTo((float) (x + getXOffset()), (float) (adjusted.getMinY() - getYOffset()));
        path.lineTo(x, (float) adjusted.getMinY());
        path.closePath();
      } else if (orientation == PlotOrientation.VERTICAL) {
        float y = (float) axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
        float x = (float) dataArea.getX();
        path = new GeneralPath();
        path.moveTo(x, y);
        path.lineTo(x + (float) this.xOffset, y - (float) this.yOffset);
        path.lineTo((float) (adjusted.getMaxX() + this.xOffset), y - (float) this.yOffset);
        path.lineTo((float) (adjusted.getMaxX()), y);
        path.closePath();
      }
      g2.setPaint(marker.getPaint());
      g2.fill(path);
      g2.setPaint(marker.getOutlinePaint());
      g2.draw(path);
    } else {
      super.drawRangeMarker(g2, plot, axis, marker, adjusted);
      // TODO: draw the interval marker with a 3D effect
    }
  }
  /**
   * 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);
  }
 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);
  }
 @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());
   }
 }
Beispiel #12
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;
  }
  /**
   * 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 dataArea.
   *
   * <p>Note that it is possible for the coordinate to fall outside the area.
   *
   * @param value the data value.
   * @param area the area for plotting the data.
   * @param edge the edge along which the axis lies.
   * @return The Java2D coordinate.
   */
  @Override
  public double valueToJava2D(double value, Rectangle2D area, RectangleEdge edge) {

    double result = Double.NaN;
    double axisMin = this.first.getFirstMillisecond();
    double axisMax = this.last.getLastMillisecond();
    if (RectangleEdge.isTopOrBottom(edge)) {
      double minX = area.getX();
      double maxX = area.getMaxX();
      if (isInverted()) {
        result = maxX + ((value - axisMin) / (axisMax - axisMin)) * (minX - maxX);
      } else {
        result = minX + ((value - axisMin) / (axisMax - axisMin)) * (maxX - minX);
      }
    } else if (RectangleEdge.isLeftOrRight(edge)) {
      double minY = area.getMinY();
      double maxY = area.getMaxY();
      if (isInverted()) {
        result = minY + (((value - axisMin) / (axisMax - axisMin)) * (maxY - minY));
      } else {
        result = maxY - (((value - axisMin) / (axisMax - axisMin)) * (maxY - minY));
      }
    }
    return result;
  }
Beispiel #15
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 #16
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 #17
0
  /**
   * Draws the outline for the plot.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param dataArea the area inside the axes.
   */
  @Override
  public void drawOutline(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(this.xOffset);
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(this.xOffset);

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(this.yOffset);
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(this.yOffset);

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    // put an outline around the data area...
    Stroke outlineStroke = plot.getOutlineStroke();
    Paint outlinePaint = plot.getOutlinePaint();
    if ((outlineStroke != null) && (outlinePaint != null)) {
      g2.setStroke(outlineStroke);
      g2.setPaint(outlinePaint);
      g2.draw(clip);
    }
  }
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
  /**
   * 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);
      }
    }
  }
Beispiel #21
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 #22
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 #23
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);
  }
  /**
   * Converts a coordinate in Java2D space to the corresponding data value, assuming that the axis
   * runs along one edge of the specified plotArea.
   *
   * @param java2DValue the coordinate in Java2D space.
   * @param plotArea the area in which the data is plotted.
   * @param edge the axis location.
   * @return The data value.
   */
  @Override
  public double java2DToValue(double java2DValue, Rectangle2D plotArea, RectangleEdge edge) {

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

    double plotMin = 0.0;
    double plotMax = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
      plotMin = plotArea.getX();
      plotMax = plotArea.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
      plotMin = plotArea.getMaxY();
      plotMax = plotArea.getMinY();
    }

    if (isInverted()) {
      return switchedPow10(
          axisMax - ((java2DValue - plotMin) / (plotMax - plotMin)) * (axisMax - axisMin));
    } else {
      return switchedPow10(
          axisMin + ((java2DValue - plotMin) / (plotMax - plotMin)) * (axisMax - axisMin));
    }
  }
  /**
   * 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));
    }
  }
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);
 }
 /** @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 #28
0
 private Rectangle2D getLabelBB() {
   Rectangle2D bb = getContentsBoundingBox();
   return new Rectangle2D.Double(
       bb.getMaxX() - labelBB.getWidth(),
       bb.getMinY() - labelBB.getHeight(),
       labelBB.getWidth(),
       labelBB.getHeight());
 }
Beispiel #29
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());
  }