Draw2D v2.0

org.eclipse.draw2d.geometry
Class PointList

java.lang.Object
  |
  +--org.eclipse.draw2d.geometry.PointList
All Implemented Interfaces:
Serializable

public class PointList
extends Object
implements Serializable

Provides support for a list of points.

See Also:
Serialized Form

Constructor Summary
PointList()
          Constructs an empty PointList.
PointList(int size)
          Constructs a PointList with capacity size.
 
Method Summary
 void addPoint(int x, int y)
          Adds the input point values to this PointList.
 void addPoint(Point p)
          Adds Point p to this PointList.
 Rectangle getBounds()
          Returns rectangular area in which all the points in this list would fit.
 Point getFirstPoint()
          Returns the first point in the list.
 Point getLastPoint()
          Returns the last point in the list.
 Point getMidpoint()
           
 Point getPoint(int index)
          Returns the point in the list pointed to by the index.
 Point getPoint(Point p, int index)
          Copies the x and y values of the Point at index into the x and y fields of p and returns p.
 void insertPoint(Point p, int index)
          Inserts a given point at a specified index in the list.
 void removeAllPoints()
          Removes all the points stored by this list.
 Point removePoint(int index)
          Removes the point at the specified index from the PointList, and returns it.
 void setPoint(Point pt, int index)
          Overwrites a point at an index in the list with the input point.
 int size()
          Returns the number of points in this PointList.
 int[] toIntArray()
          Returns the contents of this PointList as an integer array.
 void translate(int x, int y)
          Moves the origin (0,0) of the coordinate system of all the points to the Point (x,y).
 void translate(Point pt)
          Moves the origin (0,0) of the coordinate system of all the points to the Point pt.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PointList

public PointList()
Constructs an empty PointList.
Since:
2.0

PointList

public PointList(int size)
Constructs a PointList with capacity size.
Parameters:
size - Number of points to hold.
Since:
2.0
Method Detail

addPoint

public void addPoint(Point p)
Adds Point p to this PointList.
Since:
2.0
See Also:
removePoint(int)

addPoint

public void addPoint(int x,
                     int y)
Adds the input point values to this PointList.
Parameters:
x - X value of a point to add.
y - Y value of a point to add.
Since:
2.0

getBounds

public Rectangle getBounds()
Returns rectangular area in which all the points in this list would fit.
Returns:
Bounding region as a rectangle.
Since:
2.0

getFirstPoint

public Point getFirstPoint()
Returns the first point in the list.
Returns:
The first point in the list.
Since:
2.0

getLastPoint

public Point getLastPoint()
Returns the last point in the list.
Returns:
The last point in the list or null if there are no elements.
Since:
2.0

getMidpoint

public Point getMidpoint()

getPoint

public Point getPoint(int index)
Returns the point in the list pointed to by the index. The index starts at 0.
Parameters:
index - Position of the point in the list.
Returns:
The point at index.
Since:
2.0

getPoint

public Point getPoint(Point p,
                      int index)
Copies the x and y values of the Point at index into the x and y fields of p and returns p.
Since:
2.0

insertPoint

public void insertPoint(Point p,
                        int index)
Inserts a given point at a specified index in the list.
Parameters:
p - Point to be inserted.
index - Position where the point is to be inserted.
Throws:
IndexOutOfBoundsException - if the insert index is is beyond the list capacity or if it is negative.
Since:
2.0
See Also:
setPoint(Point,int)

removeAllPoints

public void removeAllPoints()
Removes all the points stored by this list. Resets all the properties based on the point information.
Since:
2.0

removePoint

public Point removePoint(int index)
Removes the point at the specified index from the PointList, and returns it.
Parameters:
index - Index of the point to be removed.
Returns:
The point which has been removed.
Throws:
IndexOutOfBoundsException - if the removal index is is beyond the list capacity.
Since:
2.0
See Also:
addPoint(Point)

setPoint

public void setPoint(Point pt,
                     int index)
Overwrites a point at an index in the list with the input point.
Parameters:
pt - Point which is to be stored at the index.
index - Index where the given point is to be stored.
Since:
2.0

size

public int size()
Returns the number of points in this PointList.
Returns:
The number of points.
Since:
2.0

toIntArray

public int[] toIntArray()
Returns the contents of this PointList as an integer array.
Returns:
The points in the list as an array of integers.
Since:
2.0

translate

public void translate(Point pt)
Moves the origin (0,0) of the coordinate system of all the points to the Point pt. This updates the position of all the points in this PointList.
Parameters:
pt - Position by which all the points will be shifted.
Since:
2.0
See Also:
translate(int,int)

translate

public void translate(int x,
                      int y)
Moves the origin (0,0) of the coordinate system of all the points to the Point (x,y). This updates the position of all the points in this PointList.
Parameters:
x - Amount by which all the points will be shifted on the X axis.
y - Amount by which all the points will be shifted on the Y axis.
Since:
2.0
See Also:
translate(Point)

Draw2D v2.0