List of usage examples for java.awt.geom RectangularShape clone
public Object clone()
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
public static Shape translateChartShape(Shape shape, Rectangle2D imageArea, JFreeChart chart) { if (shape instanceof Line2D) { Line2D line = (Line2D) shape; double length = line.getP1().distance(line.getP2()); if (length == 0) { Point2D point = line.getP1(); Point2D newPoint = ChartMaskingUtilities.translateChartPoint(point, imageArea, chart); Shape oShape = ShapeUtilities.createDiagonalCross(5f, 0.2f); // Shape oShape = ShapeUtilities.createRegularCross(3f, 0.5f); Shape newShape = ShapeUtilities.createTranslatedShape(oShape, newPoint.getX(), newPoint.getY()); return newShape; } else if (length < 1e-6) { if (line.getP1().getX() == line.getP2().getX()) { double newX = ChartMaskingUtilities.translateChartPoint(line.getP1(), imageArea, chart).getX(); Line2D newLine = new Line2D.Double(newX, imageArea.getMinY(), newX, imageArea.getMaxY()); return newLine; } else { double newY = ChartMaskingUtilities.translateChartPoint(line.getP1(), imageArea, chart).getY(); Line2D newLine = new Line2D.Double(imageArea.getMinX(), newY, imageArea.getMaxX(), newY); return newLine; }/*from w ww . j av a 2s. c om*/ } Line2D newShape = (Line2D) line.clone(); Point2D newP1 = translateChartPoint(line.getP1(), imageArea, chart); Point2D newP2 = translateChartPoint(line.getP2(), imageArea, chart); newShape.setLine(newP1, newP2); return newShape; } else if (shape instanceof RectangularShape) { RectangularShape rect = (RectangularShape) shape; RectangularShape newShape = (RectangularShape) rect.clone(); Rectangle2D bound = rect.getBounds2D(); Point2D start = new Point2D.Double(bound.getMinX(), bound.getMinY()); Point2D end = new Point2D.Double(bound.getMaxX(), bound.getMaxY()); Point2D screenStart = translateChartPoint(start, imageArea, chart); Point2D screenEnd = translateChartPoint(end, imageArea, chart); newShape.setFrame(new Rectangle2D.Double(Math.min(screenStart.getX(), screenEnd.getX()), Math.min(screenStart.getY(), screenEnd.getY()), Math.abs(screenStart.getX() - screenEnd.getX()), Math.abs(screenStart.getY() - screenEnd.getY()))); return newShape; } else { return shape; } }
From source file:ShapeTransform.java
/** * Translates a given shape. Special care is taken to preserve the shape's * original class, if the shape is a rectangle or a line. * //from w w w. j av a 2s. c o m * @param s * the shape * @param x * the x coordinate where the shape is translated to * @param y * the y coordinate where the shape is translated to * @return the translated shape */ public static Shape translateShape(final Shape s, final double x, final double y) { if (s instanceof RectangularShape) { final RectangularShape rect = (RectangularShape) s; final RectangularShape retval = (RectangularShape) rect.clone(); retval.setFrame(retval.getX() + x, retval.getY() + y, retval.getWidth(), retval.getHeight()); return retval; } if (s instanceof Line2D) { final Line2D line = (Line2D) s; final Line2D retval = (Line2D) line.clone(); retval.setLine(retval.getX1() + x, retval.getY1() + y, retval.getX2() + x, retval.getY2() + y); return retval; } final AffineTransform af = AffineTransform.getTranslateInstance(x, y); return af.createTransformedShape(s); }
From source file:ShapeTransform.java
/** * Resizes a rectangle. This works for real rectangles and produces funny * results for RoundRects etc ..//from w w w .j a v a 2 s . c o m * * @param rectangularShape * the rectangle * @param width * the new width of the rectangle * @param height * the new height of the rectangle. * @return the resized rectangle. */ public static Shape resizeRect(final RectangularShape rectangularShape, final double width, final double height) { final RectangularShape retval = (RectangularShape) rectangularShape.clone(); retval.setFrame(retval.getX(), retval.getY(), width, height); return retval; }
From source file:org.kepler.monitor.figure.BaseFigure.java
protected BaseFigure(RectangularShape shape) { this._shape = (RectangularShape) shape.clone(); }
From source file:tufts.vue.LWComponent.java
/** @return our shape, full transformed into map coords and ultimate scale when drawn at 100% map zoom * this is used for portal clipping, and will be imperfect for some scaled shapes, such as RountRect's * This only works for raw shapes that are RectangularShapes -- other Shape types just return the bounding * box in map coordinates (e.g., a link shape) *///from ww w .j ava 2 s.co m public RectangularShape getMapShape() { // Will not work for shapes like RoundRect when scaled -- e..g, corner scaling will be off final Shape s = getZeroShape(); // if (getMapScale() != 1f && s instanceof RectangularShape) { // todo: do if any transform, not just scale if (s instanceof RectangularShape) { // todo: cache this: only need to updaate if location, size or scale changes // (Also, on the scale or location change of any parent!) RectangularShape rshape = (RectangularShape) s; rshape = (RectangularShape) rshape.clone(); AffineTransform a = getZeroTransform(); Point2D.Float loc = new Point2D.Float(); a.transform(loc, loc); rshape.setFrame(loc.x, loc.y, rshape.getWidth() * a.getScaleX(), rshape.getHeight() * a.getScaleY()); //System.out.println("TRANSFORMED SHAPE: " + rshape + " for " + this); return rshape; } else { return getMapBounds(); } }