sclass JMiniJavaIDE is Swingable { settable SimpleLiveValue lvScript = stringLiveValue(); S sectionTitle = "Mini Java IDE"; sS helpText = "Javaaa"; transient CompileResult compileResult; transient RSyntaxTextAreaWithSearch taScript; transient new Q compileQ; transient JLabel lblCompileResult; transient JButton btnRun; transient JavaCompletionProvider completionProvider; transient AutoCompletion autoComplete; transient settable IStringifier stringifier; class JavaCompletionProvider extends DefaultCompletionProvider { @Override public L getCompletionByInputText(S inputText) { print("getCompletionByInputText: " + quote(inputText)); ret ll( /*new BasicCompletion(this, inputText + "YesYes"), new BasicCompletion(this, inputText + "NoNo")*/); } @Override public L getCompletionsImpl(JTextComponent comp) { ret getCompletionByInputText(getAlreadyEnteredText(comp)); } } visual { taScript = liveValueRSyntaxTextArea_bothWays(lvScript); awtCalcEvery(taScript.textArea(), 5.0, -> compileQ.add(r compile)); swing { completionProvider = new JavaCompletionProvider; completionProvider.setAutoActivationRules(true, " "); autoComplete = new AutoCompletion(completionProvider); autoComplete.setAutoActivationEnabled(true); autoComplete.install(taScript.textArea); } ret jCenteredSection(sectionTitle, centerAndSouthWithMargin( taScript.visualize(), centerAndEastWithMargin( jBorderlessHigherScrollPane(lblCompileResult = jlabel()), vstack( jline( btnRun = jbutton("Run" := rThread runButtonAction), jPopDownButton_noText( "Show Scripting Help", rThread { showTextWordWrapped("Gazelle 'Left arrow script' Help", helpText) }, ) )) ))); } bool visible() { ret isShowing(lblCompileResult); } void compile { var script = lvScript!; var result = compileResult; if (result == null || !eq(result.script, script)) { setStatus("Compiling..."); try { result = new CompileResult; result.script = script; result.className = "UserCode_" + now(); result.adaptedScript = adaptScript(result); result.java = result.adaptedScript; //result.adaptedScript = "mainClassName " + result.className + "\n\n" + result.script; //result.java = transpileRaw(result.adaptedScript); result.compiledObject = veryQuickJava_finish_specialMainClass(result.className, result.java); print(compiledObject := result.compiledObject); } catch print e { result.compileError = e; } compileResult = result; setText(lblCompileResult, compileResult); updateRunButtonState(); } } void updateRunButtonState() { setEnabled(btnRun, runButtonShouldBeEnabled()); } swappable bool runButtonShouldBeEnabled() { ret compileResult != null && compileResult.runnable(); } CompileResult freshCompileResult() { runInQAndWait(compileQ, r compile); ret compileResult; } O compiledObject() { ret freshCompileResult().compiledObject; } swappable void runButtonAction { runScript(); } void runScript { //showText_fast_noWrap("Script Error", renderStackTrace(e)); var result = freshCompileResult(); if (result.compiledObject != null) { setStatus("Running"); result.result = okOrError(-> callCompiledObject(result.compiledObject)); setStatus(result.result.isOK() ? shorten(stringify(stringifier, result.result!)) : exceptionToStringShorter(result.result.error())); } } class CompileResult { S script, adaptedScript, java; S className; Class compiledObject; Throwable compileError; OKOrError result; toString { if (compileError == null) ret "Compiled OK"; S msg = compileError.getMessage(); msg = dropPrefixFromLines("> ", msg); var errors = parseECJOutputForErrors(msg); if (nempty(errors)) { var error = first(errors); // rough but usually works print(codeLine := quote(error.codeLine)); pnlQuoted(asList(lines_iterator(script))); int lineNr = indexOfLine(script, tabsToSpaces(error.codeLine)); error.lineNr = lineNr+1; ret str(error); } ret msg; } bool runnable() { ret compiledObject != null; } } void setStatus(S status) { setText(lblCompileResult, status); } swappable S extraClassMembers(S script) { ret ""; } swappable S adaptScript(CompileResult result) { ret tok_moveImportsUp("class " + result.className + "{" + extraClassMembers(result.script) + "\n" + evalJava_prep(result.script) + "}"); } swappable O callCompiledObject(O object) { ret callCalc(object); } }