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

60
LINES

< > BotCompany Repo | #1035950 // JGallery_v2

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (14299L/86K).

sclass JGallery_v2 {
  JPanel panel = jpanel(new VScrollingWrapLayout);
  
  settable new ThumbnailCache thumbnailCache;
  
  event adaptingButton(JThumbnailButton btn);
  event fileClicked(File imageFile);
  
  void add(File imageFile) {
    if (imageFile == null) ret;
    addComponent(panel, makeButton(imageFile));
  }
  
  JThumbnailButton makeButton(File imageFile) {
    var btn = new JThumbnailButton(thumbnailCache, imageFile);
    onClick(btn, rThread { fileClicked(btn.imageFile()) });
    adaptingButton(btn);
    ret btn;
  }
  
  void setImageFiles(Cl<File> imageFiles) {
    removeAllButtons();
    addAll(imageFiles);
  }
  
  void addAll(Iterable<File> imageFiles) {
    fOr (f : imageFiles) add(f);
  }
  
  L<JThumbnailButton> buttons() {
    ret childrenOfType(panel, JThumbnailButton);
  }
  
  void removeAllButtons {
    removeAllComponents(panel);
  }
  
  JThumbnailButton findButton(File imageFile) {
    if (imageFile == null) null;
    ret first(buttons(), btn -> eq(btn.imageFile, imageFile));
  }
  
  cachedVisual
    jscroll_vertical(panel);
    
  void unselectAll() swing {
    for (btn : buttons())
      btn.setSelected(false);
  }
    
  JThumbnailButton selectFile(File imageFile) swing {
    unselectAll();
    var btn = findButton(imageFile);
    if (btn != null) {
      btn.setSelected(true);
      scrollIntoView(btn);
    }
    ret btn;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): elmgxqgtpvxh, mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1035950
Snippet name: JGallery_v2
Eternal ID of this version: #1035950/14
Text MD5: 983336933abb444300e7ff7a96b42845
Transpilation MD5: 2c27bcc97e8dbe90a9614bd320e94b5a
Author: stefan
Category: javax / io
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-17 19:48:34
Source code size: 1445 bytes / 60 lines
Pitched / IR pitched: No / No
Views / Downloads: 160 / 278
Version history: 13 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)