Search in sources :

Example 91 with GeneralPath

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

the class EscherGraphics2d method drawPolyline.

public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
    if (nPoints > 0) {
        GeneralPath generalpath = new GeneralPath();
        generalpath.moveTo(xPoints[0], yPoints[0]);
        for (int j = 1; j < nPoints; j++) generalpath.lineTo(xPoints[j], yPoints[j]);
        draw(generalpath);
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath)

Example 92 with GeneralPath

use of java.awt.geom.GeneralPath in project android_frameworks_base by crdroidandroid.

the class Path_Delegate method transform.

/**
     * Transform the points in this path by matrix, and write the answer
     * into dst. If dst is null, then the the original path is modified.
     *
     * @param matrix The matrix to apply to the path
     * @param dst    The transformed path is written here. If dst is null,
     *               then the the original path is modified
     */
public void transform(Matrix_Delegate matrix, Path_Delegate dst) {
    if (matrix.hasPerspective()) {
        assert false;
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_AFFINE, "android.graphics.Path#transform() only " + "supports affine transformations.", null, null);
    }
    GeneralPath newPath = new GeneralPath();
    PathIterator iterator = mPath.getPathIterator(matrix.getAffineTransform());
    newPath.append(iterator, false);
    if (dst != null) {
        dst.mPath = newPath;
    } else {
        mPath = newPath;
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath) PathIterator(java.awt.geom.PathIterator)

Example 93 with GeneralPath

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

the class RadarPlot method drawRadar.

protected void drawRadar(Graphics2D g2, Rectangle2D plotArea, PlotRenderingInfo info, int pieIndex, PieDataset data) {
    // adjust the plot area by the interior spacing value
    double gapHorizontal = plotArea.getWidth() * this.interiorGap;
    double gapVertical = plotArea.getHeight() * this.interiorGap;
    double radarX = plotArea.getX() + gapHorizontal / 2;
    double radarY = plotArea.getY() + gapVertical / 2;
    double radarW = plotArea.getWidth() - gapHorizontal;
    double radarH = plotArea.getHeight() - gapVertical;
    // NOTE that non-circular radar charts are not currently supported.
    if (true) {
        //circular) {
        double min = Math.min(radarW, radarH) / 2;
        radarX = (radarX + radarX + radarW) / 2 - min;
        radarY = (radarY + radarY + radarH) / 2 - min;
        radarW = 2 * min;
        radarH = 2 * min;
    }
    double radius = radarW / 2;
    double centerX = radarX + radarW / 2;
    double centerY = radarY + radarH / 2;
    Rectangle2D radarArea = new Rectangle2D.Double(radarX, radarY, radarW, radarH);
    // plot the data (unless the dataset is null)...
    if ((data != null) && (data.getKeys().size() > 0)) {
        // get a list of categories...
        List keys = data.getKeys();
        int numAxes = keys.size();
        // draw each of the axes on the radar chart, and register
        // the shape of the radar line.
        double multiplier = 1.0;
        GeneralPath lineShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1);
        GeneralPath gridShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1);
        int axisNumber = -1;
        Iterator iterator = keys.iterator();
        while (iterator.hasNext()) {
            Comparable currentKey = (Comparable) iterator.next();
            axisNumber++;
            Number dataValue = data.getValue(currentKey);
            double value = (dataValue != null ? dataValue.doubleValue() : 0);
            if (value > 1 || Double.isNaN(value) || Double.isInfinite(value))
                value = 1.0;
            if (value < 0)
                value = 0.0;
            multiplier *= value;
            double angle = 2 * Math.PI * axisNumber / numAxes;
            double deltaX = Math.sin(angle) * radius;
            double deltaY = -Math.cos(angle) * radius;
            // draw the spoke
            g2.setPaint(axisPaint);
            g2.setStroke(axisStroke);
            Line2D line = new Line2D.Double(centerX, centerY, centerX + deltaX, centerY + deltaY);
            g2.draw(line);
            // register the grid line and the shape line
            if (axisNumber == 0) {
                gridShape.moveTo((float) deltaX, (float) deltaY);
                lineShape.moveTo((float) (deltaX * value), (float) (deltaY * value));
            } else {
                gridShape.lineTo((float) deltaX, (float) deltaY);
                lineShape.lineTo((float) (deltaX * value), (float) (deltaY * value));
            }
            if (showAxisLabels) {
                // draw the label
                double labelX = centerX + deltaX * (1 + axisLabelGap);
                double labelY = centerY + deltaY * (1 + axisLabelGap);
                String label = currentKey.toString();
                drawLabel(g2, radarArea, label, axisNumber, labelX, labelY);
            }
        }
        gridShape.closePath();
        lineShape.closePath();
        // draw five gray concentric gridlines
        g2.translate(centerX, centerY);
        g2.setPaint(gridLinePaint);
        g2.setStroke(gridLineStroke);
        for (int i = 5; i > 0; i--) {
            Shape scaledGrid = gridShape.createTransformedShape(AffineTransform.getScaleInstance(i / 5.0, i / 5.0));
            g2.draw(scaledGrid);
        }
        // get the color for the plot shape.
        Paint dataPaint = plotLinePaint;
        if (dataPaint == ADAPTIVE_COLORING) {
            //multiplier = Math.exp(Math.log(multiplier) * 2 / numAxes);
            dataPaint = getMultiplierColor((float) multiplier);
        }
        // compute a slightly transparent version of the plot color for
        // the fill.
        Paint dataFill = null;
        if (dataPaint instanceof Color && getForegroundAlpha() != 1.0)
            dataFill = new Color(((Color) dataPaint).getRed() / 255f, ((Color) dataPaint).getGreen() / 255f, ((Color) dataPaint).getBlue() / 255f, getForegroundAlpha());
        else
            dataFill = dataPaint;
        // draw the plot shape.  First fill with a parially
        // transparent color, then stroke with the opaque color.
        g2.setPaint(dataFill);
        g2.fill(lineShape);
        g2.setPaint(dataPaint);
        g2.setStroke(plotLineStroke);
        g2.draw(lineShape);
        // cleanup the graphics context.
        g2.translate(-centerX, -centerY);
    }
}
Also used : Shape(java.awt.Shape) GeneralPath(java.awt.geom.GeneralPath) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) Iterator(java.util.Iterator) List(java.util.List)

