/**
   @version 1.0 06-05-2008
   @author Agustin J. Gonzalez
*/

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

/**
   A panel with two tanks and a control system. A simulation to practice 
   with applets.
*/
public class PlantPanel extends JPanel
{  
   public PlantPanel()
   {  
      setLayout(new BorderLayout());
		//Se cambia el eje X por el eje Y, para que se vea vertical
		menuPanel= new Box(BoxLayout.Y_AXIS); 
		menuPanel.setBorder(new EmptyBorder(5,3,40,1));
		view= new PlantView();
		view.setPreferredSize(new Dimension(750,500));

		dt=0.05F; // 50 ms is the delta t of the simulation. 
		TimePace timer = new TimePace(this);
		menuPanel.add(timer.getGUI());
		menuPanel.add(Box.createRigidArea(new Dimension(10,30)));

		Tank tank1= new Tank(new Point(450,160), view, 1);
		menuPanel.add(tank1.getGUI());
		menuPanel.add(Box.createRigidArea(new Dimension(10,30)));
		view.addEquipment(tank1);
      
		Tank tank2= new Tank(new Point(510,265), view, 2);
		menuPanel.add(tank2.getGUI());
		menuPanel.add(Box.createRigidArea(new Dimension(10,50)));
		view.addEquipment(tank2);

		tank1.setReceiver(tank2);

		Controller control = new Controller(new Point(390,330), tank2);
		view.addEquipment(control);
		menuPanel.add(Box.createRigidArea(new Dimension(10,0)));
		menuPanel.add(control.getGUI());

		//Se insertan los graficos 
		grafics grafico1 = new grafics(new Point(50,200),view,1,tank1,control);
		menuPanel.add(grafico1.getGUI());
		menuPanel.add(Box.createRigidArea(new Dimension(10,0)));
		view.addEquipment(grafico1);

		grafics grafico2 = new grafics(new Point(50,400),view,2,tank2,control);
		menuPanel.add(grafico2.getGUI());
		menuPanel.add(Box.createRigidArea(new Dimension(10,0)));
		view.addEquipment(grafico2);
		//Se modifico el BorderLayout para que se viera a la derecha
		add(menuPanel, BorderLayout.EAST); 
		add(view, BorderLayout.CENTER);

		timer.start();
   }
   public void simulationTick(){
	   view.timeTick(dt);
	   view.repaint();
   }
   private JComponent menuPanel;
   private PlantView view;
   private float dt;  
}
