Beispiel #1
0
  /**
   * Used when an existing appointment is opened for editing... Need to init the fields in the
   * dialog box
   *
   * @param parent the owner frame that invokes the dialog box
   * @param title the title of the dialog box
   * @param model whether the box is modal or not
   * @param a used to hold the info of the appointment being edited
   */
  public ApptDialog(MyCalendar parent, String title, String uid1, boolean modal, Appt a) {

    super(parent, "Appointment for " + title, modal);
    initComponents();
    date = title;
    uid = uid1;

    jTextFieldName.setText(a.getName());
    jTextFieldPhone.setText(a.getNumber());

    jComboBoxStartMinutes.setSelectedIndex(a.getStartMinute());
    jComboBoxStartHours.setSelectedIndex(a.getStartHour());
    if (a.isStartPM()) {
      jRadioButtonAM.setSelected(false);
      jRadioButtonPM.setSelected(true);
    } else {
      jRadioButtonAM.setSelected(true);
      jRadioButtonPM.setSelected(false);
    }

    jTextFieldNotes.setText(a.getNotes());
    owner = parent;
    appointment = a;

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    // setVisible(true);
  }
Beispiel #2
0
  /**
   * Private method used when the "Add button is clicked on the dialog box. Either adds the
   * appointment or spawns an error message if invalid info entered
   */
  private void jButtonAddMouseClicked(java.awt.event.MouseEvent evt) {

    int startHours = Integer.parseInt((String) jComboBoxStartHours.getSelectedItem());
    int startMinutes = Integer.parseInt((String) jComboBoxStartMinutes.getSelectedItem());
    int endHours = startHours == 12 ? 1 : startHours + 1;
    int endMinutes = 0;
    boolean startPM = false, endPM = false;

    if (jRadioButtonPM.isSelected()) startPM = true;

    if (startHours == 11) endPM = true;
    else endPM = startPM;

    String startTime =
        startHours + ":" + String.format("%02d", startMinutes) + " " + (startPM ? "PM" : "AM");
    String endTime =
        endHours + ":" + String.format("%02d", endMinutes) + " " + (endPM ? "PM" : "AM");
    int x = startHours + (startPM ? 12 : 0);
    int start = Integer.parseInt(x + "" + String.format("%02d", startMinutes));
    x = endHours + (endPM ? 12 : 0);
    int end = Integer.parseInt(x + "" + String.format("%02d", endMinutes));

    // hours = 9-5
    boolean outHours =
        (startPM && startHours > MyCalendar.endLimit - 1)
            || (!startPM && startHours < MyCalendar.startLimit);

    if (outHours
        || end <= start
        || !isValidInput(jTextFieldName.getText())
        || !isValidInput(jTextFieldPhone.getText())) {
      // invalid input throw popup
      EntryErrorDialog error = new EntryErrorDialog(owner, true);
      error.setVisible(true);

    } else {
      Appt newAppt =
          new Appt(
              date,
              jTextFieldName.getText(),
              jTextFieldPhone.getText(),
              startTime,
              endTime,
              jTextFieldNotes.getText(),
              uid);
      if (appointment != null) {
        if (!newAppt.equals(appointment)) {
          // delete and create new if edited version is not the same
          owner.deleteAppt(appointment);
          if (owner.addAppt(newAppt)) {
            setVisible(false);
          } else {
            ApptFullErrorDialog error = new ApptFullErrorDialog(owner, true);
            error.setVisible(true);
            owner.addAppt(appointment);
          }
        }
      } else {
        if (owner.addAppt(newAppt)) {
          setVisible(false);
        } else {
          ApptFullErrorDialog error = new ApptFullErrorDialog(owner, true);
          error.setVisible(true);
        }
      }
    }
  }