sclass JLeftArrowScriptIDE is Swingable { settable SimpleLiveValue<S> lvScript = stringLiveValue(); settable S sectionTitle = "Left arrow script"; sS helpText = !include string #1034045; transient CompileResult compileResult; transient RSyntaxTextAreaWithSearch taScript; transient new Q compileQ; transient JLabel lblCompileResult; transient JButton btnRun; transient SingleComponentPanel scpResult; transient LeftArrowCompletionProvider completionProvider; transient AutoCompletion autoComplete; settable transient G22Utils g22utils; settable double scriptTimeout = 10.0; settable transient bool showTitle = true; class LeftArrowCompletionProvider extends DefaultCompletionProvider { /*@Override public L<Completion> getCompletionByInputText(S inputText) { print("getCompletionByInputText: " + quote(inputText)); ret ll( new BasicCompletion(this, inputText + "YesYes"), new BasicCompletion(this, inputText + "NoNo")); }*/ /*@Override public L<Completion> getCompletions(JTextComponent comp) { var l = super.getCompletions(comp); print("getCompletions: " + l); ret l; }*/ @Override public L<Completion> getCompletionsImpl(JTextComponent comp) { try { print("getCompletionsImpl"); S text = getText(comp); GazelleV_LeftArrowScriptParser parser = makeParser(); LeftArrowScriptAutoCompleter completer = new(g22utils, parser); enableScaffolding(completer); completer.seek(text, getCaretPosition(comp)); ret map(completer.searcher().withScores(), completion -> { BasicCompletion c = new(this, completion!); c.setRelevance((int) completion.score()); ret c; }); } catch print e { ret ll(); } //ret getCompletionByInputText(getAlreadyEnteredText(comp)); } } visual { taScript = liveValueRSyntaxTextArea_bothWays(lvScript); taScript.menuLessOperation(); awtCalcEvery(taScript.textArea(), 1.0, -> compileQ.add(r compile)); swing { completionProvider = new LeftArrowCompletionProvider; completionProvider.setAutoActivationRules(true, " "); autoComplete = new AutoCompletion(completionProvider); autoComplete.setAutoCompleteSingleChoices(false); autoComplete.setAutoActivationEnabled(true); autoComplete.setAutoActivationDelay(2000); autoComplete.install(taScript.textArea); print("Auto-complete installed on " + taScript.textArea); } JComponent vis = centerAndSouthWithMargin( taScript.visualize(), centerAndEastWithMargin( jBorderlessHigherScrollPane(lblCompileResult = jlabel()), centerAndSouth(jpanel(), jline( btnRun = jbutton("Run" := rThread runScript), jPopDownButton_noText( "Show Scripting Help", rThread { showTextWordWrapped("Gazelle 'Left arrow script' Help", helpText) }, "Show Global Class Names", rThread showGlobalClassNames, ) )) )); if (showTitle) vis = jCenteredSection(sectionTitle, vis); if (scpResult != null) vis = jhsplit( jCenteredSection("Image will show here", scpResult), vis); ret vis; } bool visible() { ret isShowing(lblCompileResult); } void compile { var script = lvScript!; var result = compileResult; if (result == null || !eq(result.script, script)) { try { result = new CompileResult; result.script = script; result.parser = makeParser(); result.parsedScript = result.parser.parse(result.script); print(result.parsedScript); } catch e { 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; } GazelleV_LeftArrowScript.Script parsedScript() { ret freshCompileResult().parsedScript; } swappable void runScript() { var result = freshCompileResult(); if (result.parsedScript != null) { result.result = okOrError(-> callCompiledObjectWithTimeout(result.parsedScript)); showScriptResult(result.result); } } void showScriptResult(OKOrError result) { if (result.isOK()) setStatus(shorten(g22utils.stringify(result!))); else setStatus(exceptionToStringShorter_dontDropOuterExceptions(result.error())); } class CompileResult { S script; GazelleV_LeftArrowScriptParser parser; Throwable compileError; GazelleV_LeftArrowScript.Script parsedScript; OKOrError result; toString { ret compileError != null ? exceptionToStringShorter_dontDropOuterExceptions(compileError) : "Compiled OK"; } bool runnable() { ret parsedScript != null; } } void setStatus(S status) { setText(lblCompileResult, status); } swappable void modifyParser(GazelleV_LeftArrowScriptParser parser) { } void showStatus(S status) { setText(lblCompileResult, status); } void showRuntimeError(Throwable e) { showStatus(exceptionToStringShorter(e)); } void withResultPanel { scpResult if null = singleComponentPanel(); } swappable VarContext makeVarContextForExecution() { ret new VarContext; } O callCompiledObjectWithTimeout(double timeoutSeconds default scriptTimeout, GazelleV_LeftArrowScript.Script object, VarContext ctx default makeVarContextForExecution()) { O result = evalWithTimeoutOrTypedException(timeoutSeconds, -> object.get(ctx)); if (result cast BufferedImage) scpResult?.set(jscroll_centered_borderless(g22utils.stdImageSurface(result))); ret result; } GazelleV_LeftArrowScriptParser makeParser() { var parser = g22utils.leftArrowParser(); modifyParser(parser); print("Function containers: " + parser.functionContainers); ret parser; } void showGlobalClassNames() { showText("Global Class Names", pnlToString(toCIMap(makeParser().globalClassNames()))); } }
Began life as a copy of #1034022
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): bhatertpkbcr, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034363 |
Snippet name: | JLeftArrowScriptIDE (backup with two status bars) |
Eternal ID of this version: | #1034363/3 |
Text MD5: | 1d62dac4df01b5ffef0d3d8fa33120f6 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-03 09:34:01 |
Source code size: | 6607 bytes / 207 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 138 / 156 |
Version history: | 2 change(s) |
Referenced in: | [show references] |