Home
Categories
Dictionary
Download
Project Details
Changes Log
License

JDiffTextPanel



The JDiffTextPanel class allows to apply a GNU diff to two text content and show the diff result from the two texts side by side. It uses the Diff engine internally.

Algorithms

There are three modes for showing the differences between two text content:
  • The default mode shows added, deleted, or updated lines
  • The TYPE_WITHIN_LINES_BASIC mode shows added, deleted, or updated lines. The updated lines shows the differences within the lines using a basic character by character comparison
  • The TYPE_WITHIN_LINES_DIFF mode shows added, deleted, or updated lines. The updated lines shows the differences within the lines using a diff algorithm within the line

Default algorithm

The default DiffAlgorithm.TYPE_FULL_LINES mode shows added, deleted, or updated lines.

compareresult

Simple diff mode

The DiffAlgorithm.TYPE_WITHIN_LINES_BASIC mode shows added, deleted, or updated lines. The updated lines shows the differences within the lines using a basic character by character comparison.

compareresult2

Full diff mode

The DiffAlgorithm.TYPE_WITHIN_LINES_DIFF mode shows added, deleted, or updated lines. The updated lines shows the differences within the lines using a diff algorithm within the line.
compareresult3

Example

The following code creates a diff component:
      String[] a = { "aaaTOTOaaa", "aaaTATAaaa", "aaaTATAaaa", "aaaTRRaaa" };
      String[] b = { "aaaTOTaaa", "aaaTATAaaa", "aaaTATA TIaaa", "aaaTATAaaa", "aaaTUTUaaa", "aaaTPPaaa", "aaaTRRaaa", "aaaTRIaaa" };

      JFrame frame = new JFrame("JDiffTextPanel");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Container pane = frame.getContentPane();
      pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
      CodeEditorDefaults defaults = new CodeEditorDefaults();
      defaults.setPopup(new DefaultEditorPopup());

      JDiffTextPanel panel = new JDiffTextPanel(a, b, defaults);
      panel.setTokenMarker(new BasicTokenMarker());
      pane.add(panel);
      frame.pack();
      frame.setVisible(true);
with the folllowing result:
compareresultexample

See also


Categories: diff

Copyright 2016-2019 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence