Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

40
LINES

< > BotCompany Repo | #1016105 // ButtonIconLoader - load the "lazy" icon from network or disk

JavaX fragment (include)

1  
sclass ButtonIconLoader {
2  
  DynamicStack stack;
3  
  Set<JButton> loadedButtons = weakIdentityHashSet();
4  
  DeQ loadQ;
5  
  JScrollPane scrollPane;
6  
  ChangeListener changeListener;
7  
8  
  *(final DynamicStack *stack) {
9  
    bindToComponent(stack, r {
10  
      scrollPane = enclosingScrollPane(stack);
11  
      changeListener = scrollPaneOnScroll(scrollPane, r { update() });
12  
      update();
13  
    }, r {
14  
      if (scrollPane != null) {
15  
        scrollPane.getViewport().removeChangeListener(changeListener);
16  
        scrollPane = null;
17  
        changeListener = null;
18  
      }
19  
    });
20  
  }
21  
  
22  
  void update() swing {
23  
    for (final JButton b : reversed((L<JButton>) (L) stackElementsShowing(stack))) {
24  
      if (add_byContains(loadedButtons, b)) pcall {
25  
        TextImageAction tia = cast metaGet(TextImageAction.class, b);
26  
        fS imageID = (S) mapGet(tia.more, 'lazyImageID);
27  
        if (empty(imageID)) continue;
28  
        qAdd(r {
29  
          setButtonImage(b,
30  
            scaleBufferedImageToMaxWidthOrHeight(loadImage2(imageID), niceButtons_maxImageSize());
31  
        });
32  
      }
33  
    }
34  
  }
35  
  
36  
  void qAdd(Runnable r) {
37  
    if (loadQ == null) loadQ = startDeQ();
38  
    loadQ.addFirst(r);
39  
  }
40  
}

Author comment

Began life as a copy of #1015389

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: #1016105
Snippet name: ButtonIconLoader - load the "lazy" icon from network or disk
Eternal ID of this version: #1016105/5
Text MD5: 030f9527c8385aedd23e4195b37cc264
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-12 22:08:13
Source code size: 1209 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 385 / 957
Version history: 4 change(s)
Referenced in: [show references]