* Added image download source with HQ images (mtgImage).

This commit is contained in:
LevelX2 2014-04-22 17:20:35 +02:00
parent be0db95dbe
commit 712eac2b3d
4 changed files with 103 additions and 8 deletions

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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<CardDownloadData> cardsToDownload = DownloadPictures.this.cards;
if (checkBox.isSelected()) {
DownloadPictures.this.type2cards = new ArrayList<CardDownloadData>();
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<CardDownloadData> getNeededCards(List<CardInfo> allCards) {
ArrayList<CardDownloadData> cardsToDownload = new ArrayList<CardDownloadData>();
ArrayList<CardDownloadData> cardsToDownload = new ArrayList<>();
/**
* read all card names and urls
*/
ArrayList<CardDownloadData> allCardsUrls = new ArrayList<CardDownloadData>();
ArrayList<CardDownloadData> allCardsUrls = new ArrayList<>();
HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();
/**

View file

@ -18,7 +18,7 @@
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<version>1.2.17</version>
<type>jar</type>
</dependency>
@ -30,7 +30,7 @@
<dependency>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-jdbc</artifactId>
<version>4.42</version>
<version>4.48</version>
</dependency>
</dependencies>