static editJavaXSnippet_Editor editJavaXSnippet(fS snippetID) { ret swingConstruct(editJavaXSnippet_Editor, snippetID); } sclass editJavaXSnippet_Editor { S snippetID; JTextArea textArea; JButton btnSave, btnTranspile, btnMTranspile, btnReload, btnEleuReload; L<JButton> buttons; int snippetType; JLabel lblStatus; *(S _snippetID) { snippetID = formatSnippetID(_snippetID); showFrame(snippetID, centerAndSouth(textArea = typeWriterTextArea(), lblStatus = jlabel())); frameIcon(textArea, #1004655); addFrameMenu(textArea, "File", "Reload from server", r { reload() }, "Butter-Reload", r { eleuReload() }); addDirectMenuItem(textArea, "Run!", r { nohupJavax(snippetID) }); thread { setFrameTitle(textArea, "E: " + getSnippetTitle(snippetID) + " [" + snippetID + "]"); } // Customize text area textArea.setTabSize(2); lblStatus.setText("Loading..."); btnSave = new JButton("Save on server"); btnSave.addActionListener(actionListener { saveSnippet(null); }); btnTranspile = new JButton("Save & transpile"); btnTranspile.addActionListener(actionListener { transpile(false); }); btnMTranspile = new JButton("S & Multi-transpile"); btnMTranspile.addActionListener(actionListener { transpile(true); }); buttons = ll(btnReload, btnSave, btnTranspile); jdisable(buttons); // XXX cursor bug? textArea.setEditable(false); // still loading snippetType = getSnippetType(snippetID); JScrollPane bottom = new JScrollPane( snippetType != 42 ? jflowRight(btnSave, btnTranspile, btnMTranspile, btnReload, btnEleuReload) : jflowRight(btnSave, btnReload)); addToWindow(textArea, bottom); onUpdate(textArea, r { jenable(buttons); }); reload(); } void saveSnippet(final Runnable next) { final S text = textArea.getText(); jdisable(buttons); lblStatus.setText("Saving..."); thread { fS page = editSnippet(snippetID, text); awt { lblStatus.setText("Saved snippet: " + page); jenable(buttons); callF(next); } } } void transpile(final bool multi) { saveSnippet(r { lblStatus.setText("Transpiling..."); jdisable(btnEleuReload); thread "Transpiling" { try { final Pair<Bool, S> p = transpileOnServer(snippetID, multi ? "medium" : "quick"); awt { if (p.a) lblStatus.setText("Transpiled OK!"); else { lblStatus.setText("Transpilation error. " + p.b); showText("Transpilation Error", p.b); } } } catch e { printStackTrace(e); lblStatus.setText("Transpilation problem. " + e); } jenable(btnEleuReload); } }); } void reload() { thread "Load Snippet" { final S s = loadSnippet(snippetID); awt { lblStatus.setText("Loaded " + s.length() + " chars."); textArea.setText(s); //textArea.scrollRectToVisible(new Rectangle(0, 0, 1, 1)); textArea.setCaretPosition(0); jenable(buttons); textArea.setEditable(true); textArea.requestFocus(); } } } void eleuReload() { time { butterReload(snippetID); } infoBox("Reloaded in " + lastTiming_format100ms()); } }
Began life as a copy of #1004360
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1010354 |
Snippet name: | editJavaXSnippet using JTextArea [v2, dev.] |
Eternal ID of this version: | #1010354/6 |
Text MD5: | 7e65c6454f4002fda24dc1b4e489cd62 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-05-02 09:37:19 |
Source code size: | 3577 bytes / 124 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 428 / 669 |
Version history: | 5 change(s) |
Referenced in: | #1010350 - Select JavaX snippet to edit [OK] |