edu.neu.ccs.gui
Class Path

java.lang.Object
  extended byedu.neu.ccs.gui.Path

public class Path
extends Object

Class Path encapsulates an interface Strategy that defines the requirement for a strategy that can automatically build a GeneralPath given vertex and tangent data.

Specifically, the strategy requires:

Class Path also provides some examples of Strategy objects and some useful static methods.

Class Path cannot be instantiated.

In 2.4.0, the interface contract for Path.Strategy was changed to permit the designer to specify what will happen if the tangent array that is passed the method makePath happens to be null. In prior versions of this class, the designer was forced to return an empty GeneralPath and had no other choice.

In 2.4.0, the methods to show shape structure were refactored to use the tools in the class PathList and to follow the corresponding conventions for the parameters and their defaults.

Finally, in 2.4.0, certain static methods were moved to BaseShape and renamed to be consistent with conventions there.

In 2.6.0b, added one additional showShapeStructure method to correspond to an added method in PathList.

Since:
2.3
Version:
2.6.0b
See Also:
Shape, GeneralPath

Nested Class Summary
static interface Path.Strategy
          The Strategy interface requires one method that returns a GeneralPath given its input parameters.
 
Field Summary
static Path.Strategy BEZIER_CUBIC
          BEZIER_CUBIC is a Strategy that constructs a GeneralPath as the Bezier cubic defined by the given vertex and tangent arrays.
static Path.Strategy BEZIER_FRAME
          BEZIER_FRAME is a Strategy that constructs a GeneralPath as the Bezier polygonal frame associated with the given vertex and tangent arrays.
static Path.Strategy BEZIER_TANGENT_SEGMENTS
          BEZIER_TANGENT_SEGMENTS is a Strategy that constructs a GeneralPath as a disjoint sequence of tangent segments.
static Rectangle2D.Double DOT
          The standard dot centered at (0,0).
static int HALF
          Half of the standard dot size.
static Path.Strategy POLYGON
          POLYGON is a Strategy that constructs a GeneralPath as the polygon defined by the given vertex array.
static Path.Strategy POLYGON_DOTS
          POLYGON_DOTS is a Strategy that constructs a GeneralPath using a sequence of moveTo, lineTo pairs, one for each vertex in the vertex array.
static int SIZE
          The standard dot size.
static BasicStroke STROKE
          The standard stroke.
static int THICK
          The standard stroke thickness.
 
Constructor Summary
private Path()
          Private constructor to prevent instantiation.
 
Method Summary
static GeneralPath append(GeneralPath path, Shape[] shape, boolean connect)
          Returns the GeneralPath obtained by appending the given sequence of Shape objects to the given GeneralPath using the given boolean value to determine the connection at every stage.
static GeneralPath append(GeneralPath path, Shape[] shape, boolean[] connect)
          Returns the GeneralPath obtained by appending the given sequence of Shape objects to the given GeneralPath using the given sequence of boolean values to determine the connection at each stage.
static String shapeToString(Shape shape)
          Returns the structural information about a Shape as a large, multi-line String that contains all of the information in the PathIterator for the shape.
static void showShapeStructure(Graphics g, Shape shape)
          Shows the shape structure in the given graphics context.
static void showShapeStructure(Graphics g, Shape shape, Color fillColor, Color drawColor, Color vertexDotsColor, Color controlDotsColor, Color vertexFrameColor, Color bezierFrameColor, Color pathPointsColor, int thickness, int divisions)
          Shows the shape structure in the given graphics context.
static void showShapeStructure(Graphics g, Shape shape, Color fillColor, Color drawColor, Color vertexDotsColor, Color controlDotsColor, Color vertexFrameColor, Color bezierFrameColor, int thickness)
          Shows the shape structure in the given graphics context.
static void showShapeStructure(Graphics g, Shape shape, Color fillColor, Color drawColor, int thickness)
          Shows the shape structure in the given graphics context.
static void showShapeStructure(Graphics g, Shape shape, int thickness)
          Shows the shape structure in the given graphics context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIZE

public static final int SIZE
The standard dot size.

See Also:
Constant Field Values

HALF

public static final int HALF
Half of the standard dot size.

See Also:
Constant Field Values

DOT

public static final Rectangle2D.Double DOT
The standard dot centered at (0,0).


THICK

public static final int THICK
The standard stroke thickness.

See Also:
Constant Field Values

STROKE

public static final BasicStroke STROKE
The standard stroke.


POLYGON

public static final Path.Strategy POLYGON

POLYGON is a Strategy that constructs a GeneralPath as the polygon defined by the given vertex array.

The given tangent array is not used.


POLYGON_DOTS

public static final Path.Strategy POLYGON_DOTS

POLYGON_DOTS is a Strategy that constructs a GeneralPath using a sequence of moveTo, lineTo pairs, one for each vertex in the vertex array.

The given tangent array is not used.

The given closuremode is not used. The path is geometrically open.


BEZIER_CUBIC

public static final Path.Strategy BEZIER_CUBIC

BEZIER_CUBIC is a Strategy that constructs a GeneralPath as the Bezier cubic defined by the given vertex and tangent arrays.

This strategy uses the tangent array but if the given tangent array is null then the strategy Path.POLYGON is used on the vertex array instead.


BEZIER_FRAME

public static final Path.Strategy BEZIER_FRAME

BEZIER_FRAME is a Strategy that constructs a GeneralPath as the Bezier polygonal frame associated with the given vertex and tangent arrays.

The closuremode is used to determine whether the Bezier frame is closed or open.

This strategy uses the tangent array but if the given tangent array is null then the strategy Path.POLYGON is used on the vertex array instead.


