Skip to content

Commit

Permalink
Revert "refactoring and fix for JabRef#2403"
Browse files Browse the repository at this point in the history
This reverts commit cf094bb.
  • Loading branch information
koppor committed Dec 26, 2016
1 parent b04a88d commit 2b7fb2c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/main/java/net/sf/jabref/gui/date/DatePickerButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.sf.jabref.Globals;
import net.sf.jabref.gui.IconTheme;
import net.sf.jabref.gui.fieldeditors.FieldEditor;
import net.sf.jabref.logic.util.date.EasyDateFormat;
import net.sf.jabref.preferences.JabRefPreferences;

import com.github.lgooddatepicker.components.DatePicker;
Expand All @@ -25,16 +26,11 @@ public class DatePickerButton implements DateChangeListener {
private final DatePicker datePicker;
private final JPanel panel = new JPanel();
private final FieldEditor editor;
private final DateTimeFormatter dateTimeFormatter;
private final boolean isoFormat;


public DatePickerButton(FieldEditor pEditor, boolean useIsoFormat) {
if (useIsoFormat) {
dateTimeFormatter = DateTimeFormatter.ISO_DATE;
} else {
dateTimeFormatter = DateTimeFormatter.ofPattern(Globals.prefs.get(JabRefPreferences.TIME_STAMP_FORMAT));
}

public DatePickerButton(FieldEditor pEditor, Boolean isoFormat) {
this.isoFormat = isoFormat;
// Create a date picker with hidden text field (showing button only).
DatePickerSettings dateSettings = new DatePickerSettings();
dateSettings.setVisibleDateTextField(false);
Expand All @@ -54,9 +50,13 @@ public DatePickerButton(FieldEditor pEditor, boolean useIsoFormat) {
public void dateChanged(DateChangeEvent dateChangeEvent) {
LocalDate date = datePicker.getDate();
if (date != null) {
editor.setText(dateTimeFormatter.format(date.atStartOfDay()));
if (isoFormat) {
editor.setText(date.format(DateTimeFormatter.ISO_DATE));
} else {
EasyDateFormat.fromTimeStampFormat(Globals.prefs.get(JabRefPreferences.TIME_STAMP_FORMAT)).getDateAt(date.atStartOfDay());
}
} else {
// in this case the user selected "clear" in the date picker, so we just clear the field
// in this case the user selected "none" in the date picker, so we just clear the field
editor.setText("");
}
// Set focus to editor component after changing its text:
Expand Down

0 comments on commit 2b7fb2c

Please sign in to comment.