1 | sclass InputChooser implements Swingable {
|
2 | DynModule module; |
3 | bool myInput; |
4 | S ownInput; |
5 | |
6 | transient int delay; |
7 | transient ReliableSingleThread rst; |
8 | transient S input; |
9 | transient JPanel panel; |
10 | transient JTextField tfInput; |
11 | transient JCheckBox cbInput; |
12 | |
13 | *() {} // only for persistence
|
14 | *(DynModule *module) {}
|
15 | |
16 | S input() { ret input; }
|
17 | S _freshInput() { ret myInput ? ownInput : dm_getInterestingString(); }
|
18 | |
19 | void forceUpdate { input = null; module.updateMe(); }
|
20 | void forgetInput { input = null; }
|
21 | |
22 | bool update() {
|
23 | S s = _freshInput(); |
24 | ifdef InputChooser_verbose |
25 | print("Fresh input: " + s);
|
26 | endifdef |
27 | if (neq(input, s)) {
|
28 | input = s; |
29 | true; //dm_updateModule(); |
30 | } |
31 | false; |
32 | } |
33 | |
34 | public JComponent visualize() {
|
35 | if (panel != null) ret panel; |
36 | tfInput = jcenteredtextfield(ownInput); |
37 | cbInput = setToolTip("Checked: Use my own input. Unchecked: take input from AI bar on the top of OS", jcheckbox(myInput));
|
38 | |
39 | onChangeAndNow(cbInput, r {
|
40 | setEnabled(tfInput, isChecked(cbInput)); |
41 | myInput = isChecked(cbInput); |
42 | updateModule(); |
43 | }); |
44 | onChange(tfInput, r {
|
45 | if (myInput) {
|
46 | ownInput = getText(tfInput); |
47 | updateModule(); |
48 | } |
49 | }); |
50 | ret panel = westAndCenter(cbInput, tfInput); |
51 | } |
52 | |
53 | void updateModule {
|
54 | if (rst == null) rst = rstWithDelay(delay, r { module.updateMe() });
|
55 | rst.trigger(); |
56 | } |
57 | |
58 | InputChooser setDelay(int delay) { this.delay = delay; this; }
|
59 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1016450 |
| Snippet name: | InputChooser |
| Eternal ID of this version: | #1016450/19 |
| Text MD5: | 07c6d64bc1fade95c0d59d645979f92b |
| Author: | stefan |
| Category: | javax / stefan's os |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2018-10-09 16:47:35 |
| Source code size: | 1562 bytes / 59 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 647 / 1258 |
| Version history: | 18 change(s) |
| Referenced in: | [show references] |