ewe.fx
Class GeneralPath

java.lang.Object
  extended byewe.fx.GeneralPath

public class GeneralPath
extends Object

A GeneralPath is used for creating lines by appending sequences of straight lines, quadratic curves and cubic (Bezier) curves.

After you create the GeneralPath you can convert it to a Polygon for drawing on a Graphics context, or to a sequence of floating point co-ordinates for other purposes.

You create the path by starting with an initial moveTo(xstart,ystart) to start at that point. You then do sequences of lineTo(), quadTo() or curveTo() calls to add segments to the path. You can call closePath() at the end (optionally) to create a closed path.


Field Summary
static int GET_LINES_AS_INTS
          This is an option for getLines().
static int TRANSFORM_HORIZONTAL_MIRROR
          A Transform operation.
static int TRANSFORM_HORIZONTAL_STRETCH
          A Transform operation.
static int TRANSFORM_ROTATE
          A Transform operation.
static int TRANSFORM_SCALE
          A Transform operation.
static int TRANSFORM_TRANSLATE
          A Transform operation.
static int TRANSFORM_VERTICAL_MIRROR
          A Transform operation.
static int TRANSFORM_VERTICAL_STRETCH
          A Transform operation.
 
Constructor Summary
GeneralPath()
          Create an empty GeneralPath with a default pre-allocated capacity.
GeneralPath(int capacity)
          Create an empty GeneralPath with a pre-allocated capacity.
 
Method Summary
 void append(GeneralPath path, boolean connect)
          Append another path to this path.
 void append(GeneralPath path, boolean connect, boolean relative)
          Append another path to this path.
 void closePath()
          This method indicates that a line should be drawn from the most recent added point to the most recent moveTo() point.
 int countPoints()
          This returns the number of points that has been added to the GeneralPath so far.
 void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
          Draw a Bezier curve from the last point to the co-ordinates (x3,y3) using (x1,y1) and (x2,y2) as the curve's control points.
 float[] getBoundingRect(float[] dest)
          Get the bounding Rectangle for the GeneralPath.
 Rect getBounds(Rect dest)
          Get the bounds of the path as a Rect - which holds only integer values.
 GeneralPath getCopy()
          Get a copy of this GeneralPath.
 Object[] getLines(boolean includeLastPoint, int options)
          This returns the lines as integer or floating point values.
 int getLines(Object destx, Object desty, int offset, boolean includeLastPoint, int options)
          Convert the GeneralPath to an sequence of lines that fit the path.
 float[] getXPoints()
          This returns the array of x co-ordinates of the points added to the GeneralPath.
 float[] getYPoints()
          This returns the array of y co-ordinates of the points added to the GeneralPath.
 void lineTo(float x, float y)
          Draw a line from the last point to the co-ordinates (x,y).
 void moveTo(float x, float y)
          Move the current point to the specified x,y location.
 boolean openPath()
          If the last operation in this GeneralPath is a closePath(), this will remove it, thereby opening the path again.
 void quadTo(float x1, float y1, float x2, float y2)
          Draw a quadratic curve from the last point to the co-ordinates (x2,y2) using (x1,y1) as the curve's control point.
 GeneralPath reverse()
          This reverses the sub-path direction.
 Polygon toPolygon()
          Convert the GeneralPath to a Polygon object - which stores all co-ordinates as integer values.
 GeneralPath transform(double m00, double m10, double m01, double m11, double m02, double m12)
          This does an Affine Transform on the GeneralPath to produce a new GeneralPath.
 GeneralPath transform(int transformOperation, float x, float y, double factor)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

GET_LINES_AS_INTS

public static final int GET_LINES_AS_INTS
This is an option for getLines().

See Also:
Constant Field Values

TRANSFORM_TRANSLATE

public static final int TRANSFORM_TRANSLATE
A Transform operation. For this operation the X and Y co-ordinate parameters specify distances to translate each point in the x and y plane. The factor parameter is not use.

See Also:
Constant Field Values

TRANSFORM_ROTATE

public static final int TRANSFORM_ROTATE
A Transform operation. For this operation the X and Y co-ordinate parameters specify the center point for the rotation. The factor parameter specifies the degrees in which to rotate the path.

See Also:
Constant Field Values

