Skip to content

Commit

Permalink
Fixed comments (and a few other things)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Mar 17, 2016
1 parent 97b58db commit fc69e3a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 66 deletions.
40 changes: 17 additions & 23 deletions src/main/java/net/sf/jabref/bibtex/BibtexSingleField.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@
import java.util.EnumSet;
import java.util.Set;

import net.sf.jabref.gui.GUIGlobals;

// --------------------------------------------------------------------------
// a container class for all properties of a bibtex-field
// --------------------------------------------------------------------------
/**
*
* Class for keeping properties of a single BibTeX/BibLatex field
*
*/
public class BibtexSingleField {

// some fieldname constants
// 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,
Expand All @@ -32,9 +34,9 @@ private enum Flag {

// contains the standard, private, displayable, writable infos
// default is: not standard, public, displayable and writable
private final Set<Flag> flag = EnumSet.of(Flag.DISPLAYABLE, Flag.WRITEABLE);
private final Set<Flag> flags = EnumSet.of(Flag.DISPLAYABLE, Flag.WRITEABLE);

private int length = GUIGlobals.DEFAULT_FIELD_LENGTH;
private int length = DEFAULT_FIELD_LENGTH;
private double weight = DEFAULT_FIELD_WEIGHT;

// the extras data
Expand All @@ -46,11 +48,6 @@ private enum Flag {
// "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, Flag.STANDARD);
Expand All @@ -75,9 +72,6 @@ public BibtexSingleField(String fieldName, boolean pStandard, double pWeight, in
length = pLength;
}

// -----------------------------------------------------------------------
// -----------------------------------------------------------------------

/**
* Sets or onsets the given flag
* @param setToOn if true, set the flag; if false, unset the flat
Expand All @@ -86,40 +80,40 @@ public BibtexSingleField(String fieldName, boolean pStandard, double pWeight, in
private void setFlag(boolean setToOn, Flag flagID) {
if (setToOn) {
// set the flag
flag.add(flagID);
flags.add(flagID);
} else {
// unset the flag
flag.remove(flagID);
flags.remove(flagID);
}
}

// -----------------------------------------------------------------------
public boolean isStandard() {
return flag.contains(Flag.STANDARD);
return flags.contains(Flag.STANDARD);
}

public void setPrivate() {
flag.add(Flag.PRIVATE);
flags.add(Flag.PRIVATE);
}

public boolean isPrivate() {
return flag.contains(Flag.PRIVATE);
return flags.contains(Flag.PRIVATE);
}

public void setDisplayable(boolean value) {
setFlag(value, Flag.DISPLAYABLE);
}

public boolean isDisplayable() {
return flag.contains(Flag.DISPLAYABLE);
return flags.contains(Flag.DISPLAYABLE);
}

public void setWriteable(boolean value) {
setFlag(value, Flag.WRITEABLE);
}

public boolean isWriteable() {
return flag.contains(Flag.WRITEABLE);
return flags.contains(Flag.WRITEABLE);
}

// -----------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/sf/jabref/gui/GUIGlobals.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,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
Expand Down
66 changes: 33 additions & 33 deletions src/main/java/net/sf/jabref/gui/InternalBibtexFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
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;
Expand Down Expand Up @@ -67,7 +69,7 @@ public class InternalBibtexFields {
private final Map<String, BibtexSingleField> fieldSet;

// contains all known (and public) bibtex fieldnames
private final String[] PUBLIC_FIELDS;
private final List<String> PUBLIC_FIELDS = new ArrayList<>();


private InternalBibtexFields() {
Expand Down Expand Up @@ -243,18 +245,16 @@ private InternalBibtexFields() {
}

// collect all public fields for the PUBLIC_FIELDS array
List<String> 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);
}

/**
Expand Down Expand Up @@ -299,53 +299,53 @@ private void add(BibtexSingleField field) {
// --------------------------------------------------------------------------
// the "static area"
// --------------------------------------------------------------------------
private static BibtexSingleField getField(String name) {
private static Optional<BibtexSingleField> 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 Set<BibtexSingleFieldProperties> getFieldExtras(String name) {
BibtexSingleField sField = InternalBibtexFields.getField(name);
if (sField != null) {
return sField.getExtras();
Optional<BibtexSingleField> sField = InternalBibtexFields.getField(name);
if (sField.isPresent()) {
return sField.get().getExtras();
}
return EnumSet.noneOf(BibtexSingleFieldProperties.class);
}

public static double getFieldWeight(String name) {
BibtexSingleField sField = InternalBibtexFields.getField(name);
if (sField != null) {
return sField.getWeight();
Optional<BibtexSingleField> sField = InternalBibtexFields.getField(name);
if (sField.isPresent()) {
return sField.get().getWeight();
}
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<BibtexSingleField> 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<BibtexSingleField> 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<BibtexSingleField> 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<BibtexSingleField> sField = InternalBibtexFields.getField(field);
return !sField.isPresent() || sField.get().isDisplayable();
}

/**
Expand All @@ -355,20 +355,20 @@ public static boolean isDisplayableField(String field) {
* @return a <code>boolean</code> value
*/
public static boolean isStandardField(String field) {
BibtexSingleField sField = InternalBibtexFields.getField(field);
return (sField != null) && sField.isStandard();
Optional<BibtexSingleField> 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<BibtexSingleField> sField = InternalBibtexFields.getField(field);
return sField.isPresent() && sField.get().isNumeric();
}

/**
* returns a List with all fieldnames
*/
public static List<String> getAllFieldNames() {
return Arrays.asList(InternalBibtexFields.RUNTIME.PUBLIC_FIELDS);
return new ArrayList<>(InternalBibtexFields.RUNTIME.PUBLIC_FIELDS);
}

/**
Expand All @@ -389,14 +389,14 @@ public static List<String> 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();
}


Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/net/sf/jabref/gui/preftabs/TableColumnsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fc69e3a

Please sign in to comment.