sclass InterestingString extends Module { S theString; transient SimpleLiveValue lv = new(S); void update { lv.set(theString); } JComponent visualize() { ret centerLabel(jLiveValueLabel(lv)); } } sclass UpdateCycles extends Module { long value; transient SimpleLiveValue lv = new(S); void update { value = updateCycles; lv.set(str(value)); } JComponent visualize() { ret onLeftClick(centerLabel(makeBold(setFontSize(40, jLiveValueLabel(lv)))), rst); } void enhanceFrame(JInternalFrame f) { internalFrameTitlePopupMenuItem(f, "Update", rst); } } sclass InputToInterestingString extends Module { transient java.util.Timer timer; void start { timer = doEvery(1000, r { Hello h = findModule(Hello); if (h == null) ret; S s = h.tf != null ? getTextTrim(h.tf) : trim(h.text); showModule(csetAndReturn(uniq(InterestingString), theString := s)); }); } void cleanMeUp() { cancelTimer(timer); } } sclass ModuleCount extends Module { transient JLabel label; void update { if (label != null) setText(label, lstr(onModules())); } JComponent visualize() { ret label = setFontSize(30, jcenteredlabel(lstr(onModules()))); } void unvisualize2() { label = null; } } sclass ModuleList extends Module { transient JList list; void update() { if (list != null) fillListWithStrings(list, calc()); } Module getModule(S item) { ret getConcept(Module, parseFirstLong(item)); } JComponent visualize() { list = jlist(calc()); ret listPopupMenuItemsThreaded(list, "Delete", voidfunc(fS s) { removeConcept(getModule(s)) }, "Show", voidfunc(fS s) { showModule(getModule(s)) }, "Hide", voidfunc(fS s) { hideModule(getModule(s)) }); } L calc() { ret map(func(Module m) -> S { renderConcept(m) /* contains id as first int */ }, onModules()); } void unvisualize2() { list = null; } } sclass ModuleClasses extends Module { transient L> classes; void start() { classes = myNonAbstractClassesImplementing(Module); } JComponent visualize() { JList list = jlist(map shortClassName(classes)); VF1 instantiate = voidfunc(fS s) { showModule((Module) nu(classForName("main$" + s))); }; listPopupMenuItemsThreaded(list, "Instantiate", instantiate); ret onDoubleClickThreaded(list, instantiate); } } sclass DynModule extends Module { S moduleID, _className; // "className" is taken by DynamicObject; _className == null for old-style dyn module S oStruct; // serialized dynamic object transient O o; *() {} *(S *moduleID, S *_className) {} JComponent visualize() { ret (JComponent) callOpt(o, 'visualize); } void enhanceFrame(final JInternalFrame f) { internalFrameTitlePopupMenuItem(f, "Reload", rThread(r reload)); thread { internalFrameTitle(f, snippetTitle(moduleID)); } } void start() { if (moduleID == null) ret; Class c = hotwireDependent(moduleID); if (oStruct != null) pcall { o = unstructureInRealm(oStruct, c); } if (o == null) if (_className == null) o = c; else o = nu(_getClass(c, _className)); setOpt(o, _host := this); if (o instanceof Class) callMain(o); else callOpt(o, 'start); } void unvisualize2() { callOpt(o, 'unvisualize2); } void update() { callOpt(o, 'update); } void cleanMeUp() { oStruct = null; pcall { oStruct = struct(o); } cleanUp(o); if (!o instanceof Class) cleanUp(_getClass(o, "main")); o = null; } void reload() { JInternalFrame frame = getInternalFrame(vis); unvisualize1b(); unvisualize2(); cleanUp(this); // also sets started to false if (frame != null) setInternalFrameContents(frame, jcenteredlabel("Reloading...")); visible = false; startModule(this); if (frame != null) { cset(this, visible := true); visualizeModule(this); print("New content: " + vis); setInternalFrameContents(frame, vis); } rst.trigger(); } S sourceCode() { ret loadSnippet(moduleID); } } sclass DynamicModuleMaker extends Module { JComponent visualize() { ret jfullcenter(jbutton("Add dynamic module...", r { selectSnippetID(voidfunc(fS snippetID) { L names = concatLists(ll("None"), map getClassDeclarationName(innerClassesOfMain(getServerTranspiledWithoutLibs(snippetID)))); selectFromList("Class to use", names, voidfunc(S className) { showModule(new DynModule(snippetID, eq(className, "None") ? null : "main$" + className)); }); }); })); } } sclass Hello extends Module { S text = "class main {}"; transient JTextField tf; JComponent visualize() { ret tf = setFontSize(20, jcenteredtextfield(text)); } void unvisualize2() { if (tf != null) cset(this, text := getText(tf)); tf = null; } void enhanceFrame(JInternalFrame f) { packInternalFrameVertically(700, f); centerInternalFrame(f); f.setLocation(f.getX(), 40); } }