/**
   * The action that happens when the Add Button is pressed. We save all the values and create a new
   * object, giving it those values. The object is then passed to NetLogo for displaying.
   *
   * @param evt
   */
  private void addButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_addButtonActionPerformed
    // "preprocessor"
    int MY_OFFSET = 5;
    int BUS_STREET_CONTACT = -33;
    int BUS_LENGTH = 286;
    int BOX_OFFSET = 10;
    int TOP_OF_BUS = 50;

    System.out.println("add object");
    double weight = weightValue.getValue();
    double radius = radiusValue.getValue();
    double width = widthValue.getValue();
    int x = 0, y = 0;

    // get the bus object for the x, y coordinates
    PhysicsObject bus = ObjectManager.getInstance().getObject("bus");
    double busX = bus.getXCoord();
    double busY = bus.getYCoord();
    System.out.println("busX = " + busX + "\tbusY = " + busY);

    // If we are creating a box...
    if (boxButton.isSelected()) {
      System.out.println("making box");
      if (topButton.isSelected()) {
        x = (int) busX;
        y = (int) (busY + width + TOP_OF_BUS);
        RelationshipManager.getInstance()
            .setRelationship("object", "bus", RelationshipTypes.ABOVE_UNRESTRAINED);
        if (RelationshipManager.getInstance().getRelationship("object", "bus")
            == RelationshipTypes.ABOVE_UNRESTRAINED) System.out.println("On top works");
      } else if (insideRButton.isSelected()) {
        x = (int) busX;
        y = (int) (width * (double) MY_OFFSET);
        RelationshipManager.getInstance()
            .setRelationship("object", "bus", RelationshipTypes.INSIDE_RESTRAINED);
      } else if (insideUButton.isSelected()) {
        x = (int) busX;
        y = (int) (width * (double) MY_OFFSET);
        RelationshipManager.getInstance()
            .setRelationship("object", "bus", RelationshipTypes.INSIDE_UNRESTRAINED);
      } else if (behindButton.isSelected()) {
        x = (int) (-0.5 * (double) BUS_LENGTH);
        y = BUS_STREET_CONTACT;
        RelationshipManager.getInstance()
            .setRelationship("object", "bus", RelationshipTypes.BEHIND_ATTACHED);
      } else if (inFrontButton.isSelected()) {
        x = (int) (0.5 * (double) BUS_LENGTH);
        y = BUS_STREET_CONTACT;
        RelationshipManager.getInstance().setRelationship("object", "bus", RelationshipTypes.FRONT);
      }

      PhysicsObject boxOb =
          ObjectManager.getInstance().createSquare(x, y, (width * BOX_OFFSET), weight);
      ObjectManager.getInstance().addObject("object", boxOb);
      ObjectManager.getInstance().getObject("object").setAcceleration(0);
      ObjectManager.getInstance().getObject("object").setDecleration(0);
      System.out.println("width = " + ((SquareObject) boxOb).getWidth());
      System.out.println("weight = " + boxOb.getMass());
      System.out.println("x = " + x);
      System.out.println("y = " + y);
    }
    // else if we are creating a ball...
    else if (ballButton.isSelected()) {
      System.out.println("making ball");
      if (topButton.isSelected()) {
        x = (int) busX;
        y = (int) (busY + radius + TOP_OF_BUS);
        RelationshipManager.getInstance()
            .setRelationship("object", "bus", RelationshipTypes.ABOVE_UNRESTRAINED);
      } else if (insideRButton.isSelected()) {
        x = (int) busX;
        y = (int) (radius * (double) MY_OFFSET);
        RelationshipManager.getInstance()
            .setRelationship("object", "bus", RelationshipTypes.INSIDE_RESTRAINED);
      } else if (insideUButton.isSelected()) {
        x = (int) busX;
        y = (int) (radius * (double) MY_OFFSET);
        RelationshipManager.getInstance()
            .setRelationship("object", "bus", RelationshipTypes.INSIDE_UNRESTRAINED);
      } else if (behindButton.isSelected()) {
        x = (int) (-0.5 * BUS_LENGTH);
        y = (int) (BUS_STREET_CONTACT);
        RelationshipManager.getInstance()
            .setRelationship("object", "bus", RelationshipTypes.BEHIND_ATTACHED);
      } else if (inFrontButton.isSelected()) {
        x = (int) (0.5 * BUS_LENGTH);
        y = (int) (BUS_STREET_CONTACT);
        RelationshipManager.getInstance().setRelationship("object", "bus", RelationshipTypes.FRONT);
      }
      PhysicsObject ballOb =
          ObjectManager.getInstance().createCircle(x, y, (radius * MY_OFFSET), weight);
      ObjectManager.getInstance().addObject("object", ballOb);
      ObjectManager.getInstance().getObject("object").setAcceleration(0);
      ObjectManager.getInstance().getObject("object").setDecleration(0);
      System.out.println("weight = " + ballOb.getMass());
      System.out.println("radius = " + ((RoundObject) ballOb).getRadius());
      System.out.println("x = " + x);
      System.out.println("y = " + y);
    }
    // if the world crashed and died...
    else {
      System.out.println("failboat");
    }

    this.dispose();
  } // GEN-LAST:event_addButtonActionPerformed