use of org.mage.plugins.card.dl.sources.ScryfallSymbolsSource in project mage by magefree.
the class CardPluginImpl method downloadSymbols.
/**
* Download various symbols (mana, tap, set).
*
* @param imagesDir Path to check in and store symbols to. Can't be null.
*/
@Override
public void downloadSymbols(String imagesDir) {
final Downloader downloader = new Downloader();
final DownloadGui downloadGui = new DownloadGui(downloader);
LOGGER.info("Symbols download prepare...");
Iterable<DownloadJob> jobs;
jobs = new GathererSymbols();
for (DownloadJob job : jobs) {
downloader.add(job);
}
jobs = new GathererSets();
for (DownloadJob job : jobs) {
downloader.add(job);
}
jobs = new ScryfallSymbolsSource();
for (DownloadJob job : jobs) {
downloader.add(job);
}
/*
it = new CardFrames(imagesDir); // TODO: delete frames download (not need now)
for (DownloadJob job : it) {
g.getDownloader().add(job);
}
*/
jobs = new DirectLinksForDownload();
for (DownloadJob job : jobs) {
downloader.add(job);
}
LOGGER.info("Symbols download needs " + downloader.getJobs().size() + " files");
// download GUI dialog
JDialog dialog = new JDialog((Frame) null, "Download symbols", false);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// user force to close window/downloader
downloader.cleanup();
}
});
dialog.setLayout(new BorderLayout());
dialog.add(downloadGui);
dialog.pack();
dialog.setVisible(true);
// downloader controller thread
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
downloader.publishAllJobs();
downloader.waitFinished();
downloader.cleanup();
return null;
}
};
// downloader finisher
worker.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("state")) {
if (evt.getNewValue() == SwingWorker.StateValue.DONE) {
// all done, can close dialog and refresh symbols for UI
LOGGER.info("Symbols download finished");
dialog.dispose();
ManaSymbols.loadImages();
ImageCache.clearCache();
}
}
}
});
worker.execute();
}
Aggregations