Libraryless. Click here for Pure Java version (9891L/58K).
1 | sclass ButtonImageLoader { |
2 | DynamicStack stack; |
3 | Set<JButton> loadedButtons = weakIdentityHashSet(); |
4 | DeQ loadQ; |
5 | JScrollPane scrollPane; |
6 | ChangeListener changeListener; |
7 | settable int imageHeight = 128; |
8 | |
9 | *(DynamicStack *stack) { |
10 | bindToComponent(stack, -> { |
11 | scrollPane = enclosingScrollPane(stack); |
12 | changeListener = scrollPaneOnScroll(scrollPane, r { update() }); |
13 | update(); |
14 | }, -> { |
15 | if (scrollPane != null) { |
16 | scrollPane.getViewport().removeChangeListener(changeListener); |
17 | scrollPane = null; |
18 | changeListener = null; |
19 | } |
20 | }); |
21 | } |
22 | |
23 | void update() swing { |
24 | //new L<Runnable> l; |
25 | for (JButton b : reversed((L<JButton>) (L) stackElementsShowing(stack))) { |
26 | //if (add(loadedButtons, b)) pcall { // will strangely not work |
27 | if (add_byContains(loadedButtons, b)) pcall { |
28 | TextImageAction tia = cast metaGet(b, TextImageAction.class); |
29 | if (tia == null) continue with print("no tia"); |
30 | File f = tia.file; |
31 | if (f == null) continue with print("no file"); |
32 | qAdd(r { setAButtonsImage(b, f) }); |
33 | } |
34 | } |
35 | //if (nempty(l)) qAdd(chainRunnables_pcall(l)); |
36 | } |
37 | |
38 | void qAdd(Runnable r) { |
39 | if (loadQ == null) loadQ = startDeQ(); |
40 | loadQ.addFirst(r); |
41 | } |
42 | |
43 | // overridable |
44 | void setAButtonsImage(JButton b, File f) { |
45 | setButtonImage(b, loadPreviewImage(f)); |
46 | //print("Loaded: " + f); |
47 | } |
48 | |
49 | // overridable |
50 | BufferedImage loadPreviewImage(File f) { |
51 | ret loadPreviewImageWithExactHeight(imageHeight, f); |
52 | } |
53 | } |
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: | #1015389 |
Snippet name: | ButtonImageLoader - for buttons that represent images on disk |
Eternal ID of this version: | #1015389/19 |
Text MD5: | 667a79683467fa7e64b72d508a59dfe3 |
Transpilation MD5: | e29a1c6a5cc4bb412931bc9e6e15271a |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-15 21:51:52 |
Source code size: | 1591 bytes / 53 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 510 / 1124 |
Version history: | 18 change(s) |
Referenced in: | [show references] |