private Path createPath(Rectangle outerBoundss, Graphics graphics) { // instead of just zooming the translated-points (see // getTranslatedPoints()), // better do the calculation again by first zooming and then translating // to avoid rounding errors. final int lineWidth = 1; final double zoom = 1.0; PointList points = FigureUtil.getAdjustedPointList(getPoints(), zoom, lineWidth); List<BezierPoint> bezierPoints = getBezierPoints(points, zoom); boolean isClosed = bezierPoints.get(0).equals(bezierPoints.get(bezierPoints.size() - 1)); Path path = FigureUtil.getBezierPath(bezierPoints, isClosed); return path; }
public void paint(IFigure figure, Graphics graphics, Insets insets) { tempRect.setBounds(getPaintRectangle(figure, insets)); BorderComponent borderDef = this.rectPresentation.getTopBorder(); if (this.hasUniformBorders && borderDef.getWeight().getContent() > 0) { int w = borderDef.getWeight().getContent(); int inset = Math.max(1, w >> 1); tempRect.x += inset; tempRect.y += inset; tempRect.width -= inset + inset; tempRect.height -= inset + inset; int cornerRadius = this.rectPresentation.getCornerRadius(); float cornerWidth = cornerRadius; float cornerHeight = cornerRadius; // adjust corner for the inner path (formula found by experimenting) cornerHeight = Math.max(1, cornerHeight - (w + cornerHeight / 64)); cornerWidth = Math.max(1, cornerWidth - (w + cornerWidth / 64)); graphics.setLineWidth(borderDef.getWeight().getContent()); graphics.setForegroundColor(resourceCache.getColor(borderDef.getColor().getContent())); graphics.setLineStyle(FigureUtil.convertLineStyle(borderDef.getStyle().getContent())); graphics.drawRoundRectangle( tempRect, Math.max(0, (int) cornerWidth), Math.max(0, (int) cornerHeight)); } else { if (borderDef.getWeight().getContent() > 0) { int w = borderDef.getWeight().getContent(); graphics.setLineWidth(w); graphics.setForegroundColor(resourceCache.getColor(borderDef.getColor().getContent())); graphics.setLineStyle(FigureUtil.convertLineStyle(borderDef.getStyle().getContent())); int inset = Math.max(1, w >> 1); int x = tempRect.x; int y = tempRect.y + inset; int x2 = tempRect.x + tempRect.width; graphics.drawLine(x, y, x2, y); } borderDef = this.rectPresentation.getBottomBorder(); if (borderDef.getWeight().getContent() > 0) { int w = borderDef.getWeight().getContent(); graphics.setLineWidth(w); graphics.setForegroundColor(resourceCache.getColor(borderDef.getColor().getContent())); graphics.setLineStyle(FigureUtil.convertLineStyle(borderDef.getStyle().getContent())); int inset = Math.max(1, w >> 1); int x = tempRect.x; int y = tempRect.y + tempRect.height - inset; int x2 = tempRect.x + tempRect.width; graphics.drawLine(x, y, x2, y); } borderDef = this.rectPresentation.getLeftBorder(); if (borderDef.getWeight().getContent() > 0) { int w = borderDef.getWeight().getContent(); graphics.setLineWidth(w); graphics.setForegroundColor(resourceCache.getColor(borderDef.getColor().getContent())); graphics.setLineStyle(FigureUtil.convertLineStyle(borderDef.getStyle().getContent())); int inset = Math.max(1, w >> 1); int x = tempRect.x + inset; int y = tempRect.y; int y2 = tempRect.y + tempRect.height; graphics.drawLine(x, y, x, y2); } borderDef = this.rectPresentation.getRightBorder(); if (borderDef.getWeight().getContent() > 0) { int w = borderDef.getWeight().getContent(); graphics.setLineWidth(w); graphics.setForegroundColor(resourceCache.getColor(borderDef.getColor().getContent())); graphics.setLineStyle(FigureUtil.convertLineStyle(borderDef.getStyle().getContent())); int inset = Math.max(1, w >> 1); int x = tempRect.x + tempRect.width - inset; int y = tempRect.y; int y2 = tempRect.y + tempRect.height; graphics.drawLine(x, y, x, y2); } } }