sclass InputChooser implements Swingable { DynModule module; bool myInput; S ownInput; transient int delay; transient ReliableSingleThread rst; transient S input; transient JPanel panel; transient JTextField tfInput; transient JCheckBox cbInput; *() {} // only for persistence *(DynModule *module) {} S input() { ret input; } S _freshInput() { ret myInput ? ownInput : dm_getInterestingString(); } void forceUpdate { input = null; module.updateMe(); } void forgetInput { input = null; } bool update() { S s = _freshInput(); ifdef InputChooser_verbose print("Fresh input: " + s); endifdef if (neq(input, s)) { input = s; true; //dm_updateModule(); } false; } public JComponent visualize() { if (panel != null) ret panel; tfInput = jcenteredtextfield(ownInput); cbInput = setToolTip("Checked: Use my own input. Unchecked: take input from AI bar on the top of OS", jcheckbox(myInput)); onChangeAndNow(cbInput, r { setEnabled(tfInput, isChecked(cbInput)); myInput = isChecked(cbInput); updateModule(); }); onChange(tfInput, r { if (myInput) { ownInput = getText(tfInput); updateModule(); } }); ret panel = westAndCenter(cbInput, tfInput); } void updateModule { if (rst == null) rst = rstWithDelay(delay, r { module.updateMe() }); rst.trigger(); } InputChooser setDelay(int delay) { this.delay = delay; this; } }
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: | 435 / 1040 |
Version history: | 18 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |