1 | static editJavaXSnippet_Editor editJavaXSnippet(fS snippetID) { |
2 | ret (editJavaXSnippet_Editor) swingAndWait(func { |
3 | new editJavaXSnippet_Editor(snippetID) |
4 | }); |
5 | } |
6 | |
7 | sclass editJavaXSnippet_Editor { |
8 | S snippetID; |
9 | EditorFrame frame; |
10 | RSyntaxTextArea textArea; |
11 | JButton btnSave, btnTranspile, btnMTranspile, btnReload, btnEleuReload; |
12 | L<JButton> buttons; |
13 | int snippetType; |
14 | |
15 | *(S _snippetID) { |
16 | snippetID = formatSnippetID(_snippetID); |
17 | frame = new EditorFrame; |
18 | frameIcon(frame, "#1004655"); |
19 | |
20 | frame.setTitle(getSnippetTitle(snippetID) + " [Editing " + psI(snippetID) + "]"); |
21 | |
22 | textArea = frame.textArea; |
23 | |
24 | // Customize text area |
25 | textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); |
26 | textArea.setCodeFoldingEnabled(true); |
27 | textArea.setTabSize(2); |
28 | textArea.setTabsEmulated(true); // Spaces are MUCH better! |
29 | |
30 | frame.setStatus("Loading..."); |
31 | |
32 | btnSave = new JButton("Save on server"); |
33 | btnSave.addActionListener(actionListener { saveSnippet(null); }); |
34 | |
35 | btnTranspile = new JButton("Save & transpile"); |
36 | btnTranspile.addActionListener(actionListener { transpile(false); }); |
37 | |
38 | btnMTranspile = new JButton("S & Multi-transpile"); |
39 | btnMTranspile.addActionListener(actionListener { transpile(true); }); |
40 | |
41 | btnReload = new JButton("Reload"); |
42 | btnReload.addActionListener(actionListener { reload(); }); |
43 | |
44 | btnEleuReload = new JButton("Eleu-Reload"); |
45 | btnEleuReload.addActionListener(actionListener { eleuReload(); }); |
46 | |
47 | buttons = ll(btnReload, btnSave, btnTranspile); |
48 | |
49 | jdisable(buttons); |
50 | // XXX cursor bug? textArea.setEditable(false); // still loading |
51 | |
52 | snippetType = getSnippetType(snippetID); |
53 | JScrollPane bottom = new JScrollPane( |
54 | snippetType != 42 |
55 | ? jflowRight(btnSave, btnTranspile, btnMTranspile, btnReload, btnEleuReload) |
56 | : jflowRight(btnSave, btnReload)); |
57 | addToWindow(frame, bottom); |
58 | |
59 | onUpdate(textArea, r { |
60 | jenable(buttons); |
61 | }); |
62 | |
63 | showFrame(frame); |
64 | reload(); |
65 | } |
66 | |
67 | void saveSnippet(final Runnable next) { |
68 | final S text = textArea.getText(); |
69 | jdisable(buttons); |
70 | frame.setStatus("Saving..."); |
71 | thread { |
72 | final S url = "http://tinybrain.de:8080/tb-int/update_snippet_text.php"; |
73 | S user = loadTextFile(new File(userHome(), ".tinybrain/username").getPath(), null); |
74 | S pass = loadTextFile(new File(userHome(), ".tinybrain/userpass").getPath(), null); |
75 | S query = "id=" + parseSnippetID(snippetID) + "&text=" + urlencode(text) + "&_user=" + urlencode(user) + "&_pass=" + urlencode(pass); |
76 | final S page = doPost(query, url); |
77 | |
78 | awt { |
79 | frame.setStatus("Saved snippet: " + page); |
80 | jenable(buttons); |
81 | callF(next); |
82 | } |
83 | } |
84 | } |
85 | |
86 | void transpile(final bool multi) { |
87 | saveSnippet(r { |
88 | frame.setStatus("Transpiling..."); |
89 | jdisable(btnEleuReload); |
90 | |
91 | thread "Transpiling" { |
92 | try { |
93 | final Pair<Bool, S> p = transpileOnServer(snippetID, multi ? "medium" : "quick"); |
94 | awt { |
95 | if (p.a) |
96 | frame.setStatus("Transpiled OK!"); |
97 | else { |
98 | frame.setStatus("Transpilation error. " + p.b); |
99 | showText("Transpilation Error", p.b); |
100 | } |
101 | } |
102 | } catch e { |
103 | printStackTrace(e); |
104 | frame.setStatus("Transpilation problem. " + e); |
105 | } |
106 | jenable(btnEleuReload); |
107 | } |
108 | }); |
109 | } |
110 | |
111 | void reload() { |
112 | thread "Load Snippet" { |
113 | final S s = loadSnippet(snippetID); |
114 | awt { |
115 | frame.setStatus("Loaded " + s.length() + " chars."); |
116 | textArea.setText(s); |
117 | //textArea.scrollRectToVisible(new Rectangle(0, 0, 1, 1)); |
118 | textArea.setCaretPosition(0); |
119 | jenable(buttons); |
120 | textArea.setEditable(true); |
121 | textArea.requestFocus(); |
122 | } |
123 | } |
124 | } |
125 | |
126 | void eleuReload() { |
127 | //thread "Eleu Reload" { |
128 | S url = "http://ai1.lol/1002076/raw?q=" + urlencode("reload sub bot " + parseSnippetID(snippetID)); |
129 | openPlatformBrowser(url); |
130 | /*frame.setStatus(or2( |
131 | loadPage()), "Reload Problem"));*/ |
132 | //} |
133 | } |
134 | } |
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: | #1009480 |
Snippet name: | editJavaXSnippet [Swing] using RSyntaxTextArea |
Eternal ID of this version: | #1009480/1 |
Text MD5: | 4bd5f0bfa3cfdd82df96d78916660c5f |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-08-04 02:52:28 |
Source code size: | 4311 bytes / 134 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 443 / 467 |
Referenced in: | [show references] |