asclass JForwardingLibDownloader is Swingable { transient SingleComponentPanel scp; settable S sizeInformation; // how big is the library? selfType forward(IF0 forward) { this.forward = forward; this; } abstract S nameOfLibrary(); // library required for this platform abstract S libIDRequired(); swappable JComponent forward() { ret jcenteredlabel(nameOfLibrary() + " enabled"); } bool supported() { ret libID() != null; } bool libDownloaded() { ret fileExists(DiskSnippetCache_getLibrary(libID())); } bool hasLib() { bool has = currentProgramHasLibrary(DiskSnippetCache_getLibrary(libID())); print("Video library ID: " + libID() + ", loaded: " + has); ret has; } void addLib() { if (supported()) if (addLibraryToCurrentProgram(libID())) print(nameOfLibrary() + " loaded: " + libID()); } visualize { if (scp == null) scp = singleComponentPanel(makeComponent()); ret scp; } JComponent makeComponent() { if (!supported()) ret jcenteredlabel(nameOfLibrary() + " is not yet supported on your platform"); if (libDownloaded()) { addLib(); ret forward(); } else ret jfullcenter(centerAndEastWithMargin( jcenteredlabel("Download " + nameOfLibrary() + " for " + platformName() + appendBracketed(sizeInformation()) + "?"), jbuttonWithDisable("OK", r addLibWithProgressBar))); } void addLibWithProgressBar { scp.setComponent(jcenteredlabel("Downloading " + nameOfLibrary() + "...")); try { addLib(); scp.setComponent(forward()); } catch print e { scp.setComponent(jErrorView(e)); } } }