Esempio n. 1
0
  private void createYears(Body b) {
    VPanel bodyPanel = bodyPanels[bodyPanels.length - 1];

    yearPanel = new VPanel(bodyPanel, SWT.NONE);
    yearPanel.setData(CDT.PickerPart, PickerPart.DayOfWeekPanel);
    yearPanel.setPainter(cdt.getPainter());
    cdt.getPainter().update(yearPanel);
    VGridLayout layout = new VGridLayout(3, true);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = b.spacing;
    layout.verticalSpacing = b.spacing;
    yearPanel.setLayout(layout);

    bodyPanel.getLayout(VStackLayout.class).setDefault(yearPanel, false);

    yearButtons = new VButton[15];
    for (int year = 0; year < yearButtons.length; year++) {
      yearButtons[year] =
          new VButton(yearPanel, (cdt.field.length > 1) ? (SWT.PUSH | SWT.NO_FOCUS) : SWT.TOGGLE);
      yearButtons[year].setSquare(true);
      yearButtons[year].setData(CDT.PickerPart, PickerPart.DayOfWeekLabel);
      yearButtons[year].setData(CDT.Key.Index, year);
      yearButtons[year].setPainter(cdt.getPainter());
      cdt.getPainter().update(yearButtons[year]);
      yearButtons[year].setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
      yearButtons[year].addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event event) {
              if (event.widget == null) {
                VButton button = (VButton) event.data;
                if (button.hasStyle(SWT.TOGGLE)) {
                  for (VButton b : yearButtons) {
                    if (b != button) {
                      b.setSelection(false);
                    }
                  }
                }

                Calendar tmpcal = cdt.getCalendarInstance();
                tmpcal.set(Calendar.YEAR, Integer.parseInt(button.getText()));
                cdt.setSelection(tmpcal.getTime());

                if (cdt.field.length == 1 && cdt.getCalendarField(cdt.field[0]) == Calendar.YEAR) {
                  cdt.fireSelectionChanged(true);
                } else {
                  handleHeaderSelection(null);
                }
              }
            }
          });
    }

    if (yearButton != null) {
      yearButton.setData(Key.Panel, yearPanel);
    }
  }
Esempio n. 2
0
  private void addBodyPanel() {
    if (bodyPanels == null) {
      bodyPanels = new VPanel[1];
    } else {
      VPanel[] pa = new VPanel[bodyPanels.length + 1];
      System.arraycopy(bodyPanels, 0, pa, 0, bodyPanels.length);
      bodyPanels = pa;
      body.getLayout(VGridLayout.class).numColumns++;
    }

    VPanel picker = new VPanel(body, SWT.NONE);
    picker.setData(CDT.PickerPart, PickerPart.BodyPanel);
    picker.setPainter(cdt.getPainter());
    cdt.getPainter().update(picker);
    picker.setLayout(new VStackLayout());
    picker.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    bodyPanels[bodyPanels.length - 1] = picker;
  }
