Skip to content

Commit

Permalink
Merge branch 'master' into jdk-bug
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/net/sf/jabref/JabRef.java
  • Loading branch information
stefan-kolb committed Apr 6, 2016
2 parents 4ff9679 + 9c7b4ca commit a5541d3
Show file tree
Hide file tree
Showing 23 changed files with 665 additions and 541 deletions.
7 changes: 4 additions & 3 deletions src/main/java/net/sf/jabref/BibDatabaseContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ public BibDatabaseMode getMode() {

if (!mode.isPresent()) {
BibDatabaseMode inferredMode = BibDatabaseModeDetection.inferMode(database);
BibDatabaseMode newMode = BibDatabaseMode.BIBTEX;
if ((defaults.mode == BibDatabaseMode.BIBLATEX) || (inferredMode == BibDatabaseMode.BIBLATEX)) {
return BibDatabaseMode.BIBLATEX;
} else {
return BibDatabaseMode.BIBTEX;
newMode = BibDatabaseMode.BIBLATEX;
}
this.setMode(newMode);
return newMode;
}
return mode.get();
}
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/net/sf/jabref/JabRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ private void setLookAndFeel() {
} else {
lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
}

// FIXME: Open JDK problem
if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel) && !System.getProperty("java.runtime.name").contains("OpenJDK")) {
// try to avoid ending up with the ugly Metal L&F
Expand Down Expand Up @@ -571,21 +571,13 @@ private void setLookAndFeel() {
int fontSize = Globals.prefs.getInt(JabRefPreferences.MENU_FONT_SIZE);
UIDefaults defaults = UIManager.getDefaults();
Enumeration<Object> keys = defaults.keys();
Double zoomLevel = null;
for (Object key : Collections.list(keys)) {
if ((key instanceof String) && ((String) key).endsWith(".font")) {
FontUIResource font = (FontUIResource) UIManager.get(key);
if (zoomLevel == null) {
// zoomLevel not yet set, calculate it based on the first found font
zoomLevel = (double) fontSize / (double) font.getSize();
}
font = new FontUIResource(font.getName(), font.getStyle(), fontSize);
defaults.put(key, font);
}
}
if (zoomLevel != null) {
GUIGlobals.zoomLevel = zoomLevel;
}
}
}

