From e649e8ec62388eac9f5bf1a07a67c2bc1efd6549 Mon Sep 17 00:00:00 2001 From: North Date: Wed, 1 Jun 2011 23:35:26 +0300 Subject: [PATCH] Added mtgathering.ru download source. --- .../dl/sources/MtgatheringRuImageSource.java | 72 +++++++++++++++++++ .../plugins/card/images/DownloadPictures.java | 12 +++- .../mage/plugins/card/utils/ImageManager.java | 1 - 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/dl/sources/MtgatheringRuImageSource.java diff --git a/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/dl/sources/MtgatheringRuImageSource.java b/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/dl/sources/MtgatheringRuImageSource.java new file mode 100644 index 0000000000..12335fe808 --- /dev/null +++ b/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/dl/sources/MtgatheringRuImageSource.java @@ -0,0 +1,72 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.mage.plugins.card.dl.sources; + +import java.util.HashMap; +import java.util.Map; +import org.mage.plugins.card.utils.CardImageUtils; + +/** + * + * @author North + */ +public class MtgatheringRuImageSource implements CardImageSource { + + private static CardImageSource hqInstance; + private static CardImageSource mqInstance; + private static CardImageSource lqInstance; + private static final Map setsAliases; + + static { + setsAliases = new HashMap(); + setsAliases.put("MBS", "mirrodinbesieged"); + setsAliases.put("M11", "magic2011"); + } + private String quality; + + public static CardImageSource getHqInstance() { + if (hqInstance == null) { + hqInstance = new MtgatheringRuImageSource("hq"); + } + return hqInstance; + } + + public static CardImageSource getMqInstance() { + if (mqInstance == null) { + mqInstance = new MtgatheringRuImageSource("md"); + } + return mqInstance; + } + + public static CardImageSource getLqInstance() { + if (lqInstance == null) { + lqInstance = new MtgatheringRuImageSource("lq"); + } + return lqInstance; + } + + public MtgatheringRuImageSource(String quality) { + this.quality = quality; + } + + @Override + public String generateURL(Integer collectorId, String cardSet) throws Exception { + if (collectorId == null || cardSet == null) { + throw new Exception("Wrong parameters for image: collector id: " + collectorId + ",card set: " + cardSet); + } + if (setsAliases.get(cardSet) == null) { + String set = CardImageUtils.updateSet(cardSet, true); + String url = "http://magiccards.info/scans/en/"; + url += set.toLowerCase() + "/" + collectorId + ".jpg"; + + return url; + } else { + String set = CardImageUtils.updateSet(cardSet, true); + String url = "http://mtgathering.ru/scans/en/"; + url += set.toLowerCase() + "/" + quality + "/" + collectorId + ".jpg"; + return url; + } + } +} diff --git a/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/images/DownloadPictures.java b/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/images/DownloadPictures.java index ba1bc253d4..6912b4b48e 100644 --- a/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/images/DownloadPictures.java +++ b/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/images/DownloadPictures.java @@ -50,6 +50,7 @@ import org.mage.plugins.card.CardUrl; import org.mage.plugins.card.constants.Constants; import org.mage.plugins.card.dl.sources.CardImageSource; import org.mage.plugins.card.dl.sources.MagicCardsImageSource; +import org.mage.plugins.card.dl.sources.MtgatheringRuImageSource; import org.mage.plugins.card.dl.sources.WizardCardsImageSource; import org.mage.plugins.card.properties.SettingsManager; import org.mage.plugins.card.utils.CardImageUtils; @@ -156,7 +157,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab p0.add(jLabel1); p0.add(Box.createVerticalStrut(5)); - ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(new String[] { "magiccards.info", "wizards.com" }); + ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(new String[] { "magiccards.info", "wizards.com", "mtgathering.ru HQ", "mtgathering.ru MQ", "mtgathering.ru LQ"}); jComboBox1 = new JComboBox(); cardImageSource = MagicCardsImageSource.getInstance(); @@ -174,6 +175,15 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab case 1: cardImageSource = WizardCardsImageSource.getInstance(); break; + case 2: + cardImageSource = MtgatheringRuImageSource.getHqInstance(); + break; + case 3: + cardImageSource = MtgatheringRuImageSource.getMqInstance(); + break; + case 4: + cardImageSource = MtgatheringRuImageSource.getLqInstance(); + break; } } }); diff --git a/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/utils/ImageManager.java b/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/utils/ImageManager.java index 8c7ad4012e..1e1daad6a5 100644 --- a/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/utils/ImageManager.java +++ b/Mage.Plugins/Mage.Card.Plugin/src/main/java/org/mage/plugins/card/utils/ImageManager.java @@ -1,7 +1,6 @@ package org.mage.plugins.card.utils; import java.awt.*; -import java.awt.image.BufferedImage; public interface ImageManager { public Image getSicknessImage();