diff --git a/src/main/java/net/sf/jabref/bibtex/BibtexSingleField.java b/src/main/java/net/sf/jabref/bibtex/BibtexSingleField.java new file mode 100644 index 00000000000..39509e0c569 --- /dev/null +++ b/src/main/java/net/sf/jabref/bibtex/BibtexSingleField.java @@ -0,0 +1,167 @@ +package net.sf.jabref.bibtex; + +import java.util.EnumSet; +import java.util.Set; + +/** + * + * 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; + + + private enum Flag { + STANDARD, + PRIVATE, + DISPLAYABLE, + WRITEABLE; + } + + + // the field name + private final String name; + + // contains the standard, private, displayable, writable infos + // 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; + + // the extras data + // fieldExtras contains mappings to tell the EntryEditor to add a specific + // function to this field, for instance a "browse" button for the "pdf" field. + private Set extras = EnumSet.noneOf(BibtexSingleFieldProperties.class); + + // a comma separated list of alternative bibtex-fieldnames, e.g. + // "LCCN" is the same like "lib-congress" + // 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; + } + + public BibtexSingleField(String fieldName, boolean pStandard, int pLength) { + name = fieldName; + setFlag(pStandard, Flag.STANDARD); + 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 + * @param flagID, the id of the flag + */ + private void setFlag(boolean setToOn, Flag flagID) { + if (setToOn) { + // set the flag + flags.add(flagID); + } else { + // unset the flag + flags.remove(flagID); + } + } + + public boolean isStandard() { + return flags.contains(Flag.STANDARD); + } + + public void setPrivate() { + flags.add(Flag.PRIVATE); + } + + public boolean isPrivate() { + return flags.contains(Flag.PRIVATE); + } + + public void setDisplayable(boolean value) { + setFlag(value, Flag.DISPLAYABLE); + } + + public boolean isDisplayable() { + return flags.contains(Flag.DISPLAYABLE); + } + + public void setWriteable(boolean value) { + setFlag(value, Flag.WRITEABLE); + } + + public boolean isWriteable() { + return flags.contains(Flag.WRITEABLE); + } + + public void setExtras(Set pExtras) { + extras = pExtras; + } + + // 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 getExtras() { + return extras; + } + + 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 + */ + public int getLength() { + return this.length; + } + + public String getFieldName() { + return name; + } + + /** + * Set this field's numeric property + * + * @param numeric true to indicate that this is a numeric field. + * @return this BibtexSingleField instance. Makes it easier to call this + * method on the fly while initializing without using a local variable. + */ + public BibtexSingleField setNumeric(boolean numeric) { + if (numeric) { + extras.add(BibtexSingleFieldProperties.NUMERIC); + } else { + extras.remove(BibtexSingleFieldProperties.NUMERIC); + } + return this; + } + + public boolean isNumeric() { + return extras.contains(BibtexSingleFieldProperties.NUMERIC); + } + +} diff --git a/src/main/java/net/sf/jabref/bibtex/BibtexSingleFieldProperties.java b/src/main/java/net/sf/jabref/bibtex/BibtexSingleFieldProperties.java new file mode 100644 index 00000000000..642d1d6e8ee --- /dev/null +++ b/src/main/java/net/sf/jabref/bibtex/BibtexSingleFieldProperties.java @@ -0,0 +1,20 @@ +package net.sf.jabref.bibtex; + +import java.util.EnumSet; + +public enum BibtexSingleFieldProperties { + YES_NO, + URL, + DATEPICKER, + JOURNAL_NAMES, + EXTERNAL, + BROWSE, + SET_OWNER, + MONTH, + FILE_EDITOR, + NUMERIC; + + public static final EnumSet ALL_OPTS = EnumSet + .allOf(BibtexSingleFieldProperties.class); + +} diff --git a/src/main/java/net/sf/jabref/gui/FieldWeightDialog.java b/src/main/java/net/sf/jabref/gui/FieldWeightDialog.java index bb8c5e03461..47e9baff10d 100644 --- a/src/main/java/net/sf/jabref/gui/FieldWeightDialog.java +++ b/src/main/java/net/sf/jabref/gui/FieldWeightDialog.java @@ -28,6 +28,7 @@ import com.jgoodies.forms.builder.DefaultFormBuilder; import com.jgoodies.forms.layout.FormLayout; +import net.sf.jabref.bibtex.BibtexSingleField; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.entry.BibEntry; @@ -77,8 +78,8 @@ private JPanel buildMainPanel() { for (String field : fields) { builder.append(field); - int weight = (int) ((100 * InternalBibtexFields.getFieldWeight(field)) / GUIGlobals.MAX_FIELD_WEIGHT); - //System.out.println(weight); + int weight = (int) ((100 * InternalBibtexFields.getFieldWeight(field)) + / BibtexSingleField.MAX_FIELD_WEIGHT); JSlider slider = new JSlider(0, 100, weight);//,); sliders.put(slider, new SliderInfo(field, weight)); builder.append(slider); @@ -120,7 +121,7 @@ private void storeSettings() { SliderInfo sInfo = sliders.get(slider); // Only list the value if it has changed: if (sInfo.originalValue != slider.getValue()) { - double weight = (GUIGlobals.MAX_FIELD_WEIGHT * slider.getValue()) / 100d; + double weight = (BibtexSingleField.MAX_FIELD_WEIGHT * slider.getValue()) / 100d; InternalBibtexFields.setFieldWeight(sInfo.fieldName, weight); } } diff --git a/src/main/java/net/sf/jabref/gui/GUIGlobals.java b/src/main/java/net/sf/jabref/gui/GUIGlobals.java index 001fe8869f2..05f9b9b0d6f 100644 --- a/src/main/java/net/sf/jabref/gui/GUIGlobals.java +++ b/src/main/java/net/sf/jabref/gui/GUIGlobals.java @@ -92,20 +92,9 @@ public class GUIGlobals { public static Color activeBackground; public static Color invalidFieldBackgroundColor; - // some fieldname constants - public static final double DEFAULT_FIELD_WEIGHT = 1; - public static final double MAX_FIELD_WEIGHT = 2; - - // constants for editor types: - public static final int STANDARD_EDITOR = 1; - public static final int FILE_LIST_EDITOR = 2; public static final int MAX_BACK_HISTORY_SIZE = 10; // The maximum number of "Back" operations stored. - 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 double PE_HEIGHT = 2; // Size constants for EntryTypeForm; small, medium and large. @@ -116,7 +105,6 @@ public class GUIGlobals { public static final int INDENT = 4; public static final int LINE_LENGTH = 65; // Maximum - public static final int DEFAULT_FIELD_LENGTH = 100; public static final int NUMBER_COL_LENGTH = 32; public static final int WIDTH_ICON_COL_RANKING = 80; // Width of Ranking Icon Column diff --git a/src/main/java/net/sf/jabref/gui/InternalBibtexFields.java b/src/main/java/net/sf/jabref/gui/InternalBibtexFields.java index 98267e2a983..2d975257057 100644 --- a/src/main/java/net/sf/jabref/gui/InternalBibtexFields.java +++ b/src/main/java/net/sf/jabref/gui/InternalBibtexFields.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2003-2015 Raik Nagel and JabRef contributors +/* Copyright (C) 2003-2016 Raik Nagel and JabRef contributors This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -31,15 +31,20 @@ package net.sf.jabref.gui; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.Optional; import java.util.Set; import net.sf.jabref.Globals; import net.sf.jabref.JabRefPreferences; +import net.sf.jabref.bibtex.BibtexSingleField; +import net.sf.jabref.bibtex.BibtexSingleFieldProperties; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.IEEETranEntryTypes; import net.sf.jabref.specialfields.SpecialFieldsUtils; @@ -51,16 +56,8 @@ public class InternalBibtexFields { public static final String GROUPSEARCH = "__groupsearch"; public static final String MARKED = "__markedentry"; public static final String OWNER = "owner"; - public static final String TIMESTAMP = "timestamp"; // it's also definied at the JabRefPreferences class + public static final String TIMESTAMP = "timestamp"; private static final String ENTRYTYPE = "entrytype"; - public static final String EXTRA_YES_NO = "yesNo"; // Blank/Yes/No Combo-box - public static final String EXTRA_URL = "url"; // Drop target for URL - public static final String EXTRA_DATEPICKER = "datepicker"; // Calendar button and double-click in field to set current date - public static final String EXTRA_JOURNAL_NAMES = "journalNames"; // Journal abbreviation button - public static final String EXTRA_EXTERNAL = "external"; // Open external viewer on double-click - public static final String EXTRA_BROWSE = "browse"; // Browse button, file dialog - public static final String EXTRA_SET_OWNER = "setOwner"; // Button to set owner to current used - public static final String EXTRA_MONTH = "month"; // Button to show the months and set abbreviation public static final String[] DEFAULT_INSPECTION_FIELDS = new String[] {"author", "title", "year", BibEntry.KEY_FIELD}; @@ -72,7 +69,7 @@ public class InternalBibtexFields { private final Map fieldSet; // contains all known (and public) bibtex fieldnames - private final String[] PUBLIC_FIELDS; + private final List PUBLIC_FIELDS = new ArrayList<>(); private InternalBibtexFields() { @@ -82,43 +79,43 @@ private InternalBibtexFields() { // FIRST: all standard fields // These are the fields that BibTex might want to treat, so these // must conform to BibTex rules. - add(new BibtexSingleField("address", true, GUIGlobals.SMALL_W)); + add(new BibtexSingleField("address", true, BibtexSingleField.SMALL_W)); // 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("annote", true, GUIGlobals.LARGE_W)); - add(new BibtexSingleField("author", true, GUIGlobals.MEDIUM_W, 280)); + add(new BibtexSingleField("annote", true, BibtexSingleField.LARGE_W)); + add(new BibtexSingleField("author", true, BibtexSingleField.MEDIUM_W, 280)); add(new BibtexSingleField("booktitle", true, 175)); - add(new BibtexSingleField("chapter", true, GUIGlobals.SMALL_W)); - add(new BibtexSingleField("crossref", true, GUIGlobals.SMALL_W)); - add(new BibtexSingleField("edition", true, GUIGlobals.SMALL_W)); - add(new BibtexSingleField("editor", true, GUIGlobals.MEDIUM_W, 280)); - add(new BibtexSingleField("howpublished", true, GUIGlobals.MEDIUM_W)); - add(new BibtexSingleField("institution", true, GUIGlobals.MEDIUM_W)); - - dummy = new BibtexSingleField("journal", true, GUIGlobals.SMALL_W); - dummy.setExtras(EXTRA_JOURNAL_NAMES); + add(new BibtexSingleField("chapter", true, BibtexSingleField.SMALL_W)); + add(new BibtexSingleField("crossref", true, BibtexSingleField.SMALL_W)); + add(new BibtexSingleField("edition", true, BibtexSingleField.SMALL_W)); + add(new BibtexSingleField("editor", true, BibtexSingleField.MEDIUM_W, 280)); + add(new BibtexSingleField("howpublished", true, BibtexSingleField.MEDIUM_W)); + add(new BibtexSingleField("institution", true, BibtexSingleField.MEDIUM_W)); + + dummy = new BibtexSingleField("journal", true, BibtexSingleField.SMALL_W); + dummy.setExtras(EnumSet.of(BibtexSingleFieldProperties.JOURNAL_NAMES)); add(dummy); - dummy = new BibtexSingleField("journaltitle", true, GUIGlobals.SMALL_W); - dummy.setExtras(EXTRA_JOURNAL_NAMES); + dummy = new BibtexSingleField("journaltitle", true, BibtexSingleField.SMALL_W); + dummy.setExtras(EnumSet.of(BibtexSingleFieldProperties.JOURNAL_NAMES)); add(dummy); add(new BibtexSingleField("key", true)); - dummy = new BibtexSingleField("month", true, GUIGlobals.SMALL_W); - dummy.setExtras(EXTRA_MONTH); + dummy = new BibtexSingleField("month", true, BibtexSingleField.SMALL_W); + dummy.setExtras(EnumSet.of(BibtexSingleFieldProperties.MONTH)); add(dummy); - add(new BibtexSingleField("note", true, GUIGlobals.MEDIUM_W)); - add(new BibtexSingleField("number", true, GUIGlobals.SMALL_W, 60).setNumeric(true)); - add(new BibtexSingleField("organization", true, GUIGlobals.MEDIUM_W)); - add(new BibtexSingleField("pages", true, GUIGlobals.SMALL_W)); - add(new BibtexSingleField("publisher", true, GUIGlobals.MEDIUM_W)); - add(new BibtexSingleField("school", true, GUIGlobals.MEDIUM_W)); - add(new BibtexSingleField("series", true, GUIGlobals.SMALL_W)); + add(new BibtexSingleField("note", true, BibtexSingleField.MEDIUM_W)); + add(new BibtexSingleField("number", true, BibtexSingleField.SMALL_W, 60).setNumeric(true)); + add(new BibtexSingleField("organization", true, BibtexSingleField.MEDIUM_W)); + add(new BibtexSingleField("pages", true, BibtexSingleField.SMALL_W)); + add(new BibtexSingleField("publisher", true, BibtexSingleField.MEDIUM_W)); + add(new BibtexSingleField("school", true, BibtexSingleField.MEDIUM_W)); + add(new BibtexSingleField("series", true, BibtexSingleField.SMALL_W)); add(new BibtexSingleField("title", true, 400)); - add(new BibtexSingleField("type", true, GUIGlobals.SMALL_W)); - add(new BibtexSingleField("language", true, GUIGlobals.SMALL_W)); - add(new BibtexSingleField("volume", true, GUIGlobals.SMALL_W, 60).setNumeric(true)); - add(new BibtexSingleField("year", true, GUIGlobals.SMALL_W, 60).setNumeric(true)); + add(new BibtexSingleField("type", true, BibtexSingleField.SMALL_W)); + add(new BibtexSingleField("language", true, BibtexSingleField.SMALL_W)); + add(new BibtexSingleField("volume", true, BibtexSingleField.SMALL_W, 60).setNumeric(true)); + add(new BibtexSingleField("year", true, BibtexSingleField.SMALL_W, 60).setNumeric(true)); // custom fields not displayed at editor, but as columns in the UI dummy = new BibtexSingleField(SpecialFieldsUtils.FIELDNAME_RANKING, false); @@ -169,31 +166,30 @@ private InternalBibtexFields() { dummy.setPrivate(); add(dummy); - dummy = new BibtexSingleField("doi", true, GUIGlobals.SMALL_W); - dummy.setExtras(EXTRA_EXTERNAL); + dummy = new BibtexSingleField("doi", true, BibtexSingleField.SMALL_W); + dummy.setExtras(EnumSet.of(BibtexSingleFieldProperties.EXTERNAL)); add(dummy); - add(new BibtexSingleField("eid", true, GUIGlobals.SMALL_W)); + add(new BibtexSingleField("eid", true, BibtexSingleField.SMALL_W)); dummy = new BibtexSingleField("date", true); dummy.setPrivate(); add(dummy); - add(new BibtexSingleField("pmid", false, GUIGlobals.SMALL_W, 60).setNumeric(true)); + add(new BibtexSingleField("pmid", false, BibtexSingleField.SMALL_W, 60).setNumeric(true)); // additional fields ------------------------------------------------------ add(new BibtexSingleField("location", false)); - add(new BibtexSingleField("abstract", false, GUIGlobals.LARGE_W, 400)); + add(new BibtexSingleField("abstract", false, BibtexSingleField.LARGE_W, 400)); - dummy = new BibtexSingleField("url", false, GUIGlobals.SMALL_W); - dummy.setExtras(EXTRA_EXTERNAL); + dummy = new BibtexSingleField("url", false, BibtexSingleField.SMALL_W); + dummy.setExtras(EnumSet.of(BibtexSingleFieldProperties.EXTERNAL)); add(dummy); - add(new BibtexSingleField("comment", false, GUIGlobals.MEDIUM_W)); - add(new BibtexSingleField("keywords", false, GUIGlobals.SMALL_W)); - //FIELD_EXTRAS.put("keywords", "selector"); + add(new BibtexSingleField("comment", false, BibtexSingleField.MEDIUM_W)); + add(new BibtexSingleField("keywords", false, BibtexSingleField.SMALL_W)); dummy = new BibtexSingleField(Globals.FILE_FIELD, false); - dummy.setEditorType(GUIGlobals.FILE_LIST_EDITOR); + dummy.setExtras(EnumSet.of(BibtexSingleFieldProperties.FILE_EDITOR)); add(dummy); add(new BibtexSingleField("search", false, 75)); @@ -205,13 +201,13 @@ private InternalBibtexFields() { dummy.setDisplayable(false); add(dummy); - dummy = new BibtexSingleField(InternalBibtexFields.OWNER, false, GUIGlobals.SMALL_W); - dummy.setExtras(EXTRA_SET_OWNER); + dummy = new BibtexSingleField(InternalBibtexFields.OWNER, false, BibtexSingleField.SMALL_W); + dummy.setExtras(EnumSet.of(BibtexSingleFieldProperties.SET_OWNER)); dummy.setPrivate(); add(dummy); - dummy = new BibtexSingleField(InternalBibtexFields.TIMESTAMP, false, GUIGlobals.SMALL_W); - dummy.setExtras(EXTRA_DATEPICKER); + dummy = new BibtexSingleField(InternalBibtexFields.TIMESTAMP, false, BibtexSingleField.SMALL_W); + dummy.setExtras(EnumSet.of(BibtexSingleFieldProperties.DATEPICKER)); dummy.setPrivate(); add(dummy); @@ -240,7 +236,7 @@ private InternalBibtexFields() { // IEEEtranBSTCTL fields for (String yesNoField : IEEETranEntryTypes.IEEETRANBSTCTL_YES_NO_FIELDS) { dummy = new BibtexSingleField(yesNoField, false); - dummy.setExtras(EXTRA_YES_NO); + dummy.setExtras(EnumSet.of(BibtexSingleFieldProperties.YES_NO)); add(dummy); } @@ -249,18 +245,16 @@ private InternalBibtexFields() { } // collect all public fields for the PUBLIC_FIELDS array - List pFields = new ArrayList<>(fieldSet.size()); for (BibtexSingleField sField : fieldSet.values()) { if (!sField.isPrivate()) { - pFields.add(sField.getFieldName()); + PUBLIC_FIELDS.add(sField.getFieldName()); // or export the complete BibtexSingleField ? // BibtexSingleField.toString() { return fieldname ; } } } - PUBLIC_FIELDS = pFields.toArray(new String[pFields.size()]); // sort the entries - Arrays.sort(PUBLIC_FIELDS); + Collections.sort(PUBLIC_FIELDS); } /** @@ -298,68 +292,60 @@ public static void setNumericFieldsFromPrefs() { */ private void add(BibtexSingleField field) { // field == null check - String key = field.name; + String key = field.getFieldName(); fieldSet.put(key, field); } // -------------------------------------------------------------------------- // the "static area" // -------------------------------------------------------------------------- - private static BibtexSingleField getField(String name) { + private static Optional getField(String name) { if (name != null) { - return InternalBibtexFields.RUNTIME.fieldSet.get(name.toLowerCase()); + return Optional.ofNullable(InternalBibtexFields.RUNTIME.fieldSet.get(name.toLowerCase(Locale.ENGLISH))); } - return null; + return Optional.empty(); } - public static String getFieldExtras(String name) { - BibtexSingleField sField = InternalBibtexFields.getField(name); - if (sField != null) { - return sField.getExtras(); + public static Set getFieldExtras(String name) { + Optional sField = InternalBibtexFields.getField(name); + if (sField.isPresent()) { + return sField.get().getExtras(); } - return null; - } - - public static int getEditorType(String name) { - BibtexSingleField sField = InternalBibtexFields.getField(name); - if (sField != null) { - return sField.getEditorType(); - } - return GUIGlobals.STANDARD_EDITOR; + return EnumSet.noneOf(BibtexSingleFieldProperties.class); } public static double getFieldWeight(String name) { - BibtexSingleField sField = InternalBibtexFields.getField(name); - if (sField != null) { - return sField.getWeight(); + Optional sField = InternalBibtexFields.getField(name); + if (sField.isPresent()) { + return sField.get().getWeight(); } - return GUIGlobals.DEFAULT_FIELD_WEIGHT; + return BibtexSingleField.DEFAULT_FIELD_WEIGHT; } public static void setFieldWeight(String fieldName, double weight) { - BibtexSingleField sField = InternalBibtexFields.getField(fieldName); - if (sField != null) { - sField.setWeight(weight); + Optional sField = InternalBibtexFields.getField(fieldName); + if (sField.isPresent()) { + sField.get().setWeight(weight); } } public static int getFieldLength(String name) { - BibtexSingleField sField = InternalBibtexFields.getField(name); - if (sField != null) { - return sField.getLength(); + Optional sField = InternalBibtexFields.getField(name); + if (sField.isPresent()) { + return sField.get().getLength(); } - return GUIGlobals.DEFAULT_FIELD_LENGTH; + return BibtexSingleField.DEFAULT_FIELD_LENGTH; } public static boolean isWriteableField(String field) { - BibtexSingleField sField = InternalBibtexFields.getField(field); - return (sField == null) || sField.isWriteable(); + Optional sField = InternalBibtexFields.getField(field); + return !sField.isPresent() || sField.get().isWriteable(); } public static boolean isDisplayableField(String field) { - BibtexSingleField sField = InternalBibtexFields.getField(field); - return (sField == null) || sField.isDisplayable(); + Optional sField = InternalBibtexFields.getField(field); + return !sField.isPresent() || sField.get().isDisplayable(); } /** @@ -369,20 +355,20 @@ public static boolean isDisplayableField(String field) { * @return a boolean value */ public static boolean isStandardField(String field) { - BibtexSingleField sField = InternalBibtexFields.getField(field); - return (sField != null) && sField.isStandard(); + Optional sField = InternalBibtexFields.getField(field); + return sField.isPresent() && sField.get().isStandard(); } public static boolean isNumeric(String field) { - BibtexSingleField sField = InternalBibtexFields.getField(field); - return (sField != null) && sField.isNumeric(); + Optional sField = InternalBibtexFields.getField(field); + return sField.isPresent() && sField.get().isNumeric(); } /** * returns a List with all fieldnames */ public static List getAllFieldNames() { - return Arrays.asList(InternalBibtexFields.RUNTIME.PUBLIC_FIELDS); + return new ArrayList<>(InternalBibtexFields.RUNTIME.PUBLIC_FIELDS); } /** @@ -403,14 +389,14 @@ public static List getAllPrivateFieldNames() { * returns the fieldname of the entry at index t */ public static String getFieldName(int t) { - return InternalBibtexFields.RUNTIME.PUBLIC_FIELDS[t]; + return InternalBibtexFields.RUNTIME.PUBLIC_FIELDS.get(t); } /** * returns the number of available fields */ public static int numberOfPublicFields() { - return InternalBibtexFields.RUNTIME.PUBLIC_FIELDS.length; + return InternalBibtexFields.RUNTIME.PUBLIC_FIELDS.size(); } @@ -423,181 +409,4 @@ public static int getPreferredFieldLength(String name) { return l; }*/ - // -------------------------------------------------------------------------- - // a container class for all properties of a bibtex-field - // -------------------------------------------------------------------------- - private static class BibtexSingleField { - - private static final int STANDARD = 0x01; // it is a standard bibtex-field - private static final int PRIVATE = 0x02; // internal use, e.g. owner, timestamp - private static final int DISPLAYABLE = 0x04; // These fields cannot be shown inside the source editor panel - private static final int WRITEABLE = 0x08; // These fields will not be saved to the .bib file. - - // the fieldname - private final String name; - - // contains the standard, private, displayable, writable infos - // default is: not standard, public, displayable and writable - private int flag = BibtexSingleField.DISPLAYABLE | BibtexSingleField.WRITEABLE; - - private int length = GUIGlobals.DEFAULT_FIELD_LENGTH; - private double weight = GUIGlobals.DEFAULT_FIELD_WEIGHT; - - private int editorType = GUIGlobals.STANDARD_EDITOR; - - - // the extras data - // fieldExtras contains mappings to tell the EntryEditor to add a specific - // function to this field, for instance a "browse" button for the "pdf" field. - private String extras; - - // This value defines whether contents of this field are expected to be - // numeric values. This can be used to sort e.g. volume numbers correctly: - private boolean numeric; - - - // a comma separated list of alternative bibtex-fieldnames, e.g. - // "LCCN" is the same like "lib-congress" - // private String otherNames = null ; - - // a Hashmap for a lot of additional "not standard" properties - // todo: add the handling in a key=value manner - // private HashMap props = new HashMap() ; - - public BibtexSingleField(String fieldName, boolean pStandard) { - name = fieldName; - setFlag(pStandard, BibtexSingleField.STANDARD); - } - - public BibtexSingleField(String fieldName, boolean pStandard, double pWeight) { - name = fieldName; - setFlag(pStandard, BibtexSingleField.STANDARD); - weight = pWeight; - } - - public BibtexSingleField(String fieldName, boolean pStandard, int pLength) { - name = fieldName; - setFlag(pStandard, BibtexSingleField.STANDARD); - length = pLength; - } - - public BibtexSingleField(String fieldName, boolean pStandard, - double pWeight, int pLength) { - name = fieldName; - setFlag(pStandard, BibtexSingleField.STANDARD); - weight = pWeight; - length = pLength; - } - - // ----------------------------------------------------------------------- - // ----------------------------------------------------------------------- - - /** - * Sets or onsets the given flag - * @param setToOn if true, set the flag; if false, unset the flat - * @param flagID, the id of the flag - */ - private void setFlag(boolean setToOn, int flagID) { - if (setToOn) { - // set the flag - flag = flag | flagID; - } else { - // unset the flag - flag = flag & (0xff ^ flagID); - } - } - - private boolean isSet(int flagID) { - return (flag & flagID) == flagID; - } - - // ----------------------------------------------------------------------- - public boolean isStandard() { - return isSet(BibtexSingleField.STANDARD); - } - - public void setPrivate() { - flag = flag | BibtexSingleField.PRIVATE; - } - - public boolean isPrivate() { - return isSet(BibtexSingleField.PRIVATE); - } - - public void setDisplayable(boolean value) { - setFlag(value, BibtexSingleField.DISPLAYABLE); - } - - public boolean isDisplayable() { - return isSet(BibtexSingleField.DISPLAYABLE); - } - - public void setWriteable(boolean value) { - setFlag(value, BibtexSingleField.WRITEABLE); - } - - public boolean isWriteable() { - return isSet(BibtexSingleField.WRITEABLE); - } - - // ----------------------------------------------------------------------- - - public void setExtras(String pExtras) { - extras = pExtras; - } - - // 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 String getExtras() { - return extras; - } - - public void setEditorType(int type) { - editorType = type; - } - - public int getEditorType() { - return editorType; - } - - // ----------------------------------------------------------------------- - - 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 - */ - public int getLength() { - return this.length; - } - - // ----------------------------------------------------------------------- - - public String getFieldName() { - return name; - } - - /** - * Set this field's numeric property - * - * @param numeric true to indicate that this is a numeric field. - * @return this BibtexSingleField instance. Makes it easier to call this - * method on the fly while initializing without using a local variable. - */ - public BibtexSingleField setNumeric(boolean numeric) { - this.numeric = numeric; - return this; - } - - public boolean isNumeric() { - return numeric; - } - - } } diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java index e6d4ac88c77..a4e106d5d7e 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java @@ -43,6 +43,7 @@ import javax.swing.text.JTextComponent; import net.sf.jabref.*; import net.sf.jabref.bibtex.BibEntryWriter; +import net.sf.jabref.bibtex.BibtexSingleFieldProperties; import net.sf.jabref.model.EntryTypes; import net.sf.jabref.gui.actions.Actions; import net.sf.jabref.gui.fieldeditors.*; @@ -449,18 +450,18 @@ public void rebuildPanels() { public Optional getExtra(final FieldEditor editor) { final String fieldName = editor.getFieldName(); - final String fieldExtras = InternalBibtexFields.getFieldExtras(fieldName); + final Set fieldExtras = InternalBibtexFields.getFieldExtras(fieldName); // timestamp or a other field with datepicker command if (Globals.prefs.get(JabRefPreferences.TIME_STAMP_FIELD).equals(fieldName) - || InternalBibtexFields.EXTRA_DATEPICKER.equals(fieldExtras)) { + || fieldExtras.contains(BibtexSingleFieldProperties.DATEPICKER)) { // double click AND datefield => insert the current date (today) return FieldExtraComponents.getDateTimeExtraComponent(editor, - InternalBibtexFields.EXTRA_DATEPICKER.equals(fieldExtras)); - } else if (InternalBibtexFields.EXTRA_EXTERNAL.equals(fieldExtras)) { + fieldExtras.contains(BibtexSingleFieldProperties.DATEPICKER)); + } else if (fieldExtras.contains(BibtexSingleFieldProperties.EXTERNAL)) { // Add external viewer listener for "pdf" and "url" fields. return FieldExtraComponents.getExternalExtraComponent(editor, this); - } else if (InternalBibtexFields.EXTRA_JOURNAL_NAMES.equals(fieldExtras)) { + } else if (fieldExtras.contains(BibtexSingleFieldProperties.JOURNAL_NAMES)) { // Add controls for switching between abbreviated and full journal names. // If this field also has a FieldContentSelector, we need to combine these. return FieldExtraComponents.getJournalExtraComponent(frame, panel, editor, entry, contentSelectors, @@ -468,15 +469,15 @@ public Optional getExtra(final FieldEditor editor) { } else if (panel.getBibDatabaseContext().getMetaData().getData(Globals.SELECTOR_META_PREFIX + fieldName) != null) { return FieldExtraComponents.getSelectorExtraComponent(frame, panel, editor, contentSelectors, getStoreFieldAction()); - } else if (InternalBibtexFields.EXTRA_BROWSE.equals(fieldExtras)) { + } else if (fieldExtras.contains(BibtexSingleFieldProperties.BROWSE)) { return FieldExtraComponents.getBrowseExtraComponent(frame, editor, this); - } else if (InternalBibtexFields.EXTRA_URL.equals(fieldExtras)) { + } else if (fieldExtras.contains(BibtexSingleFieldProperties.URL)) { return FieldExtraComponents.getURLExtraComponent(editor, getStoreFieldAction()); - } else if (InternalBibtexFields.EXTRA_SET_OWNER.equals(fieldExtras)) { + } else if (fieldExtras.contains(BibtexSingleFieldProperties.SET_OWNER)) { return FieldExtraComponents.getSetOwnerExtraComponent(editor, getStoreFieldAction()); - } else if (InternalBibtexFields.EXTRA_YES_NO.equals(fieldExtras)) { + } else if (fieldExtras.contains(BibtexSingleFieldProperties.YES_NO)) { return FieldExtraComponents.getYesNoExtraComponent(editor, this); - } else if (InternalBibtexFields.EXTRA_MONTH.equals(fieldExtras)) { + } else if (fieldExtras.contains(BibtexSingleFieldProperties.MONTH)) { return FieldExtraComponents.getMonthExtraComponent(editor, this, this.frame.getCurrentBasePanel().getBibDatabaseContext().getMode()); } return Optional.empty(); diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditorTab.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditorTab.java index dad3793145a..aceadb36304 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditorTab.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditorTab.java @@ -33,6 +33,7 @@ import javax.swing.text.JTextComponent; import net.sf.jabref.*; +import net.sf.jabref.bibtex.BibtexSingleFieldProperties; import net.sf.jabref.gui.*; import net.sf.jabref.gui.autocompleter.AutoCompleteListener; import net.sf.jabref.gui.fieldeditors.FieldEditor; @@ -137,13 +138,10 @@ private void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField for (int i = 0; i < fields.size(); i++) { String field = fields.get(i); - // Create the text area: - int editorType = InternalBibtexFields.getEditorType(field); - FieldEditor fieldEditor; int defaultHeight; int wHeight = (int) (50.0 * InternalBibtexFields.getFieldWeight(field)); - if (editorType == GUIGlobals.FILE_LIST_EDITOR) { + if (InternalBibtexFields.getFieldExtras(field).contains(BibtexSingleFieldProperties.FILE_EDITOR)) { fieldEditor = new FileListEditor(frame, bPanel.getBibDatabaseContext().getMetaData(), field, null, parent); fileListEditor = (FileListEditor) fieldEditor; diff --git a/src/main/java/net/sf/jabref/gui/maintable/MainTable.java b/src/main/java/net/sf/jabref/gui/maintable/MainTable.java index ad4bfb2a4c6..e489f2f3aee 100644 --- a/src/main/java/net/sf/jabref/gui/maintable/MainTable.java +++ b/src/main/java/net/sf/jabref/gui/maintable/MainTable.java @@ -47,6 +47,7 @@ import net.sf.jabref.gui.util.comparator.IsMarkedComparator; import net.sf.jabref.gui.util.comparator.RankingFieldComparator; import net.sf.jabref.model.EntryTypes; +import net.sf.jabref.bibtex.BibtexSingleField; import net.sf.jabref.bibtex.comparator.FieldComparator; import net.sf.jabref.gui.search.matchers.SearchMatcher; import net.sf.jabref.model.entry.BibEntry; @@ -413,7 +414,7 @@ private void setWidths() { cm.getColumn(i).setPreferredWidth(Integer.parseInt(widthsFromPreferences.get(j))); } catch (NumberFormatException e) { LOGGER.info("Exception while setting column widths. Choosing default.", e); - cm.getColumn(i).setPreferredWidth(GUIGlobals.DEFAULT_FIELD_LENGTH); + cm.getColumn(i).setPreferredWidth(BibtexSingleField.DEFAULT_FIELD_LENGTH); } break; } diff --git a/src/main/java/net/sf/jabref/gui/preftabs/TableColumnsTab.java b/src/main/java/net/sf/jabref/gui/preftabs/TableColumnsTab.java index ad6a4734b56..8cff5995250 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/TableColumnsTab.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/TableColumnsTab.java @@ -19,6 +19,7 @@ import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; import net.sf.jabref.JabRefPreferences; +import net.sf.jabref.bibtex.BibtexSingleField; import net.sf.jabref.external.ExternalFileType; import net.sf.jabref.external.ExternalFileTypes; import net.sf.jabref.gui.*; @@ -91,14 +92,14 @@ static class TableRow { private int length; - public TableRow(String name) { - this.name = name; - length = GUIGlobals.DEFAULT_FIELD_LENGTH; + public TableRow() { + name = ""; + length = BibtexSingleField.DEFAULT_FIELD_LENGTH; } - public TableRow(int length) { - this.length = length; - name = ""; + public TableRow(String name) { + this.name = name; + length = BibtexSingleField.DEFAULT_FIELD_LENGTH; } public TableRow(String name, int length) { @@ -206,7 +207,7 @@ public void setValueAt(Object value, int row, int col) { if (col == 0) { rowContent.setName(value.toString()); if ("".equals(getValueAt(row, 1))) { - setValueAt(String.valueOf(GUIGlobals.DEFAULT_FIELD_LENGTH), row, 1); + setValueAt(String.valueOf(BibtexSingleField.DEFAULT_FIELD_LENGTH), row, 1); } } else { @@ -490,7 +491,7 @@ public void actionPerformed(ActionEvent e) { } for (int i = 0; i < rows.length; i++) { if (((rows[i] + i) - 1) < tableRows.size()) { - tableRows.add(Math.max(0, (rows[i] + i) - 1), new TableRow(GUIGlobals.DEFAULT_FIELD_LENGTH)); + tableRows.add(Math.max(0, (rows[i] + i) - 1), new TableRow()); } } rowCount += rows.length;