artoflife pre0.1.0-dev

org.artoflife.gui.population
Class VerticalFitnessPolicy

java.lang.Object
  |
  +--org.artoflife.gui.population.VerticalFitnessPolicy
All Implemented Interfaces:
RecordPositionPolicy
Direct Known Subclasses:
FreeVerticalFitnessPolicy

public class VerticalFitnessPolicy
extends java.lang.Object
implements RecordPositionPolicy

A RecordPositionPolicy that positions Individuals vertically according to their Fitness (scaled to some range) and horizontally by record index with a constant individual width to fit the population's ideal size across the entire width of the parent view. The ideal size is collected from the population when this is first associated with its PopulationView in setPopulationView(PopulationView) and when the bounds changes during updateBounds() so that transient fluctuations in population size don't immediately change all IndividualRecord positioning.

Author:
Steve Meyfroidt

Field Summary
protected  int individualWidth
          Calculated in updateBounds().
protected  int numberOfIndividuals
          Number of individuals to fit across width.
protected  int spacer
          Horizontal space between individuals.
protected  PopulationView view
          The parent PopulationView that uses this policy.
 
Constructor Summary
VerticalFitnessPolicy(float minFitness, float maxFitness)
          Create with a defined min and max fitness to define the vertical scale.
 
Method Summary
protected  float getFitnessForY(int y)
           
 float getMaxFitness()
           
 float getMinFitness()
           
 int getSpacer()
           
protected  int getX(org.artoflife.gui.population.IndividualRecord record, int index, int individualWidth)
           
protected  int getY(org.artoflife.gui.population.IndividualRecord record, int individualWidth, int height)
           
 void positionAfterChange(org.artoflife.gui.population.IndividualRecord record, int index)
          Reposition a record (at a given index within the view) whose Individual changed in some way.
 void positionNew(org.artoflife.gui.population.IndividualRecord record, int index)
          Find a position for an Individual newly added to the view at a specified index and set the IndividualRecord's state appropriately.
 void positionNewAt(org.artoflife.gui.population.IndividualRecord record, int index, java.awt.Point location)
          Position a record at a certain location (if possible), altering the Individual within the passed IndividualRecord if necessary to make it fit at that location.
 void repositionForViewBounds(org.artoflife.gui.population.IndividualRecord record, int index, int x, int y, int width, int height)
          Reposition an IndividualRecord (at a given index within the view) so it fits in the parent view's new bounds passed in as parameters.
 void setMaxFitness(float maxFitness)
           
 void setMinFitness(float minFitness)
           
 void setPopulationView(PopulationView view)
           
 void setSpacer(int spacer)
           
 void updateBounds()
          The bounds of the owning view have changed so can update cached dimensions here.
 void updatePopulation()
          Population being viewed has changed in some way so might update some cached dimensions here if the population size has changed for example.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

view

protected PopulationView view
The parent PopulationView that uses this policy.


numberOfIndividuals

protected int numberOfIndividuals
Number of individuals to fit across width. This is the ideal size of population gathered during setPopulationView(PopulationView) and updateBounds().


spacer

protected int spacer
Horizontal space between individuals. Default to 2.


individualWidth

protected int individualWidth
Calculated in updateBounds().

Constructor Detail

VerticalFitnessPolicy

public VerticalFitnessPolicy(float minFitness,
                             float maxFitness)
Create with a defined min and max fitness to define the vertical scale.

Method Detail

getMaxFitness

public float getMaxFitness()

setMaxFitness

public void setMaxFitness(float maxFitness)

getMinFitness

public float getMinFitness()

setMinFitness

public void setMinFitness(float minFitness)

getSpacer

public int getSpacer()

setSpacer

public void setSpacer(int spacer)

positionNew

public void positionNew(org.artoflife.gui.population.IndividualRecord record,
                        int index)
Description copied from interface: RecordPositionPolicy
Find a position for an Individual newly added to the view at a specified index and set the IndividualRecord's state appropriately.

Specified by:
positionNew in interface RecordPositionPolicy
See Also:
org.artoflife.gui.paintable.view.RecordPositionPolicy#positionNew(IndividualRecord, int)

positionNewAt

public void positionNewAt(org.artoflife.gui.population.IndividualRecord record,
                          int index,
                          java.awt.Point location)
Description copied from interface: RecordPositionPolicy
Position a record at a certain location (if possible), altering the Individual within the passed IndividualRecord if necessary to make it fit at that location. For example, VerticalFitnessPolicy sets the Individual's Fitness to fit the Y location but ignores the X location.

Specified by:
positionNewAt in interface RecordPositionPolicy
See Also:
RecordPositionPolicy.positionNewAt(org.artoflife.gui.population.IndividualRecord, int, java.awt.Point)

positionAfterChange

public void positionAfterChange(org.artoflife.gui.population.IndividualRecord record,
                                int index)
Description copied from interface: RecordPositionPolicy
Reposition a record (at a given index within the view) whose Individual changed in some way.

Specified by:
positionAfterChange in interface RecordPositionPolicy
See Also:
org.artoflife.gui.paintable.view.RecordPositionPolicy#positionAfterChange(IndividualRecord)

repositionForViewBounds

public void repositionForViewBounds(org.artoflife.gui.population.IndividualRecord record,
                                    int index,
                                    int x,
                                    int y,
                                    int width,
                                    int height)
Description copied from interface: RecordPositionPolicy
Reposition an IndividualRecord (at a given index within the view) so it fits in the parent view's new bounds passed in as parameters. Note that the view is still at its old size when this gets called.

Specified by:
repositionForViewBounds in interface RecordPositionPolicy
See Also:
org.artoflife.gui.paintable.view.RecordPositionPolicy#repositionToBounds(IndividualRecord, int, int, int, int)

updateBounds

public void updateBounds()
Description copied from interface: RecordPositionPolicy
The bounds of the owning view have changed so can update cached dimensions here. Don't rearrange record positions here though: do that in RecordPositionPolicy.repositionForViewBounds(org.artoflife.gui.population.IndividualRecord, int, int, int, int, int).

Specified by:
updateBounds in interface RecordPositionPolicy
See Also:
org.artoflife.gui.paintable.view.RecordPositionPolicy#setNewBounds(int, int, int, int)

setPopulationView

public void setPopulationView(PopulationView view)
Specified by:
setPopulationView in interface RecordPositionPolicy
Parameters:
view - the parent PopulationView using this policy.
See Also:
org.artoflife.gui.paintable.view.RecordPositionPolicy#setPopulationView(PopulationView)

updatePopulation

public void updatePopulation()
Description copied from interface: RecordPositionPolicy
Population being viewed has changed in some way so might update some cached dimensions here if the population size has changed for example.

Specified by:
updatePopulation in interface RecordPositionPolicy
See Also:
RecordPositionPolicy.updatePopulation()

getX

protected int getX(org.artoflife.gui.population.IndividualRecord record,
                   int index,
                   int individualWidth)

getY

protected int getY(org.artoflife.gui.population.IndividualRecord record,
                   int individualWidth,
                   int height)

getFitnessForY

protected float getFitnessForY(int y)

artoflife pre0.1.0-dev

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