Esempio n. 3
0
  /** create the Calendar's body, which contains the dayLabels and dayButtons */
  private void createBody() {
    body = new VPanel(this, SWT.NONE);
    body.setData(CDT.PickerPart, PickerPart.BodyPanel);
    body.setPainter(cdt.getPainter());
    cdt.getPainter().update(body);
    VGridLayout layout = new VGridLayout(1, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.horizontalSpacing = 0;
    body.setLayout(layout);
    body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    addBodyPanel();

    for (Iterator<Body> iter = cdt.builder.getBodies().iterator(); iter.hasNext(); ) {
      Body b = iter.next();
      if (b.newColumn) {
        VLabel sep = new VLabel(body, SWT.SEPARATOR | SWT.VERTICAL);
        sep.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
        body.getLayout(VGridLayout.class).numColumns++;
        addBodyPanel();
      }
      switch (b.type) {
        case Body.DAYS:
          createDays(b);
          break;
        case Body.MONTHS:
          createMonths(b);
          break;
        case Body.TIME:
          createTime(b);
          break;
        case Body.YEARS:
          createYears(b);
          break;
      }
    }

    for (VPanel bodyPanel : bodyPanels) {
      bodyPanel.getLayout(VStackLayout.class).setTopControl(null);
    }
  }
Esempio n. 4
0
  /**
   * create the footer (footerButton) for the Calendar part of this CDateTime<br>
   * there is currently no footer for the Clock part - should there be? or should this footer span
   * both parts?
   */
  private void createFooter() {
    footer = new VPanel(this, SWT.NONE);
    footer.setData(CDT.PickerPart, PickerPart.FooterPanel);
    footer.setPainter(cdt.getPainter());
    cdt.getPainter().update(footer);
    VGridLayout layout = new VGridLayout();
    layout.makeColumnsEqualWidth = cdt.builder.getFooterEqualColumns();
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 1;
    layout.marginWidth = 1;
    footer.setLayout(layout);
    footer.setLayoutData(new GridData(cdt.builder.getFooterAlignment(), SWT.FILL, true, false));

    for (Iterator<Footer> iter = cdt.builder.getFooters().iterator(); iter.hasNext(); ) {
      ((VGridLayout) footer.getLayout()).numColumns++;
      Footer f = iter.next();
      switch (f.type) {
        case Footer.CLEAR:
          clear = new VButton(footer, SWT.PUSH | SWT.NO_FOCUS);
          clear.setData(CDT.PickerPart, PickerPart.ClearButton);
          clear.setPainter(cdt.getPainter());
          cdt.getPainter().update(clear);
          clear.setLayoutData(new GridData(f.alignment, SWT.FILL, f.grab, false));
          clear.addListener(
              SWT.Selection,
              new Listener() {
                public void handleEvent(Event event) {
                  cdt.setSelection(null);
                  if (event.widget == null) {
                    cdt.fireSelectionChanged();
                  }
                }
              });
          break;
        case Footer.TODAY:
        case Footer.VERBOSE_TODAY:
          today = new VButton(footer, SWT.PUSH | SWT.NO_FOCUS);
          today.setData(CDT.PickerPart, PickerPart.TodayButton);
          today.setPainter(cdt.getPainter());
          cdt.getPainter().update(today);
          today.setLayoutData(new GridData(f.alignment, SWT.FILL, f.grab, false));
          today.addListener(
              SWT.Selection,
              new Listener() {
                public void handleEvent(Event event) {
                  cdt.setSelection(new Date());
                  if (event.widget == null) {
                    cdt.fireSelectionChanged();
                  }
                }
              });
          break;
      }
    }
  }
Esempio n. 5
0
  private void createMonths(Body b) {
    VPanel bodyPanel = bodyPanels[bodyPanels.length - 1];

    monthPanel = new VPanel(bodyPanel, SWT.NONE);
    monthPanel.setData(CDT.PickerPart, PickerPart.DayOfWeekPanel);
    monthPanel.setPainter(cdt.getPainter());
    cdt.getPainter().update(monthPanel);
    VGridLayout layout = new VGridLayout(3, true);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = b.spacing;
    layout.verticalSpacing = b.spacing;
    monthPanel.setLayout(layout);

    bodyPanel.getLayout(VStackLayout.class).setDefault(monthPanel, false);

    monthButtons = new VButton[12];
    for (int month = 0; month < monthButtons.length; month++) {
      monthButtons[month] =
          new VButton(monthPanel, (cdt.field.length > 1) ? (SWT.PUSH | SWT.NO_FOCUS) : SWT.TOGGLE);
      monthButtons[month].setSquare(true);
      monthButtons[month].setData("month", month); // $NON-NLS-1$
      monthButtons[month].setData(CDT.PickerPart, PickerPart.DayOfWeekLabel);
      monthButtons[month].setData(CDT.Key.Index, month);
      monthButtons[month].setPainter(cdt.getPainter());
      cdt.getPainter().update(monthButtons[month]);
      monthButtons[month].setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
      monthButtons[month].addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event event) {
              if (event.widget == null) {
                VButton button = (VButton) event.data;
                if (button.hasStyle(SWT.TOGGLE)) {
                  for (VButton b : monthButtons) {
                    if (b != button) {
                      b.setSelection(false);
                    }
                  }
                }

                Calendar tmpcal = cdt.getCalendarInstance();
                tmpcal.set(Calendar.MONTH, (Integer) button.getData("Month")); // $NON-NLS-1$
                cdt.setSelection(tmpcal.getTime());

                if (cdt.field.length == 1 && cdt.getCalendarField(cdt.field[0]) == Calendar.MONTH) {
                  cdt.fireSelectionChanged(true);
                } else {
                  handleHeaderSelection(null);
                }
              }
            }
          });
    }

    updateMonths();

    if (monthButton != null) {
      monthButton.setData(Key.Panel, monthPanel);
    }
  }
