!7

!include once #1017126 // transpileRaw

sclass JavaEval extends DynPrintLog {
  S expression;
  transient bool calculating;
  transient O value;
  transient JTextField tfInput;
  transient Throwable error;
  
  JComponent visualize() {
    ret northAndCenterWithMargins(
      centerAndEastWithMarginInbetween(
        tfInput = onEnter(jtextfield(expression), rThread evalIt),
        hstackWithSpacing(
          jbutton("Fresh", rThread { refresh(); evalIt() }),
          jbutton("Eval", rThread evalIt))),
      super.visualize());
  }
  
  void refresh {
    call(dm_transpiler(), 'refresh);
    print("Refreshed translator.");
  }
  
  void evalIt {
    if (calculating) ret;
    calculating = true;
    temp tempAfterwards(r { calculating = false });
    dm_javaEvalModule_doIt(gtt(tfInput));
  }
}