/** * Calculates the bounds of the line taking stroke width into account. * * @return rectangle representing the bounds of the line taking stroke width into account */ public Rectangle2D getLineBoundsWithStroke() { if (stroke != null) { return stroke.createStrokedShape(lineShape).getBounds2D(); } else { return lineShape.getBounds2D(); } }
/** {@inheritDoc} */ public boolean setBounds( final double x, final double y, final double width, final double height) { if (lineShape == null || !super.setBounds(x, y, width, height)) { return false; } final Rectangle2D lineBounds = lineShape.getBounds2D(); final Rectangle2D lineStrokeBounds = getLineBoundsWithStroke(); final double strokeOutset = Math.max( lineStrokeBounds.getWidth() - lineBounds.getWidth(), lineStrokeBounds.getHeight() - lineBounds.getHeight()); double adjustedX = x + strokeOutset / 2; double adjustedY = y + strokeOutset / 2; double adjustedWidth = width - strokeOutset; double adjustedHeight = height - strokeOutset; TEMP_TRANSFORM.setToIdentity(); TEMP_TRANSFORM.translate(adjustedX, adjustedY); TEMP_TRANSFORM.scale( adjustedWidth / lineBounds.getWidth(), adjustedHeight / lineBounds.getHeight()); TEMP_TRANSFORM.translate(-lineBounds.getX(), -lineBounds.getY()); lineShape.transformPoints(TEMP_TRANSFORM); return true; }