コード例 #1
0
  public TimeComboBoxEditor(boolean timeVisible) {
    showEditorBtn = new JButton();
    showEditorBtn.addActionListener(new ShowCalendarAction());
    calenderComponent = new JCalendar(new Date(), Locale.getDefault(), true, true, timeVisible);
    calenderComponent.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(final MouseEvent e) {
            calendarPopupMenu.setVisible(false);
          }
        });
    calendarPopupMenu = calenderComponent.createPopupMenu();
    calendarPopupMenu.addPopupMenuListener(
        new PopupMenuListener() {
          public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            calenderComponent.setDate(date);
          }

          public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            updateDate();
          }

          public void popupMenuCanceled(PopupMenuEvent e) {}
        });
    actionListeners = new LinkedList<ActionListener>();
  }
コード例 #2
0
  private void updateDate() {
    final FormattedDate newDate =
        new FormattedDate(
            calenderComponent.getDate(),
            calenderComponent.isTimeVisible() ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd");
    final String type =
        newDate.containsTime() ? IFormattedObject.TYPE_DATETIME : IFormattedObject.TYPE_DATE;
    date = FormattedDate.createDefaultFormattedDate(newDate.getTime(), type);

    if (actionListeners.size() == 0) {
      return;
    }
    final ActionEvent actionEvent = new ActionEvent(this, 0, null);
    for (final ActionListener l : actionListeners) {
      l.actionPerformed(actionEvent);
    }
  }