Class GraphView

java.lang.Object
  extended by GraphView
All Implemented Interfaces:
SimulatorView

public class GraphView
extends Object
implements SimulatorView

The GraphView provides a view of two populations of actors in the field as a line graph over time. In its current version, it can only plot exactly two different classes of animals. If further animals are introduced, they will not currently be displayed.

Version:
2011.07.31
Author:
Michael Kölling and David J. Barnes

Nested Class Summary
(package private)  class GraphView.GraphPanel
          Nested class: a component to display the graph.
 
Constructor Summary
GraphView(int width, int height, int startMax)
          Constructor.
 
Method Summary
 boolean isViable(Field field)
          Determine whether the simulation should continue to run.
 void reset()
          Prepare for a new run.
 void setColor(Class animalClass, Color color)
          Define a color to be used for a given class of animal.
 void showStatus(int step, Field field)
          Show the current status of the field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphView

public GraphView(int width,
                 int height,
                 int startMax)
Constructor.

Parameters:
width - The width of the plotter window (in pixles).
height - The height of the plotter window (in pixles).
startMax - The initial maximum value for the y axis.
world - The world object.
class1 - The first class to be plotted.
width - The second class to be plotted.
Method Detail

isViable

public boolean isViable(Field field)
Determine whether the simulation should continue to run.

Specified by:
isViable in interface SimulatorView
Returns:
true If there is more than one species alive.

reset

public void reset()
Prepare for a new run.

Specified by:
reset in interface SimulatorView

setColor

public void setColor(Class animalClass,
                     Color color)
Define a color to be used for a given class of animal.

Specified by:
setColor in interface SimulatorView
Parameters:
animalClass - The animal's Class object.
color - The color to be used for the given class.

showStatus

public void showStatus(int step,
                       Field field)
Show the current status of the field. The status is shown by displaying a line graph for two classes in the field. This view currently does not work for more (or fewer) than exactly two classes. If the field contains more than two different types of animal, only two of the classes will be plotted.

Specified by:
showStatus in interface SimulatorView
Parameters:
step - Which iteration step it is.
field - The field whose status is to be displayed.