com.jfimagine.jfgraph.geom
Class PolyLine

java.lang.Object
  |
  +--com.jfimagine.jfgraph.geom.PolyLine
All Implemented Interfaces:
java.lang.Cloneable

public class PolyLine
extends java.lang.Object
implements java.lang.Cloneable

A PolyLine class used to represents a continuous arbitrary line segments collection.

Attention: Here we used a clockwise quadrant system. And the first quadrant is under right bottom corner.

Version:
$Revision: 1.1 $
Author:
CookieMaker

Field Summary
static int POLYLINE_CLOSED
          An closed polyline, it's really a polygon
static int POLYLINE_OPEN
          An open polyline
 
Constructor Summary
PolyLine()
          Constructor for PolyLine.
PolyLine(int[] xpoints, int[] ypoints, int npoints)
          Constructor for PolyLine.
PolyLine(PolyLine line)
          Constructor for PolyLine.
 
Method Summary
 void addNode(double x, double y)
          Add a new node to polyline.
 void addNode(JFPointNode pnt)
          Add a new node to polyline.
 boolean canAddPort(double x, double y, JFPoint startPoint, JFPoint endPoint, JFPoint portPoint)
          Test if current polyline can add a port according to the position x,y.
 void cancelLastNode()
          Cancel last node.
 void clearNodes()
          Clear all nodes of this polyline.
 java.lang.Object clone()
          Creates a new object of the same class and with the same contents as this object.
 boolean closePolygon()
          close path for polygon
 boolean contains(double x, double y)
          Test if a point(x, y coordinates for instead) is on this line.
 boolean contains(double x, double y, double pickOffset)
          Test if a point(x, y coordinates for instead) is on this line.
 boolean contains(JFPoint pnt)
          Test if a point is on this line.
 boolean contains(JFPoint pnt, double pickOffset)
          Test if a point is on this line.
 boolean equals(java.lang.Object obj)
          Determines whether or not two objects are equal.
 void finishDrawing()
          Finish drawing, and combine some nodes which are on same line.
 void flipBy()
          Reverse this line by a central y coordinate of this line.
 void flipBy(double baseY)
          Reverse this line by a y coordinate.
 Rect getBounds()
          Get the bounds of this polyline.
 JFPoint getCenter()
          Get a center point on this line.
 int getEndNodeCount()
          Get end node count of polyline.
 JFPointNode getNextNode(int nodeIndex, boolean reverse)
          Get next node of a polyline.
 JFPointNode getNextNode(JFPointNode node, boolean reverse)
          Get next node of a polyline.
 JFPointNode getNode(int nodeIndex)
          Get a specified node of this polyline.
 int getNodeCount()
          Get node count of polyline.
 int getNodeIndex(JFPointNode node)
          Get a node's index inside a node list.
 java.util.List getNodeList()
          Get point node list
 int hashCode()
          Returns the hashcode for this Object.
 boolean intersects(double x1, double y1, double x2, double y2)
          Tests if the specified line segment intersects this PolyLine.
 boolean intersects(JFPointNode startPoint, JFPointNode endPoint)
          Tests if the specified line segment intersects this PolyLine.
 boolean intersects(LineSeg l)
          Tests if the specified line segment intersects the this PolyLine.
 boolean intersects(Rect rect)
          Tests if the specified rectangle intersects the interior of this PolyLine.
 boolean isPolygon()
          If this polyline is actually a polygon.
 void mirrorBy()
          Mirror this line by a central x coordinate of this line.
 void mirrorBy(double baseX)
          Mirror this line by a x coordinate.
 void moveBy(double x, double y)
          Move this line by specific x and y coordinates.
 LineSeg pickLine(double x, double y, double pickOffset)
          Pick a line segment of this polyline by a point with a pickoffset.
 LineSeg pickLine(double x, double y, double pickOffset, JFPoint startPoint, JFPoint endPoint)
          Pick a line segment of this polyline by specified a point with a pickoffset, and start point and end point restricted.
 void removeNode(int nodeIndex)
          Remove a specified node.
 void removeNode(JFPointNode node)
          Remove a specified node.
 void replaceLastNode(double x, double y)
          replace last node. and concurrently adjust the relational points.
 void rotateBy(double theta)
          Rotate this line by an angle theta.
 void rotateBy(double baseX, double baseY, double theta)
          Rotate this line by a specified point and an angle theta.
 void rotateBy(JFPoint pnt, double theta)
          Rotate this line by a specified point and an angle theta.
 void scaleBy(JFPoint basePoint, double xScale, double yScale)
          Scale current polyLine by a specified x and y scale.
 void scaleBy(JFPoint basePoint, JFPoint refPoint1, JFPoint refPoint2, double scale)
          Scale current polyline by specified points and scale percent.
 void setNodeList(int[] xpoints, int[] ypoints, int npoints)
          Set point node list
 void setNodeList(java.util.List nodeList)
          Set point node list
 java.lang.String toString()
          Convert this object to String
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

