1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-11 09:11:12 -09:00

Downloading backside image.

This commit is contained in:
magenoxx 2013-10-04 11:34:21 +04:00
parent 7800f62b70
commit 48445a4b87
2 changed files with 80 additions and 0 deletions
Mage.Client/src/main/java/org/mage/plugins/card

View file

@ -19,6 +19,7 @@ import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.dl.DownloadGui;
import org.mage.plugins.card.dl.DownloadJob;
import org.mage.plugins.card.dl.Downloader;
import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
import org.mage.plugins.card.dl.sources.GathererSets;
import org.mage.plugins.card.dl.sources.GathererSymbols;
import org.mage.plugins.card.images.ImageCache;
@ -444,6 +445,11 @@ public class CardPluginImpl implements CardPlugin {
g.getDownloader().add(job);
}
it = new DirectLinksForDownload(imagesPath);
for(DownloadJob job:it) {
g.getDownloader().add(job);
}
JDialog d = new JDialog((Frame) null, "Download pictures", false);
d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
d.addWindowListener(new WindowAdapter() {

View file

@ -0,0 +1,74 @@
/**
* GathererSymbols.java
*
* Created on 25.08.2010
*/
package org.mage.plugins.card.dl.sources;
import com.google.common.collect.AbstractIterator;
import org.mage.plugins.card.dl.DownloadJob;
import java.io.File;
import java.util.*;
import static java.lang.String.format;
import static org.mage.plugins.card.dl.DownloadJob.fromURL;
import static org.mage.plugins.card.dl.DownloadJob.toFile;
/**
* Used when we need to point to direct links to download resources from.
*
* @author noxx
*/
public class DirectLinksForDownload implements Iterable<DownloadJob> {
private static final String backsideUrl = "http://upload.wikimedia.org/wikipedia/en/a/aa/Magic_the_gathering-card_back.jpg";
private static final Map<String, String> directLinks = new LinkedHashMap<String, String>();
static {
directLinks.put("cardback.jpg", backsideUrl);
}
private static final String DEFAULT_IMAGES_PATH = File.separator + "default";
private static final File DEFAULT_OUT_DIR = new File("plugins" + File.separator + "images" + DEFAULT_IMAGES_PATH);
private static File outDir = DEFAULT_OUT_DIR;
public DirectLinksForDownload(String path) {
if (path == null) {
useDefaultDir();
} else {
changeOutDir(path);
}
}
@Override
public Iterator<DownloadJob> iterator() {
ArrayList<DownloadJob> jobs = new ArrayList<DownloadJob>();
for (Map.Entry<String, String> url : directLinks.entrySet()) {
File dst = new File(outDir, url.getKey());
jobs.add(new DownloadJob(url.getKey(), fromURL(url.getValue()), toFile(dst)));
}
return jobs.iterator();
}
private void changeOutDir(String path) {
File file = new File(path + DEFAULT_IMAGES_PATH);
if (file.exists()) {
outDir = file;
} else {
file.mkdirs();
if (file.exists()) {
outDir = file;
}
}
}
private void useDefaultDir() {
outDir = DEFAULT_OUT_DIR;
}
}