List of usage examples for java.awt Shape getBounds2D
public Rectangle2D getBounds2D();
From source file:Main.java
public static void main(String[] args) throws Exception { Shape s = new Rectangle2D.Double(0, 0, 72, 72); System.out.println(s.getBounds2D()); }
From source file:Main.java
public static boolean isVectorFont(Font font) { GlyphVector gv = font.createGlyphVector(new FontRenderContext(null, true, false), "Test"); Shape fontShape = gv.getOutline(); Rectangle2D bounds = fontShape.getBounds2D(); return !(bounds.getWidth() == 0 && bounds.getHeight() == 0); }
From source file:Utils.java
public static Shape generatePolygon(int sides, int outsideRadius, int insideRadius, boolean normalize) { Shape shape = generatePolygon(sides, outsideRadius, insideRadius); if (normalize) { Rectangle2D bounds = shape.getBounds2D(); GeneralPath path = new GeneralPath(shape); shape = path// ww w . ja v a 2s. co m .createTransformedShape(AffineTransform.getTranslateInstance(-bounds.getX(), -bounds.getY())); } return shape; }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.SmartLegendTitle.java
public static Paint transformLinearGradient(LinearGradientPaint paint, Shape target) { Rectangle2D bounds = target.getBounds2D(); float left = (float) bounds.getMinX(); float right = (float) bounds.getMaxX(); LinearGradientPaint newPaint = new LinearGradientPaint(left, 0, right, 0, paint.getFractions(), paint.getColors());/*ww w . j av a2 s.c o m*/ return newPaint; }
From source file:gov.nih.nci.caintegrator.ui.graphing.util.ImageMapUtil.java
/** * Get a collection of entities with the area shape equal to the bounding rectangle * for the shape of original entity. This is necessary because the Javascript for the sample * selection lasso can only handle rect objects. * @param entities/*from w w w.j a v a 2s . co m*/ * @return a collection of entities containing the bounding rectangles of the original entities */ private static Collection<ChartEntity> getBoundingEntities(Collection entities) { ChartEntity entity; ChartEntity boundingEntity; Shape shape; Rectangle2D boundingRect; Collection<ChartEntity> boundingEntities = new ArrayList<ChartEntity>(); for (Iterator i = entities.iterator(); i.hasNext();) { entity = (ChartEntity) i.next(); shape = entity.getArea(); boundingRect = shape.getBounds2D(); boundingEntity = new ChartEntity(boundingRect, entity.getToolTipText(), entity.getURLText()); boundingEntities.add(boundingEntity); } return boundingEntities; }
From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java
/** * * @param s//from w ww . ja va 2s.c o m * @param scalex * @param scaley * @return */ public static AffineTransform scaleAtOrigin(Shape s, float scalex, float scaley) { return scaleAtOrigin(s, s.getBounds2D().getCenterX(), s.getBounds2D().getCenterY(), scalex, scaley); }
From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java
/** * * @param entity//from w w w. ja va2 s. c om * @param chartPanel * @return */ public static Shape toViewXY(Shape entity, ChartPanel chartPanel) { return toViewXY(entity, chartPanel, new Point2D.Double(entity.getBounds2D().getCenterX(), entity.getBounds2D().getCenterY())); }
From source file:de.bund.bfr.jung.JungUtils.java
static <V, E> Shape getTransformedEdgeShape(RenderContext<V, E> rc, Layout<V, E> layout, E e) { Graph<V, E> graph = layout.getGraph(); edu.uci.ics.jung.graph.util.Pair<V> endpoints = graph.getEndpoints(e); V v1 = endpoints.getFirst();//from w w w. ja v a 2s . c o m V v2 = endpoints.getSecond(); if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<V, E>, E>getInstance(graph, e)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v1)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v2))) { return null; } Point2D p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v1)); Point2D p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v2)); float x1 = (float) p1.getX(); float y1 = (float) p1.getY(); float x2 = (float) p2.getX(); float y2 = (float) p2.getY(); Shape edgeShape = rc.getEdgeShapeTransformer().transform(Context.getInstance(graph, e)); AffineTransform edgeShapeTransform = AffineTransform.getTranslateInstance(x1, y1); if (v1.equals(v2)) { Rectangle2D bounds = rc.getVertexShapeTransformer().transform(v1).getBounds2D(); edgeShapeTransform.scale(bounds.getWidth(), bounds.getHeight()); edgeShapeTransform.translate(0, -edgeShape.getBounds2D().getWidth() / 2); } else { float dx = x2 - x1; float dy = y2 - y1; edgeShapeTransform.rotate(Math.atan2(dy, dx)); edgeShapeTransform.scale(Math.sqrt(dx * dx + dy * dy), 1.0); } return edgeShapeTransform.createTransformedShape(edgeShape); }
From source file:ShapeTransform.java
/** * Scales a given shape. The shape is first normalized, then scaled and * finally brought back into its original position. * /*from ww w . ja v a 2s.c om*/ * @param shape * the shape to be scaled * @param scaleX * the horizontal scaling factor * @param scaleY * the vertical scaling factor * @return the scaled shape */ 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(); AffineTransform af = AffineTransform.getTranslateInstance(0 - bounds.getX(), 0 - bounds.getY()); // apply normalisation translation ... Shape s = af.createTransformedShape(shape); af = AffineTransform.getScaleInstance(scaleX, scaleY); // apply scaling ... s = af.createTransformedShape(s); // now retranslate the shape to its original position ... af = AffineTransform.getTranslateInstance(bounds.getX(), bounds.getY()); return af.createTransformedShape(s); }
From source file:ShapeTransform.java
/** * Translates the given shape. The shape is translated to the origin supplied * in <code>point</code>. If scaling is requested, the shape will also be * scaled using an AffineTransform.// www . ja v a 2 s .c om * * @param s * the shape that should be transformed * @param scale * true, if the shape should be scaled, false otherwise * @param keepAR * true, if the scaled shape should keep the aspect ratio * @param width * the target width. * @param height * the target height. * @return the transformed shape */ public static Shape transformShape(final Shape s, final boolean scale, final boolean keepAR, final double width, final double height) { /** * 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; } double scaleY = 1; if (h != 0) { scaleY = height / h; } if (scaleX != 1 || scaleY != 1) { if (s instanceof RectangularShape) { return ShapeTransform.resizeRect((RectangularShape) s, w * scaleX, h * scaleY); } if (s instanceof Line2D) { return ShapeTransform.resizeLine((Line2D) s, w * scaleX, h * scaleY); } if (keepAR) { final double scaleFact = Math.min(scaleX, scaleY); return performDefaultTransformation(s, scaleFact, scaleFact); } else { return performDefaultTransformation(s, scaleX, scaleY); } } } return s; }