Example usage for java.awt.geom GeneralPath lineTo

List of usage examples for java.awt.geom GeneralPath lineTo

Introduction

In this page you can find the example usage for java.awt.geom GeneralPath lineTo.

Prototype

public abstract void lineTo(double x, double y);

Source Link

Document

Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates specified in double precision.

Usage

From source file:net.sourceforge.processdash.ui.web.reports.RadarPlot.java

protected void drawRadar(Graphics2D g2, Rectangle2D plotArea, PlotRenderingInfo info, int pieIndex,
        PieDataset data) {//w w w .  j a  va 2  s.c  om

    // 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;

    // make the radar area a square if the radar chart is to be circular...
    // 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);
    }
}

From source file:DefaultGraphics2D.java

/**
 * Draws a sequence of connected lines defined by arrays of <i>x</i> and <i>y</i>
 * coordinates. Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines
 * a point. The figure is not closed if the first point differs from the last
 * point.//from ww w  . j a v a 2s  .  co m
 * 
 * @param xPoints
 *          an array of <i>x</i> points
 * @param yPoints
 *          an array of <i>y</i> points
 * @param nPoints
 *          the total number of points
 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
 * @since JDK1.1
 */
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
    if (nPoints > 0) {
        GeneralPath path = new GeneralPath();
        path.moveTo(xPoints[0], yPoints[0]);
        for (int i = 1; i < nPoints; i++)
            path.lineTo(xPoints[i], yPoints[i]);

        draw(path);
    }
}

From source file:nl.b3p.kaartenbalie.core.server.b3pLayering.ConfigLayer.java

protected void drawTitledMessageBox(Graphics2D g2d, String title, String message, int x, int y, int w, int h) {
    /* Do some calculations and init variables. */
    g2d.setFont(KBConfiguration.OHD_messageBoxFont);
    FontMetrics fm = g2d.getFontMetrics();
    int labelHeight = KBConfiguration.OHD_messageBoxFont.getSize() + (KBConfiguration.OHD_padding * 2);
    int angling = labelHeight;
    Rectangle2D testRectangle = fm.getStringBounds(title, g2d);
    int labelWidth = (int) testRectangle.getWidth();

    if (w < labelWidth + (2 * angling)) {
        w = labelWidth + (2 * angling);//from   w ww  . j a v a2s. co m
    }
    y += labelHeight;
    /* Now draw the box...    */
    drawMessageBox(g2d, message, x, y, w, h);

    /* Draw the label background */
    g2d.setColor(KBConfiguration.OHD_labelBoxColor);
    GeneralPath label = new GeneralPath();
    label.moveTo(x, y);
    label.lineTo(x + angling, y - labelHeight);
    label.lineTo(x + angling + labelWidth, y - labelHeight);
    label.lineTo(x + (angling * 2) + labelWidth, y);
    label.closePath();
    g2d.fill(label);

    /* Draw the label Lines..  */
    g2d.setColor(KBConfiguration.OHD_borderBoxTopLeft);
    g2d.drawLine(x, y, x + angling, y - labelHeight);
    g2d.drawLine(x + angling, y - labelHeight, x + angling + labelWidth, y - labelHeight);
    g2d.setColor(KBConfiguration.OHD_borderBoxBottomRight);
    g2d.drawLine(x + angling + labelWidth, y - labelHeight, x + (angling * 2) + labelWidth, y);
    g2d.setColor(KBConfiguration.OHD_borderBoxBackground);
    g2d.drawLine(x + (angling * 2) + labelWidth, y, x, y);
    /*Then add the title... */
    g2d.setColor(KBConfiguration.OHD_labelFontBoxColor);
    g2d.drawString(title, x + angling, y - KBConfiguration.OHD_padding);

}

From source file:org.apache.fontbox.ttf.GlyphRenderer.java

private void lineTo(GeneralPath path, Point point) {
    path.lineTo(point.x, point.y);
    if (LOG.isDebugEnabled()) {
        LOG.trace("lineTo: " + String.format("%d,%d", point.x, point.y));
    }//from  w  ww.  ja v  a2  s  . co m
}

