/***************************************************
* wall.java
*
* Read data from text file that was copied from the
* RoboJDE console lines.
* Was going to be where I implemented the filter as
* well.
*
* Chris Miller
* godal83@gmail.com
*
*
****************************************************/

import java.io.*;
import java.util.*;
import javax.swing.*;


public class wall
{
	public static void main(String[] args)
	{
		//number of measurements per position
		final int MEASUREMENTS = 8;

		int i = 0, angle = 0;
		float distance = 0,x = 0, y = 0;

		Position toAdd = new Position(x,y,MEASUREMENTS); //never used but required to avoid errors

		//ArrayList to read data into and pass to drawPanel
 		ArrayList<Position> positions = new ArrayList<Position>();
		try
		{
			//didn't bother making this changeable during run since I didn't get this far in project
			File input = new File(".//test.txt");

			//create reader for the file
 			BufferedReader br = new BufferedReader(new FileReader(input));
 			String line = br.readLine();

			/*******************************************************************
			* Go through file reading each line and recreating the positions.
			* Only uses X,Y beginning of each new spot since its spinning in
			* a circle for measurements.
			*******************************************************************/
 			while(line != null)
 			{
 				StringTokenizer st = new StringTokenizer(line);
 				if((i%MEASUREMENTS) == 0)
 				{
					x = Float.valueOf(st.nextToken());
					y = Float.valueOf(st.nextToken());
					toAdd = new Position(x,y,MEASUREMENTS);

					angle = Integer.valueOf(st.nextToken());
					distance = Float.valueOf(st.nextToken());
					toAdd.setDistAndAngle(distance,angle,i%MEASUREMENTS);
				}
				else
				{
					st.nextToken(); //ignore x
					st.nextToken(); //ignore y
					angle = Integer.valueOf(st.nextToken());
					distance = Float.valueOf(st.nextToken());
					toAdd.setDistAndAngle(distance,angle,i%MEASUREMENTS);
				}

				if((i%MEASUREMENTS) == MEASUREMENTS-1)
				{
					positions.add(toAdd);
				}
				i++;
				line = br.readLine();
			}
		}
		catch(Exception e)
		{
			System.out.println(e);
			System.exit(0);
		}

		//Output the data into a window. Used for testing and showing issues in presentation
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.add(new drawPanel(positions));
		frame.setSize(800,800);
		frame.setLocation(50,50);
		frame.setVisible(true);
	}
}