Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Datepicker fix #2405

Merged
merged 3 commits into from
Dec 20, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 10 additions & 11 deletions src/main/java/net/sf/jabref/gui/date/DatePickerButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.awt.BorderLayout;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

import javax.swing.JComponent;
Expand All @@ -11,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 @@ -27,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 @@ -51,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(ZonedDateTime.from(date));
}
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
5 changes: 3 additions & 2 deletions src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -89,7 +91,6 @@
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.search.SearchQueryHighlightListener;
import net.sf.jabref.logic.util.UpdateField;
import net.sf.jabref.logic.util.date.EasyDateFormat;
import net.sf.jabref.model.EntryTypes;
import net.sf.jabref.model.FieldChange;
import net.sf.jabref.model.database.BibDatabase;
Expand Down Expand Up @@ -1459,7 +1460,7 @@ private boolean updateTimeStampIsSet() {
private Optional<FieldChange> doUpdateTimeStamp() {
String timeStampField = Globals.prefs.get(JabRefPreferences.TIME_STAMP_FIELD);
String timeStampFormat = Globals.prefs.get(JabRefPreferences.TIME_STAMP_FORMAT);
String timestamp = EasyDateFormat.fromTimeStampFormat(timeStampFormat).getCurrentDate();
String timestamp = DateTimeFormatter.ofPattern(timeStampFormat).format(LocalDateTime.now());
return UpdateField.updateField(entry, timeStampField, timestamp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
import java.util.Set;

Expand Down Expand Up @@ -32,7 +35,6 @@
import net.sf.jabref.logic.net.URLUtil;
import net.sf.jabref.logic.util.DOI;
import net.sf.jabref.logic.util.ISBN;
import net.sf.jabref.logic.util.date.EasyDateFormat;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;
Expand Down Expand Up @@ -415,26 +417,33 @@ public static Optional<JComponent> getSelectorExtraComponent(JabRefFrame frame,
* Set up field such that double click inserts the current date
* If isDataPicker is True, a button with a data picker is returned
*
* @param editor
* @param isDatePicker
* @param editor reference to the FieldEditor to display the date value
* @param useDatePicker shows a DatePickerButton if true
* @param useIsoFormat if true ISO format is always used
* @return
*/
public static Optional<JComponent> getDateTimeExtraComponent(FieldEditor editor, Boolean isDatePicker,
Boolean isoFormat) {
public static Optional<JComponent> getDateTimeExtraComponent(FieldEditor editor, boolean useDatePicker,
boolean useIsoFormat) {
((JTextArea) editor).addMouseListener(new MouseAdapter() {

@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {// double click
String date = EasyDateFormat.isoDateFormat().getCurrentDate();
String date = "";
if(useIsoFormat) {
date = DateTimeFormatter.ISO_DATE.format(LocalDate.now());
} else {
date = DateTimeFormatter.ofPattern(Globals.prefs.get(JabRefPreferences.TIME_STAMP_FORMAT)).format(
LocalDateTime.now());
}
editor.setText(date);
}
}
});

// insert a datepicker, if the extras field contains this command
if (isDatePicker) {
DatePickerButton datePicker = new DatePickerButton(editor, isoFormat);
if (useDatePicker) {
DatePickerButton datePicker = new DatePickerButton(editor, useIsoFormat);
return Optional.of(datePicker.getDatePicker());
} else {
return Optional.empty();
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/net/sf/jabref/logic/util/UpdateField.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package net.sf.jabref.logic.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import java.util.Optional;

import net.sf.jabref.logic.util.date.EasyDateFormat;
import net.sf.jabref.model.FieldChange;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;
Expand Down Expand Up @@ -86,7 +87,7 @@ public static Optional<FieldChange> updateField(BibEntry be, String field, Strin
public static void setAutomaticFields(BibEntry entry, boolean overwriteOwner, boolean overwriteTimestamp,
UpdateFieldPreferences prefs) {
String defaultOwner = prefs.getDefaultOwner();
String timestamp = EasyDateFormat.fromTimeStampFormat(prefs.getTimeStampFormat()).getCurrentDate();
String timestamp = DateTimeFormatter.ofPattern(prefs.getTimeStampFormat()).format(LocalDateTime.now());
String timeStampField = prefs.getTimeStampField();
boolean setOwner = prefs.isUseOwner() && (overwriteOwner || (!entry.hasField(FieldName.OWNER)));
boolean setTimeStamp = prefs.isUseTimeStamp() && (overwriteTimestamp || (!entry.hasField(timeStampField)));
Expand Down Expand Up @@ -131,7 +132,7 @@ public static void setAutomaticFields(Collection<BibEntry> bibs, boolean overwri

String timeStampField = prefs.getTimeStampField();
String defaultOwner = prefs.getDefaultOwner();
String timestamp = EasyDateFormat.fromTimeStampFormat(prefs.getTimeStampFormat()).getCurrentDate();
String timestamp = DateTimeFormatter.ofPattern(prefs.getTimeStampFormat()).format(LocalDateTime.now());

// Iterate through all entries
for (BibEntry curEntry : bibs) {
Expand Down
51 changes: 0 additions & 51 deletions src/main/java/net/sf/jabref/logic/util/date/EasyDateFormat.java

This file was deleted.