Esempio n. 6
0
  /**
   * create the header for the Calendar part of this CDateTime<br>
   * there is no equivalent for the Clock part
   */
  private void createHeader() {
    header = new VPanel(this, SWT.NONE);
    header.setData(CDT.PickerPart, PickerPart.HeaderPanel);
    header.setPainter(cdt.getPainter());
    cdt.getPainter().update(header);
    VGridLayout layout = new VGridLayout();
    layout.makeColumnsEqualWidth = cdt.builder.getHeaderEqualColumns();
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 2;
    layout.marginWidth = 2;
    header.setLayout(layout);
    header.setLayoutData(new GridData(cdt.builder.getHeaderAlignment(), SWT.FILL, true, false));

    GridData data;

    for (Iterator<Header> iter = cdt.builder.getHeaders().iterator(); iter.hasNext(); ) {
      ((VGridLayout) header.getLayout()).numColumns++;
      Header h = iter.next();
      data = new GridData(h.alignment, SWT.FILL, h.grab, false);
      switch (h.type) {
        case Header.DATE_NOW:
          dateNow = new VButton(header, SWT.PUSH | SWT.NO_FOCUS);
          dateNow.setData(CDT.PickerPart, PickerPart.DateNow);
          dateNow.setPainter(cdt.getPainter());
          cdt.getPainter().update(dateNow);
          dateNow.setMargins(4, 0);
          dateNow.setPolygon(new int[] {7, 7});
          dateNow.setLayoutData(data);
          dateNow.addListener(
              SWT.Selection,
              new Listener() {
                public void handleEvent(Event event) {
                  cdt.setSelection(new Date());
                  if (event.widget == null) {
                    cdt.fireSelectionChanged();
                  }
                }
              });
          break;
        case Header.MONTH:
          monthButton = new VButton(header, SWT.TOGGLE | SWT.NO_FOCUS);
          monthButton.setData(CDT.PickerPart, PickerPart.MonthLabel);
          monthButton.setPainter(cdt.getPainter());
          cdt.getPainter().update(monthButton);
          monthButton.setAlignment(h.textAlignment, SWT.CENTER);
          monthButton.setLayoutData(data);
          if (h.readOnly) {
            monthButton.setPaintNative(false);
          } else {
            if (CDT.gtk) {
              monthButton.addListener(
                  SWT.MouseWheel,
                  new Listener() {
                    public void handleEvent(Event event) {
                      if (SWT.MouseWheel == event.type) {
                        Calendar tmpcal = cdt.getCalendarInstance();
                        tmpcal.add(Calendar.MONTH, (event.count > 0) ? 1 : -1);
                        cdt.setSelection(tmpcal.getTime());
                      }
                    }
                  });
            }
            monthButton.addListener(
                SWT.Selection,
                new Listener() {
                  public void handleEvent(Event event) {
                    handleHeaderSelection((VButton) event.data);
                  }
                });

            Menu monthMenu = monthButton.createMenu();
            monthItems = new MenuItem[12];
            for (int i = 0; i < 12; i++) {
              Calendar tmpcal = cdt.getCalendarInstance();
              tmpcal.set(Calendar.MONTH, i);
              monthItems[i] = new MenuItem(monthMenu, SWT.NONE);
              monthItems[i].setData(
                  "Month", new Integer(tmpcal.get(Calendar.MONTH))); // $NON-NLS-1$
              monthItems[i].addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent e) {
                      MenuItem item = (MenuItem) e.widget;
                      Calendar tmpcal = cdt.getCalendarInstance();
                      tmpcal.set(
                          Calendar.MONTH,
                          ((Integer) item.getData("Month")).intValue()); // $NON-NLS-1$
                      cdt.setSelection(tmpcal.getTime());
                    }
                  });
            }
          }
          break;
        case Header.MONTH_NEXT:
          monthNext = new VButton(header, SWT.ARROW | SWT.RIGHT | SWT.NO_FOCUS);
          monthNext.setData(CDT.PickerPart, PickerPart.MonthNext);
          monthNext.setPainter(cdt.getPainter());
          cdt.getPainter().update(monthNext);
          monthNext.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
          monthNext.addListener(
              SWT.Selection,
              new Listener() {
                public void handleEvent(Event event) {
                  Calendar tmpcal = cdt.getCalendarInstance();
                  if (yearNext == null && yearButton != null && yearButton.getSelection()) {
                    tmpcal.add(Calendar.YEAR, 10);
                  } else {
                    tmpcal.add(Calendar.MONTH, 1);
                  }
                  cdt.setSelection(tmpcal.getTime());
                }
              });
          break;
        case Header.MONTH_PREV:
          monthPrev = new VButton(header, SWT.ARROW | SWT.LEFT | SWT.NO_FOCUS);
          monthPrev.setData(CDT.PickerPart, PickerPart.MonthPrev);
          monthPrev.setPainter(cdt.getPainter());
          cdt.getPainter().update(monthPrev);
          monthPrev.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
          monthPrev.addListener(
              SWT.Selection,
              new Listener() {
                public void handleEvent(Event event) {
                  Calendar tmpcal = cdt.getCalendarInstance();
                  if (yearPrev == null && yearButton != null && yearButton.getSelection()) {
                    tmpcal.add(Calendar.YEAR, -10);
                  } else {
                    tmpcal.add(Calendar.MONTH, -1);
                  }
                  cdt.setSelection(tmpcal.getTime());
                }
              });
          break;
        case Header.TIME:
          timeButton = new VButton(header, SWT.TOGGLE | SWT.NO_FOCUS);
          timeButton.setMargins(3, 5);
          timeButton.setImage(Resources.getIconClock());
          timeButton.setData(CDT.PickerPart, PickerPart.MonthPrev);
          timeButton.setPainter(cdt.getPainter());
          cdt.getPainter().update(timeButton);
          timeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
          timeButton.addListener(
              SWT.Selection,
              new Listener() {
                public void handleEvent(Event event) {
                  handleHeaderSelection((VButton) event.data);
                }
              });
          break;
        case Header.YEAR:
          yearButton = new VButton(header, SWT.TOGGLE | SWT.NO_FOCUS);
          yearButton.setData(CDT.PickerPart, PickerPart.YearLabel);
          yearButton.setPainter(cdt.getPainter());
          cdt.getPainter().update(yearButton);
          yearButton.setAlignment(h.textAlignment, SWT.CENTER);
          yearButton.setLayoutData(data);
          if (h.readOnly) {
            yearButton.setPaintNative(false);
          } else {
            if (CDT.gtk) {
              yearButton.addListener(
                  SWT.MouseWheel,
                  new Listener() {
                    public void handleEvent(Event event) {
                      if (SWT.MouseWheel == event.type) {
                        Calendar tmpcal = cdt.getCalendarInstance();
                        tmpcal.add(Calendar.YEAR, (event.count > 0) ? 1 : -1);
                        cdt.setSelection(tmpcal.getTime());
                      }
                    }
                  });
            }
            yearButton.addListener(
                SWT.Selection,
                new Listener() {
                  public void handleEvent(Event event) {
                    handleHeaderSelection((VButton) event.data);
                  }
                });

            Menu yearMenu = yearButton.createMenu();
            yearItems = new MenuItem[11];
            for (int i = 0; i < 11; i++) {
              yearItems[i] = new MenuItem(yearMenu, SWT.NONE);
              yearItems[i].setData("Year", new Integer(i)); // $NON-NLS-1$
              yearItems[i].addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent e) {
                      MenuItem item = (MenuItem) e.widget;
                      Calendar tmpcal = cdt.getCalendarInstance();
                      tmpcal.add(
                          Calendar.YEAR,
                          ((Integer) item.getData("Year")).intValue() - 5); // $NON-NLS-1$
                      cdt.setSelection(tmpcal.getTime());
                    }
                  });
            }
          }
          break;
        case Header.YEAR_NEXT:
          yearNext = new VButton(header, SWT.ARROW | SWT.RIGHT | SWT.NO_FOCUS);
          yearNext.setData(CDT.PickerPart, PickerPart.YearNext);
          yearNext.setPainter(cdt.getPainter());
          cdt.getPainter().update(yearNext);
          yearNext.setLayoutData(data);
          yearNext.addListener(
              SWT.Selection,
              new Listener() {
                public void handleEvent(Event event) {
                  Calendar tmpcal = cdt.getCalendarInstance();
                  if (yearButton != null && yearButton.getSelection()) {
                    tmpcal.add(Calendar.YEAR, 10);
                  } else if (cdt.field.length == 1
                      && cdt.getCalendarField(cdt.field[0]) == Calendar.YEAR) {
                    tmpcal.add(Calendar.YEAR, 10);
                  } else {
                    tmpcal.add(Calendar.YEAR, 1);
                  }
                  cdt.setSelection(tmpcal.getTime());
                }
              });
          break;
        case Header.YEAR_PREV:
          yearPrev = new VButton(header, SWT.ARROW | SWT.LEFT | SWT.NO_FOCUS);
          yearPrev.setData(CDT.PickerPart, PickerPart.YearPrev);
          yearPrev.setPainter(cdt.getPainter());
          cdt.getPainter().update(yearPrev);
          yearPrev.setLayoutData(data);
          yearPrev.addListener(
              SWT.Selection,
              new Listener() {
                public void handleEvent(Event event) {
                  Calendar tmpcal = cdt.getCalendarInstance();
                  if (yearButton != null && yearButton.getSelection()) {
                    tmpcal.add(Calendar.YEAR, -10);
                  } else if (cdt.field.length == 1
                      && cdt.getCalendarField(cdt.field[0]) == Calendar.YEAR) {
                    tmpcal.add(Calendar.YEAR, -10);
                  } else {
                    tmpcal.add(Calendar.YEAR, -1);
                  }
                  cdt.setSelection(tmpcal.getTime());
                }
              });
          break;
      }
    }
  }
