1 | sclass ForwardAndBackButtons { |
2 | JTextField tf; |
3 | O onClick; // runnable |
4 | JButton btnBack, btnForw; |
5 | new L<S> history; |
6 | int historyIdx; |
7 | |
8 | *(JTextField *tf, O *onClick) { |
9 | btnBack = jbutton(resizeImage(loadImage2(#1007466), 32), r { back() }); |
10 | btnForw = jbutton(resizeImage( |
11 | img_getCenterPortion(loadImage2(#1007467), 198, 198), 32), r { forward() }); |
12 | update(); |
13 | } |
14 | |
15 | JPanel buttons() { |
16 | ret hstackWithSpacing(6, btnBack, btnForw); |
17 | } |
18 | |
19 | void back { |
20 | if (historyIdx <= 1) ret; |
21 | --historyIdx; |
22 | tf.setText(history.get(historyIdx-1)); |
23 | go(); |
24 | } |
25 | |
26 | void forward { |
27 | if (historyIdx >= l(history)) ret; |
28 | ++historyIdx; |
29 | tf.setText(history.get(historyIdx-1)); |
30 | go(); |
31 | } |
32 | |
33 | void go { |
34 | update(); |
35 | pcallF(onClick); |
36 | } |
37 | |
38 | void submitted { |
39 | subList(history, historyIdx).clear(); |
40 | history.add(getTextTrim(tf)); |
41 | ++historyIdx; |
42 | update(); |
43 | } |
44 | |
45 | void update { |
46 | btnBack.setEnabled(historyIdx > 1); |
47 | btnForw.setEnabled(historyIdx < l(history)); |
48 | } |
49 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1007501 |
Snippet name: | ForwardAndBackButtons |
Eternal ID of this version: | #1007501/3 |
Text MD5: | a4de75988fe3e8d642d65b76744b338d |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-03-25 17:13:23 |
Source code size: | 1067 bytes / 49 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 650 / 1212 |
Version history: | 2 change(s) |
Referenced in: | [show references] |