Warning: session_start(): open(/var/lib/php/sessions/sess_c3q6mlloedpll5e9u2creod4qv, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
sS background = #1009931;
static JDesktopPane desktop;
static JTextField tfInput;
//static L modules;
static ReliableSingleThread rst = new(f updateModules);
static volatile long updateCycles;
p-noconsole {
autoRestart(5);
db();
desktop = jTiledBackgroundDesktopPane(background);
autoFixDesktopPane(desktop);
cleanExitOnFrameClose(frameIcon(#1101271, showMaximizedFrame(desktop)));
final JInternalFrame f = showCenteredInternalFrame(desktop, "Hello", 700, 150, setFontSize(20, tfInput = jcenteredtextfield("Find me some stuff")));
packInternalFrameVertically(f);
centerInternalFrame(f);
swing { f.setLocation(f.getX(), 40); }
UpdateCycles uc = conceptWhere(UpdateCycles);
if (uc != null) updateCycles = uc.value;
cset(uniq(ModuleClasses), on := true, visible := true);
for (Module m : onModules())
startModule(m);
addConceptIndex(simpleConceptIndex(rTrigger(rst)));
rst.trigger();
}
svoid updateModules {
++updateCycles;
for (Module m : onModules())
pcall { m.update(); }
}
svoid cleanMeUp {
//print('cleanMeUp);
for (Module m) if (m.vis != null) pcall {
print(m);
m.unvisualize();
}
//print("done cleanMeUp");
}
static L onModules() {
ret conceptsWhere(Module, on := true);
}
sbool hasModuleWithFields(Class extends Module> c, O... params) {
ret hasConcept(c, concatArrays(new O[] {on := true}, params));
}
svoid startModule(Module m) {
//addIfNotThere(modules, m);
lock m.lock;
if (m.started) ret;
m.started = true;
print("Starting module " + m);
m.start();
if (m.visible) showModule(m);
}
svoid showModule(final Module m) {
if (m == null) ret;
startModule(m);
lock m.lock;
if (m.vis != null) ret;
cset(m, visible := true);
visualizeModule(m);
if (m.vis != null) swing {
Rect r = m.frameRect;
if (r == null) randomRect(desktop.getWidth(), desktop.getHeight(), 10, 150, 100);
if (r == null) r = Rect(10, 10, 200, 100);
print("Showing frame at " + r);
S frameTitle = humanizeFormLabel(shortClassName(m));
JInternalFrame f;
onInternalFrameClosing(f = showInternalFrame(desktop, frameTitle, r.x, r.y, r.w, r.h, m.vis), r {
hideModule(m);
});
m.enhanceFrame(f);
}
}
svoid visualizeModule(Module m) {
pcall-messagebox {
if (m.vis == null)
m.vis = m.visualize();
if (m.vis == null)
m.vis = defaultVisualize(m);
}
}
svoid hideModule(final Module m) {
if (m == null) ret;
lock m.lock;
cset(m, visible := false);
pcall-messagebox { m.unvisualize(); }
}
concept Module {
transient Component vis;
transient bool started;
transient Lock lock = lock();
bool on = true, visible;
Rect frameRect;
JComponent visualize() { null; }
void unvisualize() { unvisualize1(); unvisualize2(); }
void enhanceFrame(JInternalFrame frame) {}
void start() {}
void unvisualize1() {
//print("unvisualize1");
JInternalFrame f = getInternalFrame(vis);
if (f != null) {
cset(this, frameRect := toRect(getBounds(f)));
disposeInternalFrame(f);
}
vis = null;
//print("done unvisualize1");
}
void unvisualize2() {}
void update() {}
void cleanMeUp_started() { started = false; }
void delete() {
unvisualize();
cleanUp(this);
super.delete();
}
}
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 long diff;
transient SimpleLiveValue lv = new(S);
void update { value = updateCycles; lv.set(str(value)); }
JComponent visualize() {
ret centerLabel(makeBold(setFontSize(40, jLiveValueLabel(lv))));
}
}
sclass InputToInterestingString extends Module {
transient java.util.Timer timer;
void start {
timer = doEvery(1000, r {
S s = getTextTrim(tfInput);
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() {
label = setFontSize(30, jcenteredlabel(lstr(onModules())));
ret label;
}
void unvisualize2() { label = null; }
}
sclass ModuleList extends Module {
transient JList list;
void update() {
if (list != null)
fillListWithStrings(list, calc());
}
JComponent visualize() {
list = jlist(calc());
listPopupMenuItem(list, "Delete", voidfunc(fS s) {
thread-messagebox {
Module m = getConcept(Module, parseFirstLong(s));
removeConcept(m);
}
});
listPopupMenuItem(list, "Show", voidfunc(fS s) {
thread-messagebox {
showModule(getConcept(Module, parseFirstLong(s)));
}
});
listPopupMenuItem(list, "Hide", voidfunc(fS s) {
thread-messagebox {
hideModule(getConcept(Module, parseFirstLong(s)));
}
});
ret list;
}
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));
listPopupMenuItem(list, "Instantiate", voidfunc(fS s) {
thread-messagebox {
showModule((Module) nu(classForName("main$" + s)));
}
});
ret list;
}
}
sclass DynModule extends Module {
S moduleID;
transient O o;
*() {}
*(S *moduleID) {}
JComponent visualize() { ret (JComponent) callOpt(o, 'visualize); }
void enhanceFrame(final JInternalFrame f) {
internalFrameTitlePopupMenu(f, voidfunc(JPopupMenu menu) {
addMenuItem(menu, "Reload", rThread(r reload));
});
thread { internalFrameTitle(f, snippetTitle(moduleID)); }
}
void start() {
if (moduleID != null) o = hotwireDependent(moduleID);
setOpt(o, host := this);
callMain(o);
}
void unvisualize1() {
JInternalFrame f = getInternalFrame(vis);
if (f != null)
cset(this, frameRect := toRect(getBounds(f)));
vis = null;
}
void unvisualize2() { callOpt(o, 'unvisualize2); }
void update() { callOpt(o, 'update); }
void cleanMeUp() {
cleanUp(o);
o = null;
}
void reload() {
JInternalFrame frame = getInternalFrame(vis);
unvisualize();
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);
setInternalFrameContents(frame, vis);
}
}
}
static JComponent defaultVisualize(Module m) {
ret jCenteredMultiLineLabel(renderConcept(m));
}
sclass DynamicModuleMaker extends Module {
JComponent visualize() {
ret jfullcenter(jbutton("Add dynamic module...", r {
selectSnippetID(voidfunc(S snippetID) {
showModule(new DynModule(snippetID));
});
}));
}
}
sS getInterestingString {
InterestingString m = findConcept(InterestingString);
ret m == null ? null : m.theString;
}