Java Code Examples for java.awt.geom.Rectangle2D#isEmpty()
The following examples show how to use
java.awt.geom.Rectangle2D#isEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardGlyphVector.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) { Rectangle2D result = null; if (sgv.invdtx == null) { result = new Rectangle2D.Float(); result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect } else { GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0); gp.transform(sgv.invdtx); result = gp.getBounds2D(); } /* Since x is the logical advance of the glyph to this point. * Because of the way that Rectangle.union is specified, this * means that subsequent unioning of a rect including that * will be affected, even if the glyph is empty. So skip such * cases. This alone isn't a complete solution since x==0 * may also not be what is wanted. The code that does the * unioning also needs to be aware to ignore empty glyphs. */ if (!result.isEmpty()) { result.setRect(result.getMinX() + x + dx, result.getMinY() + y + dy, result.getWidth(), result.getHeight()); } return result; }
Example 2
Source File: StandardGlyphVector.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) { Rectangle2D result = null; if (sgv.invdtx == null) { result = new Rectangle2D.Float(); result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect } else { GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0); gp.transform(sgv.invdtx); result = gp.getBounds2D(); } /* Since x is the logical advance of the glyph to this point. * Because of the way that Rectangle.union is specified, this * means that subsequent unioning of a rect including that * will be affected, even if the glyph is empty. So skip such * cases. This alone isn't a complete solution since x==0 * may also not be what is wanted. The code that does the * unioning also needs to be aware to ignore empty glyphs. */ if (!result.isEmpty()) { result.setRect(result.getMinX() + x + dx, result.getMinY() + y + dy, result.getWidth(), result.getHeight()); } return result; }
Example 3
Source File: DrawFactory.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Convenience method for drawing single shapes. * For drawing whole slides, use {@link Slide#draw(Graphics2D)} * * @param graphics the graphics context to draw to * @param shape the shape * @param bounds the bounds within the graphics context to draw to */ public void drawShape(Graphics2D graphics, Shape<?,?> shape, Rectangle2D bounds) { Rectangle2D shapeBounds = shape.getAnchor(); if (shapeBounds.isEmpty() || (bounds != null && bounds.isEmpty())) { return; } AffineTransform txg = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM); AffineTransform tx = new AffineTransform(); try { if (bounds != null) { double scaleX = bounds.getWidth()/shapeBounds.getWidth(); double scaleY = bounds.getHeight()/shapeBounds.getHeight(); tx.translate(bounds.getCenterX(), bounds.getCenterY()); tx.scale(scaleX, scaleY); tx.translate(-shapeBounds.getCenterX(), -shapeBounds.getCenterY()); } graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx); Drawable d = getDrawable(shape); d.applyTransform(graphics); d.draw(graphics); } finally { graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, txg); } }
Example 4
Source File: ShortTextTitle.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * Draws the title using the current font and paint. * * @param g2 the graphics target. * @param area the title area. * @param params optional parameters (ignored here). * * @return <code>null</code>. */ @Override public Object draw(Graphics2D g2, Rectangle2D area, Object params) { if (area.isEmpty()) { return null; } area = trimMargin(area); drawBorder(g2, area); area = trimBorder(area); area = trimPadding(area); g2.setFont(getFont()); g2.setPaint(getPaint()); TextUtilities.drawAlignedString(getText(), g2, (float) area.getMinX(), (float) area.getMinY(), TextAnchor.TOP_LEFT); return null; }
Example 5
Source File: StandardGlyphVector.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public Rectangle2D getVisualBounds() { Rectangle2D result = null; for (int i = 0; i < glyphs.length; ++i) { Rectangle2D glyphVB = getGlyphVisualBounds(i).getBounds2D(); if (!glyphVB.isEmpty()) { if (result == null) { result = glyphVB; } else { Rectangle2D.union(result, glyphVB, result); } } } if (result == null) { result = new Rectangle2D.Float(0, 0, 0, 0); } return result; }
Example 6
Source File: StandardGlyphVector.java From hottub with GNU General Public License v2.0 | 6 votes |
public Rectangle2D getVisualBounds() { Rectangle2D result = null; for (int i = 0; i < glyphs.length; ++i) { Rectangle2D glyphVB = getGlyphVisualBounds(i).getBounds2D(); if (!glyphVB.isEmpty()) { if (result == null) { result = glyphVB; } else { Rectangle2D.union(result, glyphVB, result); } } } if (result == null) { result = new Rectangle2D.Float(0, 0, 0, 0); } return result; }
Example 7
Source File: HtmlArea.java From htmlunit with Apache License 2.0 | 6 votes |
private boolean isEmpty() { final String shape = StringUtils.defaultIfEmpty(getShapeAttribute(), SHAPE_RECT).toLowerCase(Locale.ROOT); if ("default".equals(shape) && getCoordsAttribute() != null) { return false; } if (SHAPE_RECT.equals(shape) && getCoordsAttribute() != null) { final Rectangle2D rectangle = parseRect(); return rectangle.isEmpty(); } if (SHAPE_CIRCLE.equals(shape) && getCoordsAttribute() != null) { final Ellipse2D ellipse = parseCircle(); return ellipse.isEmpty(); } if (SHAPE_POLY.equals(shape) && getCoordsAttribute() != null) { return false; } return false; }
Example 8
Source File: StandardGlyphVector.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) { Rectangle2D result = null; if (sgv.invdtx == null) { result = new Rectangle2D.Float(); result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect } else { GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0); gp.transform(sgv.invdtx); result = gp.getBounds2D(); } /* Since x is the logical advance of the glyph to this point. * Because of the way that Rectangle.union is specified, this * means that subsequent unioning of a rect including that * will be affected, even if the glyph is empty. So skip such * cases. This alone isn't a complete solution since x==0 * may also not be what is wanted. The code that does the * unioning also needs to be aware to ignore empty glyphs. */ if (!result.isEmpty()) { result.setRect(result.getMinX() + x + dx, result.getMinY() + y + dy, result.getWidth(), result.getHeight()); } return result; }
Example 9
Source File: StandardGlyphVector.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) { Rectangle2D result = null; if (sgv.invdtx == null) { result = new Rectangle2D.Float(); result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect } else { GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0); gp.transform(sgv.invdtx); result = gp.getBounds2D(); } /* Since x is the logical advance of the glyph to this point. * Because of the way that Rectangle.union is specified, this * means that subsequent unioning of a rect including that * will be affected, even if the glyph is empty. So skip such * cases. This alone isn't a complete solution since x==0 * may also not be what is wanted. The code that does the * unioning also needs to be aware to ignore empty glyphs. */ if (!result.isEmpty()) { result.setRect(result.getMinX() + x + dx, result.getMinY() + y + dy, result.getWidth(), result.getHeight()); } return result; }
Example 10
Source File: StandardGlyphVector.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public Rectangle2D getVisualBounds() { Rectangle2D result = null; for (int i = 0; i < glyphs.length; ++i) { Rectangle2D glyphVB = getGlyphVisualBounds(i).getBounds2D(); if (!glyphVB.isEmpty()) { if (result == null) { result = glyphVB; } else { Rectangle2D.union(result, glyphVB, result); } } } if (result == null) { result = new Rectangle2D.Float(0, 0, 0, 0); } return result; }
Example 11
Source File: StandardGlyphVector.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public Rectangle2D getVisualBounds() { Rectangle2D result = null; for (int i = 0; i < glyphs.length; ++i) { Rectangle2D glyphVB = getGlyphVisualBounds(i).getBounds2D(); if (!glyphVB.isEmpty()) { if (result == null) { result = glyphVB; } else { Rectangle2D.union(result, glyphVB, result); } } } if (result == null) { result = new Rectangle2D.Float(0, 0, 0, 0); } return result; }
Example 12
Source File: StandardGlyphVector.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) { Rectangle2D result = null; if (sgv.invdtx == null) { result = new Rectangle2D.Float(); result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect } else { GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0); gp.transform(sgv.invdtx); result = gp.getBounds2D(); } /* Since x is the logical advance of the glyph to this point. * Because of the way that Rectangle.union is specified, this * means that subsequent unioning of a rect including that * will be affected, even if the glyph is empty. So skip such * cases. This alone isn't a complete solution since x==0 * may also not be what is wanted. The code that does the * unioning also needs to be aware to ignore empty glyphs. */ if (!result.isEmpty()) { result.setRect(result.getMinX() + x + dx, result.getMinY() + y + dy, result.getWidth(), result.getHeight()); } return result; }
Example 13
Source File: ShortTextTitle.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Draws the title using the current font and paint. * * @param g2 the graphics target. * @param area the title area. * @param params optional parameters (ignored here). * * @return <code>null</code>. */ @Override public Object draw(Graphics2D g2, Rectangle2D area, Object params) { if (area.isEmpty()) { return null; } area = trimMargin(area); drawBorder(g2, area); area = trimBorder(area); area = trimPadding(area); g2.setFont(getFont()); g2.setPaint(getPaint()); TextUtilities.drawAlignedString(getText(), g2, (float) area.getMinX(), (float) area.getMinY(), TextAnchor.TOP_LEFT); return null; }
Example 14
Source File: StandardGlyphVector.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) { Rectangle2D result = null; if (sgv.invdtx == null) { result = new Rectangle2D.Float(); result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect } else { GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0); gp.transform(sgv.invdtx); result = gp.getBounds2D(); } /* Since x is the logical advance of the glyph to this point. * Because of the way that Rectangle.union is specified, this * means that subsequent unioning of a rect including that * will be affected, even if the glyph is empty. So skip such * cases. This alone isn't a complete solution since x==0 * may also not be what is wanted. The code that does the * unioning also needs to be aware to ignore empty glyphs. */ if (!result.isEmpty()) { result.setRect(result.getMinX() + x + dx, result.getMinY() + y + dy, result.getWidth(), result.getHeight()); } return result; }
Example 15
Source File: ShortTextTitle.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * Draws the title using the current font and paint. * * @param g2 the graphics target. * @param area the title area. * @param params optional parameters (ignored here). * * @return <code>null</code>. */ @Override public Object draw(Graphics2D g2, Rectangle2D area, Object params) { if (area.isEmpty()) { return null; } area = trimMargin(area); drawBorder(g2, area); area = trimBorder(area); area = trimPadding(area); g2.setFont(getFont()); g2.setPaint(getPaint()); TextUtilities.drawAlignedString(getText(), g2, (float) area.getMinX(), (float) area.getMinY(), TextAnchor.TOP_LEFT); return null; }
Example 16
Source File: StandardGlyphVector.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) { Rectangle2D result = null; if (sgv.invdtx == null) { result = new Rectangle2D.Float(); result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect } else { if (sgv.invdtx.getShearX() == 0 && sgv.invdtx.getShearY() == 0) { final Rectangle2D.Float rect = strike.getGlyphOutlineBounds(glyphID); result = new Rectangle2D.Float( (float)(rect.x*sgv.invdtx.getScaleX() + sgv.invdtx.getTranslateX()), (float)(rect.y*sgv.invdtx.getScaleY() + sgv.invdtx.getTranslateY()), (float)(rect.width*sgv.invdtx.getScaleX()), (float)(rect.height*sgv.invdtx.getScaleY())); } else { GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0); gp.transform(sgv.invdtx); result = gp.getBounds2D(); } } /* Since x is the logical advance of the glyph to this point. * Because of the way that Rectangle.union is specified, this * means that subsequent unioning of a rect including that * will be affected, even if the glyph is empty. So skip such * cases. This alone isn't a complete solution since x==0 * may also not be what is wanted. The code that does the * unioning also needs to be aware to ignore empty glyphs. */ if (!result.isEmpty()) { result.setRect(result.getMinX() + x + dx, result.getMinY() + y + dy, result.getWidth(), result.getHeight()); } return result; }
Example 17
Source File: NestWorldMapPane.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
public void zoomToProduct(Product product) { final NestWorldMapPaneDataModel.Boundary[] selGeoBoundaries = dataModel.getSelectedGeoBoundaries(); final GeneralPath[] generalPaths; if (product != null && product.getSceneGeoCoding() != null) { generalPaths = getGeoBoundaryPaths(product); } else if (selGeoBoundaries.length > 0) { generalPaths = assemblePathList(selGeoBoundaries[0].geoBoundary);//selGeoBoundaries[0].boundaryPaths; } else { return; } Rectangle2D modelArea = new Rectangle2D.Double(); final Viewport viewport = layerCanvas.getViewport(); for (GeneralPath generalPath : generalPaths) { final Rectangle2D rectangle2D = generalPath.getBounds2D(); if (modelArea.isEmpty()) { if (!viewport.isModelYAxisDown()) { modelArea.setFrame(rectangle2D.getX(), rectangle2D.getMaxY(), rectangle2D.getWidth(), rectangle2D.getHeight()); } modelArea = rectangle2D; } else { modelArea.add(rectangle2D); } } Rectangle2D modelBounds = modelArea.getBounds2D(); modelBounds.setFrame(modelBounds.getX() - 2, modelBounds.getY() - 2, modelBounds.getWidth() + 4, modelBounds.getHeight() + 4); modelBounds = cropToMaxModelBounds(modelBounds); viewport.zoom(modelBounds); }
Example 18
Source File: RadialGradientPaint.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Constructs a {@code RadialGradientPaint} with a default * {@code SRGB} color space. * The gradient circle of the {@code RadialGradientPaint} is defined * by the given bounding box. * <p> * This constructor is a more convenient way to express the * following (equivalent) code:<br> * * <pre> * double gw = gradientBounds.getWidth(); * double gh = gradientBounds.getHeight(); * double cx = gradientBounds.getCenterX(); * double cy = gradientBounds.getCenterY(); * Point2D center = new Point2D.Double(cx, cy); * * AffineTransform gradientTransform = new AffineTransform(); * gradientTransform.translate(cx, cy); * gradientTransform.scale(gw / 2, gh / 2); * gradientTransform.translate(-cx, -cy); * * RadialGradientPaint gp = * new RadialGradientPaint(center, 1.0f, center, * fractions, colors, * cycleMethod, * ColorSpaceType.SRGB, * gradientTransform); * </pre> * * @param gradientBounds the bounding box, in user space, of the circle * defining the outermost extent of the gradient * @param fractions numbers ranging from 0.0 to 1.0 specifying the * distribution of colors along the gradient * @param colors array of colors to use in the gradient. The first color * is used at the focus point, the last color around the * perimeter of the circle. * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT}, * or {@code REPEAT} * * @throws NullPointerException * if {@code gradientBounds} is null, * or {@code fractions} array is null, * or {@code colors} array is null, * or {@code cycleMethod} is null * @throws IllegalArgumentException * if {@code gradientBounds} is empty, * or {@code fractions.length != colors.length}, * or {@code colors} is less than 2 in size, * or a {@code fractions} value is less than 0.0 or greater than 1.0, * or the {@code fractions} are not provided in strictly increasing order */ public RadialGradientPaint(Rectangle2D gradientBounds, float[] fractions, Color[] colors, CycleMethod cycleMethod) { // gradient center/focal point is the center of the bounding box, // radius is set to 1.0, and then we set a scale transform // to achieve an elliptical gradient defined by the bounding box this(new Point2D.Double(gradientBounds.getCenterX(), gradientBounds.getCenterY()), 1.0f, new Point2D.Double(gradientBounds.getCenterX(), gradientBounds.getCenterY()), fractions, colors, cycleMethod, ColorSpaceType.SRGB, createGradientTransform(gradientBounds)); if (gradientBounds.isEmpty()) { throw new IllegalArgumentException("Gradient bounds must be " + "non-empty"); } }
Example 19
Source File: RadialGradientPaint.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Constructs a {@code RadialGradientPaint} with a default * {@code SRGB} color space. * The gradient circle of the {@code RadialGradientPaint} is defined * by the given bounding box. * <p> * This constructor is a more convenient way to express the * following (equivalent) code:<br> * * <pre> * double gw = gradientBounds.getWidth(); * double gh = gradientBounds.getHeight(); * double cx = gradientBounds.getCenterX(); * double cy = gradientBounds.getCenterY(); * Point2D center = new Point2D.Double(cx, cy); * * AffineTransform gradientTransform = new AffineTransform(); * gradientTransform.translate(cx, cy); * gradientTransform.scale(gw / 2, gh / 2); * gradientTransform.translate(-cx, -cy); * * RadialGradientPaint gp = * new RadialGradientPaint(center, 1.0f, center, * fractions, colors, * cycleMethod, * ColorSpaceType.SRGB, * gradientTransform); * </pre> * * @param gradientBounds the bounding box, in user space, of the circle * defining the outermost extent of the gradient * @param fractions numbers ranging from 0.0 to 1.0 specifying the * distribution of colors along the gradient * @param colors array of colors to use in the gradient. The first color * is used at the focus point, the last color around the * perimeter of the circle. * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT}, * or {@code REPEAT} * * @throws NullPointerException * if {@code gradientBounds} is null, * or {@code fractions} array is null, * or {@code colors} array is null, * or {@code cycleMethod} is null * @throws IllegalArgumentException * if {@code gradientBounds} is empty, * or {@code fractions.length != colors.length}, * or {@code colors} is less than 2 in size, * or a {@code fractions} value is less than 0.0 or greater than 1.0, * or the {@code fractions} are not provided in strictly increasing order */ public RadialGradientPaint(Rectangle2D gradientBounds, float[] fractions, Color[] colors, CycleMethod cycleMethod) { // gradient center/focal point is the center of the bounding box, // radius is set to 1.0, and then we set a scale transform // to achieve an elliptical gradient defined by the bounding box this(new Point2D.Double(gradientBounds.getCenterX(), gradientBounds.getCenterY()), 1.0f, new Point2D.Double(gradientBounds.getCenterX(), gradientBounds.getCenterY()), fractions, colors, cycleMethod, ColorSpaceType.SRGB, createGradientTransform(gradientBounds)); if (gradientBounds.isEmpty()) { throw new IllegalArgumentException("Gradient bounds must be " + "non-empty"); } }
Example 20
Source File: SVGGraphics2D.java From jfreesvg with GNU General Public License v3.0 | 4 votes |
/** * Fills the specified shape with the current {@code paint}. There is * direct handling for {@code Rectangle2D}, {@code Ellipse2D} and * {@code Path2D}. All other shapes are mapped to a {@code GeneralPath} * and then filled. * * @param s the shape ({@code null} not permitted). * * @see #draw(java.awt.Shape) */ @Override public void fill(Shape s) { if (s instanceof Rectangle2D) { Rectangle2D r = (Rectangle2D) s; if (r.isEmpty()) { return; } this.sb.append("<rect "); appendOptionalElementIDFromHint(this.sb); this.sb.append("x=\"").append(geomDP(r.getX())) .append("\" y=\"").append(geomDP(r.getY())) .append("\" width=\"").append(geomDP(r.getWidth())) .append("\" height=\"").append(geomDP(r.getHeight())) .append("\" "); this.sb.append("style=\"").append(getSVGFillStyle()).append("\" "); if (!this.transform.isIdentity()) { this.sb.append("transform=\"").append(getSVGTransform( this.transform)).append("\" "); } this.sb.append(getClipPathRef()); this.sb.append("/>"); } else if (s instanceof Ellipse2D) { Ellipse2D e = (Ellipse2D) s; this.sb.append("<ellipse "); appendOptionalElementIDFromHint(this.sb); this.sb.append("cx=\"").append(geomDP(e.getCenterX())) .append("\" cy=\"").append(geomDP(e.getCenterY())) .append("\" rx=\"").append(geomDP(e.getWidth() / 2.0)) .append("\" ry=\"").append(geomDP(e.getHeight() / 2.0)) .append("\" "); this.sb.append("style=\"").append(getSVGFillStyle()).append("\" "); if (!this.transform.isIdentity()) { this.sb.append("transform=\"").append(getSVGTransform( this.transform)).append("\" "); } this.sb.append(getClipPathRef()); this.sb.append("/>"); } else if (s instanceof Path2D) { Path2D path = (Path2D) s; this.sb.append("<g "); appendOptionalElementIDFromHint(this.sb); this.sb.append("style=\"").append(getSVGFillStyle()); this.sb.append("; stroke: none").append("\" "); if (!this.transform.isIdentity()) { this.sb.append("transform=\"").append(getSVGTransform( this.transform)).append("\" "); } this.sb.append(getClipPathRef()); this.sb.append(">"); this.sb.append("<path ").append(getSVGPathData(path)).append("/>"); this.sb.append("</g>"); } else { fill(new GeneralPath(s)); // handled as a Path2D next time through } }