POLYLINE_OPEN

public static final int POLYLINE_OPEN
An open polyline

See Also:
Constant Field Values

POLYLINE_CLOSED

public static final int POLYLINE_CLOSED
An closed polyline, it's really a polygon

See Also:
Constant Field Values
Constructor Detail

PolyLine

public PolyLine()
Constructor for PolyLine.


PolyLine

public PolyLine(PolyLine line)
Constructor for PolyLine.

Parameters:
line - A polyline.

PolyLine

public PolyLine(int[] xpoints,
                int[] ypoints,
                int npoints)
Constructor for PolyLine.

Parameters:
xpoints - an array of x coordinates
ypoints - an array of y coordinates
npoints - the total number of points in the Polygon
Method Detail

isPolygon

public boolean isPolygon()
If this polyline is actually a polygon.

Returns:
True if a polygon, false polyline.

getNodeList

public java.util.List getNodeList()
Get point node list

Returns:
The point node list.

setNodeList

public void setNodeList(java.util.List nodeList)
Set point node list


setNodeList

public void setNodeList(int[] xpoints,
                        int[] ypoints,
                        int npoints)
Set point node list

Parameters:
xpoints - an array of x coordinates
ypoints - an array of y coordinates
npoints - the total number of points in the Polygon

clearNodes

public void clearNodes()
Clear all nodes of this polyline.


getNodeCount

public int getNodeCount()
Get node count of polyline.

Returns:
node count.

getEndNodeCount

public int getEndNodeCount()
Get end node count of polyline.

Returns:
End node count.

getNode

public JFPointNode getNode(int nodeIndex)
Get a specified node of this polyline.

Parameters:
nodeIndex - A node index.
Returns:
the specified node.

getNodeIndex

public int getNodeIndex(JFPointNode node)
Get a node's index inside a node list.

Parameters:
node - A specified node to be found.

removeNode

public void removeNode(JFPointNode node)
Remove a specified node.

Parameters:
node - A node in the node list to be removed.

removeNode

public void removeNode(int nodeIndex)
Remove a specified node.

Parameters:
nodeIndex - The index of specified node.

getNextNode

public JFPointNode getNextNode(JFPointNode node,
                               boolean reverse)
Get next node of a polyline.

Parameters:
node - The node to start finding.
reverse - False if get next node of this node, true if get prior node of this node.
Returns:
the next node.

getNextNode

public JFPointNode getNextNode(int nodeIndex,
                               boolean reverse)
Get next node of a polyline.

Parameters:
nodeIndex - The node index to start finding.
reverse - False if get next node of this node, true if get prior node of this node.
Returns:
the next node.

finishDrawing

public void finishDrawing()
Finish drawing, and combine some nodes which are on same line.


addNode

public void addNode(JFPointNode pnt)
Add a new node to polyline.


addNode

public void addNode(double x,
                    double y)
Add a new node to polyline.


closePolygon

public boolean closePolygon()
close path for polygon

Returns:
true if can close, false otherwise.

cancelLastNode

public void cancelLastNode()
Cancel last node.


replaceLastNode

public void replaceLastNode(double x,
                            double y)
replace last node. and concurrently adjust the relational points.


getBounds

public Rect getBounds()
Get the bounds of this polyline.

Returns:
The bounds rectangle.

getCenter

public JFPoint getCenter()
Get a center point on this line.

Returns:
The center point.

scaleBy

public void scaleBy(JFPoint basePoint,
                    JFPoint refPoint1,
                    JFPoint refPoint2,
                    double scale)
Scale current polyline by specified points and scale percent. We only support a concurrent width-height scale here, suppose width as the length from basePoint to refPoint1, height as the length from basePoint to refPoint2, and one scale percent acts on both width and height.

Parameters:
basePoint - A base point that is unmovable.
refPoint1 - A 'width' reference point.
refPoint2 - A 'height' reference point.
scale - A reference scale percent.

scaleBy

public void scaleBy(JFPoint basePoint,
                    double xScale,
                    double yScale)
Scale current polyLine by a specified x and y scale.
This is a special scale method used to scale a shape in arbitrary x and y scale.
Please see AbstractShape.scaleBy for detailed description.

Parameters:
basePoint - A base scale point for scaling reference.
xScale - A scale percentage in x coordinate, default to 1.0
yScale - A scale percentage in y coordinate, default to 1.0

moveBy

public void moveBy(double x,
                   double y)
Move this line by specific x and y coordinates.

Parameters:
x - X coordiate to moveby.
y - Y coordiate to moveby.

rotateBy

public void rotateBy(double theta)
Rotate this line by an angle theta.

Parameters:
theta - A rotate angle.

rotateBy

public void rotateBy(JFPoint pnt,
                     double theta)
Rotate this line by a specified point and an angle theta.

Parameters:
pnt - A rotate center point.
theta - A rotate angle.

