Download Jar. Uses 3874K of libraries. Click here for Pure Java version (15599L/115K).
1 | !7 |
2 | |
3 | sS background = #1009931; |
4 | static JDesktopPane desktop; |
5 | static ReliableSingleThread rst = new(f updateModules); |
6 | static volatile long updateCycles; |
7 | |
8 | p-noconsole {
|
9 | autoRestart(); |
10 | db(); |
11 | |
12 | desktop = jDesktopPaneWithSkyPicture(background, Color.black); |
13 | autoFixDesktopPane(desktop); |
14 | cleanExitOnFrameClose(frameIcon(#1101272, showMaximizedFrame(desktop))); |
15 | titlePopupMenuItem(desktop, "New Session", rThreadPcallMessageBox(r deleteAllModules)); |
16 | |
17 | initAfterDBLoad(); |
18 | } |
19 | |
20 | svoid initAfterDBLoad {
|
21 | initialModules(); |
22 | |
23 | UpdateCycles uc = conceptWhere(UpdateCycles); |
24 | if (uc != null) updateCycles = uc.value; |
25 | |
26 | for (Module m : onModules()) startModule(m); |
27 | |
28 | addConceptIndex(simpleConceptIndex(rst)); |
29 | rst.trigger(); |
30 | } |
31 | |
32 | svoid initialModules {
|
33 | if (!hasConcept(ModuleClasses)) |
34 | showModule(uniq(ModuleClasses)); |
35 | } |
36 | |
37 | svoid updateModules {
|
38 | ++updateCycles; |
39 | for (Module m : onModules()) |
40 | pcall { m.update(); }
|
41 | } |
42 | |
43 | svoid cleanMeUp {
|
44 | for (Module m) if (m.vis != null) pcall {
|
45 | m.unvisualize(); |
46 | } |
47 | |
48 | for (Module m) cleanUp(m); |
49 | } |
50 | |
51 | static L<Module> onModules() { ret conceptsWhere(Module, on := true); }
|
52 | |
53 | sbool hasModuleWithFields(Class<? extends Module> c, O... params) {
|
54 | ret hasConcept(c, concatArrays(new O[] {on := true}, params));
|
55 | } |
56 | |
57 | svoid startModule(Module m) {
|
58 | //addIfNotThere(modules, m); |
59 | lock m.lock; |
60 | if (m.started) ret; |
61 | m.started = true; |
62 | print("Starting module " + m);
|
63 | m.start(); |
64 | if (m.visible) showModule(m); |
65 | } |
66 | |
67 | svoid showModule(final Module m) {
|
68 | if (m == null) ret; |
69 | startModule(m); |
70 | lock m.lock; |
71 | if (m.vis != null) ret; |
72 | cset(m, visible := true); |
73 | visualizeModule(m); |
74 | if (m.vis != null) swing {
|
75 | Rect r = m.frameRect; |
76 | if (r == null) r = randomRect(desktop.getWidth(), desktop.getHeight(), 10, 150, 100); |
77 | if (r == null) r = Rect(10, 10, 200, 100); |
78 | print("Showing frame at " + r);
|
79 | S frameTitle = humanizeFormLabel(shortClassName(m)); |
80 | final JInternalFrame f = showInternalFrame(desktop, frameTitle, r.x, r.y, r.w, r.h, m.vis); |
81 | |
82 | internalFrameTitlePopupMenuItem(f, "Module source", r-thread { pcall-messagebox {
|
83 | S src = m.sourceCode(); |
84 | if (src != null) showText(internalFrameTitle(f) + " [Source]", src); else infoBox("No source code found");
|
85 | }}); |
86 | onInternalFrameIconified(f, r { hideModule(m) });
|
87 | onInternalFrameClosing(f, r { deleteModule(m) /* really? */ });
|
88 | m.enhanceFrame(f); |
89 | } |
90 | } |
91 | |
92 | svoid deleteModule(Module m) { removeConcept(m); }
|
93 | |
94 | svoid visualizeModule(Module m) {
|
95 | pcall-messagebox {
|
96 | if (m.vis == null) m.vis = m.visualize(); |
97 | if (m.vis == null) m.vis = defaultVisualize(m); |
98 | } |
99 | } |
100 | |
101 | svoid hideModule(final Module m) {
|
102 | if (m == null) ret; |
103 | lock m.lock; |
104 | cset(m, visible := false); |
105 | pcall-messagebox { m.unvisualize(); }
|
106 | } |
107 | |
108 | abstract concept Module {
|
109 | transient Component vis; |
110 | transient bool started; |
111 | transient Lock lock = lock(); |
112 | |
113 | bool on = true, visible; |
114 | Rect frameRect; |
115 | |
116 | JComponent visualize() { null; }
|
117 | void unvisualize() { unvisualize1(); unvisualize2(); }
|
118 | void enhanceFrame(JInternalFrame frame) {}
|
119 | void start() {}
|
120 | void unvisualize1() {
|
121 | disposeInternalFrame(getInternalFrame(vis)); |
122 | unvisualize1b(); |
123 | } |
124 | |
125 | void unvisualize1b() {
|
126 | grabFrameRect(); |
127 | vis = null; |
128 | } |
129 | void unvisualize2() {}
|
130 | void update() {}
|
131 | |
132 | void grabFrameRect() {
|
133 | JInternalFrame f = getInternalFrame(vis); |
134 | if (f != null) |
135 | cset(this, frameRect := toRect(getBounds(f))); |
136 | } |
137 | |
138 | void cleanMeUp_started() { started = false; }
|
139 | |
140 | void delete() {
|
141 | unvisualize(); |
142 | cleanUp(this); |
143 | super.delete(); |
144 | } |
145 | |
146 | S sourceCode() {
|
147 | ret javaxSourceOfMyClass1(shortClassName(this)); |
148 | } |
149 | |
150 | void triggerUpdate { rst.trigger(); }
|
151 | } |
152 | |
153 | sclass InterestingString extends Module {
|
154 | S theString; |
155 | |
156 | transient SimpleLiveValue<S> lv = new(S); |
157 | void update { lv.set(theString); }
|
158 | |
159 | JComponent visualize() {
|
160 | ret centerLabel(jLiveValueLabel(lv)); |
161 | } |
162 | } |
163 | |
164 | sclass UpdateCycles extends Module {
|
165 | long value; |
166 | transient SimpleLiveValue<S> lv = new(S); |
167 | |
168 | void update { value = updateCycles; lv.set(str(value)); }
|
169 | |
170 | JComponent visualize() {
|
171 | ret onLeftClick(centerLabel(makeBold(setFontSize(40, jLiveValueLabel(lv)))), rst); |
172 | } |
173 | |
174 | void enhanceFrame(JInternalFrame f) {
|
175 | internalFrameTitlePopupMenuItem(f, "Update", rst); |
176 | } |
177 | } |
178 | |
179 | sclass InputToInterestingString extends Module {
|
180 | transient java.util.Timer timer; |
181 | |
182 | void start {
|
183 | timer = doEvery(1000, r {
|
184 | Hello h = findModule(Hello); |
185 | if (h == null) ret; |
186 | S s = h.tf != null ? getTextTrim(h.tf) : trim(h.text); |
187 | showModule(csetAndReturn(uniq(InterestingString), theString := s)); |
188 | }); |
189 | } |
190 | |
191 | void cleanMeUp() { cancelTimer(timer); }
|
192 | } |
193 | |
194 | sclass ModuleCount extends Module {
|
195 | transient JLabel label; |
196 | |
197 | void update {
|
198 | if (label != null) setText(label, lstr(onModules())); |
199 | } |
200 | |
201 | JComponent visualize() {
|
202 | ret label = setFontSize(30, jcenteredlabel(lstr(onModules()))); |
203 | } |
204 | |
205 | void unvisualize2() { label = null; }
|
206 | } |
207 | |
208 | sclass ModuleList extends Module {
|
209 | transient JList list; |
210 | |
211 | void update() {
|
212 | if (list != null) fillListWithStrings(list, calc()); |
213 | } |
214 | |
215 | Module getModule(S item) {
|
216 | ret getConcept(Module, parseFirstLong(item)); |
217 | } |
218 | |
219 | JComponent visualize() {
|
220 | list = jlist(calc()); |
221 | ret listPopupMenuItemsThreaded(list, |
222 | "Delete", voidfunc(fS s) { removeConcept(getModule(s)) },
|
223 | "Show", voidfunc(fS s) { showModule(getModule(s)) },
|
224 | "Hide", voidfunc(fS s) { hideModule(getModule(s)) });
|
225 | } |
226 | |
227 | L<S> calc() {
|
228 | ret map(func(Module m) -> S { renderConcept(m) /* contains id as first int */ }, onModules());
|
229 | } |
230 | |
231 | void unvisualize2() { list = null; }
|
232 | } |
233 | |
234 | sclass ModuleClasses extends Module {
|
235 | transient L<Class<? extends Module>> classes; |
236 | |
237 | void start() {
|
238 | classes = myNonAbstractClassesImplementing(Module); |
239 | } |
240 | |
241 | JComponent visualize() {
|
242 | JList list = jlist(map shortClassName(classes)); |
243 | VF1<S> instantiate = voidfunc(fS s) {
|
244 | showModule((Module) nu(classForName("main$" + s)));
|
245 | }; |
246 | listPopupMenuItemsThreaded(list, "Instantiate", instantiate); |
247 | ret onDoubleClickThreaded(list, instantiate); |
248 | } |
249 | } |
250 | |
251 | sclass DynModule extends Module {
|
252 | S moduleID; |
253 | |
254 | transient O o; |
255 | |
256 | *() {}
|
257 | *(S *moduleID) {}
|
258 | |
259 | JComponent visualize() { ret (JComponent) callOpt(o, 'visualize); }
|
260 | void enhanceFrame(final JInternalFrame f) {
|
261 | internalFrameTitlePopupMenuItem(f, "Reload", rThread(r reload)); |
262 | thread { internalFrameTitle(f, snippetTitle(moduleID)); }
|
263 | } |
264 | void start() {
|
265 | if (moduleID != null) o = hotwireDependent(moduleID); |
266 | setOpt(o, host := this); |
267 | callMain(o); |
268 | } |
269 | void unvisualize2() { callOpt(o, 'unvisualize2); }
|
270 | void update() { callOpt(o, 'update); }
|
271 | void cleanMeUp() {
|
272 | cleanUp(o); |
273 | o = null; |
274 | } |
275 | |
276 | void reload() {
|
277 | JInternalFrame frame = getInternalFrame(vis); |
278 | unvisualize1b(); |
279 | unvisualize2(); |
280 | cleanUp(this); // also sets started to false |
281 | if (frame != null) |
282 | setInternalFrameContents(frame, jcenteredlabel("Reloading..."));
|
283 | visible = false; |
284 | startModule(this); |
285 | if (frame != null) {
|
286 | cset(this, visible := true); |
287 | visualizeModule(this); |
288 | print("New content: " + vis);
|
289 | setInternalFrameContents(frame, vis); |
290 | } |
291 | rst.trigger(); |
292 | } |
293 | |
294 | S sourceCode() {
|
295 | ret loadSnippet(moduleID); |
296 | } |
297 | } |
298 | |
299 | static JComponent defaultVisualize(Module m) {
|
300 | ret jCenteredMultiLineLabel(renderConcept(m)); |
301 | } |
302 | |
303 | sclass DynamicModuleMaker extends Module {
|
304 | JComponent visualize() {
|
305 | ret jfullcenter(jbutton("Add dynamic module...", r {
|
306 | selectSnippetID(voidfunc(S snippetID) {
|
307 | showModule(new DynModule(snippetID)); |
308 | }); |
309 | })); |
310 | } |
311 | } |
312 | |
313 | static <A extends Module> A findModule(Class<A> c) {
|
314 | ret findConcept(c, on := true); |
315 | } |
316 | |
317 | sS getInterestingString {
|
318 | InterestingString m = findModule(InterestingString); |
319 | ret m == null ? null : m.theString; |
320 | } |
321 | |
322 | sclass Hello extends Module {
|
323 | S text = "class main {}";
|
324 | |
325 | transient JTextField tf; |
326 | |
327 | JComponent visualize() {
|
328 | ret tf = setFontSize(20, jcenteredtextfield(text)); |
329 | } |
330 | |
331 | void unvisualize2() {
|
332 | if (tf != null) cset(this, text := getText(tf)); |
333 | tf = null; |
334 | } |
335 | |
336 | void enhanceFrame(JInternalFrame f) {
|
337 | packInternalFrameVertically(700, f); |
338 | centerInternalFrame(f); |
339 | f.setLocation(f.getX(), 40); |
340 | } |
341 | } |
342 | |
343 | sS modulesSessionGrab() {
|
344 | grabFrameRects(); |
345 | ret struct(ll(programID(), localDateWithMilliseconds())) + "\n" |
346 | + mainConcepts.xfullgrab(); |
347 | } |
348 | |
349 | svoid autoSaveModulesSession() {
|
350 | infoBox("Auto-saving session.");
|
351 | S grab; |
352 | logQuoted(javaxBackupDir(fsI(programID()) + "/auto-saved-sessions.txt"), grab = modulesSessionGrab()); |
353 | infoBox("Auto-save done (" + l(grab) + " chars)");
|
354 | } |
355 | |
356 | svoid deleteAllModules() {
|
357 | autoSaveModulesSession(); |
358 | deleteConcepts(Module); |
359 | initialModules; |
360 | } |
361 | |
362 | svoid restoreModulesSession(S text) {
|
363 | autoSaveModulesSession(); |
364 | infoBox("Releasing session");
|
365 | cleanMeUp(); |
366 | cleanUp(mainConcepts); |
367 | mainConcepts = null; |
368 | //sleepSeconds(1); |
369 | infoBox("Loading session");
|
370 | mainConcepts = new Concepts().load(dropFirstLine(text)); |
371 | initAfterDBLoad(); |
372 | infoBox("Session restore done");
|
373 | } |
374 | |
375 | svoid grabFrameRects {
|
376 | for (Module m : onModules()) m.grabFrameRect(); |
377 | } |
378 | |
379 | !include once #1015842 // SavedSessiosn |
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: | #1015808 |
| Snippet name: | Stefan's OS v1 [OK] |
| Eternal ID of this version: | #1015808/94 |
| Text MD5: | dca5c06e2f4a2ab9b5fa4254c18f2d45 |
| Transpilation MD5: | 881132d65f76e6f9ef0245a9b6b057f0 |
| Author: | stefan |
| Category: | javax / a.i. |
| Type: | JavaX source code (desktop) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2018-05-29 00:52:27 |
| Source code size: | 9602 bytes / 379 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 923 / 2561 |
| Version history: | 93 change(s) |
| Referenced in: | [show references] |