ballwar.model.paint.shape
Class PolygonFactory

java.lang.Object
  extended by ballwar.model.paint.shape.PolygonFactory
All Implemented Interfaces:
IShapeFactory
Direct Known Subclasses:
Fish1PolygonFactory, Fish2PolygonFactory

public class PolygonFactory
extends Object
implements IShapeFactory

Concrete IShapeFactory that provides the invariant behavior to instantiate a Shape that is a Polygon. This class can be instantiated and used simply by supplying the desired points in its constructor, or sub-classed an the constructor overridden. Note that this class cannot be used directly by the BallWar system because it does not have a no-parameter constructor.


Field Summary
private  AffineTransform at
          The AffineTransform used for internal calculations
private  Polygon poly
          The Polygon shape to use as the prototype.
private  double scaleFactor
          Scale factor that scales the integer Point-defined Polygon to a unit size, which requires doubles.
 
Constructor Summary
PolygonFactory(AffineTransform at, double scaleFactor, Point... pts)
          Constructor that uses an externally defined AffineTransform for internal use plus takes the defining points of the prototype Polygon and a scale factor to scale the given points to the desired unit size.
 
Method Summary
 Shape makeShape(double x, double y, double xScale, double yScale)
          Instantiates a Shape object that is the prototype Polygon translated by the given (x, y) point and scaled by given (xScale, yScale) factor times the internal scaleFactor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

poly

private Polygon poly
The Polygon shape to use as the prototype.


at

private AffineTransform at
The AffineTransform used for internal calculations


scaleFactor

private double scaleFactor
Scale factor that scales the integer Point-defined Polygon to a unit size, which requires doubles. The value of scaleFactor is The ratio of the desired unit size to the defined size of the prototype Polygon.

Constructor Detail

PolygonFactory

public PolygonFactory(AffineTransform at,
                      double scaleFactor,
                      Point... pts)
Constructor that uses an externally defined AffineTransform for internal use plus takes the defining points of the prototype Polygon and a scale factor to scale the given points to the desired unit size. Since Polygons require Point objects for their definition, a prototype Polygon cannot be defined of arbitrary size because Points are defined on an integer grid. Thus, a double scale factor is also provided that is used to scale the Polygon via the affine transform into a Shape of the desired size.

Parameters:
at - The AffineTransform to use.
scaleFactor - The ratio of the desired unit size to the defined size of the prototype Polygon.
pts - Vararg parameters that are the Points that define the Polygon around the origin as its center.
Method Detail

makeShape

public Shape makeShape(double x,
                       double y,
                       double xScale,
                       double yScale)
Instantiates a Shape object that is the prototype Polygon translated by the given (x, y) point and scaled by given (xScale, yScale) factor times the internal scaleFactor. Note that this method does *not* return a Polygon object, but rather a abstract Shape object. The return value *cannot* be cast to Polygon.

Specified by:
makeShape in interface IShapeFactory
Parameters:
x - x-coordinate of the center of the resultant Polygon
y - y-coordinate of the center of the resultant Polygon
xScale - The x-dimension of the polygon, usually the x-radius.
yScale - The y-dimension of the polygon, usually the y-radius.
Returns:
A Shape object that is the scaled prototype Polygon.