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

49
LINES

< > BotCompany Repo | #1033910 // JGallery - should rewrite

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

Libraryless. Click here for Pure Java version (24463L/158K).

1  
// TODO: this "nice buttons" logic is pretty horrific
2  
transient sclass JGallery extends MetaWithChangeListeners is Swingable {
3  
  settableWithVar L<File> files;
4  
  gettable File selectedFile;
5  
  settable bool horizontal = true;
6  
  
7  
  event adaptingButton(JButton button, File file);
8  
9  
  simplyCached DynamicStack buttons() {
10  
    ret horizontal ? makeNiceButtons() : verticalNiceButtons();
11  
  }
12  
13  
  simplyCached ButtonImageLoader imageLoader() {
14  
    ret new ButtonImageLoader(buttons());
15  
  }
16  
  
17  
  void setImageFiles(Cl<File> filesCollection) swing {
18  
    var files = asList(filesCollection);
19  
    if (eq(this.files, files)) ret;
20  
    setFiles(files);
21  
    //printVars("JGallery.setImageFiles", n2(files));
22  
    L<TextImageAction> l = filesForNiceButtons(files, lambda1 openImage);
23  
    replaceNiceButtons(buttons(), l);
24  
    
25  
    for (btn, file : unpair zip(allButtons(buttons()), files))
26  
      adaptingButton(btn, file);
27  
      
28  
    File selectedFile = selectedFile();
29  
    selectFile(selectedFile);
30  
    imageLoader().update();
31  
  }
32  
  
33  
  void selectFile(File file) swing {
34  
    selectedFile = file;
35  
    int idx = indexOf(files, file);
36  
    for (int i, JButton btn : unpair iterateWithIndex(allButtons(buttons()))) {
37  
      bool selected = i == idx;
38  
      setSelected(btn, selected);
39  
      if (selected) {
40  
        print("Selected button: " + btn);
41  
        scrollIntoView(btn);
42  
      }
43  
    }
44  
  }
45  
  
46  
  cachedVisual jHigherScrollPane(jfullcenter(buttons()));
47  
  
48  
  swappable void openImage(File f) { showImage(f); }
49  
}

Author comment

Began life as a copy of #1019109

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033910
Snippet name: JGallery - should rewrite
Eternal ID of this version: #1033910/32
Text MD5: 3a0d45ff6be06d17a146207817b90fa0
Transpilation MD5: 20eb460fbefa996ef85c6a7acd6ae41a
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-16 21:19:39
Source code size: 1540 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 215 / 453
Version history: 31 change(s)
Referenced in: [show references]