Skip to content

Commit

Permalink
Revert "Switch to LGoodDatePicker (JabRef#2340)"
Browse files Browse the repository at this point in the history
This reverts commit 8556e65.
  • Loading branch information
koppor committed Dec 26, 2016
1 parent a964cfe commit 9eaa3f5
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 62 deletions.
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 5 additions & 4 deletions external-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,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
Expand Down
Binary file added lib/microba.jar
Binary file not shown.
1 change: 0 additions & 1 deletion src/main/java/net/sf/jabref/gui/IconTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
79 changes: 25 additions & 54 deletions src/main/java/net/sf/jabref/gui/date/DatePickerButton.java
Original file line number Diff line number Diff line change
@@ -1,69 +1,55 @@
package net.sf.jabref.gui.date;

import java.awt.BorderLayout;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
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 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) {
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("");

public DatePickerButton(FieldEditor pEditor, Boolean isoFormat) {
this.isoFormat = isoFormat;
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();
String newDate = "";
public void actionPerformed(ActionEvent e) {
Date date = datePicker.getDate();
if (date != null) {
newDate = dateTimeFormatter.format(date.atStartOfDay());
}
if (!newDate.equals(editor.getText())) {
editor.setText(newDate);
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();
Expand All @@ -73,19 +59,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.");
}
}
}
}
63 changes: 63 additions & 0 deletions src/main/java/net/sf/jabref/logic/util/date/EasyDateFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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 {

/**
* The formatter objects
*/
private final DateTimeFormatter dateFormatter;


public EasyDateFormat(String dateFormat) {
this(DateTimeFormatter.ofPattern(dateFormat));
}

public EasyDateFormat(DateTimeFormatter dateFormatter) {
this.dateFormatter = dateFormatter;
}

/**
* Creates a String containing the current date (and possibly time),
* formatted according to the format set in preferences under the key
* "timeStampFormat".
*
* @return The date string.
*/
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".
*
* @return The formatted date string.
*/
public String getDateAt(ZonedDateTime dateTime) {
// first use, create an instance
return dateTime.format(dateFormatter);
}

public static EasyDateFormat fromTimeStampFormat(String timeStampFormat) {
return new EasyDateFormat(timeStampFormat);
}

public static EasyDateFormat isoDateFormat() {
return new EasyDateFormat(DateTimeFormatter.ISO_LOCAL_DATE);
}
}

0 comments on commit 9eaa3f5

Please sign in to comment.