diff --git a/build.gradle b/build.gradle index 3fffbf4e3c07..343d21c639bc 100644 --- a/build.gradle +++ b/build.gradle @@ -121,9 +121,6 @@ dependencies { compile 'org.xmlunit:xmlunit-core:2.3.0' compile 'org.xmlunit:xmlunit-matchers:2.3.0' - - compile 'com.github.lgooddatepicker:LGoodDatePicker:8.3.0' - testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:2.3.0' testCompile 'com.github.tomakehurst:wiremock:2.4.1' diff --git a/external-libraries.txt b/external-libraries.txt index fadcd0cc818d..52518a719925 100644 --- a/external-libraries.txt +++ b/external-libraries.txt @@ -135,10 +135,11 @@ Project: SwingX URL: https://swingx.java.net/ License: LGPL-3.0 -Id: com.github.lgooddatepicker:LGoodDatePicker -Project: LGoodDatePicker -URL: https://github.com/LGoodDatePicker/LGoodDatePicker -License: MIT +Id: microba +Path: lib/microba.jar +Project: Microba +URL: https://github.com/tdbear/microba +License: BSD Id: spin Path: lib/spin.jar diff --git a/lib/microba.jar b/lib/microba.jar new file mode 100644 index 000000000000..8367e76214a1 Binary files /dev/null and b/lib/microba.jar differ diff --git a/src/main/java/net/sf/jabref/gui/IconTheme.java b/src/main/java/net/sf/jabref/gui/IconTheme.java index f43f8f9bd3e0..2177138bccad 100644 --- a/src/main/java/net/sf/jabref/gui/IconTheme.java +++ b/src/main/java/net/sf/jabref/gui/IconTheme.java @@ -158,7 +158,6 @@ public enum JabRefIcon { FACEBOOK("\uf20c"), /* css: facebook */ BLOG("\uf46b"), /* css: rss */ GLOBAL_SEARCH("\uF1E7"), /* css: earth */ - DATE_PICKER("\uF0ED;"), /* css: calendar */ // STILL MISSING: GROUP_REGULAR("\uF4E6", Color.RED); diff --git a/src/main/java/net/sf/jabref/gui/date/DatePickerButton.java b/src/main/java/net/sf/jabref/gui/date/DatePickerButton.java index 6b4a3b997faa..a11d7710d33e 100644 --- a/src/main/java/net/sf/jabref/gui/date/DatePickerButton.java +++ b/src/main/java/net/sf/jabref/gui/date/DatePickerButton.java @@ -1,30 +1,26 @@ package net.sf.jabref.gui.date; import java.awt.BorderLayout; -import java.time.LocalDate; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Date; import javax.swing.JComponent; import javax.swing.JPanel; 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; -import com.github.lgooddatepicker.components.DatePickerSettings; -import com.github.lgooddatepicker.optionalusertools.DateChangeListener; -import com.github.lgooddatepicker.zinternaltools.DateChangeEvent; +import com.michaelbaranov.microba.calendar.DatePicker; /** * wrapper and service class for the DatePicker handling at the EntryEditor */ -public class DatePickerButton implements DateChangeListener { +public class DatePickerButton implements ActionListener { - private final DatePicker datePicker; + private final DatePicker datePicker = new DatePicker(); private final JPanel panel = new JPanel(); private final FieldEditor editor; private final boolean isoFormat; @@ -32,29 +28,24 @@ public class DatePickerButton implements DateChangeListener { 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); - dateSettings.setGapBeforeButtonPixels(0); - - datePicker = new DatePicker(dateSettings); - datePicker.addDateChangeListener(this); - datePicker.getComponentToggleCalendarButton().setIcon(IconTheme.JabRefIcon.DATE_PICKER.getIcon()); - datePicker.getComponentToggleCalendarButton().setText(""); - + datePicker.showButtonOnly(true); + datePicker.addActionListener(this); + datePicker.setShowTodayButton(true); panel.setLayout(new BorderLayout()); panel.add(datePicker, BorderLayout.WEST); editor = pEditor; } @Override - public void dateChanged(DateChangeEvent dateChangeEvent) { - LocalDate date = datePicker.getDate(); + public void actionPerformed(ActionEvent e) { + Date date = datePicker.getDate(); if (date != null) { if (isoFormat) { - editor.setText(date.format(DateTimeFormatter.ISO_DATE)); + editor.setText(EasyDateFormat.isoDateFormat().getDateAt(date)); } else { - EasyDateFormat.fromTimeStampFormat(Globals.prefs.get(JabRefPreferences.TIME_STAMP_FORMAT)).getDateAt(ZonedDateTime.from(date)); + editor.setText(EasyDateFormat + .fromTimeStampFormat(Globals.prefs.get(JabRefPreferences.TIME_STAMP_FORMAT)) + .getDateAt(date)); } } else { // in this case the user selected "none" in the date picker, so we just clear the field diff --git a/src/main/java/net/sf/jabref/logic/util/date/EasyDateFormat.java b/src/main/java/net/sf/jabref/logic/util/date/EasyDateFormat.java index 25885be93f6e..3eb5a03dd608 100644 --- a/src/main/java/net/sf/jabref/logic/util/date/EasyDateFormat.java +++ b/src/main/java/net/sf/jabref/logic/util/date/EasyDateFormat.java @@ -1,7 +1,9 @@ package net.sf.jabref.logic.util.date; +import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; +import java.util.Date; public class EasyDateFormat { @@ -30,6 +32,16 @@ public String getCurrentDate() { return getDateAt(ZonedDateTime.now()); } + /** + * Creates a readable Date string from the parameter date. The format is set + * in preferences under the key "timeStampFormat". + * + * @return The formatted date string. + */ + public String getDateAt(Date date) { + return getDateAt(date.toInstant().atZone(ZoneId.systemDefault())); + } + /** * Creates a readable Date string from the parameter date. The format is set * in preferences under the key "timeStampFormat".