Example #1
0
  /**
   * applies the changes of the user edit, and disposes the form, returning control back to the
   * parent form.
   */
  private void returnSuccessful() {
    try {

      // construct the days selected booleans
      boolean[] b = new boolean[7];
      for (int i = 0; i < 7; i++) b[i] = days[i].isSelected();

      // construct the new pattern
      pattern = new DayOfWeekPattern(new DateRange(startDate.getDate(), endDate.getDate()), b);

      // dispose of this form
      dispose();

      // if we catch any errors, alert the user and don't dispose the form
    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, e.getMessage(), "", JOptionPane.ERROR_MESSAGE);
    }
  }
 private void refresh() {
   header.updateDate();
   date.updateDate();
   SwingUtilities.updateComponentTreeUI(this);
 }
Example #3
0
  /**
   * Initializes this DayOfWeekDialog object, acts as a common constructor / initializer for the
   * actual constructors that would otherwise perform redundant code
   *
   * @param base the RecurrencePattern that will be used to initialize the fields
   */
  private void init(RecurrencePattern base) {
    // because base could be any type of pattern, we need
    // to somehow convert it to a DayOfWeekPattern so we
    // can use it for the defaults.  if it's null, make
    // our own default, if it's already a DayOfWeekPattern,
    // then cast it, otherwise, use it for its dateRange
    DayOfWeekPattern pattern;
    if (base == null) pattern = new DayOfWeekPattern(new DateRange(null, null), new boolean[7]);
    else if (base instanceof DayOfWeekPattern) pattern = (DayOfWeekPattern) base;
    else pattern = new DayOfWeekPattern(base.getRange(), new boolean[7]);

    setLayout(new BorderLayout());

    // dateRange fields
    startDate = new DatePanel(pattern.getRange().getStartDate(), true);
    endDate = new DatePanel(pattern.getRange().getEndDate(), true);
    JLabel duration = new JLabel();

    // dateRange listeners
    startDate.addActionListener(new DurationUpdateListener(duration, startDate, endDate));
    endDate.addActionListener(new DurationUpdateListener(duration, startDate, endDate));
    DurationUpdateListener.updateDuration(duration, startDate, endDate);

    // panel that holds the day options
    JPanel daysPanel = new JPanel();
    daysPanel.setLayout(new GridLayout(0, 1));
    daysPanel.setBorder(
        new TitledBorder(new EmptyBorder(new Insets(6, 6, 6, 6)), "select the days to recur on"));
    Calendar cal = Calendar.getInstance();
    cal.setTime(new WeekRange(null).getStartDate());
    days = new JToggleButton[7];
    boolean[] curDays = pattern.getDays();
    for (int i = 0; i < 7; i++) {
      days[i] =
          new JToggleButton(
              cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()));
      days[i].setSelected(curDays[i]);
      daysPanel.add(days[i]);
      cal.add(Calendar.DATE, 1);
    }

    // OK button
    JButton okButton = new JButton("OK");
    okButton.addActionListener(new OKActionListener());

    // panel that holds the dateRange data
    JPanel north = new JPanel();
    GroupLayout northLayout = new GroupLayout(north);
    northLayout.setAutoCreateContainerGaps(true);
    northLayout.setAutoCreateGaps(true);
    north.setLayout(northLayout);
    GroupLayoutUtility.addToGroups(
        northLayout,
        new Component[][] {
          {new JLabel("start date"), startDate},
          {new JLabel("end date"), endDate},
          {new JLabel("duration"), duration}
        });

    // add the panels
    add(north, BorderLayout.NORTH);
    add(daysPanel, BorderLayout.CENTER);
    add(okButton, BorderLayout.SOUTH);

    // set the title
    setTitle("Add / Edit Recurrence Pattern");

    pack();
    setMinimumSize(getSize());

    setLocationRelativeTo(null);
  }