java.awt.Shape#getBounds2D ( )源码实例Demo

下面列出了java.awt.Shape#getBounds2D ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: coming   文件: jMutRepair_0046_s.java
/**
 * Returns a rectangle that encloses the axis label.  This is typically 
 * used for layout purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {

    Rectangle2D result = new Rectangle2D.Double();
    String axisLabel = getLabel();
    if (axisLabel != null && !axisLabel.equals("")) {
        FontMetrics fm = g2.getFontMetrics(getLabelFont());
        Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        RectangleInsets insets = getLabelInsets();
        bounds = insets.createOutsetRectangle(bounds);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer 
            = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }

    return result;

}
 
源代码2 项目: coming   文件: jKali_0041_s.java
/**
 * Returns a rectangle that encloses the axis label.  This is typically 
 * used for layout purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {

    Rectangle2D result = new Rectangle2D.Double();
    String axisLabel = getLabel();
    if (axisLabel != null && !axisLabel.equals("")) {
        FontMetrics fm = g2.getFontMetrics(getLabelFont());
        Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        RectangleInsets insets = getLabelInsets();
        bounds = insets.createOutsetRectangle(bounds);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer 
            = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }

    return result;

}
 
源代码3 项目: coming   文件: Cardumen_0080_t.java
/**
 * Returns a rectangle that encloses the axis label.  This is typically 
 * used for layout purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {

    Rectangle2D result = new Rectangle2D.Double();
    String axisLabel = getLabel();
    if (axisLabel != null && !axisLabel.equals("")) {
        FontMetrics fm = g2.getFontMetrics(getLabelFont());
        Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        RectangleInsets insets = getLabelInsets();
        bounds = insets.createOutsetRectangle(bounds);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer 
            = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }

    return result;

}
 
源代码4 项目: coming   文件: Cardumen_00195_t.java
/**
 * Returns a rectangle that encloses the axis label.  This is typically 
 * used for layout purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {

    Rectangle2D result = new Rectangle2D.Double();
    String axisLabel = getLabel();
    if (axisLabel != null && !axisLabel.equals("")) {
        FontMetrics fm = g2.getFontMetrics(getLabelFont());
        Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        RectangleInsets insets = getLabelInsets();
        bounds = insets.createOutsetRectangle(bounds);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer 
            = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }

    return result;

}
 
源代码5 项目: pumpernickel   文件: AddRulesTest.java
private void reportFailure(String id, Shape good, Shape bad) {
	Rectangle2D r = good.getBounds2D();
	r.add(bad.getBounds2D());

	BufferedImage image = new BufferedImage(500, 500,
			BufferedImage.TYPE_INT_ARGB);
	Graphics2D g = image.createGraphics();
	g.transform(RectangularTransform.create(r,
			new Rectangle(0, 0, image.getWidth(), image.getHeight())));
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	g.setColor(Color.blue);
	g.fill(good);
	g.setColor(new Color(255, 0, 0, 128));
	g.fill(bad);
	g.dispose();
	printStream.println("the resulting shape for \"" + id
			+ "\" wasn't correct.");
	try {
		ImageIO.write(image, "png", new File("comparison " + (ctr++)
				+ ".png"));
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
源代码6 项目: seaglass   文件: AbstractRegionPainter.java
/**
 * Creates a simple vertical gradient using the shape for bounds and the
 * colors for top, two middle, and bottom colors.
 *
 * @param  s      the shape to use for bounds.
 * @param  colors the colors to use for the gradient.
 *
 * @return the gradient.
 */
protected Paint createVerticalGradient(Shape s, FourColors colors) {
    Rectangle2D bounds  = s.getBounds2D();
    float       xCenter = (float) bounds.getCenterX();
    float       yMin    = (float) bounds.getMinY();
    float       yMax    = (float) bounds.getMaxY();

    return createGradient(xCenter, yMin, xCenter, yMax, new float[] { 0f, 0.45f, 0.62f, 1f },
                          new Color[] { colors.top, colors.upperMid, colors.lowerMid, colors.bottom });
}
 
