Uses 1113K of libraries. Click here for Pure Java version (4707L/24K).
1 | !7 |
2 | |
3 | cm CurrentAction { |
4 | transient JPanel stack; |
5 | transient new RestartableCountdown deleteIfUnused; |
6 | |
7 | start { |
8 | startCountdown(); |
9 | if (dm_getBounds() == null) { |
10 | int w = getWidth(dm_desktopPane()), h = getHeight(dm_desktopPane()); |
11 | dm_setBounds(this, w-300, h-200, 300, 200); |
12 | } |
13 | } |
14 | |
15 | visualize { |
16 | ret withRightMargin(stack = dynamicVStack2()); |
17 | } |
18 | |
19 | // start countdown to delete module if unused |
20 | void startCountdown { |
21 | deleteIfUnused.start(60.0, rEnter deleteIfUnused); |
22 | } |
23 | |
24 | // API |
25 | |
26 | interface AnAction extends AutoCloseable { |
27 | void setText(S text); |
28 | } |
29 | |
30 | // Note: cancelMe will be called in GUI thread |
31 | AutoCloseable showAction(S action, Runnable cancelMe) { |
32 | deleteIfUnused.stop(); |
33 | final JLabel lbl = jlabel(action); |
34 | final JComponent c = centerAndEast(lbl, jbutton("Cancel", cancelMe)); |
35 | addAndValidate(stack, c); |
36 | ret new AnAction { |
37 | public void close() enter { |
38 | removeAndValidate(c); |
39 | //print("Remaining components: " + componentCount(stack)); |
40 | if (emptyContainer(stack)) dm_hideModule(); |
41 | startCountdown(); |
42 | } |
43 | public void setText(S text) { main.setText(lbl, text); } |
44 | }; |
45 | } |
46 | |
47 | void deleteIfUnused { |
48 | // TODO: minimal race condition |
49 | if (countComponents(stack) == 0) dm_deleteModule(); |
50 | } |
51 | } |
download show line numbers debug dex old transpilations
Travelled to 11 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1019874 |
Snippet name: | Current Actions [so they can be cancelled] |
Eternal ID of this version: | #1019874/27 |
Text MD5: | c271040898628287e5a045bd1f4e8140 |
Transpilation MD5: | 6a6ede54303fa49ae2f5247827bb371a |
Author: | stefan |
Category: | javax / stefan's os |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-07-11 16:15:07 |
Source code size: | 1370 bytes / 51 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 443 / 18621 |
Version history: | 26 change(s) |
Referenced in: | [show references] |