org.artoflife.gui.paintable
Class PaintablePhenotype

java.lang.Object
  |
  +--org.artoflife.gp.Phenotype
        |
        +--org.artoflife.gui.paintable.PaintablePhenotype
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public abstract class PaintablePhenotype
extends Phenotype

A Phenotype that can paint itself at various sizes onto a Graphics2D. Caches the last painted images to reuse if asked to paint at the same sizes again. If asked to paint at a new size, a new one is painted to fit the current size. Cached images are saved in a WeakHashMap so low memory conditions will force collection of old images.

Author:
Steve Meyfroidt
See Also:
Serialized Form

Constructor Summary
PaintablePhenotype()
           
 
Method Summary
 java.lang.Object clone()
          Phenotypes must be Cloneable so that an Individual can be cloned and then mutated as an independent new Individual.
abstract  void doPaint(java.awt.Graphics2D g, int width, int height)
          Paint onto the passed Graphics2D sized to fit the passed dimensions.
abstract  float getHeightToWidth()
           
 void paint(java.awt.Graphics2D g, int width, int height, boolean highQuality)
          Use the cached Image if available, else paint it first.
 void paintNoCache(java.awt.Graphics2D g, int width, int height, boolean highQuality)
          Paint without caching the resulting image.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PaintablePhenotype

public PaintablePhenotype()
Method Detail

paintNoCache

public void paintNoCache(java.awt.Graphics2D g,
                         int width,
                         int height,
                         boolean highQuality)
Paint without caching the resulting image.

Parameters:
g - the Graphics2D to paint onto
width - of image to paint, may be 0 when phenotype will paint at its preferred width for the provided height
height - of image to paint, may be 0 when phenotype will paint at its preferred height for the provided width
highQuality - how to paint it, either fast and dirty or slow and high quality

paint

public void paint(java.awt.Graphics2D g,
                  int width,
                  int height,
                  boolean highQuality)
Use the cached Image if available, else paint it first.

Parameters:
g - the Graphics2D to paint onto
width - of image to paint, may be 0 when phenotype will paint at its preferred width for the provided height
height - of image to paint, may be 0 when phenotype will paint at its preferred height for the provided width
highQuality - how to paint it, either fast and dirty or slow and high quality
See Also:
org.artoflife.gui.paintable.view.IndividualRecord#paint(Graphics2D)

doPaint

public abstract void doPaint(java.awt.Graphics2D g,
                             int width,
                             int height)
Paint onto the passed Graphics2D sized to fit the passed dimensions.

Parameters:
g - the Graphics2D to paint onto
width - of image to paint, may be 0 when phenotype will paint at its preferred width for the provided height
height - of image to paint, may be 0 when phenotype will paint at its preferred height for the provided width

getHeightToWidth

public abstract float getHeightToWidth()
Returns:
ratio of phenotype's height to width, for example tall is 2.0f and squat is 0.5f. This allows painted images to be scaled arbitrarily.

clone

public java.lang.Object clone()
Phenotypes must be Cloneable so that an Individual can be cloned and then mutated as an independent new Individual.

Overrides:
clone in class Phenotype
Returns:
deep clone with an empty cache

artoflife pre0.1.0-dev

Copyright © 2002 the Art Of Life team. All Rights Reserved.