!7

sS text1, text2;
static JTextArea a, b, d;
static JCheckBox trim;
static JFrame frame;

p-awt {
  // change to pretty L&F if we're the main program
  if (isMainProgram()) substance();
  
  frame = showFrame(centerAndSouth(hgrid(
    withTitle("Text A (-)", a = new JTextArea(text1)),
    withTitle("Diff", withMargin(wrap(d = new JTextArea))),
    withTitle("Text B (+)", b = new JTextArea(text2))),
    centeredLine(trim = new JCheckBox("Ignore Indent", true))));
  trim.setToolTipText("Also ignores empty lines");
  setFrameWidth(frame, 800);

  update();    
  onUpdate(ll(a, b, trim), "update");
}

svoid update {
  d.setText(unidiff(preprocess(a.getText()), preprocess(b.getText())));
}

sS preprocess(S s) {
  if (isChecked(trim))
    s = fullTrim(s);
  ret s;
}