From source file:org.apache.pdfbox.pdfviewer.font.TTFGlyph2D.java

private void lineTo(GeneralPath path, Point point) {
    path.lineTo(point.x, point.y);
    LOG.debug("lineTo: " + String.format("%d,%d", point.x, point.y));
}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

@Override
public void drawArc(ArcRenderEvent are) throws ChartException {
    if (iv != null) {
        iv.modifyEvent(are);//from w  ww  .  jav a 2  s. c o m
    }

    // CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED
    final LineAttributes lia = are.getOutline();
    if (!validateLineAttributes(are.getSource(), lia)) {
        return;
    }

    // SETUP THE FOREGROUND COLOR (DARKER BACKGROUND IF DEFINED AS NULL)
    final Color cFG = (Color) validateEdgeColor(lia.getColor(), are.getBackground(), _ids);
    if (cFG == null || cFG.getAlpha() == 0) {
        return;
    }

    // DRAW THE ARC
    Stroke sPrevious = null;
    Stroke sCurrent = getCachedStroke(lia);
    if (sCurrent != null) // SOME STROKE DEFINED?
    {
        sPrevious = _g2d.getStroke();
        _g2d.setStroke(sCurrent);
    }
    _g2d.setColor(cFG);

    if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0 && are.getInnerRadius() < are.getOuterRadius())
            || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) {
        Bounds rctOuter = getOuterRectangle(are);
        Bounds rctInner = getInnerRectangle(are);

        Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(),
                rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.OPEN);
        Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(),
                rctInner.getHeight(), are.getStartAngle() + are.getAngleExtent(), -are.getAngleExtent(),
                Arc2D.OPEN);

        double startAngle = Math.toRadians(-are.getStartAngle());
        double stopAngle = Math.toRadians(-are.getStartAngle() - are.getAngleExtent());

        double xsOuter = (rctOuter.getLeft() + (Math.cos(startAngle) * 0.5 + 0.5) * rctOuter.getWidth());
        double ysOuter = (rctOuter.getTop() + (Math.sin(startAngle) * 0.5 + 0.5) * rctOuter.getHeight());

        double xeInner = (rctInner.getLeft() + (Math.cos(stopAngle) * 0.5 + 0.5) * rctInner.getWidth());
        double yeInner = (rctInner.getTop() + (Math.sin(stopAngle) * 0.5 + 0.5) * rctInner.getHeight());

        GeneralPath gp = new GeneralPath();
        gp.append(outerArc, false);
        gp.lineTo((float) xeInner, (float) yeInner);
        gp.append(innerArc, false);
        gp.lineTo((float) xsOuter, (float) ysOuter);

        Area area = new Area(gp);
        Shape prevClip = _g2d.getClip();
        Area ar2 = new Area(area);
        if (prevClip != null) {
            Area ar1 = new Area(prevClip);
            ar2.intersect(ar1);
        }
        _g2d.setClip(ar2);
        _g2d.draw(area);
        _g2d.setClip(prevClip);

    } else {
        _g2d.draw(new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(),
                are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle())));
    }

    if (sPrevious != null) // RESTORE PREVIOUS STROKE
    {
        _g2d.setStroke(sPrevious);
    }
}

From source file:org.esa.snap.graphbuilder.gpf.ui.worldmap.NestWorldMapPane.java

