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

89
LINES

< > BotCompany Repo | #1035134 // JForwardingLibDownloader

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

Libraryless. Click here for Pure Java version (18238L/112K).

1  
sclass JForwardingLibDownloader is Swingable {
2  
  transient SingleComponentPanel scp;
3  
  
4  
  settable S libraryName;
5  
  
6  
  // snippet ID of library required for this platform
7  
  settable LS libIDs;
8  
9  
  settable S sizeInformation; // how big is the library?
10  
  
11  
  event addingLibraries(Cl<S> libIDs);
12  
  
13  
  bool supported() { ret nempty(libIDs()); }
14  
  
15  
  selfType forward(IF0<JComponent> forward) {
16  
    this.forward = forward;
17  
    this;
18  
  }
19  
  
20  
  swappable JComponent forward() {
21  
    ret vstackWithSpacing(flattenToList(
22  
      jcenteredlabel(libraryName() + " enabled"),
23  
      map(file -> jcenteredline(jFilePathLabel(file).visualize()),
24  
        libFiles()),
25  
      jbutton("Delete " + libraryName(), rThread {
26  
        if (!swingConfirm("Really?")) ret;
27  
        deleteFilesVerbose(libFiles());
28  
        scp.setComponent(makeComponent());
29  
      })));
30  
  }
31  
  
32  
  L<File> libFiles() {
33  
    ret map DiskSnippetCache_getLibrary(libIDs());
34  
  }
35  
  
36  
  bool libDownloaded() {
37  
    ret filesExist(libFiles());
38  
  }
39  
  
40  
  bool hasLib() {
41  
    bool has = currentProgramHasLibraries(libFiles());
42  
    ret has;
43  
  }
44  
  
45  
  void addLib() {
46  
    if (supported()) {
47  
      addingLibraries(libIDs());
48  
      if (addLibraries(libIDs()))
49  
        print(libraryName() + " loaded: " + libIDs());
50  
    }
51  
  }
52  
  
53  
  cachedVisualize {
54  
    if (scp == null)
55  
      scp = singleComponentPanel(makeComponent());
56  
    ret scp;
57  
  }
58  
  
59  
  JComponent makeComponent() {
60  
    if (!supported())
61  
      ret jcenteredlabel(libraryName() + " is not yet supported on your platform");
62  
      
63  
    if (libDownloaded()) {
64  
      addLib();
65  
      ret forward();
66  
    } else
67  
      ret jfullcenter(centerAndEastWithMargin(
68  
        jcenteredlabel("Download " + libraryName() + " for " + platformName() + appendBracketed(sizeInformation()) + "?"),
69  
        jbuttonWithDisable("OK", r addLibWithProgressBar)));
70  
  }
71  
  
72  
  void addLibWithProgressBar {
73  
    scp.setComponent(jcenteredlabel("Downloading " + libraryName() + "..."));
74  
    try {
75  
      addLib();
76  
      scp.setComponent(forward());
77  
    } catch print e {
78  
      scp.setComponent(jErrorView(e));
79  
    }
80  
  }
81  
  
82  
  selfType libID(S libID) { ret libIDs(llNonNulls(libID)); }
83  
  selfType libIDs(S... libIDs) { ret libIDs(asList(libIDs)); }
84  
  
85  
  void loadLibsIfDownloaded() {
86  
    if (supported() && libDownloaded())
87  
      addLib();
88  
  }
89  
}

Author comment

Began life as a copy of #1034410

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1035134
Snippet name: JForwardingLibDownloader
Eternal ID of this version: #1035134/24
Text MD5: 0d7e9c8d202787ee45cc055446f4e54b
Transpilation MD5: aad96088ae4c89706f5e2d5e0fb511d3
Author: stefan
Category: javax / video
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-11 23:53:05
Source code size: 2380 bytes / 89 lines
Pitched / IR pitched: No / No
Views / Downloads: 197 / 362
Version history: 23 change(s)
Referenced in: [show references]