|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.gui.PathNode
Class PathNode makes explicit a data structure for
the ingredients that may be used to build a Java object of class
GeneralPath.
In JPT, we introduce the PathList class that combines
an explicit sequence of PathNode objects together with a
winding rule to provide a flexible alternative to
GeneralPath.
Class PathNode introduces abbreviations for the
somewhat cumbersome names in the Java class PathIterator.
The table below shows the corresponding names and also the number of
parameters for each type of path segment.
| PathIterator Constant | PathNode Constant | Float Parameters |
SEG_MOVETO |
MOVE |
x1, y1 |
SEG_LINETO |
LINE |
x1, y1 |
SEG_QUADTO |
QUAD |
x1, y1, x2, y2 |
SEG_CUBICTO |
CUBIC |
x1, y1, x2, y2, x3, y3 |
SEG_CLOSE |
CLOSE |
None |
By Java convention in the PathIterator documentation, the
path segment parameters are referred to as x1, y1, x2, y2, x3, y3
although it is clear that only the CUBIC segment requires
all 6 parameters. We will follow these conventions in naming methods and
parameters for this class.
We will also refer to the pair x1,y1 as slot 1, x2,y2 as slot 2, and x3,y3 as slot 3 when we speak of methods that set or query slots.
Changes in 2.6.0a:
Methods getEndX() and getEndY()
were added to return the “endpoint” coordinates of the path
segment. For paths of type MOVE and LINE the
methods return x1,y1 respectively;
for paths of type QUAD the methods return x2,y2
respectively;
for paths of type CUBIC the methods return x3,y3
respectively; finally,
for paths of type CLOSE the methods return 0,0
respectively since no valid values are actually defined.
Additional changes in 2.6.0d:
move, line,
quad, cubic, and close to
construct new PathNode objects of the corresponding type.
setToMove, setToLine,
setToQuad, setToCubic, and setToClose
to set the PathNode type and supply just the required number of
numerical data parameters.
float,
changed the constructors and methods that acquire data to accept
double.
toString and toStringData to
use lower case and to use () rather than []. The new format resembles the
new factory method calls discussed above. The fromStringData
method will accept both the old format and the new format.
JavaCode that returns in a String
the Java code that might be used to make a clone of this path node.
This Java code is precisely a call to one of the 5 new factory methods.
The Java code facility is used for experimental environments.
| 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 int |
nodetype
The type of the path node; must be one of the constants: MOVE, LINE, QUAD, CUBIC, CLOSE. |
static int |
QUAD
Shorthand constant for PathIterator.SEG_QUADTO. |
static String |
standardMessage
The standard error message for fromStringData. |
protected float |
x1
The x1 parameter. |
protected float |
x2
The x2 parameter. |
protected float |
x3
The x3 parameter. |
protected float |
y1
The y1 parameter. |
protected float |
y2
The y2 parameter. |
protected float |
y3
The y3 parameter. |
| Constructor Summary | |
PathNode()
The default constructor that sets the node type to MOVE and sets all numeric data to 0. |
|
PathNode(int type,
double[] parameters)
The constructor that sets the node type and as much of the numeric data as is in the parameters array. |
|
PathNode(int type,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
The constructor that sets the node type and the numeric node data. |
|
PathNode(int type,
float[] parameters)
The constructor that sets the node type and as much of the numeric data as is in the parameters array. |
|
PathNode(PathNode node)
The constructor that copies the data of an existing path node. |
|
PathNode(String data)
Constructor that initializes a new node using the data in the String format that is produced by the
method toString(). |
|
| Method Summary | |
void |
changeLineToMove()
If the node type is LINE, changes it to MOVE, otherwise does nothing. |
void |
changeMoveToLine()
If the node type is MOVE, changes it to LINE, otherwise does nothing. |
static PathNode |
close()
Factory method the construct a PathNode
of type CLOSE. |
static PathNode |
cubic(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Factory method the construct a PathNode
of type CUBIC. |
void |
fromStringData(String state)
Sets the data of this path node using String
data in the format produced by toString(). |
float |
getEndX()
Returns the x-endpoint of this path node. |
float |
getEndY()
Returns the y-endpoint of this path node. |
int |
getNodeType()
Returns the node type which is one of the constants: MOVE, LINE, QUAD, CUBIC, CLOSE. |
int |
getNodeTypeFromStringData(String data)
Returns the node type constant that corresponds to the given String data. |
String |
getNodeTypeString()
Returns a String label corresponding to the node type. |
int |
getParameterCount()
Returns the number of numeric data parameters needed by the current node type. |
float[] |
getParameters()
Returns a copy of the current numeric data parameters. |
static PathNode[] |
getPathNodes(PathIterator iterator)
Returns an array of PathNode objects that
corresponds to the information in the given iterator. |
static PathNode[] |
getPathNodes(Shape shape)
Returns an array of PathNode objects that
corresponds to the information in the given shape. |
static PathNode[] |
getPathNodes(Shape shape,
AffineTransform transform)
Returns an array of PathNode objects that
corresponds to the information in the given shape after
being transformed by the given transform. |
static PathNode[] |
getPathNodes(Shape shape,
AffineTransform transform,
double flatness)
Returns an array of PathNode objects that
corresponds to the information in the given shape after
being transformed by the given transform and appying
the given flatness parameter. |
float[] |
getSlot(int slot)
Returns an (x,y) pair of values corresponding to the given slot index or null if the index is invalid. |
int |
getSlotCount()
Returns the number of x,y slots needed by the current node type. |
float |
getSlotX(int slot)
Returns the x-coordinate corresponding to the given slot index or 0 if the index is invalid. |
float |
getSlotY(int slot)
Returns the y-coordinate corresponding to the given slot index or 0 if the index is invalid. |
float |
getX1()
Returns the internal parameter x1. |
float |
getX2()
Returns the internal parameter x2. |
float |
getX3()
Returns the internal parameter x3. |
float |
getY1()
Returns the internal parameter y1. |
float |
getY2()
Returns the internal parameter y2. |
float |
getY3()
Returns the internal parameter y3. |
String |
JavaCode()
Returns in a String the Java code that
might be used to make a clone of this path node. |
static PathNode |
line(double x1,
double y1)
Factory method the construct a PathNode
of type LINE. |
static PathNode |
move(double x1,
double y1)
Factory method the construct a PathNode
of type MOVE. |
int |
nearSlot(double x,
double y,
double epsilon)
Searches the slots in this node and returns a slot index if the given (x,y) is within epsilon of the values in that slot; returns -1 if no such slot exists. |
int |
nearSlot(double x,
double y,
double epsilon,
Metric metric)
Searches the valid slots in this node in order and returns a slot index if the given (x,y) is within epsilon of the values in that slot relative to the given metric; returns -1 if no such slot exists. |
int |
nodeInfo(double[] coords)
Returns the node type as the return value and stores the node numeric data in the supplied array which must be non- null and of size at least 6. |
int |
nodeInfo(float[] coords)
Returns the node type as the return value and stores the node numeric data in the supplied array which must be non- null and of size at least 6. |
static PathNode |
quad(double x1,
double y1,
double x2,
double y2)
Factory method the construct a PathNode
of type QUAD. |
void |
setNodeType(int type)
Sets the node type of the node. |
void |
setParameters(double[] parameters)
Sets the internal parameters appropriate for the current node type but does not set parameters that are unused. |
void |
setParameters(double x1,
double y1)
Sets the parameters appropriate for the current node type using explicit double values. |
void |
setParameters(double x1,
double y1,
double x2,
double y2)
Sets the parameters appropriate for the current node type using explicit double values. |
void |
setParameters(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Sets the parameters appropriate for the current node type using explicit double values. |
void |
setParameters(float[] parameters)
Sets the internal parameters appropriate for the current node type but does not set parameters that are unused. |
void |
setPathNode(PathNode node)
Sets this path node to have a copy of the settings of the given path node. |
void |
setSlot(int slot,
double[] pair)
Sets the slot with the given slot index to the given x,y pair array. |
void |
setSlot(int slot,
double x,
double y)
Sets the slot with the given slot index to the given x,y values. |
void |
setSlot(int slot,
float[] pair)
Sets the slot with the given slot index to the given x,y pair array. |
void |
setToClose()
Sets this node to a CLOSE. |
void |
setToCubic(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Sets this node to a CUBIC with the given parameters. |
void |
setToLine(double x1,
double y1)
Sets this node to a LINE with the given parameters. |
void |
setToMove(double x1,
double y1)
Sets this node to a MOVE with the given parameters. |
void |
setToQuad(double x1,
double y1,
double x2,
double y2)
Sets this node to a QUAD with the given parameters. |
void |
setX1(double x1)
Sets the internal parameter x1. |
void |
setX2(double x2)
Sets the internal parameter x2. |
void |
setX3(double x3)
Sets the internal parameter x3. |
void |
setY1(double y1)
Sets the internal parameter y1. |
void |
setY2(double y2)
Sets the internal parameter y2. |
void |
setY3(double y3)
Sets the internal parameter y3. |
String |
toString()
Writes the data of this path node to a String. |
String |
toStringData()
Returns the same result as toString(). |
void |
transform(AffineTransform T)
Transforms the internal data points using the given affine transform. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int MOVE
public static final int LINE
public static final int QUAD
public static final int CUBIC
public static final int CLOSE
public static final String standardMessage
protected int nodetype
protected float x1
protected float y1
protected float x2
protected float y2
protected float x3
protected float y3
| Constructor Detail |
public PathNode()
public PathNode(int type,
float[] parameters)
The constructor that sets the node type and as much of the numeric data as is in the parameters array.
The number of data cells used in the parameters array depends on the node type according to the following rules:
MOVE: 2LINE: 2QUAD: 4CUBIC: 6CLOSE: 0Throws IllegalArgumentException if the node
type is not one of the constants: MOVE, LINE, QUAD, CUBIC,
or CLOSE.
If the parameters array is null,
the missing data is treated as 0.
If the parameters array is non-null,
then its length must be large enough to fill the required
number of parameters for the current node type or else an
IllegalArgumentException is thrown.
type - the node typeparameters - the numeric data for the node
IllegalArgumentException
public PathNode(int type,
double[] parameters)
The constructor that sets the node type and as much of the numeric data as is in the parameters array.
The number of data cells used in the parameters array depends on the node type according to the following rules:
MOVE: 2LINE: 2QUAD: 4CUBIC: 6CLOSE: 0Throws IllegalArgumentException if the node
type is not one of the constants: MOVE, LINE, QUAD, CUBIC,
or CLOSE.
If the parameters array is null,
the missing data is treated as 0.
If the parameters array is non-null,
then its length must be large enough to fill the required
number of parameters for the current node type or else an
IllegalArgumentException is thrown.
type - the node typeparameters - the numeric data for the node
IllegalArgumentException
public PathNode(int type,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
The constructor that sets the node type and the numeric node data.
The number of data items used depends on the node type according to the following rules:
MOVE: 2LINE: 2QUAD: 4CUBIC: 6CLOSE: 0Data items that will not be used may be passed as 0.
Throws IllegalArgumentException if the node
type is not one of the constants: MOVE, LINE, QUAD, CUBIC,
or CLOSE.
type - the node typex1 - parameter 0y1 - parameter 1x2 - parameter 2y2 - parameter 3x3 - parameter 4y3 - parameter 5
IllegalArgumentExceptionpublic PathNode(PathNode node)
The constructor that copies the data of an existing path node.
If the given path node is null then acts
as the default constructor.
node - the path node to copy
public PathNode(String data)
throws ParseException
Constructor that initializes a new node using the data
in the String format that is produced by the
method toString().
Throws ParseException if the data is not in
the correct format or has numeric errors.
data - the String with the state information
ParseException| Method Detail |
public final void setToMove(double x1,
double y1)
public final void setToLine(double x1,
double y1)
public final void setToQuad(double x1,
double y1,
double x2,
double y2)
public final void setToCubic(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
public final void setToClose()
public final void setPathNode(PathNode node)
Sets this path node to have a copy of the settings of the given path node.
If the given path node is null then does
nothing.
node - the path node to copypublic final void setNodeType(int type)
Sets the node type of the node.
Throws IllegalArgumentException if the node
type is not one of the constants: MOVE, LINE, QUAD, CUBIC,
or CLOSE.
Does nothing if the node type will not be changed.
If the node type is changed then the numeric data in this node may be invalid. It is the responsibility of the caller to provide valid data by other methods.
The methods setToMove, setToLine,
setToQuad, setToCubic, and
setToClose provide a mechanism to set both
the node type and the associated data in a single step.
type - the node typepublic final int getNodeType()
Returns the node type which is one of the constants: MOVE, LINE, QUAD, CUBIC, CLOSE.
public final void setParameters(float[] parameters)
Sets the internal parameters appropriate for the current node type but does not set parameters that are unused.
If the parameters array is null,
the missing data is treated as 0.
If the parameters array is non-null,
then its length must be large enough to fill the required
number of parameters for the current node type or else an
IllegalArgumentException is thrown.
parameters - the numeric data for the nodepublic final void setParameters(double[] parameters)
Sets the internal parameters appropriate for the current node type but does not set parameters that are unused.
If the parameters array is null,
the missing data is treated as 0.
If the parameters array is non-null,
then its length must be large enough to fill the required
number of parameters for the current node type or else an
IllegalArgumentException is thrown.
parameters - the numeric data for the node
public final void setParameters(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Sets the parameters appropriate for the current node type using explicit double values.
Does not set internal parameters that are unused for the current node type.
x1 - parameter 0y1 - parameter 1x2 - parameter 2y2 - parameter 3x3 - parameter 4y3 - parameter 5
public final void setParameters(double x1,
double y1,
double x2,
double y2)
Sets the parameters appropriate for the current node type using explicit double values.
Does not set internal parameters that are unused for the current node type.
Since 4 parameters is insufficient for a CUBIC node type,
throws IllegalArgumentException in this case.
Therefore, this method requires that the caller know that the node type is suitable prior to calling the method.
x1 - parameter 0y1 - parameter 1x2 - parameter 2y2 - parameter 3
public final void setParameters(double x1,
double y1)
Sets the parameters appropriate for the current node type using explicit double values.
Does not set internal parameters that are unused for the current node type.
Since 2 parameters is insufficient for a QUAD or CUBIC node type,
throws IllegalArgumentException in this case.
Therefore, this method requires that the caller know that the node type is suitable prior to calling the method.
x1 - parameter 0y1 - parameter 1public final float[] getParameters()
public final int getParameterCount()
public final int getSlotCount()
public final void setX1(double x1)
Sets the internal parameter x1.
The internal data is maintained as float.
This method does not check whether the cell is used by the current node type.
public final void setY1(double y1)
Sets the internal parameter y1.
The internal data is maintained as float.
This method does not check whether the cell is used by the current node type.
public final void setX2(double x2)
Sets the internal parameter x2.
The internal data is maintained as float.
This method does not check whether the cell is used by the current node type.
public final void setY2(double y2)
Sets the internal parameter y2.
The internal data is maintained as float.
This method does not check whether the cell is used by the current node type.
public final void setX3(double x3)
Sets the internal parameter x3.
The internal data is maintained as float.
This method does not check whether the cell is used by the current node type.
public final void setY3(double y3)
Sets the internal parameter y3.
The internal data is maintained as float.
This method does not check whether the cell is used by the current node type.
public final float getX1()
Returns the internal parameter x1.
This method does not check whether the cell is used by the current node type.
public final float getY1()
Returns the internal parameter y1.
This method does not check whether the cell is used by the current node type.
public final float getX2()
Returns the internal parameter x2.
This method does not check whether the cell is used by the current node type.
public final float getY2()
Returns the internal parameter y2.
This method does not check whether the cell is used by the current node type.
public final float getX3()
Returns the internal parameter x3.
This method does not check whether the cell is used by the current node type.
public final float getY3()
Returns the internal parameter y3.
This method does not check whether the cell is used by the current node type.
public final float getEndX()
Returns the x-endpoint of this path node. Specifically:
MOVE or LINE,
returns the internal parameter x1.
QUAD,
returns the internal parameter x2.
CUBIC,
returns the internal parameter x3.
CLOSE,
returns 0.
public final float getEndY()
Returns the y-endpoint of this path node. Specifically:
MOVE or LINE,
returns the internal parameter y1.
QUAD,
returns the internal parameter y2.
CUBIC,
returns the internal parameter y3.
CLOSE,
returns 0.
public final void setSlot(int slot,
double x,
double y)
Sets the slot with the given slot index to the given x,y values.
Requires 1 <= index <= getSlotCount()
or does nothing.
slot - the slot index 1, 2, 3x - the x-coordinatey - the y-coordinate
public final void setSlot(int slot,
float[] pair)
Sets the slot with the given slot index to the given x,y pair array.
Requires 1 <= slot <= getSlotCount()
or does nothing.
Also does nothing if pair is not float[2].
slot - the slot index 1, 2, 3pair - the float[2] array with x, y
public final void setSlot(int slot,
double[] pair)
Sets the slot with the given slot index to the given x,y pair array.
Requires 1 <= slot <= getSlotCount()
or does nothing.
Also does nothing if pair is not double[2].
slot - the slot index 1, 2, 3pair - the double[2] array with x, ypublic final float[] getSlot(int slot)
Returns an (x,y) pair of values corresponding to the given
slot index or null if the index is invalid.
Requires 1 <= slot <= getSlotCount()
to return a non-null value.
slot - the slot index 1, 2, 3public final float getSlotX(int slot)
Returns the x-coordinate corresponding to the given slot index or 0 if the index is invalid.
Requires 1 <= slot <= getSlotCount()
to return a valid value.
slot - the slot index 1, 2, 3public final float getSlotY(int slot)
Returns the y-coordinate corresponding to the given slot index or 0 if the index is invalid.
Requires 1 <= slot <= getSlotCount()
to return a valid value.
slot - the slot index 1, 2, 3
public final int nearSlot(double x,
double y,
double epsilon)
Searches the slots in this node and returns a slot index if the given (x,y) is within epsilon of the values in that slot; returns -1 if no such slot exists.
The metric Metric.MAX is used.
x - the x-coordinate of the search pointy - the y-coordinate of the search pointepsilon - the measure of closeness
public final int nearSlot(double x,
double y,
double epsilon,
Metric metric)
Searches the valid slots in this node in order and returns a slot index if the given (x,y) is within epsilon of the values in that slot relative to the given metric; returns -1 if no such slot exists.
If the given metric is null
then Metric.MAX is used.
x - the x-coordinate of the search pointy - the y-coordinate of the search pointepsilon - the measure of closenessmetric - the metric to do the distance computationpublic final int nodeInfo(float[] coords)
Returns the node type as the return value and stores
the node numeric data 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.
This method is intended to provide the behavior for
a single node that the method currentSegment
provides for each successive node in the Java interface
PathIterator.
coords - an array of size 6 to hold the node data
IllegalArgumentExceptionpublic final int nodeInfo(double[] coords)
Returns the node type as the return value and stores
the node numeric data 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.
This method is intended to provide the behavior for
a single node that the method currentSegment
provides for each successive node in the Java interface
PathIterator.
coords - an array of size 6 to hold the node data
IllegalArgumentExceptionpublic final void changeMoveToLine()
If the node type is MOVE, changes it to LINE, otherwise does nothing.
This is a helper method that may permit one to connect a node sequence to a node sequence.
public final void changeLineToMove()
If the node type is LINE, changes it to MOVE, otherwise does nothing.
This is a helper method that may permit one to disconnect a node sequence from a node sequence.
public final void transform(AffineTransform T)
Transforms the internal data points using the given affine transform.
Does nothing if the given affine transform is null.
T - the affine transformpublic final String toString()
Writes the data of this path node to a String.
The format is one of the following:
move(x1,y1)
line(x1,y1)
quad(x1,y1,x2,y2)
cubic(x1,y1,x2,y2,x3,y3)
close()
where x1, y1, x2, y2, x3, y3 are floats.
public final String toStringData()
toString().
toStringData in interface StringableStringable.fromStringData(String)
public final void fromStringData(String state)
throws ParseException
Sets the data of this path node using String
data in the format produced by toString().
For convenience, views an empty data String as equivalent
to the following default: move(0,0).
Throws ParseException if the data is not in
the correct format or has numeric errors.
fromStringData in interface Stringablestate - the String with the state information
ParseExceptionStringable.toStringData()public final String getNodeTypeString()
Returns a String label corresponding to the node type.
The 5 possible labels are move, line,
quad, cubic, and close.
public final int getNodeTypeFromStringData(String data)
throws ParseException
Returns the node type constant that corresponds to the
given String data.
The valid input data is move, line,
quad, cubic, and close.
Throws ParseException if the node type
String does not match any node type.
data - the String with the node type
ParseExceptionpublic final String JavaCode()
Returns in a String the Java code that
might be used to make a clone of this path node.
The Java code has one of the following 5 formats based on the 5 static factory methods in this class:
PathNode.move(x1,y1)PathNode.line(x1,y1)PathNode.quad(x1,y1,x2,y2)PathNode.cubic(x1,y1,x2,y2,x3,y3)PathNode.close()
public static PathNode move(double x1,
double y1)
Factory method the construct a PathNode
of type MOVE.
public static PathNode line(double x1,
double y1)
Factory method the construct a PathNode
of type LINE.
public static PathNode quad(double x1,
double y1,
double x2,
double y2)
Factory method the construct a PathNode
of type QUAD.
public static PathNode cubic(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Factory method the construct a PathNode
of type CUBIC.
public static PathNode close()
Factory method the construct a PathNode
of type CLOSE.
public static PathNode[] getPathNodes(PathIterator iterator)
Returns an array of PathNode objects that
corresponds to the information in the given iterator.
The method must execute the iteration so when it is
complete then iterator.isDone() will be true.
Returns an empty array if the given iterator is
null.
iterator - the iterator whose data is to be extractedpublic static PathNode[] getPathNodes(Shape shape)
Returns an array of PathNode objects that
corresponds to the information in the given shape.
Returns an empty array if the given shape is
null.
shape - the shape whose data is to be extracted
public static PathNode[] getPathNodes(Shape shape,
AffineTransform transform)
Returns an array of PathNode objects that
corresponds to the information in the given shape after
being transformed by the given transform.
Returns an empty array if the given shape is
null.
shape - the shape whose data is to be extractedtransform - the transform to apply to the shape data
public static PathNode[] getPathNodes(Shape shape,
AffineTransform transform,
double flatness)
Returns an array of PathNode objects that
corresponds to the information in the given shape after
being transformed by the given transform and appying
the given flatness parameter.
Returns an empty array if the given shape is
null.
shape - the shape whose data is to be extractedtransform - the transform to apply to the shape dataflatness - the flatness to require
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||