com.miginfocom.ashape
Class PolygonShape

java.lang.Object
  extended by com.miginfocom.ashape.PolygonShape
All Implemented Interfaces:
java.awt.Shape

public class PolygonShape
extends java.lang.Object
implements java.awt.Shape

Similar to Polygon and GeneralPath but can handle AtPoints. This means that the polygon is more dynamic and can have non-linear resize behaviour. For instance one can make a round rectangle with corners that will always be of a certain radius no matter how big the rectangle itself are set (scaled) to.

Only AtPoints can be added to this polygon shape.
An AtPoint can have an incoming and/or out going directional and sized vector. This means that these points can, depending on the in- and out going vectors, do what GeneralPath does with it's methods curveTo, lineTo and quadTo but in a more generic way. Since AtPoints are very flexible and can even be linked to bounds of other shapes, a PolygonShape can be made to scale in very flexible ways. Like AbsRect this shape is to be used as relative to something. If a static, only uniformly scalable shape is needed then the normal GeneralPath will be a bit faster.

Note that this is a Shape, not an AShape!

See Also:
AtPoint

Constructor Summary
PolygonShape()
          Constructor with an initial size of 10.
PolygonShape(int capacity)
          Constructor.
 
Method Summary
 void addPoint(AtPoint p)
          Adds a point to the polygon shape.
 void addPoint(float x, float y)
          Adds an AtPoint point to the polygon shape.
 void addPoints(java.util.List points)
          Adds a number of AtPoints.
 boolean contains(double x, double y)
           
 boolean contains(double x, double y, double w, double h)
           
 boolean contains(java.awt.geom.Point2D p)
           
 boolean contains(java.awt.geom.Rectangle2D r)
           
 boolean equals(java.lang.Object o)
           
 java.awt.Rectangle getBounds()
           
 java.awt.geom.Rectangle2D getBounds2D()
           
protected  java.awt.geom.GeneralPath getGeneralPath()
          Returns a new GeneralPath object that represents this polygon shape translated and scaled the way that the AtPoints indicate.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
           
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)
           
 java.util.List getPoints()
          Returns a cloned list of the points contained.
 java.awt.geom.Rectangle2D.Float getReferentialBounds()
          Returns the bounds that this polygon are using as a reference.
 float getRefHeight()
          Return the height of the referensial bounds.
 float getRefMaxX()
          Return the bounds max x value of the referensial bounds.
 float getRefMaxY()
          Return the bounds max y value of the referensial bounds.
 float getRefWidth()
          Return the width of the referensial bounds.
 float getRefX()
          Return the bounds x value of the referensial bounds.
 float getRefY()
          Return the bounds y value of the referensial bounds.
protected  java.awt.geom.GeneralPath getTransformedGeneralPath(java.awt.geom.AffineTransform at)
          Returns a new GeneralPath object that represents this polygon shape translated and scaled the way that the AtPoints indicate.
 boolean intersects(double x, double y, double w, double h)
           
 boolean intersects(java.awt.geom.Rectangle2D r)
           
protected  void invalidate()
          Sets the general path and bounds2d for validation bofore anything can be done to them.
protected  boolean isValid()
          Returns true if the contained generalPath and it's bounds are calculated.
 void setPoints(java.util.List points)
          Adds a number of AtPoints.
 void setReferentialBounds(java.awt.geom.Rectangle2D.Float b)
          Sets the bounds that this polygon should use as reference.
protected  void validate()
          Recalculates the contained general path against the current referential bounds.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PolygonShape

public PolygonShape()
Constructor with an initial size of 10. Will have a referential rectangle or 0, 0, 100, 100 to start width.

See Also:
setReferentialBounds(java.awt.geom.Rectangle2D.Float)

PolygonShape

public PolygonShape(int capacity)
Constructor. Will have a referential rectangle or 0, 0, 100, 100 to start width.

Parameters:
capacity - The initial size of the list of points.
See Also:
setReferentialBounds(java.awt.geom.Rectangle2D.Float)
Method Detail

