edu.neu.ccs.gui
Class PathListIterator

java.lang.Object
  |
  +--edu.neu.ccs.gui.PathListIterator
All Implemented Interfaces:
PathIterator

public class PathListIterator
extends Object
implements PathIterator

The PathListIterator class creates a Java PathIterator based on an internal PathList.

The caller may query or modify the internal PathList.

If a path list is used in a constructor or in the method setPathList, this iterator is linked to that path list.

The caller may reset the iterator to its initial state to allow multiple uses of the iterator.

A factory method is provided to construct a new Java Shape from the current iterator data. This method uses the Java class GeneralPath.

In construction of a Shape via GeneralPath, Java requires that the start node have type MOVE. If this condition does not hold, Java throws IllegalPathStateException. In this class, the requirement that the start node have type MOVE is tested by the method isValid(). If this method returns false and the user calls makeShape, an empty Shape will be returned by this call rather than throwing an exception.


Field Summary
static int CLOSE
          Shorthand constant for PathIterator.SEG_CLOSE.
static int CUBIC
          Shorthand constant for PathIterator.SEG_CUBICTO.
static int LINE
          Shorthand constant for PathIterator.SEG_LINETO.
static int MOVE
          Shorthand constant for PathIterator.SEG_MOVETO.
protected  PathList pathlist
          The path list used by this iterator.
static int QUAD
          Shorthand constant for PathIterator.SEG_QUADTO.
 
Fields inherited from interface java.awt.geom.PathIterator
SEG_CLOSE, SEG_CUBICTO, SEG_LINETO, SEG_MOVETO, SEG_QUADTO, WIND_EVEN_ODD, WIND_NON_ZERO
 
Constructor Summary
PathListIterator()
          The default constructor that initializes the iterator to a new PathList object with zero nodes and winding rule WindingRule.WIND_NON_ZERO.
PathListIterator(PathList list)
          The constructor that initializes the iterator using the given PathList object.
 
Method Summary
 int currentSegment(double[] coords)
          Returns the type of the current segment as the return value and stores the numeric data of the segment in the supplied array which must be non-null and of size at least 6.
 int currentSegment(float[] coords)
          Returns the type of the current segment as the return value and stores the numeric data of the segment in the supplied array which must be non-null and of size at least 6.
 PathList getPathList()
          Returns the internal PathList that is the basis for this iterator.
 int getWindingRule()
          Returns the winding rule of the iterator as an int.
 boolean isDone()
          Returns true if the iteration pointer is beyond the last available path segment in the internal path list or if this path list is not a valid path list for the construction of a Shape.
 boolean isValid()
          Returns true if this PathListIterator is a valid path iterator for the construction of a Shape.
 Shape makeShape()
          Factory method that returns a new Shape based on the current data in this iterator.
 void next()
          Advances the iteration pointer one step or anchors it one step beyond the end of the internal path list.
 void reset()
          Resets the iteration pointer to its initial state.
 void setPathList(PathList pathlist)
          Sets the internal PathList that is the basis for this iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MOVE

public static final int MOVE
Shorthand constant for PathIterator.SEG_MOVETO.

See Also:
Constant Field Values

LINE

public static final int LINE
Shorthand constant for PathIterator.SEG_LINETO.

See Also:
Constant Field Values

QUAD

public static final int QUAD
Shorthand constant for PathIterator.SEG_QUADTO.

See Also:
Constant Field Values

CUBIC

public static final int CUBIC
Shorthand constant for PathIterator.SEG_CUBICTO.

See Also:
Constant Field Values

CLOSE

public static final int CLOSE
Shorthand constant for PathIterator.SEG_CLOSE.

See Also:
Constant Field Values

pathlist

protected PathList pathlist
The path list used by this iterator.

Constructor Detail

PathListIterator

public PathListIterator()

The default constructor that initializes the iterator to a new PathList object with zero nodes and winding rule WindingRule.WIND_NON_ZERO.


PathListIterator

public PathListIterator(PathList list)

The constructor that initializes the iterator using the given PathList object.

Parameters:
list - the list to be cloned for the iterator
Method Detail

setPathList

public final void setPathList(PathList pathlist)

Sets the internal PathList that is the basis for this iterator.

Sets the internal PathList to a new path list if the given path list is null.

Parameters:
pathlist - the path list to set

getPathList

public final PathList getPathList()

Returns the internal PathList that is the basis for this iterator.

This method enables the user to query any properties of the internal path list.

In addition, the user can modify the internal path list. We believe that under certain circumstances this ability might be quite valuable. Nevertheless, we recommend caution in making use of this ability. In particular, call reset() after making any changes so the interator will be reset to its initial state.

If the path list is empty or invalid then isDone() will return true even when the iterator is in its initial state.


isValid

public final boolean isValid()

Returns true if this PathListIterator is a valid path iterator for the construction of a Shape.

More precisely, returns true if the internal path list is valid, that is, its size is zero or its size is positive and its start node has type MOVE.

If this method returns false then the isDone() method will automatically return true so only an empty Shape may be built using this iterator.


getWindingRule

public final int getWindingRule()
Returns the winding rule of the iterator as an int.

Specified by:
getWindingRule in interface PathIterator

isDone

public final boolean isDone()

Returns true if the iteration pointer is beyond the last available path segment in the internal path list or if this path list is not a valid path list for the construction of a Shape.

If an attempt is made to retrieve path segment data when isDone() is true then an IndexOutOfBoundsException will be thrown.

Specified by:
isDone in interface PathIterator

next

public final void next()
Advances the iteration pointer one step or anchors it one step beyond the end of the internal path list.

Specified by:
next in interface PathIterator

reset

public final void reset()

Resets the iteration pointer to its initial state.

If the path list is empty or invalid then isDone() will return true even when the iterator is in its initial state.


currentSegment

public final int currentSegment(float[] coords)

Returns the type of the current segment as the return value and stores the numeric data of the segment in the supplied array which must be non-null and of size at least 6.

Throws IllegalArgumentException if the supplied array does not meet the preconditions.

Overwrites the existing contents of the first 6 cells of the supplied array.

Throws IndexOutOfBoundsException if this method is called when isDone() is true.

Specified by:
currentSegment in interface PathIterator
Parameters:
coords - an array of size 6 to hold the segment data
Throws:
IllegalArgumentException
IndexOutOfBoundsException

currentSegment

public final int currentSegment(double[] coords)

Returns the type of the current segment as the return value and stores the numeric data of the segment in the supplied array which must be non-null and of size at least 6.

Throws IllegalArgumentException if the supplied array does not meet the preconditions.

Overwrites the existing contents of the first 6 cells of the supplied array.

Throws IndexOutOfBoundsException if this method is called when isDone() is true.

Specified by:
currentSegment in interface PathIterator
Parameters:
coords - an array of size 6 to hold the segment data
Throws:
IllegalArgumentException
IndexOutOfBoundsException

makeShape

public final Shape makeShape()

Factory method that returns a new Shape based on the current data in this iterator.

The iterator is reset both before and after the shape is constructed.

This method currently uses GeneralPath in its implementation.

In construction of a Shape via GeneralPath, Java requires that the start node have type MOVE. If this condition does not hold, Java throws IllegalPathStateException. In this class, the requirement that the start node have type MOVE is tested by the method isValid(). If this method returns false and the user calls makeShape, an empty Shape will be returned by this call rather than throwing an exception.