Skip to content

Commit

Permalink
refactoring and fix for JabRef#2403
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgeiger committed Dec 19, 2016
1 parent 4c11664 commit cf094bb
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,7 +10,6 @@
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 @@ -26,11 +25,16 @@ public class DatePickerButton implements DateChangeListener {
private final DatePicker datePicker;
private final JPanel panel = new JPanel();
private final FieldEditor editor;
private final boolean isoFormat;
private final DateTimeFormatter dateTimeFormatter;


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

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

0 comments on commit cf094bb

Please sign in to comment.