rotateBy

public void rotateBy(double baseX,
                     double baseY,
                     double theta)
Rotate this line by a specified point and an angle theta.

Parameters:
theta - A rotate angle.

mirrorBy

public void mirrorBy()
Mirror this line by a central x coordinate of this line. We make a up-down reverse here.


mirrorBy

public void mirrorBy(double baseX)
Mirror this line by a x coordinate. We make a left-right mirror here.

Parameters:
baseX - A mirror base x coordinate.

flipBy

public void flipBy()
Reverse this line by a central y coordinate of this line. We make a up-down flip here.


flipBy

public void flipBy(double baseY)
Reverse this line by a y coordinate. We make a up-down flip here.

Parameters:
baseY - A flip base y coordinate.

contains

public boolean contains(JFPoint pnt)
Test if a point is on this line.

Parameters:
pnt - A point to be measured.
Returns:
True if the point is on this line, false otherwise.

contains

public boolean contains(JFPoint pnt,
                        double pickOffset)
Test if a point is on this line. Here we used an analog offset for 'pick' this line.

Parameters:
pnt - A point to be measured.
pickOffset - An analog offset for 'pick' this line.
Returns:
True if the point is on this line, false otherwise.

contains

public boolean contains(double x,
                        double y)
Test if a point(x, y coordinates for instead) is on this line.

Parameters:
x - X coordinate of this point.
y - Y coordinate of this point.
Returns:
True if the point is on this line, false otherwise.

contains

public boolean contains(double x,
                        double y,
                        double pickOffset)
Test if a point(x, y coordinates for instead) is on this line. Here we used an analog offset for 'pick' this line.

Parameters:
x - X coordinate of this point.
y - Y coordinate of this point.
pickOffset - An analog pick offset that great equal than 0.
Returns:
True if the point is on this line, false otherwise.

pickLine

public LineSeg pickLine(double x,
                        double y,
                        double pickOffset)
Pick a line segment of this polyline by a point with a pickoffset.

Parameters:
x - X coordinate of this point.
y - Y coordinate of this point.
pickOffset - An analog pick offset that great equal than 0.
Returns:
A line segment picked.

pickLine

public LineSeg pickLine(double x,
                        double y,
                        double pickOffset,
                        JFPoint startPoint,
                        JFPoint endPoint)
Pick a line segment of this polyline by specified a point with a pickoffset, and start point and end point restricted.

Parameters:
x - X coordinate of this point.
y - Y coordinate of this point.
pickOffset - An analog pick offset that great equal than 0.
startPoint - Start point of a line segment.
endPoint - End point of a line segment.
Returns:
A line segment picked.

canAddPort

public boolean canAddPort(double x,
                          double y,
                          JFPoint startPoint,
                          JFPoint endPoint,
                          JFPoint portPoint)
Test if current polyline can add a port according to the position x,y.

Parameters:
x - X coordinate of the port.
y - Y coordinate of the port.
Returns:
True if can add a new port, false otherwise.

intersects

public boolean intersects(LineSeg l)
Tests if the specified line segment intersects the this PolyLine.

Parameters:
l - the specified PolyLine to test for intersection with this PolyLine
Returns:
true if the specified PolyLine intersects this PolyLine; false otherwise.
Since:
1.2

intersects

public boolean intersects(JFPointNode startPoint,
                          JFPointNode endPoint)
Tests if the specified line segment intersects this PolyLine.

Parameters:
startPoint - the first endpoint of the specified line segment
endPoint - the second endpoint of the specified line segment
Returns:
true if the specified line segment intersects the this PolyLine; false otherwise.

intersects

public boolean intersects(double x1,
                          double y1,
                          double x2,
                          double y2)
Tests if the specified line segment intersects this PolyLine.

Returns:
true if the specified line segment intersects the this PolyLine; false otherwise.

intersects

public boolean intersects(Rect rect)
Tests if the specified rectangle intersects the interior of this PolyLine.

Parameters:
rect - the specified PolyLine to test for intersection with the interior of this PolyLine
Returns:
true if the specified PolyLine intersects the interior of this PolyLine; false otherwise.

toString

public java.lang.String toString()
Convert this object to String

Overrides:
toString in class java.lang.Object
Returns:
An string represents the content of the object

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates a new object of the same class and with the same contents as this object.

Overrides:
clone in class java.lang.Object
Returns:
A clone of this instance.
java.lang.CloneNotSupportedException

hashCode

public int hashCode()
Returns the hashcode for this Object.

Overrides:
hashCode in class java.lang.Object
Returns:
hash code for this Point2D.

equals

public boolean equals(java.lang.Object obj)
Determines whether or not two objects are equal.

Overrides:
equals in class java.lang.Object
Parameters:
obj - an object to be compared with this object
Returns:
true if the object to be compared is an instance of Port and has the same values; false otherwise.


Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All Rights Reserved.