/* GpGraph.java * J Scott Cameron * * This class is a Swing component which can be dropped * into any swing frame or panel to graph the performance * of a Genetic Program */ import javax.swing.*; import java.awt.*; import java.awt.geom.*; import java.awt.font.*; import java.applet.*; import GPNodeContainer; import GPPopulation.*; import java.util.*; import java.awt.event.*; import java.io.*; public class GpGraph extends JPanel { /* vector of best GP's */ Vector data; int w, h; /* width/height */ /* parameterized constructor */ public GpGraph(Vector v) { data = v; } /* updates graph */ public void updateGraph(Vector v) { data = v; repaint(); } /* paints the graph */ public void paintComponent(Graphics g) { super.paintComponent(g); setBackground(Color.white); w = getSize().width; h = getSize().height; /* give the graph a margin of 20 pixels */ int graphBottom = h-20; int graphRight = w-20; Graphics2D g2; g2 = (Graphics2D) g; /* set rendering quality to high and turn anti-aliasing on */ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); /* find the best and worst score to set the range */ double bestScore = ((GPNodeContainer)data.get( data.size()-1)).getRating(); if (bestScore < 0) bestScore =0; int worstScore = 0; for(int i =0 ;i