Example usage for java.awt.geom GeneralPath getCurrentPoint

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

Introduction

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

Prototype

public final synchronized Point2D getCurrentPoint() 

Source Link

Document

Returns the coordinates most recently added to the end of the path as a Point2D object.

Usage

From source file:MyCanvas.java

public void paint(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;
    Point2D.Float point = new Point2D.Float(100, 100); // store start point
    GeneralPath p = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    p.moveTo(point.x, point.y);//from w ww . j a  v  a 2s .com
    p.lineTo(point.x + 20.0f, point.y - 5.0f); // Line from start to A
    point = (Point2D.Float) p.getCurrentPoint();
    p.lineTo(point.x + 5.0f, point.y - 20.0f); // Line from A to B
    point = (Point2D.Float) p.getCurrentPoint();
    p.lineTo(point.x + 5.0f, point.y + 20.0f); // Line from B to C
    point = (Point2D.Float) p.getCurrentPoint();
    p.lineTo(point.x + 20.0f, point.y + 5.0f); // Line from C to D
    point = (Point2D.Float) p.getCurrentPoint();
    p.lineTo(point.x - 20.0f, point.y + 5.0f); // Line from D to E
    point = (Point2D.Float) p.getCurrentPoint();
    p.lineTo(point.x - 5.0f, point.y + 20.0f); // Line from E to F
    point = (Point2D.Float) p.getCurrentPoint();
    p.lineTo(point.x - 5.0f, point.y - 20.0f); // Line from F to g
    p.closePath(); // Line from G to start
    g2D.draw(p);
}

From source file:savant.view.tracks.ContinuousTrackRenderer.java

@Override
public void render(Graphics2D g2, GraphPaneAdapter gp) throws RenderingException {

    renderPreCheck();//from   w w  w  . ja v  a2  s  .c o  m

    AxisRange axisRange = (AxisRange) instructions.get(DrawingInstruction.AXIS_RANGE);
    gp.setXRange(axisRange.getXRange());
    gp.setYRange(axisRange.getYRange());

    if (gp.needsToResize())
        return;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME);
    Color fillcolor = cs.getColor(ColourKey.CONTINUOUS_FILL);
    Color linecolor = cs.getColor(ColourKey.CONTINUOUS_LINE);

    GeneralPath path = new GeneralPath();
    double xFormXPos = Double.NaN, xFormYPos = Double.NaN;

    double yPixel0 = gp.transformYPos(0.0);
    LOG.debug("h=" + gp.getHeight() + ", yMin=" + gp.getYRange().getFrom() + ", unitHeight="
            + gp.getUnitHeight() + " \u27A4 yPixel0=" + yPixel0);

    double maxData = 0;
    boolean haveOpenPath = false;
    boolean haveData = false;
    if (data != null) {
        for (int i = 0; i < data.size(); i++) {
            ContinuousRecord continuousRecord = (ContinuousRecord) data.get(i);
            int xPos = continuousRecord.getPosition();
            float yPos = continuousRecord.getValue();
            if (Float.isNaN(yPos)) {
                // Hit a position with no data.  May need to close off the current path.
                if (haveOpenPath) {
                    path.lineTo(xFormXPos, yPixel0);
                    path.closePath();
                    haveOpenPath = false;
                }
            } else {
                haveData = true;
                xFormXPos = gp.transformXPos(xPos);//+gp.getUnitWidth()/2;
                xFormYPos = gp.transformYPos(yPos);
                if (!haveOpenPath) {
                    // Start our path off with a vertical line.
                    path.moveTo(xFormXPos, yPixel0);
                    haveOpenPath = true;
                }
                path.lineTo(xFormXPos, xFormYPos);
                Rectangle2D rec = new Rectangle2D.Double(
                        xFormXPos - ((xFormXPos - path.getCurrentPoint().getX()) / 2), 0,
                        Math.max(xFormXPos - path.getCurrentPoint().getX(), 1), gp.getHeight());
                recordToShapeMap.put(continuousRecord, rec);
                xFormXPos = gp.transformXPos(xPos + 1);
                path.lineTo(xFormXPos, xFormYPos);
            }
            if (yPos > maxData) {
                maxData = yPos;
            }
        }
    }
    if (!haveData) {
        throw new RenderingException("No data in range", RenderingException.INFO_PRIORITY);
    }
    if (haveOpenPath) {
        // Path needs to be closed.
        path.lineTo(xFormXPos, yPixel0);
        path.closePath();
    }

    g2.setColor(fillcolor);
    g2.fill(path);
    g2.setColor(linecolor);
    g2.draw(path);

    if (axisRange.getYRange().getFrom() < 0) {
        g2.setColor(Color.darkGray);
        g2.draw(new Line2D.Double(0.0, yPixel0, gp.getWidth(), yPixel0));
    }
}