[jabref] 01/03: patch DatePickerButton
Tony Mancill
tmancill at moszumanska.debian.org
Mon Dec 26 06:32:44 UTC 2016
This is an automated email from the git hooks/post-receive script.
tmancill pushed a commit to branch dev
in repository jabref.
commit fa70c0d34a61036dae55514d42b7494e434d363d
Author: tony mancill <tmancill at debian.org>
Date: Sun Dec 25 21:08:39 2016 -0800
patch DatePickerButton
---
debian/patches/060_DatePickerButton.patch | 122 ++++++++++++++++++++++++++++++
debian/patches/series | 1 +
2 files changed, 123 insertions(+)
diff --git a/debian/patches/060_DatePickerButton.patch b/debian/patches/060_DatePickerButton.patch
new file mode 100644
index 0000000..91e39cb
--- /dev/null
+++ b/debian/patches/060_DatePickerButton.patch
@@ -0,0 +1,122 @@
+--- a/src/main/java/net/sf/jabref/gui/date/DatePickerButton.java
++++ b/src/main/java/net/sf/jabref/gui/date/DatePickerButton.java
+@@ -1,9 +1,14 @@
+ package net.sf.jabref.gui.date;
+
+ import java.awt.BorderLayout;
++import java.awt.event.ActionEvent;
++import java.awt.event.ActionListener;
++import java.text.SimpleDateFormat;
+ import java.time.LocalDate;
++import java.time.ZoneId;
+ import java.time.format.DateTimeFormatter;
+ import java.time.format.DateTimeParseException;
++import java.util.Date;
+
+ import javax.swing.JComponent;
+ import javax.swing.JPanel;
+@@ -11,51 +16,67 @@
+ 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 org.apache.commons.logging.Log;
+ import org.apache.commons.logging.LogFactory;
+
++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 static final Log LOGGER = LogFactory.getLog(DatePickerButton.class);
+
+- private final DatePicker datePicker;
++ private final DatePicker datePicker = new 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) {
++ public DatePickerButton(FieldEditor pEditor, Boolean useIsoFormat) {
++ this.isoFormat = 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);
+- 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 actionPerformed(ActionEvent e) {
++ Date date = datePicker.getDate();
++ if (date != null) {
++ if (isoFormat) {
++ editor.setText(EasyDateFormat.isoDateFormat().getDateAt(date));
++ } else {
++ 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
++ editor.setText("");
++ }
++
++ // Set focus to editor component after changing its text:
++ editor.getTextComponent().requestFocus();
++ }
++
++
++/*
++ @Override
+ public void dateChanged(DateChangeEvent dateChangeEvent) {
+ LocalDate date = datePicker.getDate();
+ String newDate = "";
+@@ -68,6 +89,7 @@
+ // Set focus to editor component after changing its text:
+ editor.getTextComponent().requestFocus();
+ }
++*/
+
+ public JComponent getDatePicker() {
+ //return datePicker;
+@@ -81,8 +103,9 @@
+ public void updateDatePickerDate(String dateString) {
+ if(dateString!=null && !dateString.isEmpty()) {
+ try {
+- datePicker.setDate(LocalDate.parse(dateString, dateTimeFormatter));
+- } catch (DateTimeParseException exception) {
++ final Date d = Date.from(LocalDate.parse(dateString, dateTimeFormatter).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
++ datePicker.setDate(d);
++ } catch (Exception exception) {
+ LOGGER.warn("Unable to parse stored date for field '"+editor.getFieldName()+"' with current settings. "
+ + "Clear button in calender popup will not work.");
+ }
diff --git a/debian/patches/series b/debian/patches/series
index 05d6abc..27a6306 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -3,3 +3,4 @@
020_disable_automatic_upgrade_check.patch
030_xjc.patch
050_unirest_json.patch
+060_DatePickerButton.patch
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jabref.git
More information about the pkg-java-commits
mailing list