BEZIER_TANGENT_SEGMENTS

public static final Path.Strategy BEZIER_TANGENT_SEGMENTS

BEZIER_TANGENT_SEGMENTS is a Strategy that constructs a GeneralPath as a disjoint sequence of tangent segments.

The tangent segments have the form:

using the given vertex and tangent arrays.

The given closuremode is not used. The path is OPEN.

This strategy uses the tangent array but if the given tangent array is null then the strategy Path.POLYGON_DOTS is used on the vertex array instead.

Constructor Detail

Path

private Path()
Private constructor to prevent instantiation.

Method Detail

append

public static GeneralPath append(GeneralPath path,
                                 Shape[] shape,
                                 boolean[] connect)

Returns the GeneralPath obtained by appending the given sequence of Shape objects to the given GeneralPath using the given sequence of boolean values to determine the connection at each stage.

There is one more boolean value than there is a Shape object. The final boolean value determines whether or not the GeneralPath will be terminated by a closePath operation.

Precondition: For some integer N:

If connect is null then it is replaced by new boolean[N+1].

If the precondition fails, no append actions will be taken.

If the path parameter is null then a new GeneralPath will be created, modified, and returned. Since a default GeneralPath uses the winding rule GeneralPath.WIND_NON_ZERO, you are forced to accept this choice if you pass a null argument for path. To get the opposite winding rule with an empty path, you must pass instead:

new GeneralPath(GeneralPath.WIND_EVEN_ODD)

Parameters:
path - the path to extend or null
shape - the array of shapes to append
connect - the array of connection specifications or null
Returns:
the path as modified

append

public static GeneralPath append(GeneralPath path,
                                 Shape[] shape,
                                 boolean connect)

Returns the GeneralPath obtained by appending the given sequence of Shape objects to the given GeneralPath using the given boolean value to determine the connection at every stage.

Precondition: For some integer N, shape is Shape[N].

If the precondition fails, no append actions will be taken.

If the path parameter is null then a new GeneralPath will be created, modified, and returned. Since a default GeneralPath uses the winding rule GeneralPath.WIND_NON_ZERO, you are forced to accept this choice if you pass a null argument for path. To get the opposite winding rule with an empty path, you must pass instead:

new GeneralPath(GeneralPath.WIND_EVEN_ODD)

Parameters:
path - the path to extend or null
shape - the array of shapes to append
connect - the array of connection specifications or null
Returns:
the path as modified

showShapeStructure

public static void showShapeStructure(Graphics g,
                                      Shape shape,
                                      Color fillColor,
                                      Color drawColor,
                                      Color vertexDotsColor,
                                      Color controlDotsColor,
                                      Color vertexFrameColor,
                                      Color bezierFrameColor,
                                      Color pathPointsColor,
                                      int thickness,
                                      int divisions)

Shows the shape structure in the given graphics context.

If the graphics context or the shape is null, then does nothing.

Uses PathList.makeStructurePaintable and follows the conventions described in that class.

Parameters:
g - the graphics context
shape - the shape
fillColor - the fill color for the shape
drawColor - the draw color for the shape
vertexDotsColor - the color for the vertex dots
controlDotsColor - the color for the control dots
vertexFrameColor - the color for the vertex frame
bezierFrameColor - the color for the bezier frame
pathPointsColor - the color for the path points
thickness - the stroke thickness
divisions - the number of subdivisions of a unit interval when constructing path points

showShapeStructure

public static void showShapeStructure(Graphics g,
                                      Shape shape,
                                      Color fillColor,
                                      Color drawColor,
                                      Color vertexDotsColor,
                                      Color controlDotsColor,
                                      Color vertexFrameColor,
                                      Color bezierFrameColor,
                                      int thickness)

Shows the shape structure in the given graphics context.

If the graphics context or the shape is null, then does nothing.

Uses PathList.makeStructurePaintable and follows the conventions described in that class.

Parameters:
g - the graphics context
shape - the shape
fillColor - the fill color for the shape
drawColor - the draw color for the shape
vertexDotsColor - the color for the vertex dots
controlDotsColor - the color for the control dots
vertexFrameColor - the color for the vertex frame
bezierFrameColor - the color for the bezier frame
thickness - the stroke thickness

showShapeStructure

public static void showShapeStructure(Graphics g,
                                      Shape shape,
                                      Color fillColor,
                                      Color drawColor,
                                      int thickness)

Shows the shape structure in the given graphics context.

If the graphics context or the shape is null, then does nothing.

Uses PathList.makeStructurePaintable and follows the conventions described in that class.

Parameters:
g - the graphics context
shape - the shape
fillColor - the fill color for the shape
drawColor - the draw color for the shape
thickness - the stroke thickness

showShapeStructure

public static void showShapeStructure(Graphics g,
                                      Shape shape,
                                      int thickness)

Shows the shape structure in the given graphics context.

If the graphics context or the shape is null, then does nothing.

Uses PathList.makeStructurePaintable and follows the conventions described in that class.

Parameters:
g - the graphics context
shape - the shape
thickness - the stroke thickness

showShapeStructure

public static void showShapeStructure(Graphics g,
                                      Shape shape)

Shows the shape structure in the given graphics context.

If the graphics context or the shape is null, then does nothing.

Uses PathList.makeStructurePaintable and follows the conventions described in that class.

Parameters:
g - the graphics context
shape - the shape

shapeToString

public static String shapeToString(Shape shape)

Returns the structural information about a Shape as a large, multi-line String that contains all of the information in the PathIterator for the shape.

If the given shape is null returns "Null shape\n".

If the given shape is non-null then, as of 2.4.0, returns the String:

  new PathList(shape).toString()

Returns:
the shape information as a string