// Class   : marathonGraphDemo
// Author  : Russ Ethington
// Version : 1/28/96 for Java 1.0
// Notice  : Copyright (C) 1995, 1996 Russ Ethington

import java.io.*;   
import java.awt.*;
import java.lang.*;
import java.util.*;
import java.applet.*;

public class MarathonGraphDemo extends Applet
{
   private MarathonGraph marathonGraph;
   private Panel       buttonPanel;
   private Vector      theNames;
   private Vector      theDates;
   private Vector      theValues;

   public static void main(String args[]) 
   {
      Frame frame = new Frame("marathonGraphDemo");
      MarathonGraphDemo marathonGraphDemo = new MarathonGraphDemo();
      marathonGraphDemo.init();
      marathonGraphDemo.start();

      frame.add("Center", marathonGraphDemo);
      frame.resize(300, 200);
      frame.show();
   }

   public void init() 
   {
      debugLog("marathonGraphDemo:init");

      setLayout(new BorderLayout());
      
      marathonGraph = new MarathonGraph();
      theNames = new Vector();
      theDates = new Vector();
      theValues = new Vector();
      
      buttonPanel = new Panel();
      buttonPanel.setLayout(new GridLayout(1, 3));
      buttonPanel.add(new Button("Humidity"));
      buttonPanel.add(new Button("Temperature"));
      buttonPanel.add(new Button("Pressure"));

      add("Center", marathonGraph);
      add("South", buttonPanel);

      setData(20, 100);
      marathonGraph.setTitle("Daily Relative Humidity");
      marathonGraph.updateView(theNames, theDates, theValues);
   }

   public void setData(int low, int high)
   {
      debugLog("marathonGraphDemo:setData");

      int totalSets =   2;
      int totalValues = 28;

      theNames.removeAllElements();
      theDates.removeAllElements();
      theValues.removeAllElements();

      for (int i = 0; i < totalSets; i++)
      {
         theNames.addElement("Data Set " + Integer.toString(i));

         Vector newDates = new Vector();
         Vector newValues = new Vector();

         theDates.addElement(newDates);
         theValues.addElement(newValues);

         for (int j = 0; j < totalValues; j++)
         {
            String fakeDate = Integer.toString(i + 1) + "/" + Integer.toString(j) + "/95";           
            newDates.addElement(new String(fakeDate));
            double value = Math.random() * (high - low) + low;
            String fakeData = String.valueOf(value);            
            newValues.addElement(new String(fakeData));
         }
      }
   }

   public boolean action(Event event, Object object) 
   {
      debugLog("marathonGraphDemo:action");
      
      if (event.target instanceof Button) 
      {
         if (((String) object).equals("Humidity"))
         {
            setData(20, 100);
            marathonGraph.setTitle("Daily Relative Humidity");
         }
         else
         if (((String) object).equals("Temperature"))
         {
            setData(0,  30);
            marathonGraph.setTitle("Daily Temperature (C)");
         }
         else
         if (((String) object).equals("Pressure"))
         {
            setData(800, 1500);
            marathonGraph.setTitle("Daily Barometric Pressure (mb)");
         }
         marathonGraph.updateView(theNames, theDates, theValues);
         marathonGraph.repaint();
         return true;
      }
      return false;
   }

   public void start()
   {
      debugLog("marathonGraphDemo:start");
   }

   public void stop()
   {
      debugLog("marathonGraphDemo:stop");
   }

   public void debugLog(String message)
   {
//    System.out.println(message);
   }
}