Esempio n. 7
0
  private void createDays(Body b) {
    VPanel bodyPanel = bodyPanels[bodyPanels.length - 1];

    dayPanel = new VPanel(bodyPanel, SWT.NO_FOCUS);
    dayPanel.setData(CDT.PickerPart, PickerPart.DayPanel);
    dayPanel.setPainter(cdt.getPainter());
    cdt.getPainter().update(dayPanel);
    VGridLayout layout = new VGridLayout(7, true);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = b.spacing;
    layout.verticalSpacing = b.spacing;
    dayPanel.setLayout(layout);

    bodyPanel.getLayout(VStackLayout.class).setDefault(dayPanel, false);

    addListener(
        SWT.MouseWheel,
        new Listener() {
          public void handleEvent(Event event) {
            scrollCalendar((event.count > 0) ? SWT.ARROW_UP : SWT.ARROW_DOWN);
          }
        });

    Menu bodyMenu = dayPanel.createMenu();

    todayMenuItem = new MenuItem(bodyMenu, SWT.NONE);
    todayMenuItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            cdt.setSelection(new Date());
          }
        });

    showSelMenuItem = new MenuItem(bodyMenu, SWT.NONE);
    showSelMenuItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            cdt.showSelection();
          }
        });

    dayListener =
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.KeyDown:
                if (event.stateMask == 0) {
                  if (event.keyCode == SWT.KEYPAD_CR
                      || event.character == SWT.CR
                      || event.character == ' ') {
                    setSelectionFromFocusButton(event);
                  } else if (event.keyCode == SWT.HOME
                      || event.keyCode == SWT.END
                      || event.keyCode == SWT.PAGE_DOWN
                      || event.keyCode == SWT.PAGE_UP) {
                    scrollCalendar(event.keyCode);
                    setSelectionFromFocusButton(event);
                  }
                }
                break;
              case SWT.MouseDown:
                if (event.button == 3) {
                  dayPanel.getMenu().setVisible(true);
                }
                break;
              case SWT.MouseWheel:
                scrollCalendar((event.count > 0) ? SWT.ARROW_UP : SWT.ARROW_DOWN);
                break;
              case SWT.Selection:
                if (event.widget == null) {
                  VButton button = (VButton) event.data;
                  int stateMask = event.stateMask;
                  setSelectionFromButton(button, stateMask);
                  if (cdt.field.length == 1
                      && cdt.getCalendarField(cdt.field[0]) == Calendar.DATE) {
                    cdt.fireSelectionChanged(true);
                  } else {
                    cdt.fireSelectionChanged();
                  }
                }
                break;
              case SWT.Traverse:
                if (event.detail == SWT.TRAVERSE_RETURN) {
                  setSelectionFromFocusButton(event);
                } else {
                  traverseSelection(event.keyCode);
                  setSelectionFromFocusButton(event);
                }
                break;
            }
          }
        };

    dayLabels = new VLabel[DAYS_IN_WEEK];
    for (int day = 0; day < dayLabels.length; day++) {
      dayLabels[day] = new VLabel(dayPanel, SWT.CENTER);
      dayLabels[day].setData(CDT.PickerPart, PickerPart.DayOfWeekLabel);
      dayLabels[day].setData(CDT.Key.Compact, b.compact);
      dayLabels[day].setData(CDT.Key.Index, day);
      dayLabels[day].setPainter(cdt.getPainter());
      cdt.getPainter().update(dayLabels[day]);
      dayLabels[day].setMargins(1, 1);
      dayLabels[day].setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    }

    VLabel sep = new VLabel(dayPanel, SWT.HORIZONTAL | SWT.SEPARATOR);
    sep.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 7, 1));

    dayButtons = new VButton[DAYS_IN_WEEK * NUM_ROWS];
    for (int day = 0; day < dayButtons.length; day++) {
      dayButtons[day] = new VButton(dayPanel, SWT.TOGGLE);
      dayButtons[day].setData(CDT.PickerPart, PickerPart.DayButton);
      dayButtons[day].setData(CDT.Key.Index, day);
      dayButtons[day].setPainter(cdt.getPainter());
      cdt.getPainter().update(dayButtons[day]);
      dayButtons[day].setSquare(true);
      dayButtons[day].setMargins(4, 4);
      dayButtons[day].setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
      dayButtons[day].addListener(SWT.KeyDown, dayListener);
      dayButtons[day].addListener(SWT.MouseDown, dayListener);
      dayButtons[day].addListener(SWT.MouseWheel, dayListener);
      dayButtons[day].addListener(SWT.Selection, dayListener);
      dayButtons[day].addListener(SWT.Traverse, dayListener);
    }
  }
