Java Reference
In-Depth Information
Example 13−2: Scribble.java (continued)
* Return a PathIterator object that tells Java2D how to draw this scribble
**/
public PathIterator getPathIterator(AffineTransform at) {
return new ScribbleIterator(at);
}
/**
* Return a PathIterator that doesn't include curves. Ours never does.
**/
public PathIterator getPathIterator(AffineTransform at, double flatness) {
return getPathIterator(at);
}
/**
* This inner class implements the PathIterator interface to describe
* the shape of a scribble. Since a Scribble is composed of arbitrary
* movetos and linetos, we simply return their coordinates
**/
public class ScribbleIterator implements PathIterator {
protected int i = 0;
// Position in array
protected AffineTransform transform;
public ScribbleIterator(AffineTransform transform) {
this.transform = transform;
}
/** How to determine insideness and outsideness for this shape */
public int getWindingRule() { return PathIterator.WIND_NON_ZERO; }
/** Have we reached the end of the scribble path yet? */
public boolean isDone() { return i >= numPoints; }
/** Move on to the next segment of the path */
public void next() {
if (Double.isNaN(points[i])) i += 3;
else i += 2;
}
/**
* Get the coordinates of the current moveto or lineto as floats
**/
public int currentSegment(float[] coords) {
int retval;
if (Double.isNaN(points[i])) {
// If its a moveto
coords[0] = (float)points[i+1];
coords[1] = (float)points[i+2];
retval = SEG_MOVETO;
}
else {
coords[0] = (float)points[i];
coords[1] = (float)points[i+1];
retval = SEG_LINETO;
}
// If a transform was specified, use it on the coordinates
if (transform != null) transform.transform(coords, 0, coords, 0,1);
return retval;
Search WWH ::




Custom Search