/** @author Sabuj Das | [email protected] */
public class NewGameDialog extends javax.swing.JDialog {

  /** Generated serialVersionUID */
  private static final long serialVersionUID = -780567772392235659L;

  private static final GameEngine gameEngine = GameEngine.getEngine();

  private WindowOptions selectedOption = WindowOptions.CANCEL;

  /** Creates new form NewGameDialog */
  public NewGameDialog(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    firstPlayerNameTextField.setText(gameEngine.getFirstPlayer().getName());
    secPlayerTextField.setText(gameEngine.getSecondPlayer().getName());
  }

  public WindowOptions showDialog() {
    setVisible(true);
    return selectedOption;
  }

  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT
   * modify this code. The content of this method is always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    firstPlayerAnimalsButtonGroup = new javax.swing.ButtonGroup();
    secPlayerAnimalsButtonGroup = new javax.swing.ButtonGroup();
    startByButtonGroup = new javax.swing.ButtonGroup();
    boardSizeButtonGroup = new javax.swing.ButtonGroup();
    jPanel4 = new javax.swing.JPanel();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    firstPlayerNameTextField = new javax.swing.JTextField();
    jLabel9 = new javax.swing.JLabel();
    firstTigerRadioButton = new javax.swing.JRadioButton();
    firstGoatRadioButton = new javax.swing.JRadioButton();
    jLabel10 = new javax.swing.JLabel();
    jLabel11 = new javax.swing.JLabel();
    secPlayerTextField = new javax.swing.JTextField();
    jLabel12 = new javax.swing.JLabel();
    secTigerRadioButton = new javax.swing.JRadioButton();
    secGoatRadioButton = new javax.swing.JRadioButton();
    jSeparator1 = new javax.swing.JSeparator();
    jLabel13 = new javax.swing.JLabel();
    startTigerRadioButton = new javax.swing.JRadioButton();
    startGoatRadioButton = new javax.swing.JRadioButton();
    jLabel14 = new javax.swing.JLabel();
    cancelButton = new javax.swing.JButton();
    startButton = new javax.swing.JButton();
    jLabel1 = new javax.swing.JLabel();
    normalBoardSizeRadioButton = new javax.swing.JRadioButton();
    bigBoardSizeRadioButton = new javax.swing.JRadioButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
    setTitle("New Game");
    addWindowListener(
        new java.awt.event.WindowAdapter() {
          public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
          }
        });

    jPanel4.setLayout(new java.awt.GridBagLayout());

    jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
    jLabel7.setText("First Player");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(13, 4, 2, 4);
    jPanel4.add(jLabel7, gridBagConstraints);

    jLabel8.setText("Name");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(13, 2, 2, 2);
    jPanel4.add(jLabel8, gridBagConstraints);

    firstPlayerNameTextField.setText("A");
    firstPlayerNameTextField.setMinimumSize(new java.awt.Dimension(160, 20));
    firstPlayerNameTextField.setPreferredSize(new java.awt.Dimension(160, 20));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(13, 2, 2, 2);
    jPanel4.add(firstPlayerNameTextField, gridBagConstraints);

    jLabel9.setText("Animal Type");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
    jPanel4.add(jLabel9, gridBagConstraints);

    firstPlayerAnimalsButtonGroup.add(firstTigerRadioButton);
    firstTigerRadioButton.setSelected(true);
    firstTigerRadioButton.setText("Tiger");
    firstTigerRadioButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            firstTigerRadioButtonActionPerformed(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
    jPanel4.add(firstTigerRadioButton, gridBagConstraints);

    firstPlayerAnimalsButtonGroup.add(firstGoatRadioButton);
    firstGoatRadioButton.setText("Goat");
    firstGoatRadioButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            firstGoatRadioButtonActionPerformed(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
    jPanel4.add(firstGoatRadioButton, gridBagConstraints);

    jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
    jLabel10.setText("Second Player");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(2, 4, 2, 4);
    jPanel4.add(jLabel10, gridBagConstraints);

    jLabel11.setText("Name");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
    jPanel4.add(jLabel11, gridBagConstraints);

    secPlayerTextField.setText("B");
    secPlayerTextField.setMinimumSize(new java.awt.Dimension(160, 20));
    secPlayerTextField.setPreferredSize(new java.awt.Dimension(160, 20));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
    jPanel4.add(secPlayerTextField, gridBagConstraints);

    jLabel12.setText("Animal Type");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
    jPanel4.add(jLabel12, gridBagConstraints);

    secPlayerAnimalsButtonGroup.add(secTigerRadioButton);
    secTigerRadioButton.setText("Tiger");
    secTigerRadioButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            secTigerRadioButtonActionPerformed(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
    jPanel4.add(secTigerRadioButton, gridBagConstraints);

    secPlayerAnimalsButtonGroup.add(secGoatRadioButton);
    secGoatRadioButton.setSelected(true);
    secGoatRadioButton.setText("Goat");
    secGoatRadioButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            secGoatRadioButtonActionPerformed(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
    jPanel4.add(secGoatRadioButton, gridBagConstraints);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.gridwidth = 3;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    jPanel4.add(jSeparator1, gridBagConstraints);

    jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
    jLabel13.setText("Starting Animal");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 7;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(2, 4, 2, 4);
    jPanel4.add(jLabel13, gridBagConstraints);

    startByButtonGroup.add(startTigerRadioButton);
    startTigerRadioButton.setSelected(true);
    startTigerRadioButton.setText("Tiger");
    startTigerRadioButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            startTigerRadioButtonActionPerformed(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 7;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
    jPanel4.add(startTigerRadioButton, gridBagConstraints);

    startByButtonGroup.add(startGoatRadioButton);
    startGoatRadioButton.setText("Goat");
    startGoatRadioButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            startGoatRadioButtonActionPerformed(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 7;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
    jPanel4.add(startGoatRadioButton, gridBagConstraints);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 9;
    gridBagConstraints.gridwidth = 3;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    jPanel4.add(jLabel14, gridBagConstraints);

    cancelButton.setText("Cancel");
    cancelButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            cancelButtonActionPerformed(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 10;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
    jPanel4.add(cancelButton, gridBagConstraints);

    startButton.setText("Start Game");
    startButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            startButtonActionPerformed(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 10;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    jPanel4.add(startButton, gridBagConstraints);

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
    jLabel1.setText("Board Size");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 8;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(2, 4, 2, 4);
    jPanel4.add(jLabel1, gridBagConstraints);

    boardSizeButtonGroup.add(normalBoardSizeRadioButton);
    normalBoardSizeRadioButton.setSelected(true);
    normalBoardSizeRadioButton.setText("Normal");
    normalBoardSizeRadioButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            normalBoardSizeRadioButtonActionPerformed(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 8;
    jPanel4.add(normalBoardSizeRadioButton, gridBagConstraints);

    boardSizeButtonGroup.add(bigBoardSizeRadioButton);
    bigBoardSizeRadioButton.setText("Big");
    bigBoardSizeRadioButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            bigBoardSizeRadioButtonActionPerformed(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 8;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    jPanel4.add(bigBoardSizeRadioButton, gridBagConstraints);

    getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);

    pack();
  } // </editor-fold>//GEN-END:initComponents

  private void firstTigerRadioButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_firstTigerRadioButtonActionPerformed
    // TODO add your handling code here:
  } // GEN-LAST:event_firstTigerRadioButtonActionPerformed

  private void firstGoatRadioButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_firstGoatRadioButtonActionPerformed
    // TODO add your handling code here:
  } // GEN-LAST:event_firstGoatRadioButtonActionPerformed

  private void secTigerRadioButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_secTigerRadioButtonActionPerformed
    // TODO add your handling code here:
  } // GEN-LAST:event_secTigerRadioButtonActionPerformed

  private void secGoatRadioButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_secGoatRadioButtonActionPerformed
    // TODO add your handling code here:
  } // GEN-LAST:event_secGoatRadioButtonActionPerformed

  private void startTigerRadioButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_startTigerRadioButtonActionPerformed
    // TODO add your handling code here:
  } // GEN-LAST:event_startTigerRadioButtonActionPerformed

  private void startGoatRadioButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_startGoatRadioButtonActionPerformed
    // TODO add your handling code here:
  } // GEN-LAST:event_startGoatRadioButtonActionPerformed

  private void normalBoardSizeRadioButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_normalBoardSizeRadioButtonActionPerformed
    // TODO add your handling code here:
  } // GEN-LAST:event_normalBoardSizeRadioButtonActionPerformed

  private void bigBoardSizeRadioButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_bigBoardSizeRadioButtonActionPerformed
    // TODO add your handling code here:
  } // GEN-LAST:event_bigBoardSizeRadioButtonActionPerformed

  private void cancelButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_cancelButtonActionPerformed
    selectedOption = WindowOptions.CANCEL;
    dispose();
  } // GEN-LAST:event_cancelButtonActionPerformed

  private void startButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_startButtonActionPerformed
    selectedOption = WindowOptions.OK;
    dispose();
  } // GEN-LAST:event_startButtonActionPerformed

  private void formWindowClosing(
      java.awt.event.WindowEvent evt) { // GEN-FIRST:event_formWindowClosing
    selectedOption = WindowOptions.CANCEL;
  } // GEN-LAST:event_formWindowClosing

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JRadioButton bigBoardSizeRadioButton;
  private javax.swing.ButtonGroup boardSizeButtonGroup;
  private javax.swing.JButton cancelButton;
  private javax.swing.JRadioButton firstGoatRadioButton;
  private javax.swing.ButtonGroup firstPlayerAnimalsButtonGroup;
  private javax.swing.JTextField firstPlayerNameTextField;
  private javax.swing.JRadioButton firstTigerRadioButton;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel10;
  private javax.swing.JLabel jLabel11;
  private javax.swing.JLabel jLabel12;
  private javax.swing.JLabel jLabel13;
  private javax.swing.JLabel jLabel14;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JLabel jLabel8;
  private javax.swing.JLabel jLabel9;
  private javax.swing.JPanel jPanel4;
  private javax.swing.JSeparator jSeparator1;
  private javax.swing.JRadioButton normalBoardSizeRadioButton;
  private javax.swing.JRadioButton secGoatRadioButton;
  private javax.swing.ButtonGroup secPlayerAnimalsButtonGroup;
  private javax.swing.JTextField secPlayerTextField;
  private javax.swing.JRadioButton secTigerRadioButton;
  private javax.swing.JButton startButton;
  private javax.swing.ButtonGroup startByButtonGroup;
  private javax.swing.JRadioButton startGoatRadioButton;
  private javax.swing.JRadioButton startTigerRadioButton;
  // End of variables declaration//GEN-END:variables
}
 /** Creates new form NewGameDialog */
 public NewGameDialog(java.awt.Frame parent, boolean modal) {
   super(parent, modal);
   initComponents();
   firstPlayerNameTextField.setText(gameEngine.getFirstPlayer().getName());
   secPlayerTextField.setText(gameEngine.getSecondPlayer().getName());
 }