ballwar.model.paint
Class BallPaintStrategy

java.lang.Object
  extended by ballwar.model.paint.BallPaintStrategy
All Implemented Interfaces:
IPaintStrategy

public class BallPaintStrategy
extends Object
implements IPaintStrategy

Paint strategy that paints a filled circle with the Ball's radius. This functionality is duplicated by the EllipsePaintStrategy. The class demonstrates a direct implementation of IPaintStrategy.


Field Summary
private  AffineTransform at
          The AffineTransformed used for internal calculations.
private  Ellipse2D.Double ball
          Unit sized circle used as a prototype
 
Fields inherited from interface ballwar.model.IPaintStrategy
NullObject
 
Constructor Summary
BallPaintStrategy()
          No parameter constructor that creates a 1 pixel radius ball at the origin.
BallPaintStrategy(AffineTransform at, double x, double y, double width, double height)
          Constructor that allows one to create the prototype ball of arbitrary dimension and location.
 
Method Summary
 void init(Ball context)
          By default, do nothing for initialization.
 void paint(Graphics g, Ball host)
          Paints on the given graphics context using the color, scale and direction provided by the host.
 void paintXfrm(Graphics g, Ball host, AffineTransform at)
          Paints a transformed circle, as per the given AffineTransform Uses color already set in Graphics context
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ball

private Ellipse2D.Double ball
Unit sized circle used as a prototype


at

private AffineTransform at
The AffineTransformed used for internal calculations.

Constructor Detail

BallPaintStrategy

public BallPaintStrategy()
No parameter constructor that creates a 1 pixel radius ball at the origin. Instantiates a new AffineTransform for internal use.


BallPaintStrategy

public BallPaintStrategy(AffineTransform at,
                         double x,
                         double y,
                         double width,
                         double height)
Constructor that allows one to create the prototype ball of arbitrary dimension and location. The AffineTransform is externally supplied.

Parameters:
at - The AffineTransform to use for internal calculations
x - floating point x-coordinate of center of circle
y - floating point y-coordinate of center of circle
width - floating point x-radius of the circle (ellipse)
height - floating point y-radius of the circle (ellipse)
Method Detail

paint

public void paint(Graphics g,
                  Ball host)
Paints on the given graphics context using the color, scale and direction provided by the host. This is done by setting up the AffineTransform to scale then translate. Calls paintXfrm to actually perform the painting, using the set up transform. Calls paintCfg just before calling paintXfrm param g The Graphics context that will be paint on param host The host Ball that the required information will be pulled from.

Specified by:
paint in interface IPaintStrategy
Parameters:
g - The graphics context to draw upon.
host - The host ball.

paintXfrm

public void paintXfrm(Graphics g,
                      Ball host,
                      AffineTransform at)
Paints a transformed circle, as per the given AffineTransform Uses color already set in Graphics context

Specified by:
paintXfrm in interface IPaintStrategy
Parameters:
g - The Graphics context to paint on
host - The Ball host
at - the AffineTransform to use

init

public void init(Ball context)
By default, do nothing for initialization.

Specified by:
init in interface IPaintStrategy