public static ArrayList<GeneralPath> assemblePathList(GeoPos[] geoPoints) {
    final GeneralPath path = new GeneralPath(GeneralPath.WIND_NON_ZERO, geoPoints.length + 8);
    final ArrayList<GeneralPath> pathList = new ArrayList<>(16);

    if (geoPoints.length > 1) {
        double lon, lat;
        double minLon = 0, maxLon = 0;

        boolean first = true;
        for (GeoPos gp : geoPoints) {
            lon = gp.getLon();//  w  w  w.  ja  v a2 s  .c  om
            lat = gp.getLat();
            if (first) {
                minLon = lon;
                maxLon = lon;
                path.moveTo(lon, lat);
                first = false;
            }
            if (lon < minLon) {
                minLon = lon;
            }
            if (lon > maxLon) {
                maxLon = lon;
            }
            path.lineTo(lon, lat);
        }
        path.closePath();

        int runIndexMin = (int) Math.floor((minLon + 180) / 360);
        int runIndexMax = (int) Math.floor((maxLon + 180) / 360);

        if (runIndexMin == 0 && runIndexMax == 0) {
            // the path is completely within [-180, 180] longitude
            pathList.add(path);
            return pathList;
        }

        final Area pathArea = new Area(path);
        final GeneralPath pixelPath = new GeneralPath(GeneralPath.WIND_NON_ZERO);
        for (int k = runIndexMin; k <= runIndexMax; k++) {
            final Area currentArea = new Area(
                    new Rectangle2D.Float(k * 360.0f - 180.0f, -90.0f, 360.0f, 180.0f));
            currentArea.intersect(pathArea);
            if (!currentArea.isEmpty()) {
                pathList.add(areaToPath(currentArea, -k * 360.0, pixelPath));
            }
        }
    }
    return pathList;
}

From source file:org.esa.snap.graphbuilder.gpf.ui.worldmap.NestWorldMapPane.java

public static GeneralPath areaToPath(final Area negativeArea, final double deltaX,
        final GeneralPath pixelPath) {

    final float[] floats = new float[6];
    // move to correct rectangle
    final AffineTransform transform = AffineTransform.getTranslateInstance(deltaX, 0.0);
    final PathIterator iterator = negativeArea.getPathIterator(transform);

    while (!iterator.isDone()) {
        final int segmentType = iterator.currentSegment(floats);
        if (segmentType == PathIterator.SEG_LINETO) {
            pixelPath.lineTo(floats[0], floats[1]);
        } else if (segmentType == PathIterator.SEG_MOVETO) {
            pixelPath.moveTo(floats[0], floats[1]);
        } else if (segmentType == PathIterator.SEG_CLOSE) {
            pixelPath.closePath();//from w  w  w. j  a  v a  2 s  .c  o  m
        }
        iterator.next();
    }
    return pixelPath;
}

From source file:org.jcurl.math.helpers.CurveShape.java

public static Shape approximateLinear(final CurveGhost c, final double[] sections)
        throws FunctionEvaluationException {
    final double[] x_1 = { c.getC(0, 0, sections[0]), c.getC(1, 0, sections[0]) };
    final double[] x_2 = { 0, 0 };
    final GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO, sections.length + 1);
    gp.moveTo((float) x_1[0], (float) x_1[1]);
    for (int i = 1; i < sections.length; i++) {
        x_2[0] = c.getC(0, 0, sections[i]);
        x_2[1] = c.getC(1, 0, sections[i]);
        gp.lineTo((float) x_2[0], (float) x_2[1]);
        x_1[0] = x_2[0];//from   w w  w.j a v  a2 s. co m
        x_1[1] = x_2[1];
    }
    return gp;
}

From source file:org.jcurl.math.ShaperUtils.java

/**
 * Add one <a href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve">Linear
 * Bezier Curve</a> to a {@link GeneralPath}. Does <b>no</b> initial
 * {@link GeneralPath#moveTo(float, float)}.
 * /*from  w ww .j a va2s. com*/
 * <h3>Approximation algorithm</h3>
 * <p>
 * Just connect start- and endpoint.
 * <p>
 * TODO maybe re-use endpoint location and velocity. This can cause pain at
 * C1 discontinuous t's (collissions).
 * </p>
 */
static final void lineTo(final R1RNFunction f, final double tmax, final GeneralPath gp, final float zoom) {
    final float x = (float) f.at(tmax, 0, 0);
    final float y = (float) f.at(tmax, 0, 1);
    gp.lineTo(zoom * x, zoom * y);
}