From 1751cba4d3a2dde892ac8472bb5766819b0a2559 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 19 Oct 2017 18:35:39 +0800 Subject: [PATCH 1/3] Increase relative size of abstract field in editor (#3320) * Increase relative size of abstract field in editor * Fix build * Code cleanup * Fix imports --- CHANGELOG.md | 1 + .../jabref/gui/entryeditor/EntryEditor.java | 2 +- .../gui/entryeditor/FieldsEditorTab.java | 6 +- .../jabref/gui/fieldeditors/FieldEditors.java | 2 + .../gui/fieldeditors/MultilineEditor.java | 17 ++ .../jabref/model/entry/BibtexSingleField.java | 43 +-- .../org/jabref/model/entry/FieldProperty.java | 10 +- .../model/entry/InternalBibtexFields.java | 250 ++++++++---------- 8 files changed, 139 insertions(+), 192 deletions(-) create mode 100644 src/main/java/org/jabref/gui/fieldeditors/MultilineEditor.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a5b8c89c03..21fd2a531b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - Updated French translation - We improved the handling of abstracts in the "Astrophysics Data System" fetcher. [#2471](https://github.com/JabRef/jabref/issues/2471) - We added support for pasting entries in different formats [#3143](https://github.com/JabRef/jabref/issues/3143) +- We increased the relative size of the "abstract" field in the entry editor. [Feature request in the forum](http://discourse.jabref.org/t/entry-preview-in-version-4/827) - Crossreferenced entries are now used when a BibTex key is generated for an entry with empty fields. [#2811](https://github.com/JabRef/jabref/issues/2811) - We now set the WM_CLASS of the UI to org-jabref-JabRefMain to allow certain Un*x window managers to properly identify its windows - We changed the default paths for the OpenOffice/LibreOffice binaries to the default path for LibreOffice diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 9bf06e46d7b..bb0e34f19fa 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -777,7 +777,7 @@ public void actionPerformed(ActionEvent event) { //TODO: See if we need to update an AutoCompleter instance: /* - AutoCompleter aComp = panel.getSuggestionProviders().get(fieldEditor.getFieldName()); + AutoCompleter aComp = panel.getSuggestionProviders().get(fieldEditor.getName()); if (aComp != null) { aComp.addBibtexEntry(entry); } diff --git a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java index db7d64534f9..394e539a41a 100644 --- a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java @@ -94,11 +94,11 @@ private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean compresse FieldEditor fieldEditor; int defaultHeight; int wHeight = (int) (50.0 * InternalBibtexFields.getFieldWeight(field)); - if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.SINGLE_ENTRY_LINK)) { + if (InternalBibtexFields.getProperties(field).contains(FieldProperty.SINGLE_ENTRY_LINK)) { fieldEditor = new EntryLinkListEditor(frame, bPanel.getBibDatabaseContext(), field, null, parent, true); defaultHeight = 0; - } else if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.MULTIPLE_ENTRY_LINK)) { + } else if (InternalBibtexFields.getProperties(field).contains(FieldProperty.MULTIPLE_ENTRY_LINK)) { fieldEditor = new EntryLinkListEditor(frame, bPanel.getBibDatabaseContext(), field, null, parent, false); defaultHeight = 0; @@ -166,7 +166,7 @@ private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean compresse setRegularRowLayout(gridPane, rows); } - + if (GUIGlobals.currentFont != null) { gridPane.setStyle( "text-area-background: " + convertToHex(GUIGlobals.validFieldBackgroundColor) + ";" diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java index 09e1328ee9c..7f457505f89 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java @@ -72,6 +72,8 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu return new PersonsEditor(fieldName, suggestionProvider, preferences, fieldCheckers); } else if (FieldName.KEYWORDS.equals(fieldName)) { return new KeywordsEditor(fieldName, suggestionProvider, fieldCheckers, preferences); + } else if (fieldExtras.contains(FieldProperty.MULTILINE_TEXT)) { + return new MultilineEditor(fieldName, suggestionProvider, fieldCheckers, preferences); } // default diff --git a/src/main/java/org/jabref/gui/fieldeditors/MultilineEditor.java b/src/main/java/org/jabref/gui/fieldeditors/MultilineEditor.java new file mode 100644 index 00000000000..c52942ae8ac --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/MultilineEditor.java @@ -0,0 +1,17 @@ +package org.jabref.gui.fieldeditors; + +import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; +import org.jabref.logic.integrity.FieldCheckers; +import org.jabref.preferences.JabRefPreferences; + +public class MultilineEditor extends SimpleEditor implements FieldEditorFX { + + public MultilineEditor(String fieldName, AutoCompleteSuggestionProvider suggestionProvider, FieldCheckers fieldCheckers, JabRefPreferences preferences) { + super (fieldName, suggestionProvider, fieldCheckers, preferences); + } + + @Override + public double getWeight() { + return 4; + } +} diff --git a/src/main/java/org/jabref/model/entry/BibtexSingleField.java b/src/main/java/org/jabref/model/entry/BibtexSingleField.java index 7ca928aaf2e..5c1f8776e93 100644 --- a/src/main/java/org/jabref/model/entry/BibtexSingleField.java +++ b/src/main/java/org/jabref/model/entry/BibtexSingleField.java @@ -7,13 +7,6 @@ * Class for keeping properties of a single BibTeX/biblatex field */ public class BibtexSingleField { - // some field constants - public static final double DEFAULT_FIELD_WEIGHT = 1; - public static final double MAX_FIELD_WEIGHT = 2; - - public static final double SMALL_W = 0.30; - public static final double MEDIUM_W = 0.5; - public static final double LARGE_W = 1.5; public static final int DEFAULT_FIELD_LENGTH = 100; @@ -31,8 +24,7 @@ private enum Flag { // default is: not standard, public, displayable and writable private final Set flags = EnumSet.of(Flag.DISPLAYABLE, Flag.WRITEABLE); - private int length = DEFAULT_FIELD_LENGTH; - private double weight = DEFAULT_FIELD_WEIGHT; + private final int length; // properties contains a set of FieldProperty to e.g. tell the EntryEditor to add a specific // function to this field, to format names, or to control the integrity checks. @@ -43,14 +35,7 @@ private enum Flag { // private String otherNames = null ; public BibtexSingleField(String fieldName, boolean pStandard) { - name = fieldName; - setFlag(pStandard, Flag.STANDARD); - } - - public BibtexSingleField(String fieldName, boolean pStandard, double pWeight) { - name = fieldName; - setFlag(pStandard, Flag.STANDARD); - weight = pWeight; + this(fieldName, pStandard, DEFAULT_FIELD_LENGTH); } public BibtexSingleField(String fieldName, boolean pStandard, int pLength) { @@ -59,13 +44,6 @@ public BibtexSingleField(String fieldName, boolean pStandard, int pLength) { length = pLength; } - public BibtexSingleField(String fieldName, boolean pStandard, double pWeight, int pLength) { - name = fieldName; - setFlag(pStandard, Flag.STANDARD); - weight = pWeight; - length = pLength; - } - /** * Sets or onsets the given flag * @param setToOn if true, set the flag; if false, unset the flat @@ -113,24 +91,17 @@ public boolean isWriteable() { return flags.contains(Flag.WRITEABLE); } - public void setExtras(Set pExtras) { - properties = pExtras; + public BibtexSingleField withProperties(FieldProperty first, FieldProperty... rest) { + properties = EnumSet.of(first, rest); + return this; } // fieldExtras contains mappings to tell the EntryEditor to add a specific // function to this field, for instance a "browse" button for the "pdf" field. - public Set getFieldProperties() { + public Set getProperties() { return properties; } - public void setWeight(double value) { - this.weight = value; - } - - public double getWeight() { - return this.weight; - } - /** * @return The maximum (expected) length of the field value; not the length of the field name */ @@ -138,7 +109,7 @@ public int getLength() { return this.length; } - public String getFieldName() { + public String getName() { return name; } diff --git a/src/main/java/org/jabref/model/entry/FieldProperty.java b/src/main/java/org/jabref/model/entry/FieldProperty.java index 87e980812d2..1091dfbc09f 100644 --- a/src/main/java/org/jabref/model/entry/FieldProperty.java +++ b/src/main/java/org/jabref/model/entry/FieldProperty.java @@ -1,8 +1,5 @@ package org.jabref.model.entry; -import java.util.EnumSet; -import java.util.Set; - public enum FieldProperty { YES_NO, DATE, @@ -20,7 +17,6 @@ public enum FieldProperty { EDITOR_TYPE, PAGINATION, TYPE, - CROSSREF, ISO_DATE, ISBN, EPRINT, @@ -28,8 +24,6 @@ public enum FieldProperty { SINGLE_ENTRY_LINK, MULTIPLE_ENTRY_LINK, PUBLICATION_STATE, - VERBATIM; - - public static final Set ALL_OPTS = EnumSet.allOf(FieldProperty.class); - + MULTILINE_TEXT, + VERBATIM } diff --git a/src/main/java/org/jabref/model/entry/InternalBibtexFields.java b/src/main/java/org/jabref/model/entry/InternalBibtexFields.java index 46c6cc14e9a..d1e59f32fed 100644 --- a/src/main/java/org/jabref/model/entry/InternalBibtexFields.java +++ b/src/main/java/org/jabref/model/entry/InternalBibtexFields.java @@ -81,7 +81,7 @@ public class InternalBibtexFields { SpecialField.RELEVANCE.getFieldName()); // singleton instance - private static InternalBibtexFields RUNTIME = new InternalBibtexFields(FieldName.TIMESTAMP); + private static InternalBibtexFields RUNTIME = new InternalBibtexFields(); // contains all bibtex-field objects (BibtexSingleField) private final Map fieldSet; @@ -90,63 +90,56 @@ public class InternalBibtexFields { private String timeStampField; - private InternalBibtexFields(String timeStampFieldName) { + private InternalBibtexFields() { fieldSet = new HashMap<>(); BibtexSingleField dummy; // FIRST: all standard fields // These are the fields that BibTeX might want to treat, so these // must conform to BibTeX rules. - add(new BibtexSingleField(FieldName.ADDRESS, true, BibtexSingleField.SMALL_W)); + add(new BibtexSingleField(FieldName.ADDRESS, true)); // An annotation. It is not used by the standard bibliography styles, // but may be used by others that produce an annotated bibliography. // http://www.ecst.csuchico.edu/~jacobsd/bib/formats/bibtex.html - add(new BibtexSingleField(FieldName.ANNOTE, true, BibtexSingleField.LARGE_W)); - add(new BibtexSingleField(FieldName.AUTHOR, true, BibtexSingleField.MEDIUM_W, 280)); + add(new BibtexSingleField(FieldName.ANNOTE, true)); + add(new BibtexSingleField(FieldName.AUTHOR, true, 280)); add(new BibtexSingleField(FieldName.BOOKTITLE, true, 175)); - add(new BibtexSingleField(FieldName.CHAPTER, true, BibtexSingleField.SMALL_W)); - dummy = new BibtexSingleField(FieldName.CROSSREF, true, BibtexSingleField.LARGE_W); - dummy.setExtras(EnumSet.of(FieldProperty.CROSSREF, FieldProperty.SINGLE_ENTRY_LINK)); + add(new BibtexSingleField(FieldName.CHAPTER, true)); + dummy = new BibtexSingleField(FieldName.CROSSREF, true).withProperties(FieldProperty.SINGLE_ENTRY_LINK); add(dummy); - add(new BibtexSingleField(FieldName.EDITION, true, BibtexSingleField.SMALL_W)); - add(new BibtexSingleField(FieldName.EDITOR, true, BibtexSingleField.MEDIUM_W, 280)); - dummy = new BibtexSingleField(FieldName.EPRINT, true, BibtexSingleField.SMALL_W); - dummy.setExtras(EnumSet.of(FieldProperty.EPRINT)); + add(new BibtexSingleField(FieldName.EDITION, true)); + add(new BibtexSingleField(FieldName.EDITOR, true, 280)); + dummy = new BibtexSingleField(FieldName.EPRINT, true).withProperties(FieldProperty.EPRINT); add(dummy); - add(new BibtexSingleField(FieldName.HOWPUBLISHED, true, BibtexSingleField.MEDIUM_W)); - add(new BibtexSingleField(FieldName.INSTITUTION, true, BibtexSingleField.MEDIUM_W)); + add(new BibtexSingleField(FieldName.HOWPUBLISHED, true)); + add(new BibtexSingleField(FieldName.INSTITUTION, true)); - dummy = new BibtexSingleField(FieldName.ISBN, true, BibtexSingleField.SMALL_W); - dummy.setExtras(EnumSet.of(FieldProperty.ISBN)); + dummy = new BibtexSingleField(FieldName.ISBN, true).withProperties(FieldProperty.ISBN); add(dummy); - add(new BibtexSingleField(FieldName.ISSN, true, BibtexSingleField.SMALL_W)); + add(new BibtexSingleField(FieldName.ISSN, true)); - dummy = new BibtexSingleField(FieldName.JOURNAL, true, BibtexSingleField.SMALL_W); - dummy.setExtras(EnumSet.of(FieldProperty.JOURNAL_NAME)); + dummy = new BibtexSingleField(FieldName.JOURNAL, true).withProperties(FieldProperty.JOURNAL_NAME); add(dummy); - dummy = new BibtexSingleField(FieldName.JOURNALTITLE, true, BibtexSingleField.SMALL_W); - dummy.setExtras(EnumSet.of(FieldProperty.JOURNAL_NAME)); + dummy = new BibtexSingleField(FieldName.JOURNALTITLE, true).withProperties(FieldProperty.JOURNAL_NAME); add(dummy); add(new BibtexSingleField(FieldName.KEY, true)); - dummy = new BibtexSingleField(FieldName.MONTH, true, BibtexSingleField.SMALL_W); - dummy.setExtras(EnumSet.of(FieldProperty.MONTH)); + dummy = new BibtexSingleField(FieldName.MONTH, true).withProperties(FieldProperty.MONTH); add(dummy); - add(new BibtexSingleField(FieldName.NOTE, true, BibtexSingleField.MEDIUM_W)); - add(new BibtexSingleField(FieldName.NUMBER, true, BibtexSingleField.SMALL_W, 60).setNumeric(true)); - add(new BibtexSingleField(FieldName.ORGANIZATION, true, BibtexSingleField.MEDIUM_W)); - add(new BibtexSingleField(FieldName.PAGES, true, BibtexSingleField.SMALL_W)); - add(new BibtexSingleField(FieldName.PUBLISHER, true, BibtexSingleField.MEDIUM_W)); - add(new BibtexSingleField(FieldName.SCHOOL, true, BibtexSingleField.MEDIUM_W)); - add(new BibtexSingleField(FieldName.SERIES, true, BibtexSingleField.SMALL_W)); + add(new BibtexSingleField(FieldName.NOTE, true)); + add(new BibtexSingleField(FieldName.NUMBER, true, 60).setNumeric(true)); + add(new BibtexSingleField(FieldName.ORGANIZATION, true)); + add(new BibtexSingleField(FieldName.PAGES, true)); + add(new BibtexSingleField(FieldName.PUBLISHER, true)); + add(new BibtexSingleField(FieldName.SCHOOL, true)); + add(new BibtexSingleField(FieldName.SERIES, true)); add(new BibtexSingleField(FieldName.TITLE, true, 400)); - dummy = new BibtexSingleField(FieldName.TYPE, true, BibtexSingleField.SMALL_W); - dummy.getFieldProperties().add(FieldProperty.TYPE); + dummy = new BibtexSingleField(FieldName.TYPE, true).withProperties(FieldProperty.TYPE); add(dummy); - add(new BibtexSingleField(FieldName.LANGUAGE, true, BibtexSingleField.SMALL_W)); - add(new BibtexSingleField(FieldName.VOLUME, true, BibtexSingleField.SMALL_W, 60).setNumeric(true)); - add(new BibtexSingleField(FieldName.YEAR, true, BibtexSingleField.SMALL_W, 60).setNumeric(true)); + add(new BibtexSingleField(FieldName.LANGUAGE, true)); + add(new BibtexSingleField(FieldName.VOLUME, true, 60).setNumeric(true)); + add(new BibtexSingleField(FieldName.YEAR, true, 60).setNumeric(true)); // custom fields not displayed at editor, but as columns in the UI for (String fieldName : SPECIAL_FIELDS) { @@ -164,43 +157,36 @@ private InternalBibtexFields(String timeStampFieldName) { dummy.setPrivate(); add(dummy); - dummy = new BibtexSingleField(FieldName.DOI, true, BibtexSingleField.SMALL_W); - dummy.setExtras(EnumSet.of(FieldProperty.DOI)); + dummy = new BibtexSingleField(FieldName.DOI, true).withProperties(FieldProperty.DOI); add(dummy); - add(new BibtexSingleField(FieldName.EID, true, BibtexSingleField.SMALL_W)); + add(new BibtexSingleField(FieldName.EID, true)); - dummy = new BibtexSingleField(FieldName.DATE, true); - dummy.setExtras(EnumSet.of(FieldProperty.DATE)); + dummy = new BibtexSingleField(FieldName.DATE, true).withProperties(FieldProperty.DATE); add(dummy); - add(new BibtexSingleField(FieldName.PMID, false, BibtexSingleField.SMALL_W, 60).setNumeric(true)); + add(new BibtexSingleField(FieldName.PMID, false, 60).setNumeric(true)); // additional fields ------------------------------------------------------ add(new BibtexSingleField(FieldName.LOCATION, false)); - add(new BibtexSingleField(FieldName.ABSTRACT, false, BibtexSingleField.LARGE_W, 400)); + add(new BibtexSingleField(FieldName.ABSTRACT, false, 400).withProperties(FieldProperty.MULTILINE_TEXT)); - dummy = new BibtexSingleField(FieldName.URL, false, BibtexSingleField.SMALL_W); - dummy.setExtras(EnumSet.of(FieldProperty.EXTERNAL, FieldProperty.VERBATIM)); + dummy = new BibtexSingleField(FieldName.URL, false).withProperties(FieldProperty.EXTERNAL, FieldProperty.VERBATIM); add(dummy); - add(new BibtexSingleField(FieldName.COMMENT, false, BibtexSingleField.MEDIUM_W)); - add(new BibtexSingleField(FieldName.KEYWORDS, false, BibtexSingleField.SMALL_W)); + add(new BibtexSingleField(FieldName.COMMENT, false)); + add(new BibtexSingleField(FieldName.KEYWORDS, false)); - dummy = new BibtexSingleField(FieldName.FILE, false); - dummy.setExtras(EnumSet.of(FieldProperty.FILE_EDITOR, FieldProperty.VERBATIM)); + dummy = new BibtexSingleField(FieldName.FILE, false).withProperties(FieldProperty.FILE_EDITOR, FieldProperty.VERBATIM); add(dummy); - dummy = new BibtexSingleField(FieldName.RELATED, false); - dummy.setExtras(EnumSet.of(FieldProperty.MULTIPLE_ENTRY_LINK)); + dummy = new BibtexSingleField(FieldName.RELATED, false).withProperties(FieldProperty.MULTIPLE_ENTRY_LINK); add(dummy); // some biblatex fields - dummy = new BibtexSingleField(FieldName.GENDER, true, BibtexSingleField.SMALL_W); - dummy.getFieldProperties().add(FieldProperty.GENDER); + dummy = new BibtexSingleField(FieldName.GENDER, true).withProperties(FieldProperty.GENDER); add(dummy); - dummy = new BibtexSingleField(FieldName.PUBSTATE, true, BibtexSingleField.SMALL_W); - dummy.getFieldProperties().add(FieldProperty.PUBLICATION_STATE); + dummy = new BibtexSingleField(FieldName.PUBSTATE, true).withProperties(FieldProperty.PUBLICATION_STATE); add(dummy); // some internal fields ---------------------------------------------- @@ -210,14 +196,12 @@ private InternalBibtexFields(String timeStampFieldName) { dummy.setDisplayable(false); add(dummy); - dummy = new BibtexSingleField(FieldName.OWNER, false, BibtexSingleField.SMALL_W); - dummy.setExtras(EnumSet.of(FieldProperty.OWNER)); + dummy = new BibtexSingleField(FieldName.OWNER, false).withProperties(FieldProperty.OWNER); dummy.setPrivate(); add(dummy); - timeStampField = timeStampFieldName; - dummy = new BibtexSingleField(timeStampFieldName, false, BibtexSingleField.SMALL_W); - dummy.setExtras(EnumSet.of(FieldProperty.DATE)); + timeStampField = FieldName.TIMESTAMP; + dummy = new BibtexSingleField(FieldName.TIMESTAMP, false).withProperties(FieldProperty.DATE); dummy.setPrivate(); add(dummy); @@ -245,8 +229,7 @@ private InternalBibtexFields(String timeStampFieldName) { // IEEEtranBSTCTL fields that should be "yes" or "no" for (String yesNoField : IEEETRANBSTCTL_YES_NO_FIELDS) { - dummy = new BibtexSingleField(yesNoField, false); - dummy.setExtras(EnumSet.of(FieldProperty.YES_NO)); + dummy = new BibtexSingleField(yesNoField, false).withProperties(FieldProperty.YES_NO); add(dummy); } @@ -254,9 +237,9 @@ private InternalBibtexFields(String timeStampFieldName) { for (String numericField : INTEGER_FIELDS) { BibtexSingleField field = fieldSet.get(numericField); if (field == null) { - field = new BibtexSingleField(numericField, true, BibtexSingleField.SMALL_W).setNumeric(true); + field = new BibtexSingleField(numericField, true).setNumeric(true); } - field.getFieldProperties().add(FieldProperty.INTEGER); + field.getProperties().add(FieldProperty.INTEGER); add(field); } @@ -264,9 +247,9 @@ private InternalBibtexFields(String timeStampFieldName) { for (String fieldText : VERBATIM_FIELDS) { BibtexSingleField field = fieldSet.get(fieldText); if (field == null) { - field = new BibtexSingleField(fieldText, true, BibtexSingleField.SMALL_W); + field = new BibtexSingleField(fieldText, true); } - field.getFieldProperties().add(FieldProperty.VERBATIM); + field.getProperties().add(FieldProperty.VERBATIM); add(field); } @@ -274,9 +257,9 @@ private InternalBibtexFields(String timeStampFieldName) { for (String fieldText : BIBLATEX_PERSON_NAME_FIELDS) { BibtexSingleField field = fieldSet.get(fieldText); if (field == null) { - field = new BibtexSingleField(fieldText, true, BibtexSingleField.SMALL_W); + field = new BibtexSingleField(fieldText, true); } - field.getFieldProperties().add(FieldProperty.PERSON_NAMES); + field.getProperties().add(FieldProperty.PERSON_NAMES); add(field); } @@ -284,9 +267,9 @@ private InternalBibtexFields(String timeStampFieldName) { for (String fieldText : BIBLATEX_EDITOR_TYPE_FIELDS) { BibtexSingleField field = fieldSet.get(fieldText); if (field == null) { - field = new BibtexSingleField(fieldText, true, BibtexSingleField.SMALL_W); + field = new BibtexSingleField(fieldText, true); } - field.getFieldProperties().add(FieldProperty.EDITOR_TYPE); + field.getProperties().add(FieldProperty.EDITOR_TYPE); add(field); } @@ -294,9 +277,9 @@ private InternalBibtexFields(String timeStampFieldName) { for (String fieldText : BIBLATEX_PAGINATION_FIELDS) { BibtexSingleField field = fieldSet.get(fieldText); if (field == null) { - field = new BibtexSingleField(fieldText, true, BibtexSingleField.SMALL_W); + field = new BibtexSingleField(fieldText, true); } - field.getFieldProperties().add(FieldProperty.PAGINATION); + field.getProperties().add(FieldProperty.PAGINATION); add(field); } @@ -304,10 +287,10 @@ private InternalBibtexFields(String timeStampFieldName) { for (String fieldText : BIBLATEX_DATE_FIELDS) { BibtexSingleField field = fieldSet.get(fieldText); if (field == null) { - field = new BibtexSingleField(fieldText, true, BibtexSingleField.SMALL_W); + field = new BibtexSingleField(fieldText, true); } - field.getFieldProperties().add(FieldProperty.DATE); - field.getFieldProperties().add(FieldProperty.ISO_DATE); + field.getProperties().add(FieldProperty.DATE); + field.getProperties().add(FieldProperty.ISO_DATE); add(field); } @@ -315,9 +298,9 @@ private InternalBibtexFields(String timeStampFieldName) { for (String fieldText : BIBLATEX_JOURNAL_NAME_FIELDS) { BibtexSingleField field = fieldSet.get(fieldText); if (field == null) { - field = new BibtexSingleField(fieldText, true, BibtexSingleField.SMALL_W); + field = new BibtexSingleField(fieldText, true); } - field.getFieldProperties().add(FieldProperty.JOURNAL_NAME); + field.getProperties().add(FieldProperty.JOURNAL_NAME); add(field); } @@ -325,9 +308,9 @@ private InternalBibtexFields(String timeStampFieldName) { for (String fieldText : BIBLATEX_BOOK_NAME_FIELDS) { BibtexSingleField field = fieldSet.get(fieldText); if (field == null) { - field = new BibtexSingleField(fieldText, true, BibtexSingleField.SMALL_W); + field = new BibtexSingleField(fieldText, true); } - field.getFieldProperties().add(FieldProperty.BOOK_NAME); + field.getProperties().add(FieldProperty.BOOK_NAME); add(field); } @@ -335,9 +318,9 @@ private InternalBibtexFields(String timeStampFieldName) { for (String fieldText : BIBLATEX_LANGUAGE_FIELDS) { BibtexSingleField field = fieldSet.get(fieldText); if (field == null) { - field = new BibtexSingleField(fieldText, true, BibtexSingleField.SMALL_W); + field = new BibtexSingleField(fieldText, true); } - field.getFieldProperties().add(FieldProperty.LANGUAGE); + field.getProperties().add(FieldProperty.LANGUAGE); add(field); } @@ -345,9 +328,9 @@ private InternalBibtexFields(String timeStampFieldName) { for (String fieldText : BIBLATEX_MULTI_KEY_FIELDS) { BibtexSingleField field = fieldSet.get(fieldText); if (field == null) { - field = new BibtexSingleField(fieldText, true, BibtexSingleField.SMALL_W); + field = new BibtexSingleField(fieldText, true); } - field.getFieldProperties().add(FieldProperty.MULTIPLE_ENTRY_LINK); + field.getProperties().add(FieldProperty.MULTIPLE_ENTRY_LINK); add(field); } } @@ -357,7 +340,6 @@ public static void updateTimeStampField(String timeStampFieldName) { field.setName(timeStampFieldName); RUNTIME.timeStampField = timeStampFieldName; }); - } public static void updateSpecialFields(boolean serializeSpecialFields) { @@ -390,7 +372,7 @@ public static void setNumericFields(List numFields) { for (String fieldName : InternalBibtexFields.RUNTIME.fieldSet.keySet()) { BibtexSingleField field = InternalBibtexFields.RUNTIME.fieldSet.get(fieldName); if (!field.isNumeric() && nF.contains(fieldName)) { - field.setNumeric(nF.contains(fieldName)); + field.setNumeric(true); } nF.remove(fieldName); // remove, so we clear the set of all standard fields. } @@ -403,13 +385,10 @@ public static void setNumericFields(List numFields) { } - /** - * insert a field into the internal list - */ - private void add(BibtexSingleField field) { - // field == null check - String key = field.getFieldName(); - fieldSet.put(key, field); + public static Set getFieldProperties(String name) { + return getField(name) + .map(BibtexSingleField::getProperties) + .orElse(EnumSet.noneOf(FieldProperty.class)); } // -------------------------------------------------------------------------- @@ -423,35 +402,28 @@ private static Optional getField(String name) { return Optional.empty(); } - public static Set getFieldProperties(String name) { - Optional sField = InternalBibtexFields.getField(name); - if (sField.isPresent()) { - return sField.get().getFieldProperties(); - } - return EnumSet.noneOf(FieldProperty.class); + public static int getFieldLength(String name) { + return InternalBibtexFields.getField(name) + .map(BibtexSingleField::getLength) + .orElse(BibtexSingleField.DEFAULT_FIELD_LENGTH); } - public static double getFieldWeight(String name) { - Optional sField = InternalBibtexFields.getField(name); - if (sField.isPresent()) { - return sField.get().getWeight(); + /** + * returns a List with all fieldnames + */ + public static List getAllPublicFieldNames() { + // collect all public fields + List publicFields = new ArrayList<>(); + for (BibtexSingleField sField : InternalBibtexFields.RUNTIME.fieldSet.values()) { + if (!sField.isPrivate()) { + publicFields.add(sField.getName()); + } } - return BibtexSingleField.DEFAULT_FIELD_WEIGHT; - } - public static void setFieldWeight(String fieldName, double weight) { - Optional sField = InternalBibtexFields.getField(fieldName); - if (sField.isPresent()) { - sField.get().setWeight(weight); - } - } + // sort the entries + Collections.sort(publicFields); - public static int getFieldLength(String name) { - Optional sField = InternalBibtexFields.getField(name); - if (sField.isPresent()) { - return sField.get().getLength(); - } - return BibtexSingleField.DEFAULT_FIELD_LENGTH; + return publicFields; } public static boolean isWriteableField(String field) { @@ -484,24 +456,8 @@ public static boolean isInternalField(String field) { return field.startsWith("__"); } - /** - * returns a List with all fieldnames - */ - public static List getAllPublicFieldNames() { - // collect all public fields - List publicFields = new ArrayList<>(); - for (BibtexSingleField sField : InternalBibtexFields.RUNTIME.fieldSet.values()) { - if (!sField.isPrivate()) { - publicFields.add(sField.getFieldName()); - // or export the complete BibtexSingleField ? - // BibtexSingleField.toString() { return fieldname ; } - } - } - - // sort the entries - Collections.sort(publicFields); - - return publicFields; + public static List getJournalNameFields() { + return getFieldsWithProperty(FieldProperty.JOURNAL_NAME); } /** @@ -520,21 +476,20 @@ public static List getAllPublicAndInternalFieldNames() { return publicAndInternalFields; } - public static List getJournalNameFields() { - return InternalBibtexFields.getAllPublicFieldNames().stream().filter( - fieldName -> InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.JOURNAL_NAME)) - .collect(Collectors.toList()); - } - public static List getBookNameFields() { - return InternalBibtexFields.getAllPublicFieldNames().stream() - .filter(fieldName -> InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.BOOK_NAME)) - .collect(Collectors.toList()); + return getFieldsWithProperty(FieldProperty.BOOK_NAME); } public static List getPersonNameFields() { - return InternalBibtexFields.getAllPublicFieldNames().stream().filter( - fieldName -> InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.PERSON_NAMES)) + return getFieldsWithProperty(FieldProperty.PERSON_NAMES); + } + + public static List getFieldsWithProperty(FieldProperty property) { + return RUNTIME.fieldSet.values().stream() + .filter(field -> !field.isPrivate()) + .filter(field -> field.getProperties().contains(property)) + .map(BibtexSingleField::getName) + .sorted() .collect(Collectors.toList()); } @@ -542,4 +497,11 @@ public static List getIEEETranBSTctlYesNoFields() { return IEEETRANBSTCTL_YES_NO_FIELDS; } + /** + * insert a field into the internal list + */ + private void add(BibtexSingleField field) { + String key = field.getName(); + fieldSet.put(key, field); + } } From 65cacb15f0a86d7fc7c571d816fd5c5015207733 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 20 Oct 2017 09:39:26 +0800 Subject: [PATCH 2/3] Fix NPE in MainTable (#3318) * Fix NPE in MainTable * Fix build --- src/main/java/org/jabref/gui/maintable/MainTable.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index c1e04873209..9edd6805dba 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -537,12 +537,7 @@ public boolean isFileColumn(int modelIndex) { } private boolean matches(int row, Matcher m) { - Optional bibEntry = getBibEntry(row); - - if (bibEntry.isPresent()) { - return m.matches(bibEntry.get()); - } - return m.matches(null); + return getBibEntry(row).map(m::matches).orElse(false); } private boolean isComplete(int row) { From 190a5cd52e274493e046c9983a03d7422134a365 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 20 Oct 2017 16:35:07 +0800 Subject: [PATCH 3/3] Small fix in drag and drop handler of linked files (#3328) --- src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index 7bb10d7b38a..2f47c572b52 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -86,6 +86,7 @@ private void setUpFilesDragAndDrop() { if (dragboard.hasFiles()) { List linkedFiles = dragboard.getFiles().stream().map(File::toPath).map(viewModel::fromFile).collect(Collectors.toList()); items.addAll(linkedFiles); + success = true; } event.setDropCompleted(success); event.consume();