TRANSFORM_HORIZONTAL_MIRROR

public static final int TRANSFORM_HORIZONTAL_MIRROR
A Transform operation. For this operation the X co-ordinate parameter specifies the vertical plane about which the mirror will be done. The Y co-ordinate and factor parameters are not used.

See Also:
Constant Field Values

TRANSFORM_VERTICAL_MIRROR

public static final int TRANSFORM_VERTICAL_MIRROR
A Transform operation. For this operation the Y co-ordinate parameter specifies the horizontal plane about which the mirror will be done. The X co-ordinate and factor parameters are not used.

See Also:
Constant Field Values

TRANSFORM_HORIZONTAL_STRETCH

public static final int TRANSFORM_HORIZONTAL_STRETCH
A Transform operation. For this operation the X co-ordinate parameter specifies the vertical plane about which the stretching will be done. The factor parameter specifies the degree to which the path will be stretched. The Y co-ordinate is not used.

See Also:
Constant Field Values

TRANSFORM_VERTICAL_STRETCH

public static final int TRANSFORM_VERTICAL_STRETCH
A Transform operation. For this operation the Y co-ordinate parameter specifies the horizontal plane about which the stretching will be done. The factor parameter specifies the degree to which the path will be stretched. The X co-ordinate is not used.

See Also:
Constant Field Values

TRANSFORM_SCALE

public static final int TRANSFORM_SCALE
A Transform operation. For this operation the X and Y co-ordinate parameters specify the center point for the scaling. The factor parameter specifies how much it will be scaled (this is effectively a horizontal and vertical stretch done to the same factor).

See Also:
Constant Field Values
Constructor Detail

GeneralPath

public GeneralPath(int capacity)
Create an empty GeneralPath with a pre-allocated capacity. The capacity of the path will always be expanded as needed as segments are added.

Parameters:
capacity - The initial capacity of the GeneralPath.

GeneralPath

public GeneralPath()
Create an empty GeneralPath with a default pre-allocated capacity. The capacity of the path will always be expanded as needed as segments are added.

Method Detail

countPoints

public int countPoints()
This returns the number of points that has been added to the GeneralPath so far.


getXPoints

public float[] getXPoints()
This returns the array of x co-ordinates of the points added to the GeneralPath. This can be used to transform the GeneralPath in some way. The number of valid points within this array can be determined using countPoints().


getYPoints

public float[] getYPoints()
This returns the array of y co-ordinates of the points added to the GeneralPath. This can be used to transform the GeneralPath in some way. The number of valid points within this array can be determined using countPoints().


closePath

public void closePath()
This method indicates that a line should be drawn from the most recent added point to the most recent moveTo() point. This will have no effect if this cannot be done.


openPath

public boolean openPath()
If the last operation in this GeneralPath is a closePath(), this will remove it, thereby opening the path again.

Returns:
true if the last operation was a closePath(), false otherwise.

moveTo

public void moveTo(float x,
                   float y)
Move the current point to the specified x,y location.

Parameters:
x - The x-coordinate of the new point.
y - The y-coordinate of the new point.

lineTo

public void lineTo(float x,
                   float y)
Draw a line from the last point to the co-ordinates (x,y).

Parameters:
x - The x-coordinate of the end point.
y - The y-coordinate of the end point.

quadTo

public void quadTo(float x1,
                   float y1,
                   float x2,
                   float y2)
Draw a quadratic curve from the last point to the co-ordinates (x2,y2) using (x1,y1) as the curve's control point.

Parameters:
x1 - The x-coordinate of the control point.
y1 - The y-coordinate of the control point.
x2 - The x-coordinate of the end point.
y2 - The y-coordinate of the end point.
Returns:

curveTo

public void curveTo(float x1,
                    float y1,
                    float x2,
                    float y2,
                    float x3,
                    float y3)
Draw a Bezier curve from the last point to the co-ordinates (x3,y3) using (x1,y1) and (x2,y2) as the curve's control points.

Parameters:
x1 - The x-coordinate of the first control point.
y1 - The y-coordinate of the first control point.
x2 - The x-coordinate of the second control point.
y2 - The y-coordinate of the second control point.
x3 - The x-coordinate of the end point.
y3 - The y-coordinate of the end point.

