Merge branch 'master' into akh-card-frame

This commit is contained in:
Mark Langen 2017-04-04 18:36:37 -06:00 committed by GitHub
commit a2e8cedd02
272 changed files with 7641 additions and 2593 deletions

View file

@ -12,6 +12,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLayeredPane;
@ -33,6 +34,7 @@ import org.apache.log4j.Logger;
import org.mage.card.arcane.Animation;
import org.mage.card.arcane.CardPanel;
import org.mage.card.arcane.CardPanelComponentImpl;
import org.mage.card.arcane.CardPanelRenderImpl;
import org.mage.card.arcane.ManaSymbols;
import org.mage.plugins.card.dl.DownloadGui;
import org.mage.plugins.card.dl.DownloadJob;
@ -43,7 +45,6 @@ import org.mage.plugins.card.dl.sources.GathererSets;
import org.mage.plugins.card.dl.sources.GathererSymbols;
import org.mage.plugins.card.images.ImageCache;
import org.mage.plugins.card.info.CardInfoPaneImpl;
import org.mage.card.arcane.CardPanelRenderImpl;
/**
* {@link CardPlugin} implementation.
@ -108,10 +109,10 @@ public class CardPluginImpl implements CardPlugin {
cardWidthMin = (int) GUISizeHelper.battlefieldCardMinDimension.getWidth();
cardWidthMax = (int) GUISizeHelper.battlefieldCardMaxDimension.getWidth();
}
/**
* Temporary card rendering shim. Split card rendering isn't implemented yet, so
* use old component based rendering for the split cards.
* Temporary card rendering shim. Split card rendering isn't implemented
* yet, so use old component based rendering for the split cards.
*/
private CardPanel makePanel(CardView view, UUID gameId, boolean loadImage, ActionCallback callback, boolean isFoil, Dimension dimension) {
String fallback = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_RENDERING_FALLBACK, "false");
@ -584,7 +585,7 @@ public class CardPluginImpl implements CardPlugin {
Animation.showCard(card, count > 0 ? count : 1);
try {
while ((card).getAlpha() + 0.05f < 1) {
Thread.sleep(30);
TimeUnit.MILLISECONDS.sleep(30);
}
} catch (Exception e) {
e.printStackTrace();
@ -598,7 +599,7 @@ public class CardPluginImpl implements CardPlugin {
Animation.hideCard(card, count > 0 ? count : 1);
try {
while ((card).getAlpha() - 0.05f > 0) {
Thread.sleep(30);
TimeUnit.MILLISECONDS.sleep(30);
}
} catch (Exception e) {
e.printStackTrace();

View file

@ -29,6 +29,7 @@ package org.mage.plugins.card.dl.sources;
import java.io.IOException;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import org.mage.plugins.card.images.CardDownloadData;
@ -1697,7 +1698,7 @@ public class GrabbagImageSource implements CardImageSource {
public void doPause(String httpImageUrl) {
if (!httpImageUrl.startsWith("/MTG")) {
try {
Thread.sleep(2000);
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException ex) {
}
}

View file

@ -24,8 +24,7 @@
* 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.io.BufferedReader;
@ -41,6 +40,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.prefs.Preferences;
import mage.client.MageFrame;
import mage.client.dialog.PreferencesDialog;
@ -271,12 +271,12 @@ public class WizardCardsImageSource implements CardImageSource {
public String getNextHttpImageUrl() {
return null;
}
@Override
public String getFileForHttpImage(String httpImageUrl) {
return null;
}
private Map<String, String> getSetLinks(String cardSet) {
ConcurrentHashMap<String, String> setLinks = new ConcurrentHashMap<>();
ExecutorService executor = Executors.newFixedThreadPool(10);
@ -289,7 +289,7 @@ public class WizardCardsImageSource implements CardImageSource {
int firstMultiverseIdLastPage = 0;
Pages:
while (page < 999) {
String searchUrl = "http://gatherer.wizards.com/Pages/Search/Default.aspx?page=" + page +"&output=spoiler&method=visual&action=advanced&set=+[%22" + URLSetName + "%22]";
String searchUrl = "http://gatherer.wizards.com/Pages/Search/Default.aspx?page=" + page + "&output=spoiler&method=visual&action=advanced&set=+[%22" + URLSetName + "%22]";
Document doc = getDocument(searchUrl);
Elements cardsImages = doc.select("img[src^=../../Handlers/]");
if (cardsImages.isEmpty()) {
@ -320,7 +320,7 @@ public class WizardCardsImageSource implements CardImageSource {
while (!executor.isTerminated()) {
try {
Thread.sleep(1000);
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException ie) {
}
}
@ -339,7 +339,7 @@ public class WizardCardsImageSource implements CardImageSource {
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
URL url = new URL(urlString);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyServer, proxyPort));
HttpURLConnection uc = (HttpURLConnection)url.openConnection(proxy);
HttpURLConnection uc = (HttpURLConnection) url.openConnection(proxy);
uc.connect();
@ -359,7 +359,7 @@ public class WizardCardsImageSource implements CardImageSource {
Document landDoc = getDocument(urlLandDocument);
Elements variations = landDoc.select("a.variationlink");
Map<String, String> links = new HashMap<>();
if(!variations.isEmpty()) {
if (!variations.isEmpty()) {
int landNumber = 1;
for (Element variation : variations) {
Integer landMultiverseId = Integer.parseInt(variation.attr("onclick").replaceAll("[^\\d]", ""));
@ -374,7 +374,7 @@ public class WizardCardsImageSource implements CardImageSource {
}
private static String generateLink(int landMultiverseId) {
return "/Handlers/Image.ashx?multiverseid=" +landMultiverseId + "&type=card";
return "/Handlers/Image.ashx?multiverseid=" + landMultiverseId + "&type=card";
}
private int getLocalizedMultiverseId(String preferedLanguage, Integer multiverseId) throws IOException {
@ -396,7 +396,7 @@ public class WizardCardsImageSource implements CardImageSource {
Document cardLanguagesDoc = getDocument(cardLanguagesUrl);
Elements languageTableRows = cardLanguagesDoc.select("tr.cardItem");
HashMap<String, Integer> localizedIds = new HashMap<>();
if(!languageTableRows.isEmpty()) {
if (!languageTableRows.isEmpty()) {
for (Element languageTableRow : languageTableRows) {
Elements languageTableColumns = languageTableRow.select("td");
Integer localizedId = Integer.parseInt(languageTableColumns.get(0).select("a").first().attr("href").replaceAll("[^\\d]", ""));
@ -408,14 +408,14 @@ public class WizardCardsImageSource implements CardImageSource {
}
private String normalizeName(String name) {
//Split card
if(name.contains("//")) {
name = name.substring(0, name.indexOf('(') - 1);
}
//Special timeshifted name
if(name.startsWith("XX")) {
name = name.substring(name.indexOf('(') + 1, name.length() - 1);
}
//Split card
if (name.contains("//")) {
name = name.substring(0, name.indexOf('(') - 1);
}
//Special timeshifted name
if (name.startsWith("XX")) {
name = name.substring(name.indexOf('(') + 1, name.length() - 1);
}
return name.replace("\u2014", "-").replace("\u2019", "'")
.replace("\u00C6", "AE").replace("\u00E6", "ae")
.replace("\u00C3\u2020", "AE")
@ -445,7 +445,7 @@ public class WizardCardsImageSource implements CardImageSource {
if (link == null) {
int length = collectorId.length();
if (Character.isLetter(collectorId.charAt(length -1))) {
if (Character.isLetter(collectorId.charAt(length - 1))) {
length -= 1;
}
@ -507,17 +507,17 @@ public class WizardCardsImageSource implements CardImageSource {
}
}
@Override
public int getTotalImages() {
return -1;
}
@Override
public boolean isTokenSource() {
return false;
}
@Override
public void doPause(String httpImageUrl) {
}

View file

@ -1,5 +1,22 @@
package org.mage.plugins.card.images;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
import java.nio.file.AccessDeniedException;
import java.util.*;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.FileImageOutputStream;
import javax.swing.*;
import mage.cards.repository.CardInfo;
import mage.client.constants.Constants;
import mage.client.dialog.PreferencesDialog;
@ -15,23 +32,6 @@ import org.mage.plugins.card.dl.sources.*;
import org.mage.plugins.card.properties.SettingsManager;
import org.mage.plugins.card.utils.CardImageUtils;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.FileImageOutputStream;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
import java.nio.file.AccessDeniedException;
import java.util.*;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
public class DownloadPictures extends DefaultBoundedRangeModel implements Runnable {
private static final Logger logger = Logger.getLogger(DownloadPictures.class);
@ -316,7 +316,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
List<CardDownloadData> cardsToDownload = Collections.synchronizedList(new ArrayList<>());
allCardsUrls.parallelStream().forEach(card -> {
TFile file = new TFile(CardImageUtils.generateImagePath(card));
logger.debug(card.getName() + " (is_token=" + card.isToken() + "). Image is here:" + file.getAbsolutePath() + " (exists=" + file.exists() +')');
logger.debug(card.getName() + " (is_token=" + card.isToken() + "). Image is here:" + file.getAbsolutePath() + " (exists=" + file.exists() + ')');
if (!file.exists()) {
logger.debug("Missing: " + file.getAbsolutePath());
cardsToDownload.add(card);
@ -345,9 +345,8 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
return list;
}
try(InputStreamReader input = new InputStreamReader(in);
BufferedReader reader = new BufferedReader(input)) {
try (InputStreamReader input = new InputStreamReader(in);
BufferedReader reader = new BufferedReader(input)) {
String line = reader.readLine();
while (line != null) {
@ -486,7 +485,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
executor.shutdown();
while (!executor.isTerminated()) {
try {
Thread.sleep(1000);
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException ie) {
}
}