Search in sources :

Example 16 with Path2D

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

the class LineChart method drawLines.

public static void drawLines(Graphics2D g2d, List<Path2D> transformedPaths, List<LineConfig> configs, boolean grayScale) {
    assert transformedPaths.size() == configs.size();
    for (int i = 0; i < transformedPaths.size(); ++i) {
        Path2D path = transformedPaths.get(i);
        LineConfig config = configs.get(i);
        Color lineColor = config.getColor();
        if (grayScale) {
            int gray = (lineColor.getBlue() + lineColor.getRed() + lineColor.getGreen()) / 3;
            g2d.setColor(new Color(gray, gray, gray));
        } else {
            g2d.setColor(lineColor);
        }
        g2d.setStroke(config.getStroke());
        if (config.isFilled()) {
            g2d.fill(path);
        } else {
            g2d.draw(path);
        }
    }
}
Also used : Path2D(java.awt.geom.Path2D)

Example 17 with Path2D

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

the class LineChartReducer method reduce.

@Override
public Path2D reduce(@NotNull Path2D path, @NotNull LineConfig config) {
    if (path.getCurrentPoint() == null) {
        return path;
    }
    Path2D resultPath = new Path2D.Float();
    float[] coords = new float[PATH_ITERATOR_COORDS_COUNT];
    float pixel = -1;
    float minX = -1, minY = -1;
    float maxX = -1, maxY = -1;
    float curX = -1, curY = -1;
    int minIndex = -1, maxIndex = -1;
    int curIndex = 0;
    PathIterator iterator = path.getPathIterator(null);
    while (!iterator.isDone()) {
        int segType = iterator.currentSegment(coords);
        assert segType == PathIterator.SEG_MOVETO || segType == PathIterator.SEG_LINETO;
        float lastX = curX;
        float lastY = curY;
        curX = coords[0];
        curY = coords[1];
        if (curIndex > 0 && curX < lastX) {
            // The second last point must be with maximum Y
            assert equals(maxX, lastX) && equals(maxY, lastY);
            break;
        }
        if (curIndex == 0 || curX >= pixel) {
            if (curIndex > 0) {
                // Add min and max points from the previous pixel
                addMinMaxPoints(resultPath, config, minIndex, minX, minY, maxIndex, maxX, maxY);
                // Add the last point from the previous pixel
                addToResultPath(resultPath, config, lastX, lastY);
            }
            pixel = (float) Math.floor(curX) + 1;
            minX = maxX = curX;
            minY = maxY = curY;
            minIndex = maxIndex = curIndex;
            // Add the first point from the current pixel
            addToResultPath(resultPath, config, curX, curY);
        } else {
            if (minY > curY) {
                minIndex = curIndex;
                minX = curX;
                minY = curY;
            }
            if (maxY <= curY) {
                maxIndex = curIndex;
                maxX = curX;
                maxY = curY;
            }
        }
        iterator.next();
        curIndex++;
    }
    addMinMaxPoints(resultPath, config, minIndex, minX, minY, maxIndex, maxX, maxY);
    addToResultPath(resultPath, config, curX, curY);
    if (config.isStepped()) {
        // The last point won't be added if Y value is the same with previous point, so let's add it
        if (resultPath.getCurrentPoint() == null || equals((float) resultPath.getCurrentPoint().getY(), curY)) {
            addToPath(resultPath, curX, curY);
        }
    }
    return resultPath;
}
Also used : PathIterator(java.awt.geom.PathIterator) Path2D(java.awt.geom.Path2D)

Example 18 with Path2D

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

the class DividerPolygon method paint.

private void paint(Graphics2D g, int width) {
    GraphicsUtil.setupAntialiasing(g);
    if (!myApplied) {
        Shape upperCurve = makeCurve(width, myStart1, myStart2, true);
        Shape lowerCurve = makeCurve(width, myEnd1, myEnd2, false);
        Path2D path = new Path2D.Double();
        path.append(upperCurve, true);
        path.append(lowerCurve, true);
        g.setColor(myColor);
        g.fill(path);
        g.setColor(DiffUtil.getFramingColor(myColor));
        g.draw(upperCurve);
        g.draw(lowerCurve);
    } else {
        g.setColor(myColor);
        g.draw(makeCurve(width, myStart1 + 1, myStart2 + 1, true));
        g.draw(makeCurve(width, myStart1 + 2, myStart2 + 2, true));
        g.draw(makeCurve(width, myEnd1 + 1, myEnd2 + 1, false));
        g.draw(makeCurve(width, myEnd1 + 2, myEnd2 + 2, false));
    }
}
Also used : Path2D(java.awt.geom.Path2D)

Example 19 with Path2D

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

the class DiffDrawUtil method drawCurveTrapezium.

public static void drawCurveTrapezium(@NotNull Graphics2D g, int x1, int x2, int start1, int end1, int start2, int end2, @Nullable Color fillColor, @Nullable Color borderColor) {
    Shape upperCurve = makeCurve(x1, x2, start1, start2, true);
    Shape lowerCurve = makeCurve(x1, x2, end1 + 1, end2 + 1, false);
    Shape lowerCurveBorder = makeCurve(x1, x2, end1, end2, false);
    if (fillColor != null) {
        Path2D path = new Path2D.Double();
        path.append(upperCurve, true);
        path.append(lowerCurve, true);
        g.setColor(fillColor);
        g.fill(path);
    }
    if (borderColor != null) {
        g.setColor(borderColor);
        g.draw(upperCurve);
        g.draw(lowerCurveBorder);
    }
}
Also used : Path2D(java.awt.geom.Path2D)

Example 20 with Path2D

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

the class EmptyCapacity method main.

public static void main(final String[] args) {
    final Path2D path1 = new Path2D.Double(Path2D.WIND_EVEN_ODD, 0);
    path1.moveTo(10, 10);
    path1.lineTo(20, 20);
    final Path2D path2 = new Path2D.Float(Path2D.WIND_EVEN_ODD, 0);
    path2.moveTo(10, 10);
    path2.lineTo(20, 20);
}
Also used : Path2D(java.awt.geom.Path2D)

Aggregations

Path2D (java.awt.geom.Path2D)29 Rectangle2D (java.awt.geom.Rectangle2D)5 Graphics2D (java.awt.Graphics2D)4 BasicStroke (java.awt.BasicStroke)3 PathIterator (java.awt.geom.PathIterator)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