Highlighting Changes in Java

Posted by Buzz Lightyear on Stack Overflow See other posts from Stack Overflow or by Buzz Lightyear
Published on 2012-08-29T13:33:27Z Indexed on 2012/08/30 9:38 UTC
Read the original article Hit count: 160

Filed under:
|
|
|
|

Basically, i have done my program so that it will display differences in strings and display the whole line. I want to highlight (in a colour) the differences in the line.

Example:

Original at line 5
   <rect x="60.01" width="855.38" id="rect_1" y="-244.35" height="641.13" style="stroke-width: 1; stroke: rgb(0, 0, 0); fill: none; "/>

Edited at line 5
   <rect x="298.43" width="340.00" y="131.12" height="380.00" id="rect_1" style="stroke-width: 1; stroke: rgb(0, 0, 0); fill: rgb(255, 102, 0); "/>

In this example, the width is different from the 'original' from the 'edited' version. I would like to be able to highlight that difference and any other difference.

My code so far:

Patch patch = DiffUtils.diff(centralFile, remoteFile);
        StringBuffer resultsBuff = new StringBuffer(remoteFileData.length);
        for (Delta delta : patch.getDeltas())
            {
            resultsBuff.append("Original at line " + delta.getOriginal().getPosition() + "\n");
            for (Object line : delta.getOriginal().getLines())
                {
                resultsBuff.append("   " + line + "\n");
                }
            resultsBuff.append("Edited at line " + delta.getRevised().getPosition() + "\n");
            for (Object line : delta.getRevised().getLines())
                {
                resultsBuff.append("   " + line + "\n");
                }
            resultsBuff.append("\n");
            }
        return resultsBuff.toString();
        }

That will display two whole lines like the example before (the original and the edited version) I want to be able to highlight the changes that have actually been made, is there any way to do this in Java?

© Stack Overflow or respective owner

Related posts about java

Related posts about eclipse