/**
  * Sets the pattern of the appointment, validates the input, and marks the Observable as changed
  * if a change has taken place.
  *
  * @param pattern the new pattern for the appointment
  */
 private void internalSetPattern(RecurrencePattern pattern) {
   if (pattern == null ? this.recPattern != null : !pattern.equals(this.recPattern))
     this.setChanged();
   this.recPattern = pattern;
 }
Exemplo n.º 2
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);
  }