Expand Down
158 changes: 64 additions & 94 deletions src/main/java/net/sf/jabref/bibtex/comparator/FieldComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,63 @@
*/
public class FieldComparator implements Comparator<BibEntry> {

private static Collator collator;
private static final Collator COLLATOR = getCollator();

static {
private static Collator getCollator() {
try {
FieldComparator.collator = new RuleBasedCollator(
return new RuleBasedCollator(
((RuleBasedCollator) Collator.getInstance()).getRules().replace("<'\u005f'", "<' '<'\u005f'"));
} catch (ParseException e) {
FieldComparator.collator = Collator.getInstance();
return Collator.getInstance();
}
}



enum FieldType {
NAME, TYPE, YEAR, MONTH, OTHER;
}

private final String[] field;
private final String fieldName;

private final boolean isNameField;
private final boolean isTypeHeader;
private final boolean isYearField;
private final boolean isMonthField;
private final FieldType fieldType;
private final boolean isNumeric;

private final int multiplier;


public FieldComparator(String field) {
this(field, false);
}

public FieldComparator(String field, boolean reversed) {
this.fieldName = Objects.requireNonNull(field);
this.field = field.split(MainTableFormat.COL_DEFINITION_FIELD_SEPARATOR);
multiplier = reversed ? -1 : 1;
isTypeHeader = this.field[0].equals(BibEntry.TYPE_HEADER);
isNameField = "author".equals(this.field[0])
|| "editor".equals(this.field[0]);
isYearField = "year".equals(this.field[0]);
isMonthField = "month".equals(this.field[0]);
this.field = fieldName.split(MainTableFormat.COL_DEFINITION_FIELD_SEPARATOR);
fieldType = determineFieldType(this.field[0]);
isNumeric = InternalBibtexFields.isNumeric(this.field[0]);

if(fieldType == FieldType.MONTH) {
/*
* [ 1598777 ] Month sorting
*
* http://sourceforge.net/tracker/index.php?func=detail&aid=1598777&group_id=92314&atid=600306
*/
multiplier = reversed ? 1 : -1;
} else {
multiplier = reversed ? -1 : 1;
}
}

private FieldType determineFieldType(String s) {
if(BibEntry.TYPE_HEADER.equals(this.field[0])) {
return FieldType.TYPE;
} else if("author".equals(this.field[0]) || "editor".equals(this.field[0])) {
return FieldType.NAME;
} else if ("year".equals(this.field[0])) {
return FieldType.YEAR;
} else if("month".equals(this.field[0])) {
return FieldType.MONTH;
} else {
return FieldType.OTHER;
}
}

public FieldComparator(SaveOrderConfig.SortCriterion sortCriterion) {
Expand All @@ -89,116 +109,66 @@ public FieldComparator(SaveOrderConfig.SortCriterion sortCriterion) {

@Override
public int compare(BibEntry e1, BibEntry e2) {
Object f1;
Object f2;
String f1;
String f2;

if (isTypeHeader) {
if (fieldType == FieldType.TYPE) {
// Sort by type.
f1 = e1.getType();
f2 = e2.getType();
} else {

// If the field is author or editor, we rearrange names so they are
// sorted according to last name.
f1 = getField(e1);
f2 = getField(e2);
}

/*
* [ 1598777 ] Month sorting
*
* http://sourceforge.net/tracker/index.php?func=detail&aid=1598777&group_id=92314&atid=600306
*/
int localMultiplier = multiplier;
if (isMonthField) {
localMultiplier = -localMultiplier;
}

// Catch all cases involving null:
if (f1 == null) {
return f2 == null ? 0 : localMultiplier;
}

if (f2 == null) {
return -localMultiplier;
if (f1 == null && f2 == null) {
return 0;
} else if(f1 == null) {
return multiplier;
} else if (f2 == null) {
return -multiplier;
}

// Now we now that both f1 and f2 are != null
if (isNameField) {
f1 = AuthorList.fixAuthorForAlphabetization((String) f1);
f2 = AuthorList.fixAuthorForAlphabetization((String) f2);
} else if (isYearField) {
/*
* [ 1285977 ] Impossible to properly sort a numeric field
*
* http://sourceforge.net/tracker/index.php?func=detail&aid=1285977&group_id=92314&atid=600307
*/
f1 = YearUtil.toFourDigitYear((String) f1);
f2 = YearUtil.toFourDigitYear((String) f2);
} else if (isMonthField) {
/*
* [ 1535044 ] Month sorting
*
* http://sourceforge.net/tracker/index.php?func=detail&aid=1535044&group_id=92314&atid=600306
*/
f1 = MonthUtil.getMonth((String) f1).number;
f2 = MonthUtil.getMonth((String) f2).number;
if (fieldType == FieldType.NAME) {
f1 = AuthorList.fixAuthorForAlphabetization(f1);
f2 = AuthorList.fixAuthorForAlphabetization(f2);
} else if (fieldType == FieldType.YEAR) {
return Integer.compare(YearUtil.toFourDigitYearWithInts(f1), YearUtil.toFourDigitYearWithInts(f2)) * multiplier;
} else if (fieldType == FieldType.MONTH) {
return Integer.compare(MonthUtil.getMonth(f1).number, MonthUtil.getMonth(f2).number) * multiplier;
}

if (isNumeric) {
Integer i1 = null;
Integer i2 = null;
try {
i1 = StringUtil.intValueOf((String) f1);
} catch (NumberFormatException ex) {
// Parsing failed.
}

try {
i2 = StringUtil.intValueOf((String) f2);
} catch (NumberFormatException ex) {
// Parsing failed.
}
Integer i1 = StringUtil.intValueOfWithNull(f1);
Integer i2 = StringUtil.intValueOfWithNull(f2);

if ((i2 != null) && (i1 != null)) {
// Ok, parsing was successful. Update f1 and f2:
f1 = i1;
f2 = i2;
return i1.compareTo(i2) * multiplier;
} else if (i1 != null) {
// The first one was parseable, but not the second one.
// This means we consider one < two
f1 = i1;
f2 = i1 + 1;
return -1 * multiplier;
} else if (i2 != null) {
// The second one was parseable, but not the first one.
// This means we consider one > two
f2 = i2;
f1 = i2 + 1;
return 1 * multiplier;
}
// Else none of them were parseable, and we can fall back on comparing strings.
}

int result;
if ((f1 instanceof Integer) && (f2 instanceof Integer)) {
result = ((Integer) f1).compareTo((Integer) f2);
} else if (f2 instanceof Integer) {
Integer f1AsInteger = Integer.valueOf(f1.toString());
result = -f1AsInteger.compareTo((Integer) f2);
} else if (f1 instanceof Integer) {
Integer f2AsInteger = Integer.valueOf(f2.toString());
result = -((Integer) f1).compareTo(f2AsInteger);
} else {
String ours = ((String) f1).toLowerCase();
String theirs = ((String) f2).toLowerCase();
result = FieldComparator.collator.compare(ours, theirs);
}

return result * localMultiplier;
String ours = ((String) f1).toLowerCase();
String theirs = ((String) f2).toLowerCase();
return COLLATOR.compare(ours, theirs) * multiplier;
}

private Object getField(BibEntry entry) {
private String getField(BibEntry entry) {
for (String aField : field) {
Object o = entry.getFieldOrAlias(aField);
String o = entry.getFieldOrAlias(aField);
if (o != null) {
return o;
}
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/net/sf/jabref/groups/GroupSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import net.sf.jabref.gui.*;
import net.sf.jabref.gui.help.HelpFiles;
import net.sf.jabref.gui.help.HelpAction;
import net.sf.jabref.gui.maintable.MainTableDataModel;
import net.sf.jabref.gui.worker.AbstractWorker;
import net.sf.jabref.logic.search.SearchMatcher;
import net.sf.jabref.logic.search.matchers.MatcherSet;
Expand Down Expand Up @@ -723,8 +724,7 @@ public void valueChanged(TreeSelectionEvent e) {
final TreePath[] selection = groupsTree.getSelectionPaths();
if ((selection == null) || (selection.length == 0) || ((selection.length == 1)
&& (((GroupTreeNode) selection[0].getLastPathComponent()).getGroup() instanceof AllEntriesGroup))) {
panel.getFilterGroupToggle().stop();
panel.mainTable.stopShowingFloatGrouping();
panel.mainTable.getTableModel().updateGroupingState(MainTableDataModel.DisplayOption.DISABLED);
if (showOverlappingGroups.isSelected()) {
groupsTree.setHighlight2Cells(null);
}
Expand Down Expand Up @@ -785,12 +785,10 @@ public void run() {
public void update() {
// Show the result in the chosen way:
if (hideNonHits.isSelected()) {
panel.mainTable.stopShowingFloatGrouping(); // Turn off shading, if active.
panel.getFilterGroupToggle().start(); // Turn on filtering.
panel.mainTable.getTableModel().updateGroupingState(MainTableDataModel.DisplayOption.FILTER);

} else if (grayOut.isSelected()) {
panel.getFilterGroupToggle().stop(); // Turn off filtering, if active.
panel.mainTable.showFloatGrouping(); // Turn on shading.
panel.mainTable.getTableModel().updateGroupingState(MainTableDataModel.DisplayOption.FLOAT);
}

if (showOverlappingGroupsP) {
Expand Down Expand Up @@ -891,8 +889,7 @@ public void componentOpening() {
@Override
public void componentClosing() {
if (panel != null) {// panel may be null if no file is open any more
panel.getFilterGroupToggle().stop();
panel.mainTable.stopShowingFloatGrouping();
panel.mainTable.getTableModel().updateGroupingState(MainTableDataModel.DisplayOption.DISABLED);
}
frame.groupToggle.setSelected(false);
}
Expand Down

0 comments on commit a5541d3

Please sign in to comment.