G2A Many GEOs
SHARE
TWEET

Untitled

a guest Jan 19th, 2011 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package DiffTest;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Component;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.io.File;
  8. import java.io.IOException;
  9. import java.io.StringReader;
  10. import javax.swing.SwingUtilities;
  11. import org.netbeans.api.diff.Difference;
  12. import org.netbeans.api.diff.StreamSource;
  13. import org.netbeans.spi.diff.DiffProvider;
  14. import org.netbeans.spi.diff.MergeVisualizer;
  15. import org.openide.util.Exceptions;
  16. import org.openide.util.Lookup;
  17. import org.openide.windows.TopComponent;
  18.  
  19. public final class MergeVisualizerAction implements ActionListener {
  20.  
  21.     @Override
  22.     public void actionPerformed(ActionEvent e) {
  23.         try {
  24.             final StreamSource ss1 = StreamSource.createSource("name1", "Previous", "text/plain", new File("C:/Users/ehencae/Desktop/diff/previous.TXT"));
  25.             final StreamSource ss2 = StreamSource.createSource("name2", "Current", "text/plain", new File("C:/Users/ehencae/Desktop/diff/current.TXT"));
  26.             final StreamSource ss3 = StreamSource.createSource("name2", "Current", "text/plain", new StringReader(""));
  27.  
  28.             DiffProvider diffProvider = Lookup.getDefault().lookup(DiffProvider.class);
  29.             final Difference[] diffs = diffProvider.computeDiff(ss1.createReader(), ss2.createReader());
  30.  
  31.             System.out.println("Number of diffs: " + diffs.length);
  32.             for (int i = 0; i < diffs.length; i++) {
  33.                 System.out.println("Diff " + i);
  34.                 System.out.println("First test: " + diffs[i].getFirstText());
  35.                 System.out.println("Second text: " + diffs[i].getSecondText());
  36.             }
  37.  
  38.             SwingUtilities.invokeLater(new Runnable() {
  39.  
  40.                 @Override
  41.                 public void run() {
  42.                     try {
  43.                         MergeVisualizer mergeVisualizer = Lookup.getDefault().lookup(MergeVisualizer.class);
  44.                         Component c = mergeVisualizer.createView(diffs, ss1, ss2, ss3);
  45.                         TopComponent tc = new MergeTestTopComponent();
  46.                         tc.setDisplayName("Diff/Merge Editor");
  47.                         tc.setLayout(new BorderLayout());
  48.                         tc.add(c, BorderLayout.CENTER);
  49.                         tc.open();
  50.                         tc.requestActive();
  51.                     } catch (IOException ex) {
  52.                         Exceptions.printStackTrace(ex);
  53.                     }
  54.                 }
  55.             });
  56.  
  57.         } catch (IOException ex) {
  58.             Exceptions.printStackTrace(ex);
  59.         }
  60.     }
  61. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top