源代码7 项目: seaglass   文件: SplitPaneDividerPainter.java
private Paint decodeSplitPaneDividerBorderGradient(Shape s, Color border1, Color border2) {
    Rectangle2D bounds = s.getBounds2D();
    float midX = (float) bounds.getCenterX();
    float y = (float) bounds.getY();
    float h = (float) bounds.getHeight();
    return createGradient(midX, y, midX, y + h, new float[] { 0.20645161f, 0.5f, 0.7935484f }, new Color[] {
        border1,
        decodeColor(border1, border2, 0.5f),
        border2 });
}
 
源代码8 项目: buffer_bci   文件: Axis.java
/**
 * Returns a rectangle that encloses the axis label.  This is typically
 * used for layout purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {
    Rectangle2D result = new Rectangle2D.Double();
    Rectangle2D bounds = null;
    if (this.attributedLabel != null) {
        TextLayout layout = new TextLayout(
                this.attributedLabel.getIterator(), 
                g2.getFontRenderContext());
        bounds = layout.getBounds();
    } else {
        String axisLabel = getLabel();
        if (axisLabel != null && !axisLabel.equals("")) {
            FontMetrics fm = g2.getFontMetrics(getLabelFont());
            bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        }
    }
    if (bounds != null) {
        RectangleInsets insets = getLabelInsets();
        bounds = insets.createOutsetRectangle(bounds);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer
            = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }
    return result;
}
 
源代码9 项目: testarea-pdfbox2   文件: BoundingBoxFinder.java
@Override
protected void showGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement)
        throws IOException {
    super.showGlyph(textRenderingMatrix, font, code, displacement);
    Shape shape = calculateGlyphBounds(textRenderingMatrix, font, code);
    if (shape != null) {
        Rectangle2D rect = shape.getBounds2D();
        add(rect);
    }
}
 
源代码10 项目: osp   文件: BoundedImage.java
/**
 * Draws the bounds around the image.
 *
 * @param panel the drawing panel
 * @param g  the graphics context
 */
private void drawFixedBounds(DrawingPanel panel, Graphics g) {
  Point2D pt = new Point2D.Double(x, y);
  pt = toPixels.transform(pt, pt);
  Shape temp = new Rectangle2D.Double(pt.getX()-width/2, pt.getY()-height/2, width, height);
  computeFixedHotSpots(temp.getBounds2D());
  pixelBounds = temp.getBounds2D();
  if(theta!=0) {
    pixelBounds = AffineTransform.getRotateInstance(-theta, pt.getX(), pt.getY()).createTransformedShape(pixelBounds);
  }
  if(!selected) {
    return;
  }
  Graphics2D g2 = ((Graphics2D) g);
  g2.setPaint(boundsColor);
  g2.draw(pixelBounds);
  if(xyDrag) {
    g2.fillRect((int) hotSpots[CENTER].getX()-delta, (int) hotSpots[CENTER].getY()-delta, d2, d2);
    g2.setColor(edgeColor);
    g2.fillOval((int) hotSpots[CENTER].getX()-1, (int) hotSpots[CENTER].getY()-1, 3, 3);
    g2.setPaint(boundsColor);
  }
  if(rotateDrag) {
    g2.fillOval((int) hotSpots[CORNER].getX()-delta, (int) hotSpots[CORNER].getY()-delta, d2, d2);
  }
  if(heightDrag) {
    g2.fillRect((int) hotSpots[TOP].getX()-delta, (int) hotSpots[TOP].getY()-delta, d2, d2);
    g2.fillRect((int) hotSpots[BOTTOM].getX()-delta, (int) hotSpots[BOTTOM].getY()-delta, d2, d2);
  }
  if(widthDrag) {
    g2.fillRect((int) hotSpots[LEFT].getX()-delta, (int) hotSpots[LEFT].getY()-delta, d2, d2);
    g2.fillRect((int) hotSpots[RIGHT].getX()-delta, (int) hotSpots[RIGHT].getY()-delta, d2, d2);
  }
  g.setColor(Color.BLACK);
}
 
源代码11 项目: testarea-pdfbox2   文件: PageVerticalAnalyzer.java
@Override
protected void showGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement)
        throws IOException {
    super.showGlyph(textRenderingMatrix, font, code, displacement);
    Shape shape = calculateGlyphBounds(textRenderingMatrix, font, code);
    if (shape != null) {
        Rectangle2D rect = shape.getBounds2D();
        addVerticalUseSection(rect.getMinY(), rect.getMaxY());
    }
}
 
源代码12 项目: seaglass   文件: ToolBarToggleButtonPainter.java
private Paint createToolbarToggleButtonGradient(Shape s, TwoColors colors) {
    Rectangle2D bounds = s.getBounds2D();
    float x = (float) bounds.getX();
    float y = (float) bounds.getY();
    float w = (float) bounds.getWidth();
    float h = (float) bounds.getHeight();
    return createGradient((0.5f * w) + x, y, (0.5f * w) + x, h + y, new float[] { 0f, 0.35f, 0.65f, 1f }, new Color[] {
        colors.top,
        colors.bottom,
        colors.bottom,
        colors.top });
}
 
源代码13 项目: Pixelitor   文件: InnerGlowPathEffect.java
@Override
public void apply(Graphics2D g, Shape clipShape, int width, int height) {
    // opacity support added by lbalazscs
    Composite savedComposite = g.getComposite();
    if (opacity < 1.0f) {
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
    }

    // create a rect to hold the bounds
    Rectangle2D clipShapeBounds = clipShape.getBounds2D();

    if (clipShapeBounds.isEmpty()) {
        // check added by lbalazscs
        return;
    }

    width = (int) (clipShapeBounds.getWidth() + clipShapeBounds.getX());
    height = (int) (clipShapeBounds.getHeight() + clipShapeBounds.getY());
    Rectangle effectBounds = new Rectangle(0, 0, width + 2, height + 2);

    if (effectBounds.isEmpty()) {
        // check added by lbalazscs
        // this can be empty even if the clip shape bounds is not
        // when the clip shape starts at large negative coordinates
        return;
    }

    // Apply the border glow effect
    BufferedImage clipImage = getClipImage(effectBounds);
    Graphics2D g2 = clipImage.createGraphics();

    // lbalazscs: moved here from getClipImage
    // in order to avoid two createGraphics calls
    g2.clearRect(0, 0, clipImage.getWidth(), clipImage.getHeight());

    try {
        // clear the buffer
        g2.setPaint(Color.BLACK);
        g2.setComposite(AlphaComposite.Clear);
        g2.fillRect(0, 0, effectBounds.width, effectBounds.height);

        // turn on smoothing
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        paintBorderGlow(g2, clipShape, width, height);

        // clip out the parts we don't want
        g2.setComposite(AlphaComposite.Clear);
        g2.setColor(Color.WHITE);

        // clip the outside
        Area area = new Area(effectBounds);
        area.subtract(new Area(clipShape));
        g2.fill(area);
    } finally {
        // draw the final image
        g2.dispose();
    }

    g.drawImage(clipImage, 0, 0, null);


    //g.setColor(Color.MAGENTA);
    //g.draw(clipShape.getBounds2D());
    //g.drawRect(0,0,width,height);

    g.setComposite(savedComposite);
}
 
源代码14 项目: dragonwell8_jdk   文件: PeekGraphics.java
/**
 * Add the rectangle 'rect' to the area representing
 * the part of the page which is drawn into.
 */
private void addDrawingRect(Rectangle2D rect) {

    /*  For testing purposes the following line can be uncommented.
        When uncommented it causes the entire page to be rasterized
        thus eliminating errors caused by a faulty bounding box
        calculation.
    */
    //mDrawingArea.addInfinite();



    AffineTransform matrix = getTransform();

    Shape transShape = matrix.createTransformedShape(rect);

    Rectangle2D transRect = transShape.getBounds2D();

    mDrawingArea.add((float) transRect.getMinY(),
                     (float) transRect.getMaxY());


}
 
源代码15 项目: TencentKona-8   文件: PeekGraphics.java
/**
 * Add the rectangle 'rect' to the area representing
 * the part of the page which is drawn into.
 */
