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)

sclass ButtonIconLoader {
  DynamicStack stack;
  Set<JButton> loadedButtons = weakIdentityHashSet();
  DeQ loadQ;
  JScrollPane scrollPane;
  ChangeListener changeListener;

  *(final DynamicStack *stack) {
    bindToComponent(stack, r {
      scrollPane = enclosingScrollPane(stack);
      changeListener = scrollPaneOnScroll(scrollPane, r { update() });
      update();
    }, r {
      if (scrollPane != null) {
        scrollPane.getViewport().removeChangeListener(changeListener);
        scrollPane = null;
        changeListener = null;
      }
    });
  }
  
  void update() swing {
    for (final JButton b : reversed((L<JButton>) (L) stackElementsShowing(stack))) {
      if (add_byContains(loadedButtons, b)) pcall {
        TextImageAction tia = cast metaGet(TextImageAction.class, b);
        fS imageID = (S) mapGet(tia.more, 'lazyImageID);
        if (empty(imageID)) continue;
        qAdd(r {
          setButtonImage(b,
            scaleBufferedImageToMaxWidthOrHeight(loadImage2(imageID), niceButtons_maxImageSize());
        });
      }
    }
  }
  
  void qAdd(Runnable r) {
    if (loadQ == null) loadQ = startDeQ();
    loadQ.addFirst(r);
  }
}

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: 312 / 881
Version history: 4 change(s)
Referenced in: [show references]