Ejemplo n.º 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);
 }
Ejemplo n.º 2
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 paintComponent(Graphics g) {
    if (started) {
      width = this.getPreferredSize().getWidth();
      height = this.getPreferredSize().getHeight();
      double maxY = 0.0;

      Graphics2D g2 = (Graphics2D) g;
      g2.setRenderingHints(hints);

      // Disable the glasspane fade
      // g2.setColor(new Color(255, 255, 255, (int) (alphaLevel * shield)));
      // g2.drawRect(0, 0, getWidth(), getHeight());

      for (int i = 0; i < ticker.length; i++) {
        int channel = 224 - 128 / (i + 1);
        g2.setColor(new Color(channel, channel, channel, alphaLevel));
        g2.fill(ticker[i]);

        Rectangle2D bounds = ticker[i].getBounds2D();
        if (bounds.getMaxY() > maxY) maxY = bounds.getMaxY();
      }

      if (text != null && text.length() > 0) {
        FontRenderContext context = g2.getFontRenderContext();
        TextLayout layout = new TextLayout(text, getFont(), context);
        Rectangle2D bounds = layout.getBounds();
        g2.setColor(getForeground());
        layout.draw(
            g2,
            (float) (width - bounds.getWidth()) / 2,
            (float) (maxY + layout.getLeading() + 2 * layout.getAscent()));
      }
    }
  }
Ejemplo n.º 4
0
 @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());
   }
 }
 /**
  * Updates the position and size of the edit panel relative to the given location.
  *
  * @param loc the location the edit panel should be relative to
  * @param absolute if {@code true} the loc is treated as absolute position on the process
  *     renderer; if {@code false} it is treated as relative to the current process
  */
 private void updateEditPanelPosition(final Rectangle2D loc, final boolean absolute) {
   int panelX = (int) loc.getCenterX() - EDIT_PANEL_WIDTH / 2;
   int panelY = (int) loc.getY() - EDIT_PANEL_HEIGHT - ProcessDrawer.PADDING;
   // if panel would be outside process renderer, fix it
   if (panelX < WorkflowAnnotation.MIN_X) {
     panelX = WorkflowAnnotation.MIN_X;
   }
   if (panelY < 0) {
     panelY = (int) loc.getMaxY() + ProcessDrawer.PADDING;
   }
   // last fallback is cramped to the bottom. If that does not fit either, don't care
   if (panelY + EDIT_PANEL_HEIGHT > view.getSize().getHeight() - ProcessDrawer.PADDING * 2) {
     panelY = (int) loc.getMaxY();
   }
   int index = view.getModel().getProcessIndex(model.getSelected().getProcess());
   if (absolute) {
     editPanel.setBounds(panelX, panelY, EDIT_PANEL_WIDTH, EDIT_PANEL_HEIGHT);
   } else {
     Point absoluteP =
         ProcessDrawUtils.convertToAbsoluteProcessPoint(
             new Point(panelX, panelY), index, rendererModel);
     editPanel.setBounds(
         (int) absoluteP.getX(), (int) absoluteP.getY(), EDIT_PANEL_WIDTH, EDIT_PANEL_HEIGHT);
   }
 }
Ejemplo n.º 6
0
  /**
   * 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;
  }
Ejemplo n.º 7
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;
  }
  /**
   * 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);
 }
Ejemplo n.º 10
0
 /**
  * Draws a the title vertically within the specified area. This method will be called from the
  * {@link #draw(Graphics2D, Rectangle2D) draw} method.
  *
  * @param g2 the graphics device.
  * @param area the area for the title.
  */
 protected void drawVertical(Graphics2D g2, Rectangle2D area) {
   Rectangle2D titleArea = (Rectangle2D) area.clone();
   g2.setFont(this.font);
   g2.setPaint(this.paint);
   TextBlockAnchor anchor = null;
   float y = 0.0f;
   VerticalAlignment verticalAlignment = getVerticalAlignment();
   if (verticalAlignment == VerticalAlignment.TOP) {
     y = (float) titleArea.getY();
     anchor = TextBlockAnchor.TOP_RIGHT;
   } else if (verticalAlignment == VerticalAlignment.BOTTOM) {
     y = (float) titleArea.getMaxY();
     anchor = TextBlockAnchor.TOP_LEFT;
   } else if (verticalAlignment == VerticalAlignment.CENTER) {
     y = (float) titleArea.getCenterY();
     anchor = TextBlockAnchor.TOP_CENTER;
   }
   float x = 0.0f;
   RectangleEdge position = getPosition();
   if (position == RectangleEdge.LEFT) {
     x = (float) titleArea.getX();
   } else if (position == RectangleEdge.RIGHT) {
     x = (float) titleArea.getMaxX();
     if (verticalAlignment == VerticalAlignment.TOP) {
       anchor = TextBlockAnchor.BOTTOM_RIGHT;
     } else if (verticalAlignment == VerticalAlignment.CENTER) {
       anchor = TextBlockAnchor.BOTTOM_CENTER;
     } else if (verticalAlignment == VerticalAlignment.BOTTOM) {
       anchor = TextBlockAnchor.BOTTOM_LEFT;
     }
   }
   this.content.draw(g2, x, y, anchor, x, y, -Math.PI / 2.0);
 }
  /**
   * 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));
    }
  }
  /**
   * 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));
    }
  }
Ejemplo n.º 15
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);
  }
Ejemplo n.º 16
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);
  }
Ejemplo n.º 17
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);
  }
Ejemplo n.º 18
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);
    }
  }
Ejemplo n.º 19
0
  /**
   * 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;
 }
Ejemplo n.º 21
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;
  }
Ejemplo n.º 22
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");
 }
Ejemplo n.º 23
0
  /**
   * Draws an axis line at the current cursor position and edge.
   *
   * @param g2 the graphics device.
   * @param cursor the cursor position.
   * @param dataArea the data area.
   * @param edge the edge.
   */
  protected void drawAxisLine(
      Graphics2D g2, double cursor, Rectangle2D dataArea, RectangleEdge edge) {

    Line2D axisLine = null;
    if (edge == RectangleEdge.TOP) {
      axisLine = new Line2D.Double(dataArea.getX(), cursor, dataArea.getMaxX(), cursor);
    } else if (edge == RectangleEdge.BOTTOM) {
      axisLine = new Line2D.Double(dataArea.getX(), cursor, dataArea.getMaxX(), cursor);
    } else if (edge == RectangleEdge.LEFT) {
      axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, dataArea.getMaxY());
    } else if (edge == RectangleEdge.RIGHT) {
      axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, dataArea.getMaxY());
    }
    g2.setPaint(this.axisLinePaint);
    g2.setStroke(this.axisLineStroke);
    g2.draw(axisLine);
  }
 /** @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);
 }
Ejemplo n.º 25
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);
 }
Ejemplo n.º 26
0
 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);
 }
Ejemplo n.º 27
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++;
    }
  }
Ejemplo n.º 28
0
  /**
   * 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());
  }
Ejemplo n.º 29
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());
  }
Ejemplo n.º 30
0
 public void setBounds2D(Rectangle2D bounds) {
   beginUpdate();
   try {
     // set anchors (only 2 significants anchors need to be adjusted)
     topLeft.setPosition(bounds.getMinX(), bounds.getMinY());
     bottomRight.setPosition(bounds.getMaxX(), bounds.getMaxY());
   } finally {
     endUpdate();
   }
 }