Example #1
0
  private Judge getUpdatedJudge() {
    Judge newJudge = new Judge(this.nameInput.getText());

    newJudge.setRegion(this.regionInput.getText());

    if (this.isProfessional.isSelected()) {
      newJudge.setProficiency(Proficiency.PROFESSIONAL);
    } else if (this.isAmateur.isSelected()) {
      newJudge.setProficiency(Proficiency.AMATEUR);
    }

    if (this.knowsLatin.isSelected()) {
      newJudge.setSpecialtyStyle(Style.LATIN);
    }
    if (this.knowsRhythm.isSelected()) {
      newJudge.setSpecialtyStyle(Style.RHYTHM);
    }
    if (this.knowsSmooth.isSelected()) {
      newJudge.setSpecialtyStyle(Style.SMOOTH);
    }
    if (this.knowsStandard.isSelected()) {
      newJudge.setSpecialtyStyle(Style.STANDARD);
    }

    String selectedFederation = this.federationOptions.getSelectedItem().toString();
    for (Federation each : Federation.values()) {
      if (each.toString().equalsIgnoreCase(selectedFederation)) {
        newJudge.setFederation(each);
        break;
      }
    }

    return newJudge;
  }
Example #2
0
/**
 * Editor window for judge's information, including judge' proficiency, specialty, and affiliation
 *
 * @author yhou
 */
public class JudgeEditor extends JFrame {

  private static final long serialVersionUID = -3319700896266010064L;
  private static final int DEFAULT_EDIT_WIDTH = 25;

  /**
   * For testing purpose only.
   *
   * @param args
   */
  public static void main(String[] args) {
    Judge testJudge = new Judge("Test Judge");
    testJudge.setRegion("United States");
    testJudge.setProficiency(Proficiency.PROFESSIONAL);
    testJudge.setSpecialtyStyle(Style.LATIN);
    testJudge.setFederation(Federation.USADANCE);
    new JudgeEditor(testJudge);
  }

  private JPanel panel = new JPanel();

  private JLabel nameLabel = new JLabel("Name");
  private JTextField nameInput = new JTextField();

  private JLabel regionLabel = new JLabel("Region");
  private JTextField regionInput = new JTextField();

  private JRadioButton isProfessional = new JRadioButton("Professional");
  private JRadioButton isAmateur = new JRadioButton("Amateur");

  private ButtonGroup judgeProficiency = new ButtonGroup();
  private JCheckBox knowsStandard = new JCheckBox("Standard");
  private JCheckBox knowsLatin = new JCheckBox("Latin");
  private JCheckBox knowsSmooth = new JCheckBox("Smooth");
  private JCheckBox knowsRhythm = new JCheckBox("Rhythm");

  private JLabel affiliationLabel = new JLabel("Affiliation");
  private JComboBox<String> federationOptions = new JComboBox<String>(Federation.getFederations());
  private JButton confirmButton = new JButton("Confirm");

  private JButton cancelButton = new JButton("Cancel");
  private List<EditListener> editListeners = new ArrayList<EditListener>();

  private Judge target;

  public JudgeEditor(Judge judge) {
    this.target = judge;
    this.configureProficiencyButtonGroup();
    this.configureConfirmButton();
    this.configureCancelButton();
    this.assemblePanel();
    this.loadInitialInfo(judge);
    this.setTitle(SystemConstants.JUDGE_EDITOR_TITLE);
    this.setResizable(false);
    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.pack();
  }

  public void addEditListener(EditListener aListener) {
    this.editListeners.add(aListener);
  }

