import java.awt.event.*;
import javax.swing.JOptionPane;
import javax.swing.JMenuItem;

public class InsertElementListener implements ActionListener {
   private BlockSpringConfiguration bsConfig;
   
   public InsertElementListener (BlockSpringConfiguration bsc){
      bsConfig = bsc;
   }
   /**
    * Nota: Se modifico el menu, por ende, se modificaron los eventos
    * relacionados con este.
    * Al seleccionar un elemento fisico se pregunta por las caracteristicas del
    * elemento para posteriormente crearlo.
    * Se agregaron los elementos fisicos String y Fixer.
    */
   public void actionPerformed(ActionEvent e) {
      JMenuItem menuItem = (JMenuItem)(e.getSource());
      String text = menuItem.getText();
      if (text.equals("Mass")) {
         String masa = JOptionPane.showInputDialog("Enter mass:");   //1f
         String width = JOptionPane.showInputDialog("Enter width:"); //40f
         String heigh = JOptionPane.showInputDialog("Enter heigh:"); //40f
         bsConfig.add(new GBlock(Float.parseFloat(masa), new Vector2D(200f,200f), new Vector2D(), Float.parseFloat(width),Float.parseFloat(heigh)));
         bsConfig.menuSelect();
      }
      if (text.equals("Spring")){
         String restLength = JOptionPane.showInputDialog("Enter restLength:");  //200
         String stiffness = JOptionPane.showInputDialog("Enter stiffness:");   //10
         bsConfig.add(new GSpring (Float.parseFloat(restLength),Float.parseFloat(stiffness)));
      }
      if(text.equals("RubberBand")){
         String restLength = JOptionPane.showInputDialog("Enter restLength:");  //200
         String stiffness = JOptionPane.showInputDialog("Enter stiffness:");  //200
         bsConfig.add(new GRubberBand (Float.parseFloat(restLength),Float.parseFloat(stiffness)));
      }
      if(text.equals("Fixer")){
         bsConfig.add(new GFixer (new Vector2D(300f,300f),30f,30f)); //Los Fixer son cuerpos estaticos no afectados por la gravedad
      }
   
   }
}