Example 94 with GeneralPath

use of java.awt.geom.GeneralPath in project vcell by virtualcell.

the class GraphEdgeShape method paintSelf.

@Override
public void paintSelf(Graphics2D g2D, int absPosX, int absPosY) {
    super.paintSelf(g2D, absPosX, absPosY);
    // 
    if (bArrow) {
        Point startLocation = getNode1Shape().getAttachmentLocation(Shape.ATTACH_CENTER);
        Point endLocation = getNode2Shape().getAttachmentLocation(Shape.ATTACH_CENTER);
        double diffX = endLocation.x - startLocation.x;
        double diffY = endLocation.y - startLocation.y;
        double length = Math.sqrt(diffX * diffX + diffY * diffY);
        double arrowScale = 10 / length;
        Point front = new Point((int) (startLocation.x + diffX / 2 + diffX * arrowScale / 2), (int) (startLocation.y + diffY / 2 + diffY * arrowScale / 2));
        Point back = new Point((int) (startLocation.x + diffX / 2 - diffX * arrowScale / 2), (int) (startLocation.y + diffY / 2 - diffY * arrowScale / 2));
        GeneralPath path = getArrow(front, back, 10);
        g2D.fill(path);
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Point(java.awt.Point)

Example 95 with GeneralPath

use of java.awt.geom.GeneralPath in project vcell by virtualcell.

the class BioPaxInteractionParticipantShape method paintSelf.

@Override
public void paintSelf(Graphics2D g2d, int xAbs, int yAbs) {
    RenderingHints oldRenderingHints = g2d.getRenderingHints();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Color oldColor = g2d.getColor();
    g2d.setColor(forgroundColor);
    CubicCurve2D.Double cubicCurve = getCurve();
    if (participant.getType().equals(Type.CONTROLLER) || participant.getType().equals(Type.COFACTOR)) {
        Stroke previousStroke = g2d.getStroke();
        // g2d.setStroke(DASHED_STROKE);   CATALYST_STROKE
        g2d.setStroke(DASHED_STROKE);
        g2d.draw(cubicCurve);
        g2d.setStroke(previousStroke);
    } else {
        g2d.draw(cubicCurve);
    }
    int arrowDirection = 0;
    if (participant.getType().equals(Type.LEFT)) {
        arrowDirection = -1;
    } else if (participant.getType().equals(Type.RIGHT)) {
        arrowDirection = 1;
    }
    if (arrowDirection == 1) {
        double arcLength = integrateArcLength(cubicCurve, 0.0, 1.0, 10);
        double centerT = getParameterAtArcLength(cubicCurve, 0.0, 1.0, arcLength / 2, 20);
        Point2D center = evaluate(cubicCurve, centerT);
        double backT = intersectWithCircle(cubicCurve, centerT, 1.0, center.getX(), center.getY(), 4);
        Point2D back = evaluate(cubicCurve, backT);
        double frontT = intersectWithCircle(cubicCurve, centerT, 0.0, center.getX(), center.getY(), 4);
        Point2D front = evaluate(cubicCurve, frontT);
        GeneralPath arrow = getArrow(front, back, 7);
        g2d.fill(arrow);
    }
    if (arrowDirection == -1) {
        double arcLength = integrateArcLength(cubicCurve, 0.0, 1.0, 10);
        double centerT = getParameterAtArcLength(cubicCurve, 0.0, 1.0, arcLength / 2 + 2, 20);
        Point2D center = evaluate(cubicCurve, centerT);
        double backT = intersectWithCircle(cubicCurve, centerT, 0.0, center.getX(), center.getY(), 4);
        Point2D back = evaluate(cubicCurve, backT);
        double frontT = intersectWithCircle(cubicCurve, centerT, 1.0, center.getX(), center.getY(), 4);
        Point2D front = evaluate(cubicCurve, frontT);
        GeneralPath arrow = getArrow(front, back, 7);
        g2d.fill(arrow);
    }
    // draw label (nothing expected, we don't have stoichiometry around here)
    if (getLabel() != null && getLabel().length() > 0) {
        int x = start.x + (int) (start.x * correctionFactor);
        int y = start.y + (int) (start.y * correctionFactor);
        g2d.drawString(getLabel(), (x + end.x) / 2, (y + end.y) / 2);
    }
    // TODO: there are types other than LEFT, RIGHT, CONTROLLER, COFACTOR, we need to draw something for them too
    // we'll add code for that as we find them
    // 
    // Keeping below the simple code that only draws straight line
    // 
    // Point startPos = interactionShape.getSpaceManager().getAbsCenter();
    // Point endPos = physicalEntityShape.getSpaceManager().getAbsCenter();
    // 
    // if(participant.getType().equals(Type.CONTROLLER) || participant.getType().equals(Type.COFACTOR)) {
    // Stroke previousStroke = g2d.getStroke();
    // g2d.setStroke(CATALYST_STROKE);
    // g2d.drawLine(startPos.x, startPos.y, endPos.x, endPos.y);
    // g2d.setStroke(previousStroke);
    // } else {
    // g2d.drawLine(startPos.x, startPos.y, endPos.x, endPos.y);
    // 
    // }
    // if(participant.getType().equals(Type.LEFT)) {
    // ArrowPainter.paintArrow(g2d, endPos, startPos, ARROW_LENGTH, ARROW_WIDTH);
    // } else if(participant.getType().equals(Type.RIGHT)) {
    // ArrowPainter.paintArrow(g2d, startPos, endPos, ARROW_LENGTH, ARROW_WIDTH);
    // }
    // String label = getLabel();
    // if(label != null) {
    // g2d.drawString(label, xAbs + labelPos.x, yAbs + labelPos.y);
    // }
    g2d.setColor(oldColor);
    g2d.setRenderingHints(oldRenderingHints);
}
Also used : Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath) Point2D(java.awt.geom.Point2D) Color(java.awt.Color) CubicCurve2D(java.awt.geom.CubicCurve2D) RenderingHints(java.awt.RenderingHints) Point(java.awt.Point)

Aggregations

GeneralPath (java.awt.geom.GeneralPath)96 Point (java.awt.Point)14 AffineTransform (java.awt.geom.AffineTransform)14 PathIterator (java.awt.geom.PathIterator)14 Graphics2D (java.awt.Graphics2D)8 Rectangle2D (java.awt.geom.Rectangle2D)8 Color (java.awt.Color)7 Paint (java.awt.Paint)7 BasicStroke (java.awt.BasicStroke)6 Point2D (java.awt.geom.Point2D)6 Stroke (java.awt.Stroke)5 Area (java.awt.geom.Area)4 Shape (java.awt.Shape)3 CubicCurve2D (java.awt.geom.CubicCurve2D)3 LayoutPathImpl (sun.font.LayoutPathImpl)3 GradientPaint (java.awt.GradientPaint)2 Rectangle (java.awt.Rectangle)2 Line2D (java.awt.geom.Line2D)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 JBColor (com.intellij.ui.JBColor)1