getLines

public int getLines(Object destx,
                    Object desty,
                    int offset,
                    boolean includeLastPoint,
                    int options)
Convert the GeneralPath to an sequence of lines that fit the path.

Parameters:
destx - The destination for the x-coordinates. This should be an array of int or array of float values and must match the type of desty. This can be null to indicate that you want a count of the maximum number of points that will be generated.
desty - The destination for the y-coordinates. This should be an array of int or array of float values and must match the type of destx. This can be null to indicate that you want a count of the maximum number of points that will be generated.
offset - The start point in the destination arrays for the points.
includeLastPoint - If this is true then the last point (which will be the same as the start point for a closed polygon) will be included, otherwise it will be omitted. If you are going to be using this data in Graphics.drawPolygon() then set this to false, since that method will automatically close the polygon by drawing back to the first point.
options - No options are defined as yet.
Returns:
The number of points needed or used.

append

public void append(GeneralPath path,
                   boolean connect)
Append another path to this path.

Parameters:
path - The other path to add to this path.
connect - If this is true then a line segment will be placed from the last point of this path to the first point of the other path IF the first operation of the other GeneralPath is a moveTo().

append

public void append(GeneralPath path,
                   boolean connect,
                   boolean relative)
Append another path to this path.

Parameters:
path - The other path to add to this path.
connect - If this is true then a line segment will be placed from the last point of this path to the first point of the other path IF the first operation of the other GeneralPath is a moveTo().
relative - If this is true then all co-ordinates of the other path will be considered relative to the first point of this path.

getBoundingRect

public float[] getBoundingRect(float[] dest)
Get the bounding Rectangle for the GeneralPath.

Parameters:
dest - An array of 4 floats - if it is null a new array will be created and returned. dest[0] will hold the leftmost x value, dest[1] the topmost y value, dest[2] the width (distance from the leftmost to the rightmost x value) and dest[3] the height (distance from the topmost to the bottommost y value).

getBounds

public Rect getBounds(Rect dest)
Get the bounds of the path as a Rect - which holds only integer values.


getLines

public Object[] getLines(boolean includeLastPoint,
                         int options)
This returns the lines as integer or floating point values.

Parameters:
includeLastPoint - If this is true then the last point (which will be the same as the start point for a closed polygon) will be included, otherwise it will be omitted. If you are going to be using this data in Graphics.drawPolygon() then set this to false, since that method will automatically close the polygon by drawing back to the first point.
options - GET_LINES_AS_INTS to return the lines as int values, otherwise it will be returned as floats.
Returns:
An Object array containing two arrays - the array at index 0 is the array of X co-ordinates, the array at index 1 is the array of Y co-ordinates.

toPolygon

public Polygon toPolygon()
Convert the GeneralPath to a Polygon object - which stores all co-ordinates as integer values.


getCopy

public GeneralPath getCopy()
Get a copy of this GeneralPath. You can then manipulate the copy without affecting this path.


reverse

public GeneralPath reverse()
This reverses the sub-path direction. It should only be used for open segments that start with a moveTo(). The path will also start with a moveTo() to the last end point and ignore the first operation (which should be a moveTo()).

Returns:
This GeneralPath with its points reversed.

transform

public GeneralPath transform(int transformOperation,
                             float x,
                             float y,
                             double factor)
Parameters:
transformOperation - The selected operation - should be one of the TRANSFORM_XXX values.
x - The x-coordinate to be used by the transform. Its use depends on the transform selected.
y - The y-coordinate to be used by the transform. Its use depends on the transform selected.
factor - A value representing some paramter used for the transform. For example for TRANSFORM_ROTATE it will be the number of degrees to rotate the path.
Returns:
This GeneralPath after transformation.

transform

public GeneralPath transform(double m00,
                             double m10,
                             double m01,
                             double m11,
                             double m02,
                             double m12)
This does an Affine Transform on the GeneralPath to produce a new GeneralPath. All the other predefined transforms are also affine transforms and can actually be done though this method as well.

For each x and y point in the GeneralPath, the corresponding x' and y' points in the new GeneralPath will be given by:

x' = m00*x + m01*y + m02;
y' = m10*x + m11*y + m12;