Search in sources :

Example 6 with Path2D

use of java.awt.geom.Path2D in project intellij-community by JetBrains.

the class EditorPainter method getBorderShape.

private static Shape getBorderShape(float x, float y, float width, int height, boolean rounded) {
    if (width <= 0 || height <= 0)
        return null;
    Shape outer = rounded ? new RoundRectangle2D.Float(x, y, width, height, 2, 2) : new Rectangle2D.Float(x, y, width, height);
    if (width <= 2 || height <= 2)
        return outer;
    Shape inner = new Rectangle2D.Float(x + 1, y + 1, width - 2, height - 2);
    Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
    path.append(outer, false);
    path.append(inner, false);
    return path;
}
Also used : RoundRectangle2D(java.awt.geom.RoundRectangle2D) Path2D(java.awt.geom.Path2D) Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D)

Example 7 with Path2D

use of java.awt.geom.Path2D in project android by JetBrains.

the class LineChart method draw.

@Override
protected void draw(Graphics2D g2d, Dimension dim) {
    if (myLinePaths.size() != myLinesConfig.size()) {
        // e.g. updateData/postAnimate has not been invoked before this draw call.
        return;
    }
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    AffineTransform scale = AffineTransform.getScaleInstance(dim.getWidth(), dim.getHeight());
    // Cache the transformed line paths for reuse below.
    List<Path2D> transformedPaths = new ArrayList<>(myLinePaths.size());
    for (int i = 0; i < myLinePaths.size(); ++i) {
        Path2D scaledPath = new Path2D.Float(myLinePaths.get(i), scale);
        scaledPath = myReducer.reduce(scaledPath, myLinePathConfigs.get(i));
        transformedPaths.add(scaledPath);
        if (isDrawDebugInfo()) {
            int count = 0;
            PathIterator it = scaledPath.getPathIterator(null);
            while (!it.isDone()) {
                ++count;
                it.next();
            }
            addDebugInfo("# of points drawn: %d", count);
        }
    }
    // 1st pass - draw all the lines in the background.
    drawLines(g2d, transformedPaths, myLinePathConfigs, false);
    // 2nd pass - call each custom renderer instances to redraw any regions/lines as needed.
    myCustomRenderers.forEach(renderer -> renderer.renderLines(this, g2d, transformedPaths, myLinePathConfigs));
}
Also used : PathIterator(java.awt.geom.PathIterator) Path2D(java.awt.geom.Path2D) TDoubleArrayList(gnu.trove.TDoubleArrayList) AffineTransform(java.awt.geom.AffineTransform)

Example 8 with Path2D

use of java.awt.geom.Path2D in project jdk8u_jdk by JetBrains.

the class LineBorder 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
     */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if ((this.thickness > 0) && (g instanceof Graphics2D)) {
        Graphics2D g2d = (Graphics2D) g;
        Color oldColor = g2d.getColor();
        g2d.setColor(this.lineColor);
        Shape outer;
        Shape inner;
        int offs = this.thickness;
        int size = offs + offs;
        if (this.roundedCorners) {
            float arc = .2f * offs;
            outer = new RoundRectangle2D.Float(x, y, width, height, offs, offs);
            inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc);
        } else {
            outer = new Rectangle2D.Float(x, y, width, height);
            inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size);
        }
        Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
        path.append(outer, false);
        path.append(inner, false);
        g2d.fill(path);
        g2d.setColor(oldColor);
    }
}
Also used : Shape(java.awt.Shape) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Path2D(java.awt.geom.Path2D) Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Graphics2D(java.awt.Graphics2D)

Example 9 with Path2D

use of java.awt.geom.Path2D in project jdk8u_jdk by JetBrains.

the class TitledBorder 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
     */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Border border = getBorder();
    String title = getTitle();
    if ((title != null) && !title.isEmpty()) {
        int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING;
        JLabel label = getLabel(c);
        Dimension size = label.getPreferredSize();
        Insets insets = getBorderInsets(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;
        }
        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;
        }
        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 (border != null) {
        border.paintBorder(c, g, x, y, width, height);
    }
}
Also used : Graphics(java.awt.Graphics) Insets(java.awt.Insets) Path2D(java.awt.geom.Path2D) Rectangle(java.awt.Rectangle) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Graphics2D(java.awt.Graphics2D)

Example 10 with Path2D

use of java.awt.geom.Path2D in project WordCram by danbernier.

the class SvgWordRenderer method renderShape.

private void renderShape(Shape shape) {
    Path2D.Double path2d = new Path2D.Double(shape);
    // or WIND_NON_ZERO
    path2d.setWindingRule(Path2D.WIND_EVEN_ODD);
    PathIterator pathIter = path2d.getPathIterator(null);
    float[] coords = new float[6];
    p("<path d=\"");
    while (!pathIter.isDone()) {
        int type = pathIter.currentSegment(coords);
        switch(type) {
            case PathIterator.SEG_MOVETO:
                p("M" + coords[0] + " " + coords[1]);
                break;
            case PathIterator.SEG_LINETO:
                p("L" + coords[0] + " " + coords[1]);
                break;
            case PathIterator.SEG_QUADTO:
                p("Q" + coords[0] + " " + coords[1] + " " + coords[2] + " " + coords[3]);
                break;
            case PathIterator.SEG_CUBICTO:
                p("C" + coords[0] + " " + coords[1] + " " + coords[2] + " " + coords[3] + " " + coords[4] + " " + coords[5]);
                break;
            case PathIterator.SEG_CLOSE:
                p("Z");
                break;
        }
        pathIter.next();
    }
    pl("\"/>");
}
Also used : PathIterator(java.awt.geom.PathIterator) 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