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

public class Alumnos_transicion implements View
{
	private int origen_x, origen_y;
	private int diametro_alumnos = 80;
	private ArrayList<Ellipse2D> Alumnos_vista;
	private ArrayList<Integer> Alumnos_t;
	private JPanel panel;
	private Font my_font;
	private Timer t11, t12, t21, t22, t31, t32, t41, t42;
	private int x11, y11, x12, y12, x21, y21, x22, y22, x31, y31, x32, y32, x41, y41, x42, y42;
	private Fila f1, f2, f3, f4;
	Alumnos_transicion(int Ox, int Oy, ArrayList <Integer> a, Fila fila1, Fila fila2, Fila fila3, Fila fila4)
	{
		origen_x = Ox;
		origen_y = Oy;
		Alumnos_t = a;
		f1 = fila1; f2 = fila2; f3 = fila3; f4 = fila4;
		Alumnos_vista = new ArrayList<Ellipse2D>();
		for (int i = 0; i < 8; i++)
		{
			Alumnos_vista.add(new Ellipse2D.Double(origen_x + 9*diametro_alumnos, origen_y, diametro_alumnos, diametro_alumnos));
		}
		for (int i = 0; i < 8; i++)
		{
			Alumnos_t.add(3);
		}
		my_font = new Font ("Verdana", 1, 55);
		t11 = new Timer(25, new ActionListener(){
			public void actionPerformed (ActionEvent e){
				if (y11 != 200)
					y11 = y11 - 5;
				else if (x11 != 650)
					x11 = x11 - 5;
				else
				{
					f1.setV_fila1();
					Alumnos_t.set(0,3);
					t11.stop();
				}
				Alumnos_vista.get(0).setFrame(x11, y11, diametro_alumnos, diametro_alumnos);
				repaint();
			}
		});
		t12 = new Timer(25, new ActionListener(){
			public void actionPerformed (ActionEvent e){
				if (y12 != 200)
					y12 = y12 - 5;
				else if (x12 != 570)
					x12 = x12 - 5;
				else
				{
					f1.setV_fila2();
					Alumnos_t.set(1,3);
					t12.stop();
				}
				Alumnos_vista.get(1).setFrame(x12, y12, diametro_alumnos, diametro_alumnos);
				repaint();
			}
		});
		t21 = new Timer(25, new ActionListener(){
			public void actionPerformed (ActionEvent e){
				if (y21 != 200)
					y21 = y21 - 5;
				else if (x21 != 890)
					x21 = x21 + 5;
				else
				{
					f2.setV_fila1();
					Alumnos_t.set(2,3);
					t21.stop();
				}
				Alumnos_vista.get(2).setFrame(x21, y21, diametro_alumnos, diametro_alumnos);
				repaint();
			}
		});
		t22 = new Timer(25, new ActionListener(){
			public void actionPerformed (ActionEvent e){
				if (y22 != 200)
					y22 = y22 - 5;
				else if (x22 != 810)
					x22 = x22 + 5;
				else
				{
					f2.setV_fila2();
					Alumnos_t.set(3,3);
					t22.stop();
				}
				Alumnos_vista.get(3).setFrame(x22, y22, diametro_alumnos, diametro_alumnos);
				repaint();
			}
		});
		t31 = new Timer(25, new ActionListener(){
			public void actionPerformed (ActionEvent e){
				if (y31 != 400)
					y31 = y31 - 5;
				else if (x31 != 650)
					x31 = x31 - 5;
				else
				{
					f3.setV_fila1();
					Alumnos_t.set(4,3);
					t31.stop();
				}
				Alumnos_vista.get(4).setFrame(x31, y31, diametro_alumnos, diametro_alumnos);
				repaint();
			}
		});
		t32 = new Timer(25, new ActionListener(){
			public void actionPerformed (ActionEvent e){
				if (y32 != 400)
					y32 = y32 - 5;
				else if (x32 != 570)
					x32 = x32 - 5;
				else
				{
					f3.setV_fila2();
					Alumnos_t.set(5,3);
					t32.stop();
				}
				Alumnos_vista.get(5).setFrame(x32, y32, diametro_alumnos, diametro_alumnos);
				repaint();
			}
		});
		t41 = new Timer(25, new ActionListener(){
			public void actionPerformed (ActionEvent e){
				if (y41 != 400)
					y41 = y41 - 5;
				else if (x41 != 890)
					x41 = x41 + 5;
				else
				{
					f4.setV_fila1();
					Alumnos_t.set(6,3);
					t41.stop();
				}
				Alumnos_vista.get(6).setFrame(x41, y41, diametro_alumnos, diametro_alumnos);
				repaint();
			}
		});
		t42 = new Timer(25, new ActionListener(){
			public void actionPerformed (ActionEvent e){
				if (y42 != 400)
					y42 = y42 - 5;
				else if (x42 != 810)
					x42 = x42 + 5;
				else
				{
					f4.setV_fila2();
					Alumnos_t.set(7,3);
					t42.stop();
				}
				Alumnos_vista.get(7).setFrame(x42, y42, diametro_alumnos, diametro_alumnos);
				repaint();
			}
		});
	}
	
	
	public void paint_view (Graphics2D g2d)
	{
		//g2d.setFont(my_font);
		for (int i = 0; i < Alumnos_t.size(); i++)
		{
			if (Alumnos_t.get(i) == 0)
			{
				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_t.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_t.get(i) == 2)
			{
				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 Gotofila11(int a)
	{
		Alumnos_t.set(0,a);
		x11 = origen_x + diametro_alumnos*9;
		y11 = origen_y;
		Alumnos_vista.get(0).setFrame(x11, y11, diametro_alumnos, diametro_alumnos);
		f1.add_fila1(a);
		repaint();
		t11.start();
	}
	
	public void Gotofila12(int a)
	{
		Alumnos_t.set(1,a);
		x12 = origen_x + diametro_alumnos*9;
		y12 = origen_y;
		Alumnos_vista.get(1).setFrame(x12, y12, diametro_alumnos, diametro_alumnos);
		f1.add_fila2(a);
		repaint();
		t12.start();
	}
	
	public void Gotofila21(int a)
	{
		Alumnos_t.set(2,a);
		x21 = origen_x + diametro_alumnos*9;
		y21 = origen_y;
		Alumnos_vista.get(2).setFrame(x21, y21, diametro_alumnos, diametro_alumnos);
		f2.add_fila1(a);
		repaint();
		t21.start();
	}
	
	public void Gotofila22(int a)
	{
		Alumnos_t.set(3,a);
		x22 = origen_x + diametro_alumnos*9;
		y22 = origen_y;
		Alumnos_vista.get(3).setFrame(x22, y22, diametro_alumnos, diametro_alumnos);
		f2.add_fila2(a);
		repaint();
		t22.start();
	}
	
	public void Gotofila31(int a)
	{
		Alumnos_t.set(4,a);
		x31 = origen_x + diametro_alumnos*9;
		y31 = origen_y;
		Alumnos_vista.get(4).setFrame(x31, y31, diametro_alumnos, diametro_alumnos);
		f3.add_fila1(a);
		repaint();
		t31.start();
	}
	
	public void Gotofila32(int a)
	{
		Alumnos_t.set(5,a);
		x32 = origen_x + diametro_alumnos*9;
		y32 = origen_y;
		Alumnos_vista.get(5).setFrame(x32, y32, diametro_alumnos, diametro_alumnos);
		f3.add_fila2(a);
		repaint();
		t32.start();
	}
	
	public void Gotofila41(int a)
	{
		Alumnos_t.set(6,a);
		x41 = origen_x + diametro_alumnos*9;
		y41 = origen_y;
		Alumnos_vista.get(6).setFrame(x41, y41, diametro_alumnos, diametro_alumnos);
		f4.add_fila1(a);
		repaint();
		t41.start();
	}
	
	public void Gotofila42(int a)
	{
		Alumnos_t.set(7,a);
		x42 = origen_x + diametro_alumnos*9;
		y42 = origen_y;
		Alumnos_vista.get(7).setFrame(x42, y42, diametro_alumnos, diametro_alumnos);
		f4.add_fila2(a);
		repaint();
		t42.start();
	}
	public void setPanel(JPanel p)
	{
		panel=p;
	}
	
	public void repaint() 
	{
		panel.repaint();
	}
}