import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Properties;
import java.io.FileInputStream;

class LabFrame extends JFrame {
   public LabFrame() {
      setTitle("Blocks and Springs Laboratory");
      setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
      float RefreshTime=0;
      float DeltaTime=0;
      double timeWindowSize=0;
      
      Properties propiedades = new Properties();
      try{
      FileInputStream fichero = new FileInputStream("PhysicsLab.ini");
      propiedades.load(fichero);
      }catch(Exception e){;}
      
      String value1 = propiedades.getProperty("RefreshTime");
      String value2 = propiedades.getProperty("DeltaTime");
      String value3 = propiedades.getProperty("timeWindowSize");
      
      if(value1 != null && value2 != null){     
	      	 RefreshTime = Float.parseFloat(value1);
	     	 DeltaTime = Float.parseFloat(value2);
	  }
	  else if(value1 != null && value2 == null){
	    	 RefreshTime = Float.parseFloat(value1);
	     	 DeltaTime = 0.0001f;
	  }
	  else if(value1 == null && value2 != null){
	    	 RefreshTime = 0.08f;
	     	 DeltaTime = Float.parseFloat(value2);
	  }
	  else {
	      	 RefreshTime = 0.08f;
	     	 DeltaTime = 0.0001f;
	  }
      
      if(value3 == null){timeWindowSize = 30;}
      else{ timeWindowSize = Double.parseDouble(value3);}
      
      LabMenuBar menuBar=new LabMenuBar();
      JPanel jl2=new JPanel();
      Container contentPane = getContentPane();
      BlockSpringConfiguration bsConfig = new BlockSpringConfiguration(jl2,timeWindowSize);
      LabPanel panel = new LabPanel(bsConfig);

      bsConfig.setLabPanel(panel);   
      InsertElementListener ieListener = new InsertElementListener(bsConfig);
      
      Simulator sim = new Simulator(bsConfig,RefreshTime, DeltaTime); 
      SimulatorListener sListener = new SimulatorListener(sim);
      menuBar = new LabMenuBar(ieListener, sListener,bsConfig);
      MouseListener mListener = new MouseListener(bsConfig, panel);
      panel.addMouseMotionListener(mListener);
      panel.addMouseListener(mListener);
      
      JSplitPane panel1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
      panel1.add(panel); panel1.add(jl2);
      panel.setMinimumSize(new Dimension(700,500));
      jl2.setMinimumSize(new Dimension(300,500));
 
      contentPane.add(panel1);
      setJMenuBar(menuBar);
      
   }
   public static final int DEFAULT_WIDTH = 1200;
   public static final int DEFAULT_HEIGHT = 700;
}
  public class PhysicsLab {
   public static void main(String[] args) {
      LabFrame labFrame = new LabFrame();
      labFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
      labFrame.setVisible(true);
   } 
  }

