ballworld.model.paint
Class ImagePaintStrategy

java.lang.Object
  extended by ballworld.model.paint.APaintStrategy
      extended by ballworld.model.paint.ImagePaintStrategy
All Implemented Interfaces:
IPaintStrategy
Direct Known Subclasses:
PlanetImagePaintStrategy, SoccerImagePaintStrategy, UprightImagePaintStrategy

public class ImagePaintStrategy
extends APaintStrategy

Paint strategy that paints an image from a file, scaled to the host Ball's radius. Note that this class cannot be used by the BallWar system directly as it is missing a no-parameter constructor.


Field Summary
private  double fillFactor
          The percentage of the average of the width and height of the image that defines a unit radius for the image.
private  java.awt.Image image
          The image to paint
private  java.awt.image.ImageObserver imageObs
          ImageObserver needed for some image operations
protected  java.awt.geom.AffineTransform localAT
          A local affine transform used to transform the image into its unit size and location.
private  double scaleFactor
          Ratio of the unit radius circle to the effective radius size of the image.
 
Fields inherited from class ballworld.model.paint.APaintStrategy
at
 
Fields inherited from interface ballworld.model.IPaintStrategy
NullObject
 
Constructor Summary
ImagePaintStrategy(java.awt.geom.AffineTransform at, java.lang.String filename, double fillFactor)
          Constructor that takes an external AffineTransform, the filename of the image to paint and a fill factor of the image.
ImagePaintStrategy(java.lang.String filename, double fillFactor)
          Constructor that takes the image filename and fill factor.
 
Method Summary
 void init(Ball host)
          Initializes the internal ImageObserver reference from the host Ball Also calculates the net scale factor for the image.
 void paintXfrm(java.awt.Graphics g, Ball host, java.awt.geom.AffineTransform at)
          Draws the image on the given Graphics context using the given affine transform in combination with the local affine transform.
 
Methods inherited from class ballworld.model.paint.APaintStrategy
paint, paintCfg
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

imageObs

private java.awt.image.ImageObserver imageObs
ImageObserver needed for some image operations


image

private java.awt.Image image
The image to paint


scaleFactor

private double scaleFactor
Ratio of the unit radius circle to the effective radius size of the image. This is the inverse of the fill factor times half the average of the width and height of the image.


fillFactor

private double fillFactor
The percentage of the average of the width and height of the image that defines a unit radius for the image. This is also the collision bounds of the image in terms of a percentage.


localAT

protected java.awt.geom.AffineTransform localAT
A local affine transform used to transform the image into its unit size and location.

Constructor Detail

ImagePaintStrategy

public ImagePaintStrategy(java.lang.String filename,
                          double fillFactor)
Constructor that takes the image filename and fill factor. An AffineTransform is instantiated for internal use. GIF, JPG, PNG and any other file that can be loaded by an ImageIcon object can be used, including animated GIF's as the above files are.

Parameters:
filename - The filename of the image file to use.
fillFactor - The ratio of the desired average radius of the image to the actual average of the image's width and height.

ImagePaintStrategy

public ImagePaintStrategy(java.awt.geom.AffineTransform at,
                          java.lang.String filename,
                          double fillFactor)
Constructor that takes an external AffineTransform, the filename of the image to paint and a fill factor of the image.

Parameters:
at - The AffineTransform to use internally.
filename - The filename of the image file to use.
fillFactor - The ratio of the desired average diameter of the image to the actual average of the image's width and height.
Method Detail

paintXfrm

public void paintXfrm(java.awt.Graphics g,
                      Ball host,
                      java.awt.geom.AffineTransform at)
Draws the image on the given Graphics context using the given affine transform in combination with the local affine transform.

Specified by:
paintXfrm in class APaintStrategy
Parameters:
g - The graphics context to paint on
host - The host Ball
at - The AffineTransform to use.

init

public void init(Ball host)
Initializes the internal ImageObserver reference from the host Ball Also calculates the net scale factor for the image.

Specified by:
init in interface IPaintStrategy
Overrides:
init in class APaintStrategy
Parameters:
host - The host Ball