  private void assemblePanel() {
    MigLayout layout = new MigLayout();
    this.panel.setLayout(layout);

    this.panel.add(this.nameLabel, "cell 0 0 1 1");
    this.panel.add(this.nameInput, "cell 1 0 5 1");
    this.nameInput.setColumns(DEFAULT_EDIT_WIDTH);

    this.panel.add(this.regionLabel, "cell 0 1 1 1");
    this.panel.add(this.regionInput, "cell 1 1 5 1");
    this.regionInput.setColumns(DEFAULT_EDIT_WIDTH);

    this.panel.add(this.isProfessional, "cell 1 2 1 1");
    this.panel.add(this.isAmateur, "cell 2 2 1 1");

    this.panel.add(this.knowsStandard, "cell 0 3 1 1");
    this.panel.add(this.knowsLatin, "cell 1 3 1 1");
    this.panel.add(this.knowsSmooth, "cell 2 3 1 1");
    this.panel.add(this.knowsRhythm, "cell 3 3 1 1");

    this.panel.add(this.affiliationLabel, "cell 0 5 1 1");
    this.panel.add(this.federationOptions, "cell 1 5 4 1");

    this.panel.add(this.confirmButton, "cell 1 6 1 1");
    this.panel.add(this.cancelButton, "cell 2 6 1 1");

    this.add(this.panel);
  }

  /**
   * Configure the functionality of the cancel button, which drops all data entered in this form and
   * close out the window
   */
  private void configureCancelButton() {
    this.cancelButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });
  }

  private void configureConfirmButton() {
    this.confirmButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Database.getInstance().updateJudge(target, getUpdatedJudge());
            for (EditListener eachListener : editListeners) {
              eachListener.dataEdited();
            }
            dispose();
          }
        });
  }

  private void configureProficiencyButtonGroup() {
    this.judgeProficiency.add(this.isProfessional);
    this.judgeProficiency.add(this.isAmateur);
  }

  /**
   * Load the initial judge information into corresponding editing area/spots.
   *
   * @param judge
   */
  private void loadInitialInfo(Judge judge) {

    this.nameInput.setText(judge.getName());

    if (judge.getRegion() != null) {
      this.regionInput.setText(judge.getRegion());
    }
    // set proficiency button
    if (judge.getProficiency() == null) {
      // skip
    } else if (judge.isProfessional()) {
      this.isProfessional.setSelected(true);
    } else if (judge.isAmateur()) {
      this.isAmateur.setSelected(true);
    }

    // set specialties
    if (judge.specializedInSmooth()) {
      this.knowsSmooth.setSelected(true);
    }
    if (judge.specializedInRhythm()) {
      this.knowsRhythm.setSelected(true);
    }
    if (judge.specializedInStandard()) {
      this.knowsStandard.setSelected(true);
    }
    if (judge.specializedInLatin()) {
      this.knowsLatin.setSelected(true);
    }

    if (judge.isAffiliated()) {
      for (int i = 0; i < this.federationOptions.getItemCount(); i++) {
        if (this.federationOptions.getItemAt(i).equals(judge.getFederation().toString())) {
          this.federationOptions.setSelectedIndex(i);
          ;
          break;
        }
      }
    }
  }

  private Judge getUpdatedJudge() {
    Judge newJudge = new Judge(this.nameInput.getText());

    newJudge.setRegion(this.regionInput.getText());

    if (this.isProfessional.isSelected()) {
      newJudge.setProficiency(Proficiency.PROFESSIONAL);
    } else if (this.isAmateur.isSelected()) {
      newJudge.setProficiency(Proficiency.AMATEUR);
    }

    if (this.knowsLatin.isSelected()) {
      newJudge.setSpecialtyStyle(Style.LATIN);
    }
    if (this.knowsRhythm.isSelected()) {
      newJudge.setSpecialtyStyle(Style.RHYTHM);
    }
    if (this.knowsSmooth.isSelected()) {
      newJudge.setSpecialtyStyle(Style.SMOOTH);
    }
    if (this.knowsStandard.isSelected()) {
      newJudge.setSpecialtyStyle(Style.STANDARD);
    }

    String selectedFederation = this.federationOptions.getSelectedItem().toString();
    for (Federation each : Federation.values()) {
      if (each.toString().equalsIgnoreCase(selectedFederation)) {
        newJudge.setFederation(each);
        break;
      }
    }

    return newJudge;
  }
}