Examples of Rectangle2D


Examples of java.awt.geom.Rectangle2D

  /**
   * @see Graphics#setClip(int, int, int, int)
   */
  public void setClip(final int x, final int y, final int width, final int height)
  {
    final Rectangle2D rect = new Rectangle2D.Double(x, y, width, height);
    setClip(rect);
  }
View Full Code Here

Examples of java.awt.geom.Rectangle2D

    {
      try
      {
        final TexturePaint tp = (TexturePaint)paint;
        final BufferedImage img = tp.getImage();
        final Rectangle2D rect = tp.getAnchorRect();
        final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null);
        final PdfPatternPainter pattern = cb.createPattern(image.getWidth(), image.getHeight());
        final AffineTransform inverse = this.normalizeMatrix();
        inverse.translate(rect.getX(), rect.getY());
        inverse.scale(rect.getWidth() / image.getWidth(), -rect.getHeight() / image.getHeight());
        final double[] mx = new double[6];
        inverse.getMatrix(mx);
        pattern.setPatternMatrix((float)mx[0], (float)mx[1], (float)mx[2], (float)mx[3], (float)mx[4], (float)mx[5]) ;
        image.setAbsolutePosition(0,0);
        pattern.addImage(image);
View Full Code Here

Examples of java.awt.geom.Rectangle2D

    {
      height = computeDimension(name, y1, y2);
    }

    // create the bounds as specified by the user
    final Rectangle2D bounds =
        new Rectangle2D.Float(computePosition(name, x1, x2),
            computePosition(name, y1, y2), width, height);

    if (x1 == x2)
    {
      // assume that we have a vertical line
      final VerticalLineElementFactory elementFactory = new VerticalLineElementFactory();
      elementFactory.setName(name);
      elementFactory.setColor(c);
      elementFactory.setStroke(stroke);
      elementFactory.setX(new Float(bounds.getX()));
      elementFactory.setY(new Float(bounds.getY()));
      elementFactory.setMinimumWidth(new Float(bounds.getWidth()));
      elementFactory.setMinimumHeight(new Float(bounds.getHeight()));
      elementFactory.setScale(Boolean.TRUE);
      elementFactory.setKeepAspectRatio(Boolean.FALSE);
      elementFactory.setShouldDraw(Boolean.TRUE);
      element = elementFactory.createElement();
    }
    else if (y1 == y2)
    {
      // assume that we have a horizontal line
      final HorizontalLineElementFactory elementFactory = new HorizontalLineElementFactory();
      elementFactory.setName(name);
      elementFactory.setColor(c);
      elementFactory.setStroke(stroke);
      elementFactory.setX(new Float(bounds.getX()));
      elementFactory.setY(new Float(bounds.getY()));
      elementFactory.setMinimumWidth(new Float(bounds.getWidth()));
      elementFactory.setMinimumHeight(new Float(bounds.getHeight()));
      elementFactory.setScale(Boolean.TRUE);
      elementFactory.setKeepAspectRatio(Boolean.FALSE);
      elementFactory.setShouldDraw(Boolean.TRUE);
      element = elementFactory.createElement();
    }
    else
    {
      // here comes the magic - we transform the line into the absolute space;
      // this should preserve the general appearance. Heck, and if not, then
      // it is part of the users responsibility to resolve that. Magic does not
      // solve all problems, you know.
      final Line2D line = new Line2D.Float
          (Math.abs(x1), Math.abs(y1), Math.abs(x2), Math.abs(y2));
      final Rectangle2D shapeBounds = line.getBounds2D();
      final Shape transformedShape =
          ShapeTransform.translateShape(line, -shapeBounds.getX(), -shapeBounds.getY());
      // and use that shape with the user's bounds to create the element.
      final ContentElementFactory elementFactory = new ContentElementFactory();
      elementFactory.setName(name);
      elementFactory.setColor(c);
      elementFactory.setStroke(stroke);
View Full Code Here

Examples of java.awt.geom.Rectangle2D

    {
      height = Math.max(y2, y1) - Math.min(y2, y1);
    }

    // create the bounds as specified by the user
    final Rectangle2D bounds =
        new Rectangle2D.Float(Math.min(x1, x2), Math.min(y1, y2), width, height);


    if (x1 == x2)
    {
      // assume that we have a vertical line
      final VerticalLineElementFactory elementFactory = new VerticalLineElementFactory();
      elementFactory.setName(name);
      elementFactory.setColor(c);
      elementFactory.setStroke(stroke);
      elementFactory.setX(new Float(bounds.getX()));
      elementFactory.setY(new Float(bounds.getY()));
      elementFactory.setMinimumWidth(new Float(bounds.getWidth()));
      elementFactory.setMinimumHeight(new Float(bounds.getHeight()));
      elementFactory.setScale(Boolean.TRUE);
      elementFactory.setKeepAspectRatio(Boolean.FALSE);
      elementFactory.setShouldDraw(Boolean.TRUE);
      element = elementFactory.createElement();
    }
    else if (y1 == y2)
    {
      // assume that we have a horizontal line
      final HorizontalLineElementFactory elementFactory = new HorizontalLineElementFactory();
      elementFactory.setName(name);
      elementFactory.setColor(c);
      elementFactory.setStroke(stroke);
      elementFactory.setX(new Float(bounds.getX()));
      elementFactory.setY(new Float(bounds.getY()));
      elementFactory.setMinimumWidth(new Float(bounds.getWidth()));
      elementFactory.setMinimumHeight(new Float(bounds.getHeight()));
      elementFactory.setScale(Boolean.TRUE);
      elementFactory.setKeepAspectRatio(Boolean.FALSE);
      elementFactory.setShouldDraw(Boolean.TRUE);
      element = elementFactory.createElement();
    }
    else
    {
      // here comes the magic - we transform the line into the absolute space;
      // this should preserve the general appearance. Heck, and if not, then
      // it is part of the users reponsibility to resolve that. Magic does not
      // solve all problems, you know.
      final Line2D line = new Line2D.Float
          (Math.abs(x1), Math.abs(y1), Math.abs(x2), Math.abs(y2));
      final Rectangle2D shapeBounds = line.getBounds2D();
      final Shape transformedShape =
          ShapeTransform.translateShape(line, -shapeBounds.getX(), -shapeBounds.getY());
      // and use that shape with the user's bounds to create the element.
      final ContentElementFactory elementFactory = new ContentElementFactory();
      elementFactory.setName(name);
      elementFactory.setColor(c);
      elementFactory.setStroke(stroke);
      elementFactory.setX(new Float(shapeBounds.getX()));
      elementFactory.setY(new Float(shapeBounds.getY()));
      elementFactory.setMinimumWidth(new Float(shapeBounds.getWidth()));
      elementFactory.setMinimumHeight(new Float(shapeBounds.getHeight()));
      elementFactory.setContent(transformedShape);
      elementFactory.setScale(Boolean.TRUE);
      elementFactory.setKeepAspectRatio(Boolean.FALSE);
      elementFactory.setShouldDraw(Boolean.TRUE);
      element = elementFactory.createElement();
View Full Code Here

Examples of java.awt.geom.Rectangle2D

  private int findPageFormat(final Rectangle2D[] positions, final long xPosition, final long yPosition)
  {
    final int posCount = positions.length;
    for (int i = 0; i < posCount; i++)
    {
      final Rectangle2D rect = positions[i];
      if (StrictGeomUtility.toInternalValue(rect.getMinY()) == yPosition &&
          StrictGeomUtility.toInternalValue(rect.getMinX()) == xPosition)
      {
        return i;
      }
    }
    return -1;
View Full Code Here

Examples of java.awt.geom.Rectangle2D

    if (draw == false && fill == false)
    {
      return;
    }

    final Rectangle2D b = this.shape.getBounds2D();
    double x = area.getMinX() + b.getWidth() / 2.0 + 1.0;
    final double y = area.getCenterY();
    final Shape s = getShape();
    g2.translate(x, y);
    g2.setPaint(Color.black);
    if (this.draw)
    {
      g2.setStroke(new BasicStroke(0.5f));
      g2.draw(s);
    }
    if (this.fill)
    {
      g2.fill(s);
    }
    g2.translate(-x, -y);
    x += b.getWidth() / 2.0 + 3.0;
    g2.setFont(this.font);

    final FontRenderContext frc = g2.getFontRenderContext();
    final Font f = g2.getFont();
//    final FontMetrics fm = g2.getFontMetrics(f);
View Full Code Here

Examples of java.awt.geom.Rectangle2D

     * Always scale to the maximum bounds ...
     */
    if (scale)
    {

      final Rectangle2D boundsShape = s.getBounds2D();
      final double w = boundsShape.getWidth();
      final double h = boundsShape.getHeight();
      double scaleX = 1;

      if (w != 0)
      {
        scaleX = width / w;
View Full Code Here

Examples of java.awt.geom.Rectangle2D

        return new GeneralPath();
      }
      return new Line2D.Float(clipped[0], clipped[1]);
    }

    final Rectangle2D boundsCorrected = bounds.getBounds2D();
    boundsCorrected.setRect(-DELTA, -DELTA,
        DELTA + boundsCorrected.getWidth(), DELTA + boundsCorrected.getHeight());
    final Area a = new Area(boundsCorrected);
    if (a.isEmpty())
    {
      // don't clip  ... Area does not like lines
      // operations with lines always result in an empty Bounds:(0,0,0,0) area
View Full Code Here

Examples of java.awt.geom.Rectangle2D

   */
  private static Shape performDefaultTransformation(final Shape shape,
                                                    final double scaleX,
                                                    final double scaleY)
  {
    /**
     * Apply the normalisation shape transform ... bring the shape to pos (0,0)
     */
    final Rectangle2D bounds = shape.getBounds2D();
    final AffineTransform translateTransform
        = AffineTransform.getTranslateInstance(0 - bounds.getX(), 0 - bounds.getY());
    // apply normalisation translation ...
    final Shape translatedShape = translateTransform.createTransformedShape(shape);

    final AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
    // apply scaling ...
    final Shape scaledShape = scaleTransform.createTransformedShape(translatedShape);

    // now retranslate the shape to its original position ...
    final AffineTransform translateBackTransform =
        AffineTransform.getTranslateInstance(bounds.getX(), bounds.getY());
    return translateBackTransform.createTransformedShape(scaledShape);
  }
View Full Code Here

Examples of java.awt.geom.Rectangle2D

    {
      return Printable.NO_SUCH_PAGE;
    }

    final Graphics2D g2 = (Graphics2D) graphics;
    final Rectangle2D bounds = new Rectangle2D.Double
        (0, 0, pageFormat.getImageableWidth(), pageFormat.getImageableHeight());
    drawable.draw(g2, bounds);
    return Printable.PAGE_EXISTS;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.