Search in sources :

Example 21 with Path2D

use of java.awt.geom.Path2D in project poi by apache.

the class DrawFreeformShape method computeOutlines.

protected Collection<Outline> computeOutlines(Graphics2D graphics) {
    List<Outline> lst = new ArrayList<Outline>();
    FreeformShape<?, ?> fsh = getShape();
    Path2D sh = fsh.getPath();
    AffineTransform tx = (AffineTransform) graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
    if (tx == null) {
        tx = new AffineTransform();
    }
    java.awt.Shape canvasShape = tx.createTransformedShape(sh);
    FillStyle fs = fsh.getFillStyle();
    StrokeStyle ss = fsh.getStrokeStyle();
    Path path = new Path(fs != null, ss != null);
    lst.add(new Outline(canvasShape, path));
    return lst;
}
Also used : Path(org.apache.poi.sl.draw.geom.Path) Path2D(java.awt.geom.Path2D) ArrayList(java.util.ArrayList) FillStyle(org.apache.poi.sl.usermodel.FillStyle) AffineTransform(java.awt.geom.AffineTransform) Outline(org.apache.poi.sl.draw.geom.Outline) StrokeStyle(org.apache.poi.sl.usermodel.StrokeStyle)

Example 22 with Path2D

use of java.awt.geom.Path2D in project java-swing-tips by aterai.

the class TitledBorder2 method paintBorder.

/**
     * Paints the border for the specified component with the
     * specified position and size.
     * @param c the component for which this border is being painted
     * @param g the paint graphics
     * @param x the x position of the painted border
     * @param y the y position of the painted border
     * @param width the width of the painted border
     * @param height the height of the painted border
     */
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Border border = getBorder();
    String title = getTitle();
    if (Objects.nonNull(title) && !title.isEmpty()) {
        int edge = border instanceof TitledBorder2 ? 0 : EDGE_SPACING;
        JLabel label = getLabel(c);
        Dimension size = label.getPreferredSize();
        Insets insets = makeBorderInsets(border, c, new Insets(0, 0, 0, 0));
        int borderX = x + edge;
        int borderY = y + edge;
        int borderW = width - edge - edge;
        int borderH = height - edge - edge;
        int labelY = y;
        int labelH = size.height;
        int position = getPosition();
        switch(position) {
            case ABOVE_TOP:
                insets.left = 0;
                insets.right = 0;
                borderY += labelH - edge;
                borderH -= labelH - edge;
                break;
            case TOP:
                insets.top = edge + insets.top / 2 - labelH / 2;
                if (insets.top < edge) {
                    borderY -= insets.top;
                    borderH += insets.top;
                } else {
                    labelY += insets.top;
                }
                break;
            case BELOW_TOP:
                labelY += insets.top + edge;
                break;
            case ABOVE_BOTTOM:
                labelY += height - labelH - insets.bottom - edge;
                break;
            case BOTTOM:
                labelY += height - labelH;
                insets.bottom = edge + (insets.bottom - labelH) / 2;
                if (insets.bottom < edge) {
                    borderH += insets.bottom;
                } else {
                    labelY -= insets.bottom;
                }
                break;
            case BELOW_BOTTOM:
                insets.left = 0;
                insets.right = 0;
                labelY += height - labelH;
                borderH -= labelH - edge;
                break;
            default:
        }
        insets.left += edge + TEXT_INSET_H;
        insets.right += edge + TEXT_INSET_H;
        int labelX = x;
        int labelW = width - insets.left - insets.right;
        if (labelW > size.width) {
            labelW = size.width;
        }
        switch(getJustification(c)) {
            case LEFT:
                labelX += insets.left;
                break;
            case RIGHT:
                labelX += width - insets.right - labelW;
                break;
            case CENTER:
                labelX += (width - labelW) / 2;
                break;
            default:
        }
        if (border != null) {
            if (position != TOP && position != BOTTOM) {
                border.paintBorder(c, g, borderX, borderY, borderW, borderH);
            } else {
                Graphics g2 = g.create();
                if (g2 instanceof Graphics2D) {
                    Graphics2D g2d = (Graphics2D) g2;
                    Path2D path = new Path2D.Float();
                    path.append(new Rectangle(borderX, borderY, borderW, labelY - borderY), false);
                    path.append(new Rectangle(borderX, labelY, labelX - borderX - TEXT_SPACING, labelH), false);
                    path.append(new Rectangle(labelX + labelW + TEXT_SPACING, labelY, borderX - labelX + borderW - labelW - TEXT_SPACING, labelH), false);
                    path.append(new Rectangle(borderX, labelY + labelH, borderW, borderY - labelY + borderH - labelH), false);
                    g2d.clip(path);
                }
                border.paintBorder(c, g2, borderX, borderY, borderW, borderH);
                g2.dispose();
            }
        }
        g.translate(labelX, labelY);
        label.setSize(labelW, labelH);
        label.paint(g);
        g.translate(-labelX, -labelY);
    } else if (Objects.nonNull(border)) {
        border.paintBorder(c, g, x, y, width, height);
    }
}
Also used : Path2D(java.awt.geom.Path2D)

Example 23 with Path2D

use of java.awt.geom.Path2D in project processdash by dtuma.

the class MultiWindowCheckboxIcon method paintIcon.

public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2 = (Graphics2D) g.create();
    float scale = (float) g2.getTransform().getScaleX();
    g2.setStroke(new BasicStroke(1 / scale));
    paintFrame(g2, x + 12, y);
    paintFrame(g2, x + 16, y + 3);
    g2.setColor(boxColor);
    g2.drawRect(x + 0, y + 1, 8, 8);
    if (isChecked()) {
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(checkColor);
        g2.setStroke(new BasicStroke(scale > 1.3 ? 1.5f : 1));
        Path2D p = new Path2D.Float();
        p.moveTo(x + 2, y + 5);
        p.lineTo(x + 4, y + 7);
        p.lineTo(x + 6, y + 3);
        g2.draw(p);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Path2D(java.awt.geom.Path2D) Graphics2D(java.awt.Graphics2D)

Example 24 with Path2D

use of java.awt.geom.Path2D in project processdash by dtuma.

the class AbstractRecolorableIcon method shape.

protected Shape shape(float... coords) {
    Path2D result = new Path2D.Float();
    result.moveTo(coords[0], coords[1]);
    for (int i = 2; i < coords.length; i += 2) result.lineTo(coords[i], coords[i + 1]);
    result.closePath();
    return result;
}
Also used : Path2D(java.awt.geom.Path2D)

Aggregations

Path2D (java.awt.geom.Path2D)24 Graphics2D (java.awt.Graphics2D)4 BasicStroke (java.awt.BasicStroke)3 PathIterator (java.awt.geom.PathIterator)3 Rectangle2D (java.awt.geom.Rectangle2D)3 TDoubleArrayList (gnu.trove.TDoubleArrayList)2 Color (java.awt.Color)2 Font (java.awt.Font)2 AffineTransform (java.awt.geom.AffineTransform)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 Point2D (aima.core.util.math.geom.shapes.Point2D)1 RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)1 SeriesData (com.android.tools.adtui.model.SeriesData)1 Dimension (java.awt.Dimension)1 Graphics (java.awt.Graphics)1 Insets (java.awt.Insets)1 Paint (java.awt.Paint)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 Shape (java.awt.Shape)1