Esempio n. 8
0
  /** set / update the text and font color of the <code>dayButton</code>s. */
  private void updateDays() {
    if (dayPanel != null) {
      Calendar date = cdt.getCalendarInstance();
      Calendar active = cdt.getCalendarInstance();
      Calendar today = cdt.getCalendarInstance(System.currentTimeMillis());
      for (int day = 0; day < dayButtons.length; day++) {
        if ((dayButtons[day] != null)) {
          date.setTime((Date) dayButtons[day].getData(CDT.Key.Date));

          boolean isToday =
              (date.get(Calendar.YEAR) == today.get(Calendar.YEAR))
                  && (date.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR));
          boolean isActive =
              (date.get(Calendar.YEAR) == active.get(Calendar.YEAR))
                  && (date.get(Calendar.MONTH) == active.get(Calendar.MONTH));

          dayButtons[day].setText(getFormattedDate("d", date.getTime())); // $NON-NLS-1$
          dayButtons[day].setData(CDT.Key.Today, isToday);
          dayButtons[day].setData(CDT.Key.Active, isActive);

          cdt.getPainter().update(dayButtons[day]);
        }
      }

      int focusButton = -1;

      for (int i = 0; i < dayButtons.length; i++) {
        dayButtons[i].setSelection(false);
      }

      if (cdt.hasSelection()) {
        Calendar first = cdt.getCalendarInstance((Date) dayButtons[0].getData(CDT.Key.Date));
        first.set(Calendar.MILLISECOND, 0);
        first.set(Calendar.SECOND, 0);
        first.set(Calendar.MINUTE, 0);
        first.set(Calendar.HOUR_OF_DAY, 0);

        Calendar last =
            cdt.getCalendarInstance((Date) dayButtons[dayButtons.length - 1].getData(CDT.Key.Date));
        last.set(Calendar.MILLISECOND, 0);
        last.set(Calendar.SECOND, 0);
        last.set(Calendar.MINUTE, 0);
        last.set(Calendar.HOUR_OF_DAY, 0);
        last.add(Calendar.DATE, 1);
        last.add(Calendar.MILLISECOND, -1);

        Date selection = cdt.getSelection();
        Calendar scal = cdt.getCalendarInstance(selection);
        for (int j = 0; j < dayButtons.length; j++) {
          Calendar tmpcal = cdt.getCalendarInstance((Date) dayButtons[j].getData(CDT.Key.Date));
          if ((scal.get(Calendar.DATE) == tmpcal.get(Calendar.DATE))
              && (scal.get(Calendar.MONTH) == tmpcal.get(Calendar.MONTH))
              && (scal.get(Calendar.YEAR) == tmpcal.get(Calendar.YEAR))) {
            dayButtons[j].setSelection(true);
            focusButton = j;
            break;
          }
        }
        if (focusButton >= 0) {
          dayButtons[focusButton].setFocus();
        }
      }

      dayPanel.redraw();
    }
  }