From 712eac2b3daf6059d9e0f25e70f1a4db826f0ad3 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 22 Apr 2014 17:20:35 +0200 Subject: [PATCH] * Added image download source with HQ images (mtgImage). --- .../dl/sources/MagicCardsImageSource.java | 2 - .../card/dl/sources/MtgImageSource.java | 93 +++++++++++++++++++ .../plugins/card/images/DownloadPictures.java | 12 ++- Mage/pom.xml | 4 +- 4 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MtgImageSource.java diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MagicCardsImageSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MagicCardsImageSource.java index d6f8dea211..d1d9082475 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MagicCardsImageSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MagicCardsImageSource.java @@ -2,9 +2,7 @@ package org.mage.plugins.card.dl.sources; import java.util.HashMap; import java.util.Map; -import mage.client.MageFrame; import mage.client.dialog.PreferencesDialog; -import static mage.client.dialog.PreferencesDialog.KEY_CARD_IMAGES_PREF_LANGUAGE; import org.mage.plugins.card.images.CardDownloadData; import org.mage.plugins.card.utils.CardImageUtils; diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MtgImageSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MtgImageSource.java new file mode 100644 index 0000000000..e77b7612d5 --- /dev/null +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MtgImageSource.java @@ -0,0 +1,93 @@ +/* +* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + +package org.mage.plugins.card.dl.sources; + +import java.util.HashMap; +import java.util.Map; +import static javax.swing.UIManager.put; +import mage.client.dialog.PreferencesDialog; +import org.mage.plugins.card.images.CardDownloadData; +import org.mage.plugins.card.utils.CardImageUtils; + +/** + * + * @author LevelX2 + */ + +public class MtgImageSource implements CardImageSource { + + private static CardImageSource instance = new MtgImageSource(); + + public static CardImageSource getInstance() { + if (instance == null) { + instance = new MtgImageSource(); + } + return instance; + } + + @Override + public String generateURL(CardDownloadData card) throws Exception { + Integer collectorId = card.getCollectorId(); + String cardSet = card.getSet(); + if (collectorId == null || cardSet == null) { + throw new Exception("Wrong parameters for image: collector id: " + collectorId + ",card set: " + cardSet); + } + String set = CardImageUtils.updateSet(cardSet, true); + + StringBuilder url = new StringBuilder("http://mtgimage.com/set/"); + url.append(set.toUpperCase()).append("/").append(card.getName()); + + if (card.isTwoFacedCard()) { + url.append(card.isSecondSide() ? "b" : "a"); + } + if (card.isSplitCard()) { + url.append("a"); + } + if (card.isFlipCard()) { + if (card.isFlippedSide()) { // download rotated by 180 degree image + url.append("b"); + } else { + url.append("a"); + } + } + url.append(".jpg"); + + return url.toString(); + } + + @Override + public String generateTokenUrl(CardDownloadData card) { + return null; + } + + @Override + public Float getAverageSize() { + return 70.0f; + } +} \ No newline at end of file diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java b/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java index 305797797d..2a1b519abc 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java @@ -35,6 +35,7 @@ import java.net.URL; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import org.mage.plugins.card.dl.sources.MtgImageSource; public class DownloadPictures extends DefaultBoundedRangeModel implements Runnable { @@ -111,7 +112,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"/*, "mtgathering.ru HQ", "mtgathering.ru MQ", "mtgathering.ru LQ"*/}); + ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(new String[] { "magiccards.info", "wizards.com", "mtgimage.com (HQ)" /*, "mtgathering.ru HQ", "mtgathering.ru MQ", "mtgathering.ru LQ"*/}); jComboBox1 = new JComboBox(); cardImageSource = MagicCardsImageSource.getInstance(); @@ -129,6 +130,9 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab case 1: cardImageSource = WizardCardsImageSource.getInstance(); break; + case 2: + cardImageSource = MtgImageSource.getInstance(); + break; } int count = DownloadPictures.this.cards.size(); float mb = (count * cardImageSource.getAverageSize()) / 1024; @@ -172,7 +176,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab public void actionPerformed(ActionEvent e) { ArrayList cardsToDownload = DownloadPictures.this.cards; if (checkBox.isSelected()) { - DownloadPictures.this.type2cards = new ArrayList(); + DownloadPictures.this.type2cards = new ArrayList<>(); for (CardDownloadData data : DownloadPictures.this.cards) { if (data.isType2() || data.isToken()) { DownloadPictures.this.type2cards.add(data); @@ -213,12 +217,12 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab private static ArrayList getNeededCards(List allCards) { - ArrayList cardsToDownload = new ArrayList(); + ArrayList cardsToDownload = new ArrayList<>(); /** * read all card names and urls */ - ArrayList allCardsUrls = new ArrayList(); + ArrayList allCardsUrls = new ArrayList<>(); HashSet ignoreUrls = SettingsManager.getIntance().getIgnoreUrls(); /** diff --git a/Mage/pom.xml b/Mage/pom.xml index 9bb6ead7f0..311367fbce 100644 --- a/Mage/pom.xml +++ b/Mage/pom.xml @@ -18,7 +18,7 @@ log4j log4j - 1.2.14 + 1.2.17 jar @@ -30,7 +30,7 @@ com.j256.ormlite ormlite-jdbc - 4.42 + 4.48