addPoint

public void addPoint(AtPoint p)
Adds a point to the polygon shape.

Parameters:
p - The point to add. Not null.

addPoint

public void addPoint(float x,
                     float y)
Adds an AtPoint point to the polygon shape.

Parameters:
x - The x component.
y - The y component.

addPoints

public void addPoints(java.util.List points)
Adds a number of AtPoints.

Parameters:
points - The points to add. Not null. Must only contain AtPoint objects.

setPoints

public void setPoints(java.util.List points)
Adds a number of AtPoints.

Parameters:
points - The points to add. Not null. Must only contain AtPoint objects.

getPoints

public java.util.List getPoints()
Returns a cloned list of the points contained. Type is AtPoint objects.

Returns:
A cloned list of the points contained. Never null.

setReferentialBounds

public void setReferentialBounds(java.awt.geom.Rectangle2D.Float b)
Sets the bounds that this polygon should use as reference. Note that this may not be the same bounds returned from getBounds2D() since it is only used as a reference.

Parameters:
b - The reference bounds. Not null. Object cloned for local storage.

getReferentialBounds

public java.awt.geom.Rectangle2D.Float getReferentialBounds()
Returns the bounds that this polygon are using as a reference. Note that this may not be the same bounds returned from getBounds2D() since it is only used as a reference.

Returns:
The reference bounds. Not null. New object returned.

getRefX

public float getRefX()
Return the bounds x value of the referensial bounds.

Returns:
The bounds x value of the referensial bounds.

getRefMaxX

public float getRefMaxX()
Return the bounds max x value of the referensial bounds.

Returns:
The bounds max x value of the referensial bounds.

getRefY

public float getRefY()
Return the bounds y value of the referensial bounds.

Returns:
The bounds y value of the referensial bounds.

getRefMaxY

public float getRefMaxY()
Return the bounds max y value of the referensial bounds.

Returns:
The bounds max y value of the referensial bounds.

getRefWidth

public float getRefWidth()
Return the width of the referensial bounds.

Returns:
The width of the referensial bounds.

getRefHeight

public float getRefHeight()
Return the height of the referensial bounds.

Returns:
The height of the referensial bounds.

contains

public boolean contains(java.awt.geom.Point2D p)
Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(java.awt.geom.Rectangle2D r)
Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(double x,
                        double y)
Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Specified by:
contains in interface java.awt.Shape

getBounds

public java.awt.Rectangle getBounds()
Specified by:
getBounds in interface java.awt.Shape

getBounds2D

public java.awt.geom.Rectangle2D getBounds2D()
Specified by:
getBounds2D in interface java.awt.Shape

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
Specified by:
getPathIterator in interface java.awt.Shape

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at,
                                                  double flatness)
Specified by:
getPathIterator in interface java.awt.Shape

intersects

public boolean intersects(java.awt.geom.Rectangle2D r)
Specified by:
intersects in interface java.awt.Shape

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Specified by:
intersects in interface java.awt.Shape

invalidate

protected void invalidate()
Sets the general path and bounds2d for validation bofore anything can be done to them.


isValid

protected boolean isValid()
Returns true if the contained generalPath and it's bounds are calculated.

Returns:
true if the contained generalPath and it's bounds are calculated.

validate

protected void validate()
Recalculates the contained general path against the current referential bounds. Also get the bounds out of the general path and stored it in bounds2D.


getGeneralPath

protected java.awt.geom.GeneralPath getGeneralPath()
Returns a new GeneralPath object that represents this polygon shape translated and scaled the way that the AtPoints indicate.

Returns:
A new GeneralPath object
See Also:
getReferentialBounds()

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

getTransformedGeneralPath

protected java.awt.geom.GeneralPath getTransformedGeneralPath(java.awt.geom.AffineTransform at)
Returns a new GeneralPath object that represents this polygon shape translated and scaled the way that the AtPoints indicate. Any sheer in at will be applied uniformly though.

Parameters:
at - The affine transform. May be null.
Returns:
A new GeneralPath object


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.