import mkgray.gui.*;
import java.awt.*;
import java.io.*;
import java.util.*;

public class ShoeGraphs implements Runnable {
  Frame f;
  boolean initialized;
  SimpleGraph graphs[] = new SimpleGraph[15];

  public static void main(String s[]){
    new ShoeGraphs();
  }

  ShoeGraphs() {
    Thread runthis = new Thread(this);
    runthis.start();
    while(true){
    if(initialized){
	f.repaint();
	for(int i=0;i<15;i++){
	  graphs[i].repaint();
	}
     }
	try { Thread.sleep(200); } catch (Exception e) { }
   }
  }

  public void run() {
    int value;
    long lastt=0;
    long startt, endt;
    f = new Frame();
    f.setLayout(new GridLayout(5,3));
    for(int i=0;i<15;i++){
      f.add(graphs[i] = new SimpleGraph());
      graphs[i].addPoint(0,0);
      graphs[i].range(0,255);
      graphs[i].sliding(true);
      graphs[i].windowWidth(15.0);
      graphs[i].tickSeperation(3.0);
      graphs[i].tickless(true);
      graphs[i].debug(false);
    }
    initialized = true;
    f.setBounds(0,0,300,300);
    f.pack();
    f.doLayout();
    f.show();
    int ct = 0;
    int n = 0;
    int graphnum = 0;
    double np, pp;
    Random rand = new Random();
    InputStreamReader isr;
    StreamTokenizer st = new StreamTokenizer(isr=new InputStreamReader(System.in));
    st.parseNumbers();
    st.eolIsSignificant(true);
    value = 0;
    System.out.println("Initialized");
    while(true) {
      System.out.print(".");
      try {
	int it = 0;
	while(!isr.ready()){
	  graphs[it].repaint();
	  Thread.sleep(100);
	  it++;
	  if(it == 15)
	    it = 0;
	}
	st.nextToken();
      } catch (Exception e) { }
      if(st.ttype == StreamTokenizer.TT_NUMBER) {
	graphs[graphnum].addPoint(ct, st.nval);
	graphs[graphnum].repaint();
	graphnum++;
      }
      else if(st.ttype == StreamTokenizer.TT_EOF)
	return;
      else if(st.ttype == StreamTokenizer.TT_EOL) {
	ct++;
	System.out.println("Line time: "+(System.currentTimeMillis()-lastt));
	lastt = System.currentTimeMillis();
	graphnum = 0;
      }
      if(graphnum == 0){
	if(ct%10 == 0)
	  Runtime.getRuntime().gc();
	try { Thread.sleep(50); } catch (Exception e) { }
      }
    }
  }
}










