diff --git a/build.gradle b/build.gradle index d77dfb9ace8e..b199203b7693 100644 --- a/build.gradle +++ b/build.gradle @@ -88,8 +88,6 @@ dependencies { compile 'org.openoffice:ridl:4.1.2' compile 'org.openoffice:unoil:4.1.2' - compile 'com.github.bkromhout:java-diff-utils:2.1.1' - antlr3 'org.antlr:antlr:3.5.2' compile 'org.antlr:antlr-runtime:3.5.2' diff --git a/external-libraries.txt b/external-libraries.txt index 50b8112da024..fadcd0cc818d 100644 --- a/external-libraries.txt +++ b/external-libraries.txt @@ -45,11 +45,6 @@ Project: Apache Commons Logging URL: http://commons.apache.org/logging/ License: Apache-2.0 -Id: com.github.bkromhout:java-diff-utils -Project: java-diff-utils -URL: https://github.com/bkromhout/java-diff-utils -License: Apache-2.0 - Id: com.jgoodies:jgoodies-common Project: JGoodies Common URL: http://www.jgoodies.com/downloads/libraries/ diff --git a/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java b/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java index e5b65c483095..1b19f585e3c5 100644 --- a/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java +++ b/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java @@ -34,7 +34,6 @@ import net.sf.jabref.logic.bibtex.LatexFieldFormatter; import net.sf.jabref.logic.formatter.casechanger.SentenceCaseFormatter; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.util.strings.DiffHighlighting; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.InternalBibtexFields; @@ -272,7 +271,7 @@ private void setupEntryTypeRow(JPanel mergePanel) { mergePanel.add(boldFontLabel(Localization.lang("Entry type")), CELL_CONSTRAINTS.xy(1, 1)); JTextPane leftTypeDisplay = new DiffHighlightingTextPane(); - leftTypeDisplay.setText(DiffHighlighting.HTML_START + leftEntry.getType() + DiffHighlighting.HTML_END); + leftTypeDisplay.setText(leftEntry.getType()); mergePanel.add(leftTypeDisplay, CELL_CONSTRAINTS.xy(3, 1)); if (leftEntry.getType().equals(rightEntry.getType())) { identicalTypes = true; @@ -290,13 +289,14 @@ private void setupEntryTypeRow(JPanel mergePanel) { typeRadioButtons.get(0).setSelected(true); } JTextPane rightTypeDisplay = new DiffHighlightingTextPane(); - rightTypeDisplay.setText(DiffHighlighting.HTML_START + rightEntry.getType() + DiffHighlighting.HTML_END); + rightTypeDisplay.setText(rightEntry.getType()); mergePanel.add(rightTypeDisplay, CELL_CONSTRAINTS.xy(11, 1)); } private void setupHeadingRows() { mainPanel.add(boldFontLabel(Localization.lang("Use")), CELL_CONSTRAINTS.xyw(4, 1, 7, "center, bottom")); mainPanel.add(diffMode, CELL_CONSTRAINTS.xy(11, 1, "right, bottom")); + diffMode.setVisible(false); // Set headings for (int i = 0; i < 6; i++) { @@ -362,33 +362,11 @@ private void updateTextPanes(Collection fields) { for (String field : fields) { String leftString = leftEntry.getField(field).orElse(""); String rightString = rightEntry.getField(field).orElse(""); - switch (diffMode.getSelectedIndex()) { - case 0: // Plain text - break; - case 1: // Latexdiff style - word - rightString = DiffHighlighting.generateDiffHighlighting(leftString, rightString, " "); - break; - case 2: // Latexdiff style - character - rightString = DiffHighlighting.generateDiffHighlighting(leftString, rightString, ""); - break; - case 3: // Symmetric style - word - String tmpLeftString = DiffHighlighting.generateSymmetricHighlighting(leftString, rightString, " "); - rightString = DiffHighlighting.generateSymmetricHighlighting(rightString, leftString, " "); - leftString = tmpLeftString; - break; - case 4: // Symmetric style - character - tmpLeftString = DiffHighlighting.generateSymmetricHighlighting(leftString, rightString, ""); - rightString = DiffHighlighting.generateSymmetricHighlighting(rightString, leftString, ""); - leftString = tmpLeftString; - break; - default: // Shouldn't happen - break; - } if ((leftString != null) && leftTextPanes.containsKey(field)) { - leftTextPanes.get(field).setText(DiffHighlighting.HTML_START + leftString + DiffHighlighting.HTML_END); + leftTextPanes.get(field).setText(leftString); } if ((rightString != null) && rightTextPanes.containsKey(field)) { - rightTextPanes.get(field).setText(DiffHighlighting.HTML_START + rightString + DiffHighlighting.HTML_END); + rightTextPanes.get(field).setText(rightString); } } SwingUtilities.invokeLater(() -> scrollPane.getVerticalScrollBar() diff --git a/src/main/java/net/sf/jabref/logic/util/strings/DiffHighlighting.java b/src/main/java/net/sf/jabref/logic/util/strings/DiffHighlighting.java deleted file mode 100644 index ba6463b1f69e..000000000000 --- a/src/main/java/net/sf/jabref/logic/util/strings/DiffHighlighting.java +++ /dev/null @@ -1,101 +0,0 @@ -package net.sf.jabref.logic.util.strings; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -import difflib.Delta; -import difflib.DiffUtils; - -public class DiffHighlighting { - - private static final String ADDITION_START = ""; - private static final String REMOVAL_START = ""; - private static final String CHANGE_START = ""; - private static final String TAG_END = ""; - - public static final String HTML_START = ""; - public static final String HTML_END = ""; - - - public static String generateDiffHighlighting(String baseString, String modifiedString, String separator) { - Objects.requireNonNull(separator); - if ((baseString != null) && (modifiedString != null)) { - List stringList = new ArrayList<>(Arrays.asList(baseString.split(separator))); - List> deltaList = new ArrayList<>( - DiffUtils.diff(stringList, Arrays.asList(modifiedString.split(separator))).getDeltas()); - Collections.reverse(deltaList); - for (Delta delta : deltaList) { - int startPos = delta.getOriginal().getPosition(); - List lines = delta.getOriginal().getLines(); - int offset = 0; - switch (delta.getType()) { - case CHANGE: - for (String line : lines) { - stringList.set(startPos + offset, (offset == 0 ? DiffHighlighting.REMOVAL_START : "") + line); - offset++; - } - stringList.set((startPos + offset) - 1, - stringList.get((startPos + offset) - 1) + DiffHighlighting.TAG_END + separator + DiffHighlighting.ADDITION_START - + String.join(separator, delta.getRevised().getLines()) + DiffHighlighting.TAG_END); - break; - case DELETE: - for (String line : lines) { - stringList.set(startPos + offset, (offset == 0 ? DiffHighlighting.REMOVAL_START : "") + line); - offset++; - } - stringList.set((startPos + offset) - 1, - stringList.get((startPos + offset) - 1) + DiffHighlighting.TAG_END); - break; - case INSERT: - stringList.add(delta.getOriginal().getPosition(), - DiffHighlighting.ADDITION_START + String.join(separator, delta.getRevised().getLines()) + DiffHighlighting.TAG_END); - break; - default: - break; - } - } - return String.join(separator, stringList); - } - return modifiedString; - } - - public static String generateSymmetricHighlighting(String baseString, String modifiedString, String separator) { - if ((baseString != null) && (modifiedString != null)) { - List stringList = new ArrayList<>(Arrays.asList(baseString.split(separator))); - List> deltaList = new ArrayList<>(DiffUtils - .diff(stringList, new ArrayList<>(Arrays.asList(modifiedString.split(separator)))).getDeltas()); - Collections.reverse(deltaList); - for (Delta delta : deltaList) { - int startPos = delta.getOriginal().getPosition(); - List lines = delta.getOriginal().getLines(); - int offset = 0; - switch (delta.getType()) { - case CHANGE: - for (String line : lines) { - stringList.set(startPos + offset, (offset == 0 ? DiffHighlighting.CHANGE_START : "") + line); - offset++; - } - stringList.set((startPos + offset) - 1, stringList.get((startPos + offset) - 1) + DiffHighlighting.TAG_END); - break; - case DELETE: - for (String line : lines) { - stringList.set(startPos + offset, (offset == 0 ? DiffHighlighting.ADDITION_START : "") + line); - offset++; - } - stringList.set((startPos + offset) - 1, stringList.get((startPos + offset) - 1) + DiffHighlighting.TAG_END); - break; - case INSERT: - break; - default: - break; - } - } - return String.join(separator, stringList); - } - return modifiedString; - } - -} diff --git a/src/test/java/net/sf/jabref/logic/util/strings/DiffHighlightingTest.java b/src/test/java/net/sf/jabref/logic/util/strings/DiffHighlightingTest.java deleted file mode 100644 index 1ba979657bcf..000000000000 --- a/src/test/java/net/sf/jabref/logic/util/strings/DiffHighlightingTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package net.sf.jabref.logic.util.strings; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - - -public class DiffHighlightingTest { - - @Test - public void testGenerateDiffHighlightingBothNullReturnsNull() { - assertNull(DiffHighlighting.generateDiffHighlighting(null, null, "")); - } - - @Test(expected = NullPointerException.class) - public void testNullSeparatorThrowsNPE() { - assertNull(DiffHighlighting.generateDiffHighlighting("", "", null)); - } - - @Test - public void testGenerateDiffHighlightingNoDiff() { - assertEquals("foo", DiffHighlighting.generateDiffHighlighting("foo", "foo", "")); - } - - @Test - public void testGenerateDiffHighlightingSingleWordAddTextWordDiff() { - assertEquals("foo foobar", - DiffHighlighting.generateDiffHighlighting("foo", "foobar", " ")); - } - - @Test - public void testGenerateDiffHighlightingSingleWordAddTextCharacterDiff() { - assertEquals("foobar", DiffHighlighting.generateDiffHighlighting("foo", "foobar", "")); - } - - @Test - public void testGenerateDiffHighlightingSingleWordDeleteTextWordDiff() { - assertEquals("foobar foo", - DiffHighlighting.generateDiffHighlighting("foobar", "foo", " ")); - } - - @Test - public void testGenerateDiffHighlightingSingleWordDeleteTextCharacterDiff() { - assertEquals("foobar", DiffHighlighting.generateDiffHighlighting("foobar", "foo", "")); - } - - @Test - public void generateSymmetricHighlightingSingleWordAddTextWordDiff() { - assertEquals("foo", - DiffHighlighting.generateSymmetricHighlighting("foo", "foobar", " ")); - } - - @Test - public void generateSymmetricHighlightingSingleWordAddTextCharacterDiff() { - assertEquals("foo", DiffHighlighting.generateSymmetricHighlighting("foo", "foobar", "")); - } - - @Test - public void generateSymmetricHighlightingSingleWordDeleteTextWordDiff() { - assertEquals("foobar", - DiffHighlighting.generateSymmetricHighlighting("foobar", "foo", " ")); - } - - @Test - public void generateSymmetricHighlightingSingleWordDeleteTextCharacterDiff() { - assertEquals("foobar", DiffHighlighting.generateSymmetricHighlighting("foobar", "foo", "")); - } - - @Test - public void generateSymmetricHighlightingMultipleWordsDeleteTextCharacterDiff() { - assertEquals("foobar and something", - DiffHighlighting.generateSymmetricHighlighting("foobar and something", "foo and thing", "")); - } - - @Test - public void generateSymmetricHighlightingMultipleWordsDeleteTextWordDiff() { - assertEquals("foo bar and some thing", - DiffHighlighting.generateSymmetricHighlighting("foo bar and some thing", "foo and thing", " ")); - } -}