ballworld.model.paint
Class APaintStrategy

java.lang.Object
  extended by ballworld.model.paint.APaintStrategy
All Implemented Interfaces:
IPaintStrategy
Direct Known Subclasses:
ADecoratorPaintStrategy, AnimatePaintStrategy, ImagePaintStrategy, MultiPaintStrategy, ShapePaintStrategy

public abstract class APaintStrategy
extends java.lang.Object
implements IPaintStrategy

An abstract paint strategy that provides default behavior for its subclasses.


Field Summary
protected  java.awt.geom.AffineTransform at
          The affine transform used by this paint strategy to translate, scale and rotate the image.
 
Fields inherited from interface ballworld.model.IPaintStrategy
NullObject
 
Constructor Summary
APaintStrategy(java.awt.geom.AffineTransform at)
          Constructor that initializes the strategy with an affine transform
 
Method Summary
 void init(Ball context)
          By default, do nothing for initialization.
 void paint(java.awt.Graphics g, Ball host)
          Paints on the given graphics context using the color, scale and direction provided by the host.
protected  void paintCfg(java.awt.Graphics g, Ball host)
          Used for doing additional configurations by a subclass.
abstract  void paintXfrm(java.awt.Graphics g, Ball host, java.awt.geom.AffineTransform at)
          Paints the host onto the given Graphics context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

at

protected java.awt.geom.AffineTransform at
The affine transform used by this paint strategy to translate, scale and rotate the image.

Constructor Detail

APaintStrategy

public APaintStrategy(java.awt.geom.AffineTransform at)
Constructor that initializes the strategy with an affine transform

Parameters:
at - The AffineTransform for this paint strategy to use.
Method Detail

paint

public void paint(java.awt.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 rotate then scale then translate. Calls paintXfrm to actually perform the painting, using the set up transform. Calls paintCfg just before calling paintXfrm

Specified by:
paint in interface IPaintStrategy
Parameters:
g - The Graphics context that will be paint on
host - The host Ball that the required information will be pulled from.

init

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

Specified by:
init in interface IPaintStrategy
Parameters:
context - The ball to initialize.

paintCfg

protected void paintCfg(java.awt.Graphics g,
                        Ball host)
Used for doing additional configurations by a subclass. The translation, rotation and scaling transformations have already been applied to this class's AffineTransform instance. This method is called before the paint method's final delegation to paintXfrm. This method is designed to be overridden by the subclass. By default the behavior is a no-op.

Parameters:
g - The Graphics context that will be drawn upon.
host - The Ball to be painted.

paintXfrm

public abstract void paintXfrm(java.awt.Graphics g,
                               Ball host,
                               java.awt.geom.AffineTransform at)
Paints the host onto the given Graphics context. The image is translated, scaled and rotated as determined by the given affine transformation. This method is intended to be called either by a class's (or superclass's) own paint method or by another paint strategy who is sharing the affine transform. This allows the same transformation to be shared amongst multiple paint strategies.

Parameters:
g - The graphics context to draw upon.
host - The host ball.
at - The affine transform to use.