Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Switch to LGoodDatePicker #2340

Merged
merged 3 commits into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions external-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ Project: SwingX
URL: https://swingx.java.net/
License: LGPL-3.0

Id: microba
Path: lib/microba.jar
Project: Microba
URL: https://github.com/tdbear/microba
License: BSD
Id: com.github.lgooddatepicker:LGoodDatePicker
Path: lib/LGoodDatePicker-8.2.2.jar
Project: LGoodDatePicker
URL: https://github.com/LGoodDatePicker/LGoodDatePicker
License: MIT

Id: spin
Path: lib/spin.jar
Expand Down
Binary file added lib/LGoodDatePicker-8.2.2.jar
Binary file not shown.
Binary file removed lib/microba.jar
Binary file not shown.
1 change: 1 addition & 0 deletions src/main/java/net/sf/jabref/gui/IconTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ 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
39 changes: 24 additions & 15 deletions src/main/java/net/sf/jabref/gui/date/DatePickerButton.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
package net.sf.jabref.gui.date;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

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.michaelbaranov.microba.calendar.DatePicker;
import com.github.lgooddatepicker.components.DatePicker;
import com.github.lgooddatepicker.components.DatePickerSettings;
import com.github.lgooddatepicker.optionalusertools.DateChangeListener;
import com.github.lgooddatepicker.zinternaltools.DateChangeEvent;

/**
* wrapper and service class for the DatePicker handling at the EntryEditor
*/
public class DatePickerButton implements ActionListener {
public class DatePickerButton implements DateChangeListener {

private final DatePicker datePicker = new DatePicker();
private final DatePicker datePicker;
private final JPanel panel = new JPanel();
private final FieldEditor editor;
private final boolean isoFormat;


public DatePickerButton(FieldEditor pEditor, Boolean isoFormat) {
this.isoFormat = isoFormat;
datePicker.showButtonOnly(true);
datePicker.addActionListener(this);
datePicker.setShowTodayButton(true);
// Create a date picker: With Hidden text field (Showing button only).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hidden and showing (lower case)

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("");

panel.setLayout(new BorderLayout());
panel.add(datePicker, BorderLayout.WEST);
editor = pEditor;
}

@Override
public void actionPerformed(ActionEvent e) {
Date date = datePicker.getDate();
public void dateChanged(DateChangeEvent dateChangeEvent) {
LocalDate date = datePicker.getDate();
if (date != null) {
if (isoFormat) {
editor.setText(EasyDateFormat.isoDateFormat().getDateAt(date));
editor.setText(date.format(DateTimeFormatter.ISO_DATE));
} else {
editor.setText(EasyDateFormat
.fromTimeStampFormat(Globals.prefs.get(JabRefPreferences.TIME_STAMP_FORMAT))
.getDateAt(date));
EasyDateFormat.fromTimeStampFormat(Globals.prefs.get(JabRefPreferences.TIME_STAMP_FORMAT)).getDateAt(ZonedDateTime.from(date));
}
} else {
// in this case the user selected "none" in the date picker, so we just clear the field
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/net/sf/jabref/logic/util/date/EasyDateFormat.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
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 {

Expand Down Expand Up @@ -32,16 +30,6 @@ 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".
Expand Down