Example usage for java.awt.geom PathIterator PathIterator

List of usage examples for java.awt.geom PathIterator PathIterator

Introduction

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

Prototype

PathIterator

Source Link

Usage

From source file:TransferableScribblePane.java

public PathIterator getPathIterator(final AffineTransform transform) {
    return new PathIterator() {
        int curseg = -1; // current segment

        // Copy the current segment for thread-safety, so we don't
        // mess up of a segment is added while we're iterating
        int numsegs = PolyLine.this.numsegs;

        public boolean isDone() {
            return curseg >= numsegs;
        }/*from  www.ja v  a2 s  .com*/

        public void next() {
            curseg++;
        }

        // Get coordinates and type of current segment as floats
        public int currentSegment(float[] data) {
            int segtype;
            if (curseg == -1) { // First time we're called
                data[0] = x0; // Data is the origin point
                data[1] = y0;
                segtype = SEG_MOVETO; // Returned as a moveto segment
            } else { // Otherwise, the data is a segment endpoint
                data[0] = x0 + coords[curseg * 2];
                data[1] = y0 + coords[curseg * 2 + 1];
                segtype = SEG_LINETO; // Returned as a lineto segment
            }
            // If a tranform was specified, transform point in place
            if (transform != null)
                transform.transform(data, 0, data, 0, 1);
            return segtype;
        }

        // Same as last method, but use doubles
        public int currentSegment(double[] data) {
            int segtype;
            if (curseg == -1) {
                data[0] = x0;
                data[1] = y0;
                segtype = SEG_MOVETO;
            } else {
                data[0] = x0 + coords[curseg * 2];
                data[1] = y0 + coords[curseg * 2 + 1];
                segtype = SEG_LINETO;
            }
            if (transform != null)
                transform.transform(data, 0, data, 0, 1);
            return segtype;
        }

        // This only matters for closed shapes
        public int getWindingRule() {
            return WIND_NON_ZERO;
        }
    };
}