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).

1  
sclass JGallery_v2 {
2  
  JPanel panel = jpanel(new VScrollingWrapLayout);
3  
  
4  
  settable new ThumbnailCache thumbnailCache;
5  
  
6  
  event adaptingButton(JThumbnailButton btn);
7  
  event fileClicked(File imageFile);
8  
  
9  
  void add(File imageFile) {
10  
    if (imageFile == null) ret;
11  
    addComponent(panel, makeButton(imageFile));
12  
  }
13  
  
14  
  JThumbnailButton makeButton(File imageFile) {
15  
    var btn = new JThumbnailButton(thumbnailCache, imageFile);
16  
    onClick(btn, rThread { fileClicked(btn.imageFile()) });
17  
    adaptingButton(btn);
18  
    ret btn;
19  
  }
20  
  
21  
  void setImageFiles(Cl<File> imageFiles) {
22  
    removeAllButtons();
23  
    addAll(imageFiles);
24  
  }
25  
  
26  
  void addAll(Iterable<File> imageFiles) {
27  
    fOr (f : imageFiles) add(f);
28  
  }
29  
  
30  
  L<JThumbnailButton> buttons() {
31  
    ret childrenOfType(panel, JThumbnailButton);
32  
  }
33  
  
34  
  void removeAllButtons {
35  
    removeAllComponents(panel);
36  
  }
37  
  
38  
  JThumbnailButton findButton(File imageFile) {
39  
    if (imageFile == null) null;
40  
    ret first(buttons(), btn -> eq(btn.imageFile, imageFile));
41  
  }
42  
  
43  
  cachedVisual
44  
    jscroll_vertical(panel);
45  
    
46  
  void unselectAll() swing {
47  
    for (btn : buttons())
48  
      btn.setSelected(false);
49  
  }
50  
    
51  
  JThumbnailButton selectFile(File imageFile) swing {
52  
    unselectAll();
53  
    var btn = findButton(imageFile);
54  
    if (btn != null) {
55  
      btn.setSelected(true);
56  
      scrollIntoView(btn);
57  
    }
58  
    ret btn;
59  
  }
60  
}

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: 94 / 190
Version history: 13 change(s)
Referenced in: [show references]