/****************************************************
* draw.java
*
* Draws all the points measured by the robot.
* This code would have to be completely rewritten
* if data filtering was completed and is just here
* for testing and presentation.
*
* Chris Miller
* godal83@gmail.com
*
*
******************************************************/

import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.lang.*;


public class drawPanel extends JPanel
{
	final int MAX_X = 100;
	final int MIN_X = -100;
	final int MAX_Y = 100;
	final int MIN_Y = -100;

	ArrayList<Position> positions;

	public drawPanel(ArrayList<Position> inList)
	{
		positions = inList;
	}

	protected void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D)g;

		int screenWidth = getWidth();
		int screenHeight = getHeight();

		float spotSize = 5;

		float spotX = 0;
		float spotY = 0;
		float plotX = 0;
		float plotY = 0;

		int angle = 0;
		float distance = 0;

		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);


		g2.draw(new Line2D.Double(((double)screenWidth)/2,0,((double)screenWidth)/2,screenHeight));
		g2.draw(new Line2D.Double(0,((double)screenHeight)/2,screenWidth,((double)screenHeight)/2));
		for(int i = 0;i < positions.size();i++)
		{
			g2.setPaint(Color.red);
			spotX = positions.get(i).getX();
			spotY = positions.get(i).getY();
			plotX = ((screenWidth/2) + (((float)screenWidth)/((float)(MAX_X - MIN_X)))*spotX)-(spotSize/2);
			plotY = ((screenHeight/2) - (((float)screenHeight)/((float)(MAX_Y - MIN_Y)))*spotY)-(spotSize/2);
			g2.fill(new Ellipse2D.Float(plotX,plotY,spotSize,spotSize));

			g2.setPaint(Color.green);
			for(int j = 0;j < positions.get(i).size();j++)
			{
				angle = positions.get(i).getAngle(j);
				distance = positions.get(i).getDistance(j);
				spotX = positions.get(i).getX() + ((float)(Math.cos(((((float)angle)/360)*(2*Math.PI)))*distance));
				spotY = positions.get(i).getY() + ((float)(Math.sin(((((float)angle)/360)*(2*Math.PI)))*distance));
				plotX = ((screenWidth/2) + (((float)screenWidth)/((float)(MAX_X - MIN_X)))*spotX)-(spotSize/2);
				plotY = ((screenHeight/2) - (((float)screenHeight)/((float)(MAX_Y - MIN_Y)))*spotY)-(spotSize/2);
				g2.fill(new Ellipse2D.Float(plotX,plotY,spotSize,spotSize));
				g2.drawString(Integer.toString(i),plotX,plotY);
			}
		}
	}

}