1 | sclass InterestingString extends Module { |
2 | S theString; |
3 | |
4 | transient SimpleLiveValue<S> lv = new(S); |
5 | void update { lv.set(theString); } |
6 | |
7 | JComponent visualize() { |
8 | ret centerLabel(jLiveValueLabel(lv)); |
9 | } |
10 | } |
11 | |
12 | sclass UpdateCycles extends Module { |
13 | long value; |
14 | transient SimpleLiveValue<S> lv = new(S); |
15 | |
16 | void update { value = updateCycles; lv.set(str(value)); } |
17 | |
18 | JComponent visualize() { |
19 | ret jSection("INTERNAL UPDATES", onLeftClick(centerLabel(makeBold(setFontSize(40, jLiveValueLabel(lv)))), rstUpdateModules)); |
20 | } |
21 | |
22 | void enhanceFrame(JInternalFrame f) { |
23 | internalFrameTitlePopupMenuItem(f, "Update", rstUpdateModules); |
24 | } |
25 | } |
26 | |
27 | sclass InputToInterestingString extends Module { |
28 | transient java.util.Timer timer; |
29 | transient S lastHello, lastTop; |
30 | |
31 | void start { |
32 | timer = doEvery(1000, r { |
33 | Hello h = findModule(Hello); |
34 | S hello = h == null ? null : h.tf != null ? getText(h.tf) : h.text; |
35 | S top = getText(tfTopInput); |
36 | S value = null; |
37 | if (neq(hello, lastHello)) |
38 | value = hello; |
39 | else if (neq(top, lastTop)) |
40 | value = top; |
41 | if (value == null) |
42 | value = or2(top, hello); |
43 | lastHello = hello; |
44 | lastTop = top; |
45 | |
46 | startModule(csetAndReturn(uniq(InterestingString), theString := value)); |
47 | }); |
48 | } |
49 | |
50 | void cleanMeUp() { cancelTimer(timer); } |
51 | } |
52 | |
53 | sclass ModuleCount extends Module { |
54 | transient JLabel label; |
55 | |
56 | void update { |
57 | if (label != null) setText(label, lstr(onModules())); |
58 | } |
59 | |
60 | JComponent visualize() { |
61 | ret jSection("MODULES", label = setFontSize(30, jcenteredlabel(lstr(onModules())))); |
62 | } |
63 | |
64 | void unvisualize2() { label = null; } |
65 | } |
66 | |
67 | sclass ModuleList extends StaticModule_CalculatedList { |
68 | transient AutoCloseable listener; |
69 | |
70 | *() { |
71 | listener = vmBus_onMessages(vmBus_modulesListChangeMessages(), rThread { |
72 | //print("Updating module list"); |
73 | update(); |
74 | }); |
75 | } |
76 | |
77 | void cleanMeUp_ml { |
78 | closeAutoCloseable(listener); |
79 | } |
80 | |
81 | Module getModule(S item) { |
82 | ret getConcept(Module, parseFirstLong(item)); |
83 | } |
84 | |
85 | S moduleName() { if (eq(getClass(), ModuleList)) ret "Loaded Modules"; ret super.moduleName(); } |
86 | |
87 | JComponent visualize() { |
88 | super.visualize(); |
89 | onDoubleClickOrEnter(list, voidfunc(fS s) { showModule(getModule(s)) }); |
90 | listPopupMenuItemsThreaded(list, |
91 | "Delete", voidfunc(fS s) { removeConcept(getModule(s)) }, |
92 | "Show", voidfunc(fS s) { showModule(getModule(s)) }, |
93 | "Hide", voidfunc(fS s) { hideModule(getModule(s)) }); |
94 | listPopupMenu(list, voidfunc(JPopupMenu menu, S s) { |
95 | final Module m = getModule(s); |
96 | if (m cast DynamicModule) |
97 | addMenuItem(menu, "Reload", rThread { m.reload() }); |
98 | }); |
99 | ret list; |
100 | } |
101 | |
102 | L<S> calc() { |
103 | ret map(func(final Module m) -> S { |
104 | //renderConcept(m) /* contains id as first int */ |
105 | "[" + m.id + "] " + or2(pcallF(func -> S { m.moduleName() }), "?") |
106 | }, modulesToList()); |
107 | } |
108 | |
109 | L<Module> modulesToList() { ret onModules(); } |
110 | } |
111 | |
112 | sclass InvisibleModules extends ModuleList { |
113 | L<Module> modulesToList() { |
114 | ret sortedByMethodIC('moduleName, filterByField(onModules(), visible := false)); |
115 | } |
116 | |
117 | visualize { ret jSection("INVISIBLE MODULES", super.visualize()); } |
118 | } |
119 | |
120 | sclass ModuleClasses extends Module { |
121 | transient L<Class<? extends Module>> classes; |
122 | |
123 | void start() { |
124 | classes = filter(func(Class<? extends Module> c) -> bool { !isTrue(callOpt(c, 'needsParameters)) }, |
125 | myNonAbstractClassesImplementing(Module)); |
126 | } |
127 | |
128 | JComponent visualize() { |
129 | JList list = jlist(map shortClassName(classes)); |
130 | VF1<S> instantiate = voidfunc(fS s) { |
131 | showModule((Module) nu(classForName("main$" + s))); |
132 | }; |
133 | VF1<S> defaultAction = voidfunc(fS s) { |
134 | makeOrShowStaticModuleOfType(s); |
135 | }; |
136 | listPopupMenuItemsThreaded(list, "Instantiate", instantiate); |
137 | listPopupMenu(list, voidfunc(JPopupMenu menu, S item) { |
138 | Class<? extends Module> c = classForName("main$" + item); |
139 | final L<? extends Module> l = staticModulesOfType(c); |
140 | if (nempty(l)) |
141 | addMenuItem(menu, l(l) == 1 ? "Show instance" : "Show all " + l(l) + " instances", r-thread { showModules(l) }); |
142 | }); |
143 | ret onDoubleClickThreaded(list, defaultAction); |
144 | } |
145 | } |
146 | |
147 | sclass DynamicModuleMaker extends Module { |
148 | L uSearchData() { |
149 | ret ll(pair("Add dynamic module", r doIt)); |
150 | } |
151 | |
152 | void doIt { |
153 | stefansOS_addDynamicModuleDialog(); |
154 | } |
155 | |
156 | JComponent visualize() { |
157 | ret jfullcenter(jbutton("Add dynamic module...", r doIt); |
158 | } |
159 | } |
160 | |
161 | sclass Hello extends Module { |
162 | S text = "class main {}"; |
163 | |
164 | transient JTextField tf; |
165 | |
166 | void start { |
167 | makeModule(InputToInterestingString); |
168 | } |
169 | |
170 | JComponent visualize() { |
171 | ret tf = setFontSize(20, jcenteredtextfield(text)); |
172 | } |
173 | |
174 | void unvisualize2() { |
175 | if (tf != null) cset(this, text := getText(tf)); |
176 | tf = null; |
177 | } |
178 | |
179 | void enhanceFrame(JInternalFrame f) { |
180 | packInternalFrameVertically(700, f); |
181 | centerInternalFrame(f); |
182 | f.setLocation(f.getX(), 40); |
183 | } |
184 | |
185 | void setText(S text) { |
186 | temp enter(); |
187 | cset(this, +text); |
188 | main.setText(tf, text); |
189 | } |
190 | } |
download show line numbers debug dex old transpilations
Travelled to 20 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, jcllbfdqhrgy, lpdgvwnxivlt, mqqgnosmbjvj, omdjrrnzbjjv, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, snaazhdonpnp, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1015885 |
Snippet name: | Standard Modules [Include] |
Eternal ID of this version: | #1015885/57 |
Text MD5: | 925638b2f6a041f6237bc88dccee3698 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-11-10 20:06:32 |
Source code size: | 5283 bytes / 190 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 472 / 3055 |
Version history: | 56 change(s) |
Referenced in: | [show references] |