edu.neu.ccs.gui
Class Path

java.lang.Object
  |
  +--edu.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.

Since:
2.3
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 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.
 
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 float[][] bezierTangentSegments(float[][] vertex, float[][] tangent)
          Returns a float array that contains the Bezier tangent segments for the given vertex and tangent arrays.
static float[][] closedBezierFrame(float[][] vertex, float[][] tangent)
          Returns a float array that contains the points on the closed Bezier frame for the given vertex and tangent arrays.
static void dot(Graphics g, double x, double y, Color color)
          Paints a dot of size 4 at the given position (x, y), in the given color, in the given graphics context.
static void line(Graphics g, double x1, double y1, double x2, double y2, Color color)
          Paints a line of thickness 2 from (x1, y1) to (x2, y2), in the given color, in the given graphics context.
static float[][] openBezierFrame(float[][] vertex, float[][] tangent)
          Returns a float array that contains the points on the open Bezier frame for the given vertex and tangent arrays.
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 showShapeDots(Graphics g, Shape shape, Color dotColor)
          Shows the dots of the given shape, in the given dot color, in the given graphics context.
static void showShapeFrame(Graphics g, Shape shape, Color frameColor)
          Shows the shape of the frame of the given shape, in the given frame color, in the given graphics context.
static void showShapeFrameDots(Graphics g, Shape shape, Color dotColor)
          Shows the dots of the frame of the given shape, in the given dot color, in the given graphics context.
static void showShapeStructure(Graphics g, Shape shape)
          Shows the shape, its frame, its frame dots, and its own dots, in the default colors, in the given graphics context.
static void showShapeStructure(Graphics g, Shape shape, Color shapeColor, Color frameColor, Color shapeDotColor, Color frameDotColor)
          Shows the shape, its frame, its frame dots, and its own dots, in the given colors or their defaults, 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

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 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.


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.


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.

Method Detail

closedBezierFrame

public static float[][] closedBezierFrame(float[][] vertex,
                                          float[][] tangent)

Returns a float array that contains the points on the closed Bezier frame for the given vertex and tangent arrays.

Precondition: For some integer N:

Postcondition: For M = 3 * N, the array returned is float[M][2]. For each index i less than N, with j = (i + 1) (mod N), the sequence of three points

is placed in the next available set of three array slots.

If the precondition fails, then float[0][2] is returned.

Parameters:
vertex - the array of vertex information
tangent - the array of tangent information
Returns:
the array with the Bezier frame points

openBezierFrame

public static float[][] openBezierFrame(float[][] vertex,
                                        float[][] tangent)

Returns a float array that contains the points on the open Bezier frame for the given vertex and tangent arrays.

Precondition: For some integer N:

Postcondition: If N is non-zero, then for M = 3 * N - 2, the array returned is float[M][2]. For each index i less than (N - 1), with j = i + 1, the sequence of three points

is placed in the next available set of three array slots. Then the final vertex is placed in the final array slot.

If the precondition fails or N is 0, then float[0][2] is returned.

Parameters:
vertex - the array of vertex information
tangent - the array of tangent information
Returns:
the array with the Bezier frame points

bezierTangentSegments

public static float[][] bezierTangentSegments(float[][] vertex,
                                              float[][] tangent)

Returns a float array that contains the Bezier tangent segments for the given vertex and tangent arrays.

Precondition: For some integer N:

Postcondition: For M = 2 * N, the array returned is float[M][2]. For each index i, the sequence of two points

is placed in the next available set of two array slots.

If the precondition fails, then float[0][2] is returned.

Parameters:
vertex - the array of vertex information
tangent - the array of tangent information
Returns:
the array with the Bezier tangent segments

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.

If the path parameter is null then a new GeneralPath will be created, modified, and returned.

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.

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
See Also:
GeneralPath.append(java.awt.Shape, boolean)

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.

If the path parameter is null then a new GeneralPath will be created, modified, and returned.

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

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

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
See Also:
GeneralPath.append(java.awt.Shape, boolean)

dot

public static void dot(Graphics g,
                       double x,
                       double y,
                       Color color)

Paints a dot of size 4 at the given position (x, y), in the given color, in the given graphics context.

If the graphics context is null, then does nothing.

If the color is null, it is set to Color.red.

Parameters:
g - the graphics context
x - the x-position
y - the y-position
color - the color for painting

line

public static void line(Graphics g,
                        double x1,
                        double y1,
                        double x2,
                        double y2,
                        Color color)

Paints a line of thickness 2 from (x1, y1) to (x2, y2), in the given color, in the given graphics context.

If the graphics context is null, then does nothing.

If the color is null, it is set to Color.green.

Parameters:
g - the graphics context
x1 - the start x-position
y1 - the start y-position
x2 - the final x-position
y2 - the final y-position
color - the color for painting

showShapeFrame

public static void showShapeFrame(Graphics g,
                                  Shape shape,
                                  Color frameColor)

Shows the shape of the frame of the given shape, in the given frame color, in the given graphics context.

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

If the frame color is null, it is set to Color.green.

Parameters:
g - the graphics context
shape - the shape to frame
frameColor - the color of the frame

showShapeDots

public static void showShapeDots(Graphics g,
                                 Shape shape,
                                 Color dotColor)

Shows the dots of the given shape, in the given dot color, in the given graphics context.

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

If the dot color is null, it is set to Color.red.

Parameters:
g - the graphics context
shape - the shape to show dots
dotColor - the color of the dots

showShapeFrameDots

public static void showShapeFrameDots(Graphics g,
                                      Shape shape,
                                      Color dotColor)

Shows the dots of the frame of the given shape, in the given dot color, in the given graphics context.

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

If the dot color is null, it is set to Color.orange.

Parameters:
g - the graphics context
shape - the shape to show frame dots
dotColor - the color of the frame dots

showShapeStructure

public static void showShapeStructure(Graphics g,
                                      Shape shape,
                                      Color shapeColor,
                                      Color frameColor,
                                      Color shapeDotColor,
                                      Color frameDotColor)

Shows the shape, its frame, its frame dots, and its own dots, in the given colors or their defaults, in the given graphics context.

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

Defaults for null color values:

Parameters:
g - the graphics context
shape - the shape to show frame dots
shapeColor - the color of the shape
frameColor - the color of the frame
shapeDotColor - the color of the shape dots
frameDotColor - the color of the frame dots

showShapeStructure

public static void showShapeStructure(Graphics g,
                                      Shape shape)

Shows the shape, its frame, its frame dots, and its own dots, in the default colors, in the given graphics context.

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

Defaults for color values:

Parameters:
g - the graphics context
shape - the shape to show frame dots

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.

Returns:
the shape information as a string