sclass JForwardingLibDownloader is Swingable { transient SingleComponentPanel scp; settable S libraryName; // snippet ID of library required for this platform settable LS libIDs; settable S sizeInformation; // how big is the library? event addingLibraries(Cl libIDs); bool supported() { ret nempty(libIDs()); } selfType forward(IF0 forward) { this.forward = forward; this; } swappable JComponent forward() { ret vstackWithSpacing(flattenToList( jcenteredlabel(libraryName() + " enabled"), map(file -> jcenteredline(jFilePathLabel(file).visualize()), libFiles()), jbutton("Delete " + libraryName(), rThread { if (!swingConfirm("Really?")) ret; deleteFilesVerbose(libFiles()); scp.setComponent(makeComponent()); }))); } L libFiles() { ret map DiskSnippetCache_getLibrary(libIDs()); } bool libDownloaded() { ret filesExist(libFiles()); } bool hasLib() { bool has = currentProgramHasLibraries(libFiles()); ret has; } void addLib() { if (supported()) { addingLibraries(libIDs()); if (addLibraries(libIDs())) print(libraryName() + " loaded: " + libIDs()); } } cachedVisualize { if (scp == null) scp = singleComponentPanel(makeComponent()); ret scp; } JComponent makeComponent() { if (!supported()) ret jcenteredlabel(libraryName() + " is not yet supported on your platform"); if (libDownloaded()) { addLib(); ret forward(); } else ret jfullcenter(centerAndEastWithMargin( jcenteredlabel("Download " + libraryName() + " for " + platformName() + appendBracketed(sizeInformation()) + "?"), jbuttonWithDisable("OK", r addLibWithProgressBar))); } void addLibWithProgressBar { scp.setComponent(jcenteredlabel("Downloading " + libraryName() + "...")); try { addLib(); scp.setComponent(forward()); } catch print e { scp.setComponent(jErrorView(e)); } } selfType libID(S libID) { ret libIDs(llNonNulls(libID)); } selfType libIDs(S... libIDs) { ret libIDs(asList(libIDs)); } void loadLibsIfDownloaded() { if (supported() && libDownloaded()) addLib(); } }