use of javafx.application.Preloader in project tokentool by RPTools.
the class TokenTool method init.
@Override
public void init() throws Exception {
// Since we are using multiple plugins (Twelve Monkeys for PSD and JAI for jpeg2000) in the same
// uber jar,
// the META-INF/services/javax.imageio.spi.ImageReaderSpi gets overwritten. So we need to
// register them manually:
// https://github.com/jai-imageio/jai-imageio-core/issues/29
IIORegistry registry = IIORegistry.getDefaultInstance();
registry.registerServiceProvider(new com.github.jaiimageio.jpeg2000.impl.J2KImageReaderSpi());
appInstance = this;
VERSION = getVersion();
// Lets install/update the overlays if newer version
AppSetup.install(VERSION);
log = LogManager.getLogger(TokenTool.class);
// Log some basic info
log.info("Environment: " + Sentry.getStoredClient().getEnvironment());
if (!Sentry.getStoredClient().getEnvironment().toLowerCase().equals("production"))
log.info("Not in Production mode and thus will not log any events to Sentry.io");
log.info("Release: " + Sentry.getStoredClient().getRelease());
log.info("OS: " + ThreadContext.get("OS"));
log.info("3D Hardware Available? " + Platform.isSupported(ConditionalFeature.SCENE3D));
// Now lets cache any overlays we find and update preLoader with progress
overlayCount = (int) Files.walk(AppConstants.OVERLAY_DIR.toPath()).filter(Files::isRegularFile).count();
overlayTreeItems = cacheOverlays(AppConstants.OVERLAY_DIR, null, THUMB_SIZE);
// All Done!
notifyPreloader(new Preloader.ProgressNotification(1.0));
}
use of javafx.application.Preloader in project tokentool by RPTools.
the class TokenTool method cacheOverlays.
/**
* @author Jamz
* @throws IOException
* @since 2.0
* <p>This method loads and processes all the overlays found in user.home/overlays and it can
* take a minute to load as it creates thumbnail versions for the comboBox so we call this
* during the init and display progress in the preLoader (splash screen).
*/
private TreeItem<Path> cacheOverlays(File dir, TreeItem<Path> parent, int THUMB_SIZE) throws IOException {
TreeItem<Path> root = new TreeItem<>(dir.toPath());
root.setExpanded(false);
log.debug("caching " + dir.getAbsolutePath());
File[] files = dir.listFiles();
for (File file : files) {
if (file.isDirectory()) {
cacheOverlays(file, root, THUMB_SIZE);
} else {
Path filePath = file.toPath();
TreeItem<Path> imageNode = new TreeItem<>(filePath, ImageUtil.getOverlayThumb(new ImageView(), filePath));
root.getChildren().add(imageNode);
notifyPreloader(new Preloader.ProgressNotification((double) loadCount++ / overlayCount));
}
}
if (parent != null) {
// When we show the overlay image, the TreeItem value is "" so we need to
// sort those to the bottom for a cleaner look and keep sub dir's at the top.
// If a node has no children then it's an overlay, otherwise it's a directory...
root.getChildren().sort(new Comparator<TreeItem<Path>>() {
@Override
public int compare(TreeItem<Path> o1, TreeItem<Path> o2) {
if (o1.getChildren().size() == 0 && o2.getChildren().size() == 0)
return 0;
else if (o1.getChildren().size() == 0)
return Integer.MAX_VALUE;
else if (o2.getChildren().size() == 0)
return Integer.MIN_VALUE;
else
return o1.getValue().compareTo(o2.getValue());
}
});
parent.getChildren().add(root);
}
return root;
}