Пример #1
0
  @Override
  public Date getEntryDate() {

    // return DateUtils.removeTimeFromDate((Date) entryDateSpinnerModel
    // 		.getValue());

    String entryDateText = entryDateSpinnerEditor.getTextField().getText();
    if (entryDateText == null) {
      return null;
    }
    try {
      return DateUtils.parseDate(entryDateText);
    } catch (ParseException e) {
      return null;
    }
  }
Пример #2
0
  @Override
  protected void createComponents() {
    super.createComponents();

    Date initDate = DateUtils.currentDate();
    Date latestDate = initDate;
    Date earliestDate = DateUtils.earliestDate();

    entryDateLabel = new JLabel("Entry Date:");

    entryDateSpinnerModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);
    entryDateSpinner = new JSpinner(entryDateSpinnerModel);
    entryDateSpinnerEditor = new JSpinner.DateEditor(entryDateSpinner, DateUtils.DATE_FORMAT);
    entryDateSpinner.setEditor(entryDateSpinnerEditor);
    entryDateSpinnerEditor
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {

              @Override
              public void changedUpdate(DocumentEvent e) {
                return;
              }

              @Override
              public void insertUpdate(DocumentEvent e) {
                processChange(e);
              }

              @Override
              public void removeUpdate(DocumentEvent e) {
                processChange(e);
              }

              private void processChange(DocumentEvent e) {
                if (eventsAreDisabled()) {
                  return;
                }
                if (entryDateSpinnerEditor.getTextField().hasFocus()) {
                  entryDateChanged();
                }
              }
            });
    //		entryDateSpinner.addChangeListener(new ChangeListener() {
    //			@Override
    //			public void stateChanged(ChangeEvent e) {
    //				if (eventsAreDisabled()) {
    //					return;
    //				}
    //				entryDateChanged();
    //			}
    //		});

    countLabel = new JLabel("Count:");

    countField = new JTextField(5);
    countField.addKeyListener(
        new KeyListener() {
          @Override
          public void keyPressed(KeyEvent e) {
            return;
          }

          @Override
          public void keyReleased(KeyEvent e) {
            if (eventsAreDisabled()) {
              return;
            }
            countChanged();
          }

          @Override
          public void keyTyped(KeyEvent arg0) {
            return;
          }
        });
  }