private void addDrawingRect(Rectangle2D rect) {

    /*  For testing purposes the following line can be uncommented.
        When uncommented it causes the entire page to be rasterized
        thus eliminating errors caused by a faulty bounding box
        calculation.
    */
    //mDrawingArea.addInfinite();



    AffineTransform matrix = getTransform();

    Shape transShape = matrix.createTransformedShape(rect);

    Rectangle2D transRect = transShape.getBounds2D();

    mDrawingArea.add((float) transRect.getMinY(),
                     (float) transRect.getMaxY());


}
 
源代码16 项目: jdk8u60   文件: PeekGraphics.java
/**
 * Add the rectangle 'rect' to the area representing
 * the part of the page which is drawn into.
 */
private void addDrawingRect(Rectangle2D rect) {

    /*  For testing purposes the following line can be uncommented.
        When uncommented it causes the entire page to be rasterized
        thus eliminating errors caused by a faulty bounding box
        calculation.
    */
    //mDrawingArea.addInfinite();



    AffineTransform matrix = getTransform();

    Shape transShape = matrix.createTransformedShape(rect);

    Rectangle2D transRect = transShape.getBounds2D();

    mDrawingArea.add((float) transRect.getMinY(),
                     (float) transRect.getMaxY());


}
 
源代码17 项目: Bytecoder   文件: PeekGraphics.java
/**
 * Add the rectangle 'rect' to the area representing
 * the part of the page which is drawn into.
 */
private void addDrawingRect(Rectangle2D rect) {

    /*  For testing purposes the following line can be uncommented.
        When uncommented it causes the entire page to be rasterized
        thus eliminating errors caused by a faulty bounding box
        calculation.
    */
    //mDrawingArea.addInfinite();



    AffineTransform matrix = getTransform();

    Shape transShape = matrix.createTransformedShape(rect);

    Rectangle2D transRect = transShape.getBounds2D();

    mDrawingArea.add((float) transRect.getMinY(),
                     (float) transRect.getMaxY());


}
 
源代码18 项目: jdk8u-jdk   文件: PeekGraphics.java
/**
 * Add the rectangle 'rect' to the area representing
 * the part of the page which is drawn into.
 */
private void addDrawingRect(Rectangle2D rect) {

    /*  For testing purposes the following line can be uncommented.
        When uncommented it causes the entire page to be rasterized
        thus eliminating errors caused by a faulty bounding box
        calculation.
    */
    //mDrawingArea.addInfinite();



    AffineTransform matrix = getTransform();

    Shape transShape = matrix.createTransformedShape(rect);

    Rectangle2D transRect = transShape.getBounds2D();

    mDrawingArea.add((float) transRect.getMinY(),
                     (float) transRect.getMaxY());


}
 
源代码19 项目: openjdk-8   文件: PeekGraphics.java
/**
 * Add the rectangle 'rect' to the area representing
 * the part of the page which is drawn into.
 */
private void addDrawingRect(Rectangle2D rect) {

    /*  For testing purposes the following line can be uncommented.
        When uncommented it causes the entire page to be rasterized
        thus eliminating errors caused by a faulty bounding box
        calculation.
    */
    //mDrawingArea.addInfinite();



    AffineTransform matrix = getTransform();

    Shape transShape = matrix.createTransformedShape(rect);

    Rectangle2D transRect = transShape.getBounds2D();

    mDrawingArea.add((float) transRect.getMinY(),
                     (float) transRect.getMaxY());


}
 
源代码20 项目: seaglass   文件: AbstractRegionPainter.java
/**
 * Creates a simple horizontal gradient using the shape for bounds and the
 * colors for top and bottom colors.
 *
 * @param  s      the shape to use for bounds.
 * @param  colors the colors to use for the gradient.
 *
 * @return the gradient.
 */
protected Paint createHorizontalGradient(Shape s, TwoColors colors) {
    Rectangle2D bounds  = s.getBounds2D();
    float       xMin    = (float) bounds.getMinX();
    float       xMax    = (float) bounds.getMaxX();
    float       yCenter = (float) bounds.getCenterY();

    return createGradient(xMin, yCenter, xMax, yCenter, new float[] { 0f, 1f }, new Color[] { colors.top, colors.bottom });
}