//Fila.java
import java.awt.*;
import java.awt.geom.*;
import java.util.ArrayList;
import java.awt.event.*;
import javax.swing.*;

public class Fila implements View
{
	private int origen_x, origen_y, diametro_alumnos;
	private ArrayList<Ellipse2D> Alumnos_vista;
	private ArrayList<Integer> Alumnos_fila;
	private ArrayList<Integer> Alumnos_visibles;
	private JPanel panel;
	private Rectangle2D fila;
	private Timer t1;
	private Timer t2;
	private Font my_font;
	Fila(int Ox, int Oy, int diametro, ArrayList <Integer> a)
	{
		origen_x = Ox;
		origen_y = Oy;
		diametro_alumnos = diametro;
		Alumnos_fila = a;
		Alumnos_visibles = new ArrayList<Integer>();
		Alumnos_visibles.add(0);
		Alumnos_visibles.add(0);
		fila = new Rectangle2D.Double(origen_x, origen_y, 2*diametro, diametro);
		Alumnos_vista = new ArrayList<Ellipse2D>();
		for (int i = 0; i < 2; i++)
		{
			Alumnos_vista.add(new Ellipse2D.Double(Ox + (diametro_alumnos) - (diametro_alumnos*i), Oy, diametro_alumnos, diametro_alumnos));
		}
		my_font = new Font ("Verdana", 1, 55);
		t1 = new Timer(5000, new ActionListener (){ 
			public void actionPerformed(ActionEvent event) {
				Alumnos_fila.set(0,3);
				Alumnos_visibles.set(0,0);
				t1.stop();
			}
		});
		t2 = new Timer(5000, new ActionListener (){ 
			public void actionPerformed(ActionEvent event) {
				Alumnos_fila.set(1,3);
				Alumnos_visibles.set(1,0);
				t2.stop();
			}
		});
	}
	
	
	public void paint_view (Graphics2D g2d)
	{
		g2d.setColor(Color.BLUE);
		g2d.fill(fila);
		g2d.setFont(my_font);
		for (int i = 0; i < Alumnos_fila.size(); i++)
		{
			if ((Alumnos_fila.get(i) == 0) && (Alumnos_visibles.get(i) == 1))
			{
				g2d.setColor(Color.GRAY);
				g2d.fill(Alumnos_vista.get(i));
				g2d.setColor(Color.WHITE);
				g2d.drawString("N", origen_x + (diametro_alumnos) - (diametro_alumnos*i) + (diametro_alumnos/4) - 2, origen_y + diametro_alumnos*3/4);	
			}
			else if ((Alumnos_fila.get(i) == 1) && (Alumnos_visibles.get(i) == 1))
			{
				g2d.setColor(Color.GREEN);
				g2d.fill(Alumnos_vista.get(i));
				g2d.setColor(Color.WHITE);
				g2d.drawString("V", origen_x + (diametro_alumnos) - (diametro_alumnos*i) + diametro_alumnos/4, origen_y + diametro_alumnos*3/4);	
			}
			else if ((Alumnos_fila.get(i) == 2) && (Alumnos_visibles.get(i) == 1))
			{
				g2d.setColor(Color.YELLOW);
				g2d.fill(Alumnos_vista.get(i));
				g2d.setColor(Color.WHITE);
				g2d.drawString("D", origen_x + (diametro_alumnos) - (diametro_alumnos*i) + diametro_alumnos/4, origen_y + diametro_alumnos*3/4);	
			}
		}
	}
	
	public void setPanel(JPanel p)
	{
		panel=p;
	}
	
	public void repaint() 
	{
		panel.repaint();
	}
	
	public void add_fila1(int a)
	{
		Alumnos_fila.set(0,a);
	}
	public void add_fila2(int a)
	{
		Alumnos_fila.set(1,a);
	}
	
	public void setV_fila1()
	{
		Alumnos_visibles.set(0,1);
		t1.start();
	}
	public void setV_fila2()
	{
		Alumnos_visibles.set(1,1);
		t2.start();
	}
	
	public boolean isfree1() {
		if (Alumnos_fila.get(0)==3) {return true;}
		else {return false;}
	}
	public boolean isfree2() {
		if (Alumnos_fila.get(1)==3) {return true;}
		else {return false;}
	}
}