From 5ce8850a73eb989ceed95717ab5f5dc521baa29f Mon Sep 17 00:00:00 2001 From: Symbolk Date: Tue, 25 Sep 2018 11:37:26 +0800 Subject: [PATCH 1/2] Fix highlight offset issue in swingdiff. --- .../client/diff/swing/MappingsPanel.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/MappingsPanel.java b/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/MappingsPanel.java index 4f3d92599..435743ecb 100644 --- a/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/MappingsPanel.java +++ b/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/MappingsPanel.java @@ -26,6 +26,7 @@ import java.awt.GridLayout; import java.io.FileReader; import java.io.IOException; +import java.io.StringReader; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; @@ -97,10 +98,8 @@ public MappingsPanel(String srcPath, String dstPath, TreeContext src, TreeContex add(split); try { - txtSrc.getUI().getEditorKit(txtSrc).read(Files.newBufferedReader(Paths.get(srcPath), - Charset.forName("UTF-8")), txtSrc.getDocument(), 0); - txtDst.getUI().getEditorKit(txtDst).read(Files.newBufferedReader(Paths.get(dstPath), - Charset.forName("UTF-8")), txtDst.getDocument(), 0); + txtSrc.getUI().getEditorKit(txtSrc).read(new StringReader(readFileAsString(srcPath)), txtSrc.getDocument(), 0); + txtDst.getUI().getEditorKit(txtDst).read(new StringReader(readFileAsString(dstPath)), txtDst.getDocument(), 0); } catch (IOException | BadLocationException e) { e.printStackTrace(); } @@ -109,6 +108,17 @@ public MappingsPanel(String srcPath, String dstPath, TreeContext src, TreeContex openNodes(); } + private static String readFileAsString(String filePath) { + String content = ""; + try { + content = new String(Files.readAllBytes(Paths.get(filePath))); + content = content.replaceAll("\r\n", "\r\n "); + } catch (IOException e) { + e.printStackTrace(); + } + return content; + } + private void openNodes() { for (ITree t: classifyTrees.getSrcDelTrees()) openNode(panSrc, t); for (ITree t: classifyTrees.getDstAddTrees()) openNode(panDst, t); From f3855e4461bd7d2651e7e54e44575e7fa8887a0b Mon Sep 17 00:00:00 2001 From: Symbolk Date: Thu, 27 Sep 2018 23:13:02 +0800 Subject: [PATCH 2/2] Fix checkstyle issues. --- .../client/diff/swing/MappingsPanel.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/MappingsPanel.java b/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/MappingsPanel.java index 435743ecb..21ee446c9 100644 --- a/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/MappingsPanel.java +++ b/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/MappingsPanel.java @@ -98,25 +98,30 @@ public MappingsPanel(String srcPath, String dstPath, TreeContext src, TreeContex add(split); try { - txtSrc.getUI().getEditorKit(txtSrc).read(new StringReader(readFileAsString(srcPath)), txtSrc.getDocument(), 0); - txtDst.getUI().getEditorKit(txtDst).read(new StringReader(readFileAsString(dstPath)), txtDst.getDocument(), 0); + txtSrc + .getUI() + .getEditorKit(txtSrc) + .read(new StringReader(readFileAsString(srcPath)), txtSrc.getDocument(), 0); + txtDst + .getUI() + .getEditorKit(txtDst) + .read(new StringReader(readFileAsString(dstPath)), txtDst.getDocument(), 0); } catch (IOException | BadLocationException e) { e.printStackTrace(); } - setPreferredSize(new Dimension(1024, 768)); openNodes(); } private static String readFileAsString(String filePath) { - String content = ""; - try { - content = new String(Files.readAllBytes(Paths.get(filePath))); - content = content.replaceAll("\r\n", "\r\n "); - } catch (IOException e) { - e.printStackTrace(); - } - return content; + String content = ""; + try { + content = new String(Files.readAllBytes(Paths.get(filePath))); + content = content.replaceAll("\r\n", "\r\n "); + } catch (IOException e) { + e.printStackTrace(); + } + return content; } private void openNodes() {