Skip to content

Commit

Permalink
Revert "set current Date in DatePicker"
Browse files Browse the repository at this point in the history
This reverts commit 03ce835.
  • Loading branch information
koppor committed Dec 26, 2016
1 parent 20b9f71 commit b04a88d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 45 deletions.
29 changes: 4 additions & 25 deletions src/main/java/net/sf/jabref/gui/date/DatePickerButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.awt.BorderLayout;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import javax.swing.JComponent;
import javax.swing.JPanel;
Expand All @@ -17,16 +16,12 @@
import com.github.lgooddatepicker.components.DatePickerSettings;
import com.github.lgooddatepicker.optionalusertools.DateChangeListener;
import com.github.lgooddatepicker.zinternaltools.DateChangeEvent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* wrapper and service class for the DatePicker handling at the EntryEditor
*/
public class DatePickerButton implements DateChangeListener {

private static final Log LOGGER = LogFactory.getLog(DatePickerButton.class);

private final DatePicker datePicker;
private final JPanel panel = new JPanel();
private final FieldEditor editor;
Expand Down Expand Up @@ -58,12 +53,11 @@ public DatePickerButton(FieldEditor pEditor, boolean useIsoFormat) {
@Override
public void dateChanged(DateChangeEvent dateChangeEvent) {
LocalDate date = datePicker.getDate();
String newDate = "";
if (date != null) {
newDate = dateTimeFormatter.format(date.atStartOfDay());
}
if (!newDate.equals(editor.getText())) {
editor.setText(newDate);
editor.setText(dateTimeFormatter.format(date.atStartOfDay()));
} else {
// in this case the user selected "clear" in the date picker, so we just clear the field
editor.setText("");
}
// Set focus to editor component after changing its text:
editor.getTextComponent().requestFocus();
Expand All @@ -73,19 +67,4 @@ public JComponent getDatePicker() {
//return datePicker;
return panel;
}

/**
* Used to set the calender popup to the currently used Date
* @param dateString
*/
public void updateDatePickerDate(String dateString) {
if(dateString!=null && !dateString.isEmpty()) {
try {
datePicker.setDate(LocalDate.parse(dateString, dateTimeFormatter));
} catch (DateTimeParseException exception) {
LOGGER.warn("Unable to parse stored date for field '"+editor.getFieldName()+"' with current settings. "
+ "Clear button in calender popup will not work.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,26 +444,6 @@ public void mouseClicked(MouseEvent e) {
// insert a datepicker, if the extras field contains this command
if (useDatePicker) {
DatePickerButton datePicker = new DatePickerButton(editor, useIsoFormat);

// register a DocumentListener on the underlying text document which notifies the DatePicker which date is currently set
((JTextArea) editor).getDocument().addDocumentListener(new DocumentListener() {

@Override
public void insertUpdate(DocumentEvent e) {
datePicker.updateDatePickerDate(editor.getText());
}

@Override
public void removeUpdate(DocumentEvent e) {
datePicker.updateDatePickerDate(editor.getText());
}

@Override
public void changedUpdate(DocumentEvent e) {
datePicker.updateDatePickerDate(editor.getText());
}
});

return Optional.of(datePicker.getDatePicker());
} else {
return Optional.empty();
Expand Down

0 comments on commit b04a88d

Please sign in to comment.