forked from External/mage
Change all line endings to LF
This commit is contained in:
parent
13d9a56b7a
commit
430ae503c7
17069 changed files with 1263498 additions and 1263497 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,26 +1,26 @@
|
|||
package org.mage.plugins.card.constants;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.io.File;
|
||||
|
||||
public class Constants {
|
||||
|
||||
public static final String RESOURCE_PATH_SET = File.separator + "sets" + File.separator;
|
||||
|
||||
public static final String RESOURCE_PATH_MANA_SMALL = File.separator + "symbols" + File.separator + "small";
|
||||
public static final String RESOURCE_PATH_MANA_LARGE = File.separator + "symbols" + File.separator + "large";
|
||||
public static final String RESOURCE_PATH_MANA_MEDIUM = File.separator + "symbols" + File.separator + "medium";
|
||||
|
||||
public static final String RESOURCE_PATH_SET_SMALL = RESOURCE_PATH_SET + File.separator + "small" + File.separator;
|
||||
|
||||
public static final Rectangle CARD_SIZE_FULL = new Rectangle(101, 149);
|
||||
public static final Rectangle THUMBNAIL_SIZE_FULL = new Rectangle(102, 146);
|
||||
|
||||
public interface IO {
|
||||
|
||||
String imageBaseDir = "plugins" + File.separator + "images";
|
||||
String IMAGE_PROPERTIES_FILE = "image.url.properties";
|
||||
}
|
||||
|
||||
public static final String CARD_IMAGE_PATH_TEMPLATE = "." + File.separator + "plugins" + File.separator + "images/{set}/{name}.{collector}.full.jpg";
|
||||
}
|
||||
package org.mage.plugins.card.constants;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.io.File;
|
||||
|
||||
public class Constants {
|
||||
|
||||
public static final String RESOURCE_PATH_SET = File.separator + "sets" + File.separator;
|
||||
|
||||
public static final String RESOURCE_PATH_MANA_SMALL = File.separator + "symbols" + File.separator + "small";
|
||||
public static final String RESOURCE_PATH_MANA_LARGE = File.separator + "symbols" + File.separator + "large";
|
||||
public static final String RESOURCE_PATH_MANA_MEDIUM = File.separator + "symbols" + File.separator + "medium";
|
||||
|
||||
public static final String RESOURCE_PATH_SET_SMALL = RESOURCE_PATH_SET + File.separator + "small" + File.separator;
|
||||
|
||||
public static final Rectangle CARD_SIZE_FULL = new Rectangle(101, 149);
|
||||
public static final Rectangle THUMBNAIL_SIZE_FULL = new Rectangle(102, 146);
|
||||
|
||||
public interface IO {
|
||||
|
||||
String imageBaseDir = "plugins" + File.separator + "images";
|
||||
String IMAGE_PROPERTIES_FILE = "image.url.properties";
|
||||
}
|
||||
|
||||
public static final String CARD_IMAGE_PATH_TEMPLATE = "." + File.separator + "plugins" + File.separator + "images/{set}/{name}.{collector}.full.jpg";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,100 +1,100 @@
|
|||
/*
|
||||
* 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.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import org.mage.plugins.card.dl.DownloadJob;
|
||||
import static org.mage.plugins.card.dl.DownloadJob.fromURL;
|
||||
import static org.mage.plugins.card.dl.DownloadJob.toFile;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class CardFrames implements Iterable<DownloadJob> {
|
||||
|
||||
private static final String FRAMES_PATH = File.separator + "frames";
|
||||
private static final File DEFAULT_OUT_DIR = new File("plugins" + File.separator + "images" + FRAMES_PATH);
|
||||
private static File outDir = DEFAULT_OUT_DIR;
|
||||
|
||||
static final String BASE_DOWNLOAD_URL = "http://ct-magefree.rhcloud.com/resources/img/";
|
||||
static final String TEXTURES_FOLDER = "textures";
|
||||
static final String PT_BOXES_FOLDER = "pt";
|
||||
|
||||
private static final String[] TEXTURES = {"U", "R", "G", "B", "W", "A",
|
||||
"BG_LAND", "BR_LAND", "WU_LAND", "WB_LAND", "UB_LAND", "GW_LAND", "RW_LAND",
|
||||
"RG_LAND", "GU_LAND", "UR_LAND"
|
||||
// NOT => "BW_LAND","BU_LAND","WG_LAND","WR_LAND",
|
||||
};
|
||||
private static final String[] PT_BOXES = {"U", "R", "G", "B", "W", "A"};
|
||||
|
||||
public CardFrames(String path) {
|
||||
if (path == null) {
|
||||
useDefaultDir();
|
||||
} else {
|
||||
changeOutDir(path);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<DownloadJob> iterator() {
|
||||
ArrayList<DownloadJob> jobs = new ArrayList<>();
|
||||
for (String texture : TEXTURES) {
|
||||
jobs.add(generateDownloadJob(TEXTURES_FOLDER, texture));
|
||||
}
|
||||
for (String pt_box : PT_BOXES) {
|
||||
jobs.add(generateDownloadJob(PT_BOXES_FOLDER, pt_box));
|
||||
}
|
||||
return jobs.iterator();
|
||||
}
|
||||
|
||||
private DownloadJob generateDownloadJob(String dirName, String name) {
|
||||
File dst = new File(outDir, name + ".png");
|
||||
String url = BASE_DOWNLOAD_URL + dirName + "/" + name + ".png";
|
||||
return new DownloadJob("frames-" + dirName + "-" + name, fromURL(url), toFile(dst));
|
||||
}
|
||||
|
||||
private void useDefaultDir() {
|
||||
outDir = DEFAULT_OUT_DIR;
|
||||
}
|
||||
|
||||
private void changeOutDir(String path) {
|
||||
File file = new File(path + FRAMES_PATH);
|
||||
if (file.exists()) {
|
||||
outDir = file;
|
||||
} else {
|
||||
file.mkdirs();
|
||||
if (file.exists()) {
|
||||
outDir = file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import org.mage.plugins.card.dl.DownloadJob;
|
||||
import static org.mage.plugins.card.dl.DownloadJob.fromURL;
|
||||
import static org.mage.plugins.card.dl.DownloadJob.toFile;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class CardFrames implements Iterable<DownloadJob> {
|
||||
|
||||
private static final String FRAMES_PATH = File.separator + "frames";
|
||||
private static final File DEFAULT_OUT_DIR = new File("plugins" + File.separator + "images" + FRAMES_PATH);
|
||||
private static File outDir = DEFAULT_OUT_DIR;
|
||||
|
||||
static final String BASE_DOWNLOAD_URL = "http://ct-magefree.rhcloud.com/resources/img/";
|
||||
static final String TEXTURES_FOLDER = "textures";
|
||||
static final String PT_BOXES_FOLDER = "pt";
|
||||
|
||||
private static final String[] TEXTURES = {"U", "R", "G", "B", "W", "A",
|
||||
"BG_LAND", "BR_LAND", "WU_LAND", "WB_LAND", "UB_LAND", "GW_LAND", "RW_LAND",
|
||||
"RG_LAND", "GU_LAND", "UR_LAND"
|
||||
// NOT => "BW_LAND","BU_LAND","WG_LAND","WR_LAND",
|
||||
};
|
||||
private static final String[] PT_BOXES = {"U", "R", "G", "B", "W", "A"};
|
||||
|
||||
public CardFrames(String path) {
|
||||
if (path == null) {
|
||||
useDefaultDir();
|
||||
} else {
|
||||
changeOutDir(path);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<DownloadJob> iterator() {
|
||||
ArrayList<DownloadJob> jobs = new ArrayList<>();
|
||||
for (String texture : TEXTURES) {
|
||||
jobs.add(generateDownloadJob(TEXTURES_FOLDER, texture));
|
||||
}
|
||||
for (String pt_box : PT_BOXES) {
|
||||
jobs.add(generateDownloadJob(PT_BOXES_FOLDER, pt_box));
|
||||
}
|
||||
return jobs.iterator();
|
||||
}
|
||||
|
||||
private DownloadJob generateDownloadJob(String dirName, String name) {
|
||||
File dst = new File(outDir, name + ".png");
|
||||
String url = BASE_DOWNLOAD_URL + dirName + "/" + name + ".png";
|
||||
return new DownloadJob("frames-" + dirName + "-" + name, fromURL(url), toFile(dst));
|
||||
}
|
||||
|
||||
private void useDefaultDir() {
|
||||
outDir = DEFAULT_OUT_DIR;
|
||||
}
|
||||
|
||||
private void changeOutDir(String path) {
|
||||
File file = new File(path + FRAMES_PATH);
|
||||
if (file.exists()) {
|
||||
outDir = file;
|
||||
} else {
|
||||
file.mkdirs();
|
||||
if (file.exists()) {
|
||||
outDir = file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,98 +1,98 @@
|
|||
/*
|
||||
* 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 org.mage.plugins.card.images.CardDownloadData;
|
||||
|
||||
/**
|
||||
* Site was shutdown by wizards Feb. 2015
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @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 getSourceName() {
|
||||
return "mtgimage.com";
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
StringBuilder url = new StringBuilder("http://mtgimage.com/set/");
|
||||
url.append(cardSet.toUpperCase()).append("/");
|
||||
|
||||
if (card.isSplitCard()) {
|
||||
url.append(card.getDownloadName().replaceAll(" // ", ""));
|
||||
} else {
|
||||
url.append(card.getDownloadName().replaceAll(" ", "%20"));
|
||||
}
|
||||
|
||||
if (card.isTwoFacedCard()) {
|
||||
url.append(card.isSecondSide() ? "b" : "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;
|
||||
}
|
||||
/*
|
||||
* 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 org.mage.plugins.card.images.CardDownloadData;
|
||||
|
||||
/**
|
||||
* Site was shutdown by wizards Feb. 2015
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @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 getSourceName() {
|
||||
return "mtgimage.com";
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
StringBuilder url = new StringBuilder("http://mtgimage.com/set/");
|
||||
url.append(cardSet.toUpperCase()).append("/");
|
||||
|
||||
if (card.isSplitCard()) {
|
||||
url.append(card.getDownloadName().replaceAll(" // ", ""));
|
||||
} else {
|
||||
url.append(card.getDownloadName().replaceAll(" ", "%20"));
|
||||
}
|
||||
|
||||
if (card.isTwoFacedCard()) {
|
||||
url.append(card.isSecondSide() ? "b" : "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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,219 +1,219 @@
|
|||
/*
|
||||
* 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.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.prefs.Preferences;
|
||||
import mage.client.MageFrame;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Connection.ProxyType;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.mage.plugins.card.images.CardDownloadData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class MythicspoilerComSource implements CardImageSource {
|
||||
|
||||
private static CardImageSource instance;
|
||||
private static Map<String, String> setsAliases;
|
||||
private static Map<String, String> cardNameAliases;
|
||||
private static Map<String, Set<String>> cardNameAliasesStart;
|
||||
private final Map<String, Map<String, String>> sets;
|
||||
|
||||
public static CardImageSource getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new MythicspoilerComSource();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return "mythicspoiler.com";
|
||||
}
|
||||
|
||||
public MythicspoilerComSource() {
|
||||
sets = new LinkedHashMap<>();
|
||||
setsAliases = new HashMap<>();
|
||||
setsAliases.put("exp", "bfz");
|
||||
cardNameAliases = new HashMap<>();
|
||||
// set+wrong name from web side => correct card name
|
||||
cardNameAliases.put("MM2-otherwordlyjourney", "otherworldlyjourney");
|
||||
cardNameAliases.put("THS-fellhideminotaur", "felhideminotaur");
|
||||
cardNameAliases.put("THS-purphorosemissary", "purphorossemissary");
|
||||
cardNameAliases.put("THS-soldierofpantheon", "soldierofthepantheon");
|
||||
cardNameAliases.put("THS-vulpinegolaith", "vulpinegoliath");
|
||||
cardNameAliases.put("ORI-kothopedhoarderofsouls", "kothophedsoulhoarder");
|
||||
cardNameAliases.put("BFZ-unisonstrike", "tandemtactics");
|
||||
cardNameAliases.put("BFZ-eldrazidevastator", "eldrazidevastator");
|
||||
cardNameAliases.put("BFZ-kozliekschanneler", "kozilekschanneler");
|
||||
cardNameAliases.put("OGW-wastes", "wastes1");
|
||||
cardNameAliases.put("OGW-wastes2", "wastes2");
|
||||
|
||||
cardNameAliasesStart = new HashMap<>();
|
||||
HashSet<String> names = new HashSet<>();
|
||||
names.add("eldrazidevastator.jpg");
|
||||
cardNameAliasesStart.put("BFZ", names);
|
||||
}
|
||||
|
||||
private Map<String, String> getSetLinks(String cardSet) {
|
||||
Map<String, String> setLinks = new HashMap<>();
|
||||
try {
|
||||
String setNames = setsAliases.get(cardSet.toLowerCase());
|
||||
Set<String> aliasesStart = new HashSet<>();
|
||||
if (cardNameAliasesStart.containsKey(cardSet)) {
|
||||
aliasesStart.addAll(cardNameAliasesStart.get(cardSet));
|
||||
}
|
||||
if (setNames == null) {
|
||||
setNames = cardSet.toLowerCase();
|
||||
}
|
||||
Preferences prefs = MageFrame.getPreferences();
|
||||
Connection.ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
|
||||
for (String setName : setNames.split("\\^")) {
|
||||
String URLSetName = URLEncoder.encode(setName, "UTF-8");
|
||||
String baseUrl = "http://mythicspoiler.com/" + URLSetName + "/";
|
||||
String urlDocument;
|
||||
Document doc;
|
||||
if (proxyType.equals(ProxyType.NONE)) {
|
||||
urlDocument = baseUrl;
|
||||
doc = Jsoup.connect(urlDocument).get();
|
||||
} else {
|
||||
String proxyServer = prefs.get("proxyAddress", "");
|
||||
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
|
||||
URL url = new URL(baseUrl);
|
||||
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyServer, proxyPort));
|
||||
HttpURLConnection uc = (HttpURLConnection) url.openConnection(proxy);
|
||||
|
||||
uc.connect();
|
||||
|
||||
String line;
|
||||
StringBuffer tmp = new StringBuffer();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
|
||||
while ((line = in.readLine()) != null) {
|
||||
tmp.append(line);
|
||||
}
|
||||
doc = Jsoup.parse(String.valueOf(tmp));
|
||||
}
|
||||
|
||||
Elements cardsImages = doc.select("img[src^=cards/]"); // starts with cards/
|
||||
if (!aliasesStart.isEmpty()) {
|
||||
for (String text : aliasesStart) {
|
||||
cardsImages.addAll(doc.select("img[src^=" + text + "]"));
|
||||
}
|
||||
}
|
||||
if (cardsImages.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (Element cardsImage : cardsImages) {
|
||||
String cardLink = cardsImage.attr("src");
|
||||
String cardName = null;
|
||||
if (cardLink.startsWith("cards/") && cardLink.endsWith(".jpg")) {
|
||||
cardName = cardLink.substring(6, cardLink.length() - 4);
|
||||
} else if (aliasesStart.contains(cardLink)) {
|
||||
cardName = cardLink.substring(0, cardLink.length() - 4);;
|
||||
}
|
||||
if (cardName != null && !cardName.isEmpty()) {
|
||||
if (cardNameAliases.containsKey(cardSet + "-" + cardName)) {
|
||||
cardName = cardNameAliases.get(cardSet + "-" + cardName);
|
||||
} else {
|
||||
if (cardName.endsWith("1") || cardName.endsWith("2") || cardName.endsWith("3") || cardName.endsWith("4") || cardName.endsWith("5")) {
|
||||
if (!cardName.startsWith("forest")
|
||||
&& !cardName.startsWith("swamp")
|
||||
&& !cardName.startsWith("mountain")
|
||||
&& !cardName.startsWith("island")
|
||||
&& !cardName.startsWith("plains")) {
|
||||
|
||||
cardName = cardName.substring(0, cardName.length() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
setLinks.put(cardName, baseUrl + cardLink);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (IOException ex) {
|
||||
System.out.println("Exception when parsing the mythicspoiler page: " + ex.getMessage());
|
||||
}
|
||||
return setLinks;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
if (card.isFlippedSide()) { //doesn't support rotated images
|
||||
return null;
|
||||
}
|
||||
Map<String, String> setLinks = sets.get(cardSet);
|
||||
if (setLinks == null) {
|
||||
setLinks = getSetLinks(cardSet);
|
||||
sets.put(cardSet, setLinks);
|
||||
}
|
||||
String searchName = card.getDownloadName().toLowerCase()
|
||||
.replaceAll(" ", "")
|
||||
.replaceAll("-", "")
|
||||
.replaceAll("'", "")
|
||||
.replaceAll(",", "");
|
||||
String link = setLinks.get(searchName);
|
||||
return link;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateTokenUrl(CardDownloadData card
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getAverageSize() {
|
||||
return 50.0f;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.prefs.Preferences;
|
||||
import mage.client.MageFrame;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Connection.ProxyType;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.mage.plugins.card.images.CardDownloadData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class MythicspoilerComSource implements CardImageSource {
|
||||
|
||||
private static CardImageSource instance;
|
||||
private static Map<String, String> setsAliases;
|
||||
private static Map<String, String> cardNameAliases;
|
||||
private static Map<String, Set<String>> cardNameAliasesStart;
|
||||
private final Map<String, Map<String, String>> sets;
|
||||
|
||||
public static CardImageSource getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new MythicspoilerComSource();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return "mythicspoiler.com";
|
||||
}
|
||||
|
||||
public MythicspoilerComSource() {
|
||||
sets = new LinkedHashMap<>();
|
||||
setsAliases = new HashMap<>();
|
||||
setsAliases.put("exp", "bfz");
|
||||
cardNameAliases = new HashMap<>();
|
||||
// set+wrong name from web side => correct card name
|
||||
cardNameAliases.put("MM2-otherwordlyjourney", "otherworldlyjourney");
|
||||
cardNameAliases.put("THS-fellhideminotaur", "felhideminotaur");
|
||||
cardNameAliases.put("THS-purphorosemissary", "purphorossemissary");
|
||||
cardNameAliases.put("THS-soldierofpantheon", "soldierofthepantheon");
|
||||
cardNameAliases.put("THS-vulpinegolaith", "vulpinegoliath");
|
||||
cardNameAliases.put("ORI-kothopedhoarderofsouls", "kothophedsoulhoarder");
|
||||
cardNameAliases.put("BFZ-unisonstrike", "tandemtactics");
|
||||
cardNameAliases.put("BFZ-eldrazidevastator", "eldrazidevastator");
|
||||
cardNameAliases.put("BFZ-kozliekschanneler", "kozilekschanneler");
|
||||
cardNameAliases.put("OGW-wastes", "wastes1");
|
||||
cardNameAliases.put("OGW-wastes2", "wastes2");
|
||||
|
||||
cardNameAliasesStart = new HashMap<>();
|
||||
HashSet<String> names = new HashSet<>();
|
||||
names.add("eldrazidevastator.jpg");
|
||||
cardNameAliasesStart.put("BFZ", names);
|
||||
}
|
||||
|
||||
private Map<String, String> getSetLinks(String cardSet) {
|
||||
Map<String, String> setLinks = new HashMap<>();
|
||||
try {
|
||||
String setNames = setsAliases.get(cardSet.toLowerCase());
|
||||
Set<String> aliasesStart = new HashSet<>();
|
||||
if (cardNameAliasesStart.containsKey(cardSet)) {
|
||||
aliasesStart.addAll(cardNameAliasesStart.get(cardSet));
|
||||
}
|
||||
if (setNames == null) {
|
||||
setNames = cardSet.toLowerCase();
|
||||
}
|
||||
Preferences prefs = MageFrame.getPreferences();
|
||||
Connection.ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
|
||||
for (String setName : setNames.split("\\^")) {
|
||||
String URLSetName = URLEncoder.encode(setName, "UTF-8");
|
||||
String baseUrl = "http://mythicspoiler.com/" + URLSetName + "/";
|
||||
String urlDocument;
|
||||
Document doc;
|
||||
if (proxyType.equals(ProxyType.NONE)) {
|
||||
urlDocument = baseUrl;
|
||||
doc = Jsoup.connect(urlDocument).get();
|
||||
} else {
|
||||
String proxyServer = prefs.get("proxyAddress", "");
|
||||
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
|
||||
URL url = new URL(baseUrl);
|
||||
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyServer, proxyPort));
|
||||
HttpURLConnection uc = (HttpURLConnection) url.openConnection(proxy);
|
||||
|
||||
uc.connect();
|
||||
|
||||
String line;
|
||||
StringBuffer tmp = new StringBuffer();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
|
||||
while ((line = in.readLine()) != null) {
|
||||
tmp.append(line);
|
||||
}
|
||||
doc = Jsoup.parse(String.valueOf(tmp));
|
||||
}
|
||||
|
||||
Elements cardsImages = doc.select("img[src^=cards/]"); // starts with cards/
|
||||
if (!aliasesStart.isEmpty()) {
|
||||
for (String text : aliasesStart) {
|
||||
cardsImages.addAll(doc.select("img[src^=" + text + "]"));
|
||||
}
|
||||
}
|
||||
if (cardsImages.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (Element cardsImage : cardsImages) {
|
||||
String cardLink = cardsImage.attr("src");
|
||||
String cardName = null;
|
||||
if (cardLink.startsWith("cards/") && cardLink.endsWith(".jpg")) {
|
||||
cardName = cardLink.substring(6, cardLink.length() - 4);
|
||||
} else if (aliasesStart.contains(cardLink)) {
|
||||
cardName = cardLink.substring(0, cardLink.length() - 4);;
|
||||
}
|
||||
if (cardName != null && !cardName.isEmpty()) {
|
||||
if (cardNameAliases.containsKey(cardSet + "-" + cardName)) {
|
||||
cardName = cardNameAliases.get(cardSet + "-" + cardName);
|
||||
} else {
|
||||
if (cardName.endsWith("1") || cardName.endsWith("2") || cardName.endsWith("3") || cardName.endsWith("4") || cardName.endsWith("5")) {
|
||||
if (!cardName.startsWith("forest")
|
||||
&& !cardName.startsWith("swamp")
|
||||
&& !cardName.startsWith("mountain")
|
||||
&& !cardName.startsWith("island")
|
||||
&& !cardName.startsWith("plains")) {
|
||||
|
||||
cardName = cardName.substring(0, cardName.length() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
setLinks.put(cardName, baseUrl + cardLink);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (IOException ex) {
|
||||
System.out.println("Exception when parsing the mythicspoiler page: " + ex.getMessage());
|
||||
}
|
||||
return setLinks;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
if (card.isFlippedSide()) { //doesn't support rotated images
|
||||
return null;
|
||||
}
|
||||
Map<String, String> setLinks = sets.get(cardSet);
|
||||
if (setLinks == null) {
|
||||
setLinks = getSetLinks(cardSet);
|
||||
sets.put(cardSet, setLinks);
|
||||
}
|
||||
String searchName = card.getDownloadName().toLowerCase()
|
||||
.replaceAll(" ", "")
|
||||
.replaceAll("-", "")
|
||||
.replaceAll("'", "")
|
||||
.replaceAll(",", "");
|
||||
String link = setLinks.get(searchName);
|
||||
return link;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateTokenUrl(CardDownloadData card
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getAverageSize() {
|
||||
return 50.0f;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,196 +1,196 @@
|
|||
package org.mage.plugins.card.images;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public class CardDownloadData {
|
||||
|
||||
private String name;
|
||||
private String downloadName;
|
||||
private String set;
|
||||
private String tokenSetCode;
|
||||
private Integer collectorId;
|
||||
private Integer type;
|
||||
private boolean token;
|
||||
private boolean twoFacedCard;
|
||||
private boolean secondSide;
|
||||
private boolean flipCard;
|
||||
private boolean flippedSide;
|
||||
private boolean splitCard;
|
||||
private boolean usesVariousArt;
|
||||
private boolean isType2;
|
||||
|
||||
public CardDownloadData(String name, String set, Integer collectorId, boolean usesVariousArt, Integer type, String tokenSetCode) {
|
||||
this(name, set, collectorId, usesVariousArt, type, tokenSetCode, false);
|
||||
}
|
||||
|
||||
public CardDownloadData(String name, String set, Integer collectorId, boolean usesVariousArt, Integer type, String tokenSetCode, boolean token) {
|
||||
this(name, set, collectorId, usesVariousArt, type, tokenSetCode, token, false, false);
|
||||
}
|
||||
|
||||
public CardDownloadData(String name, String set, Integer collectorId, boolean usesVariousArt, Integer type, String tokenSetCode, boolean token, boolean twoFacedCard, boolean secondSide) {
|
||||
this.name = name;
|
||||
this.set = set;
|
||||
this.collectorId = collectorId;
|
||||
this.usesVariousArt = usesVariousArt;
|
||||
this.type = type;
|
||||
this.token = token;
|
||||
this.twoFacedCard = twoFacedCard;
|
||||
this.secondSide = secondSide;
|
||||
this.tokenSetCode = tokenSetCode;
|
||||
}
|
||||
|
||||
public CardDownloadData(final CardDownloadData card) {
|
||||
this.name = card.name;
|
||||
this.set = card.set;
|
||||
this.collectorId = card.collectorId;
|
||||
this.token = card.token;
|
||||
this.twoFacedCard = card.twoFacedCard;
|
||||
this.secondSide = card.secondSide;
|
||||
this.type = card.type;
|
||||
this.usesVariousArt = card.usesVariousArt;
|
||||
this.tokenSetCode = card.tokenSetCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final CardDownloadData other = (CardDownloadData) obj;
|
||||
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.set == null) ? (other.set != null) : !this.set.equals(other.set)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.collectorId, other.collectorId) && (this.collectorId == null || !this.collectorId.equals(other.collectorId))) {
|
||||
return false;
|
||||
}
|
||||
if (this.token != other.token) {
|
||||
return false;
|
||||
}
|
||||
if (this.twoFacedCard != other.twoFacedCard) {
|
||||
return false;
|
||||
}
|
||||
if (this.secondSide != other.secondSide) {
|
||||
return false;
|
||||
}
|
||||
if (this.isType2 != other.isType2) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0);
|
||||
hash = 47 * hash + (this.set != null ? this.set.hashCode() : 0);
|
||||
hash = 47 * hash + (this.collectorId != null ? this.collectorId.hashCode() : 0);
|
||||
hash = 47 * hash + (this.type != null ? this.type.hashCode() : 0);
|
||||
hash = 47 * hash + (this.token ? 1 : 0);
|
||||
hash = 47 * hash + (this.twoFacedCard ? 1 : 0);
|
||||
hash = 47 * hash + (this.secondSide ? 1 : 0);
|
||||
hash = 47 * hash + (this.isType2 ? 1 : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
public Integer getCollectorId() {
|
||||
return collectorId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSet() {
|
||||
return set;
|
||||
}
|
||||
|
||||
public void setSet(String set) {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
public String getTokenSetCode() {
|
||||
return tokenSetCode;
|
||||
}
|
||||
|
||||
public void setTokenSetCode(String tokenSetCode) {
|
||||
this.tokenSetCode = tokenSetCode;
|
||||
}
|
||||
|
||||
public boolean isToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(boolean token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public boolean isTwoFacedCard() {
|
||||
return twoFacedCard;
|
||||
}
|
||||
|
||||
public boolean isSecondSide() {
|
||||
return secondSide;
|
||||
}
|
||||
|
||||
public String getDownloadName() {
|
||||
return downloadName == null ? name : downloadName;
|
||||
}
|
||||
|
||||
public void setDownloadName(String downloadName) {
|
||||
this.downloadName = downloadName;
|
||||
}
|
||||
|
||||
public boolean isFlipCard() {
|
||||
return flipCard;
|
||||
}
|
||||
|
||||
public void setFlipCard(boolean flipCard) {
|
||||
this.flipCard = flipCard;
|
||||
}
|
||||
|
||||
public boolean isSplitCard() {
|
||||
return splitCard;
|
||||
}
|
||||
|
||||
public void setSplitCard(boolean splitCard) {
|
||||
this.splitCard = splitCard;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean getUsesVariousArt() {
|
||||
return usesVariousArt;
|
||||
}
|
||||
|
||||
public boolean isFlippedSide() {
|
||||
return flippedSide;
|
||||
}
|
||||
|
||||
public void setFlippedSide(boolean flippedSide) {
|
||||
this.flippedSide = flippedSide;
|
||||
}
|
||||
|
||||
public boolean isType2() {
|
||||
return isType2;
|
||||
}
|
||||
|
||||
public void setType2(boolean type2) {
|
||||
isType2 = type2;
|
||||
}
|
||||
}
|
||||
package org.mage.plugins.card.images;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public class CardDownloadData {
|
||||
|
||||
private String name;
|
||||
private String downloadName;
|
||||
private String set;
|
||||
private String tokenSetCode;
|
||||
private Integer collectorId;
|
||||
private Integer type;
|
||||
private boolean token;
|
||||
private boolean twoFacedCard;
|
||||
private boolean secondSide;
|
||||
private boolean flipCard;
|
||||
private boolean flippedSide;
|
||||
private boolean splitCard;
|
||||
private boolean usesVariousArt;
|
||||
private boolean isType2;
|
||||
|
||||
public CardDownloadData(String name, String set, Integer collectorId, boolean usesVariousArt, Integer type, String tokenSetCode) {
|
||||
this(name, set, collectorId, usesVariousArt, type, tokenSetCode, false);
|
||||
}
|
||||
|
||||
public CardDownloadData(String name, String set, Integer collectorId, boolean usesVariousArt, Integer type, String tokenSetCode, boolean token) {
|
||||
this(name, set, collectorId, usesVariousArt, type, tokenSetCode, token, false, false);
|
||||
}
|
||||
|
||||
public CardDownloadData(String name, String set, Integer collectorId, boolean usesVariousArt, Integer type, String tokenSetCode, boolean token, boolean twoFacedCard, boolean secondSide) {
|
||||
this.name = name;
|
||||
this.set = set;
|
||||
this.collectorId = collectorId;
|
||||
this.usesVariousArt = usesVariousArt;
|
||||
this.type = type;
|
||||
this.token = token;
|
||||
this.twoFacedCard = twoFacedCard;
|
||||
this.secondSide = secondSide;
|
||||
this.tokenSetCode = tokenSetCode;
|
||||
}
|
||||
|
||||
public CardDownloadData(final CardDownloadData card) {
|
||||
this.name = card.name;
|
||||
this.set = card.set;
|
||||
this.collectorId = card.collectorId;
|
||||
this.token = card.token;
|
||||
this.twoFacedCard = card.twoFacedCard;
|
||||
this.secondSide = card.secondSide;
|
||||
this.type = card.type;
|
||||
this.usesVariousArt = card.usesVariousArt;
|
||||
this.tokenSetCode = card.tokenSetCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final CardDownloadData other = (CardDownloadData) obj;
|
||||
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.set == null) ? (other.set != null) : !this.set.equals(other.set)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.collectorId, other.collectorId) && (this.collectorId == null || !this.collectorId.equals(other.collectorId))) {
|
||||
return false;
|
||||
}
|
||||
if (this.token != other.token) {
|
||||
return false;
|
||||
}
|
||||
if (this.twoFacedCard != other.twoFacedCard) {
|
||||
return false;
|
||||
}
|
||||
if (this.secondSide != other.secondSide) {
|
||||
return false;
|
||||
}
|
||||
if (this.isType2 != other.isType2) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0);
|
||||
hash = 47 * hash + (this.set != null ? this.set.hashCode() : 0);
|
||||
hash = 47 * hash + (this.collectorId != null ? this.collectorId.hashCode() : 0);
|
||||
hash = 47 * hash + (this.type != null ? this.type.hashCode() : 0);
|
||||
hash = 47 * hash + (this.token ? 1 : 0);
|
||||
hash = 47 * hash + (this.twoFacedCard ? 1 : 0);
|
||||
hash = 47 * hash + (this.secondSide ? 1 : 0);
|
||||
hash = 47 * hash + (this.isType2 ? 1 : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
public Integer getCollectorId() {
|
||||
return collectorId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSet() {
|
||||
return set;
|
||||
}
|
||||
|
||||
public void setSet(String set) {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
public String getTokenSetCode() {
|
||||
return tokenSetCode;
|
||||
}
|
||||
|
||||
public void setTokenSetCode(String tokenSetCode) {
|
||||
this.tokenSetCode = tokenSetCode;
|
||||
}
|
||||
|
||||
public boolean isToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(boolean token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public boolean isTwoFacedCard() {
|
||||
return twoFacedCard;
|
||||
}
|
||||
|
||||
public boolean isSecondSide() {
|
||||
return secondSide;
|
||||
}
|
||||
|
||||
public String getDownloadName() {
|
||||
return downloadName == null ? name : downloadName;
|
||||
}
|
||||
|
||||
public void setDownloadName(String downloadName) {
|
||||
this.downloadName = downloadName;
|
||||
}
|
||||
|
||||
public boolean isFlipCard() {
|
||||
return flipCard;
|
||||
}
|
||||
|
||||
public void setFlipCard(boolean flipCard) {
|
||||
this.flipCard = flipCard;
|
||||
}
|
||||
|
||||
public boolean isSplitCard() {
|
||||
return splitCard;
|
||||
}
|
||||
|
||||
public void setSplitCard(boolean splitCard) {
|
||||
this.splitCard = splitCard;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean getUsesVariousArt() {
|
||||
return usesVariousArt;
|
||||
}
|
||||
|
||||
public boolean isFlippedSide() {
|
||||
return flippedSide;
|
||||
}
|
||||
|
||||
public void setFlippedSide(boolean flippedSide) {
|
||||
this.flippedSide = flippedSide;
|
||||
}
|
||||
|
||||
public boolean isType2() {
|
||||
return isType2;
|
||||
}
|
||||
|
||||
public void setType2(boolean type2) {
|
||||
isType2 = type2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,383 +1,383 @@
|
|||
package org.mage.plugins.card.images;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ComputationException;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import com.mortennobel.imagescaling.ResampleOp;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.imageio.ImageIO;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.view.CardView;
|
||||
import net.java.truevfs.access.TFile;
|
||||
import net.java.truevfs.access.TFileInputStream;
|
||||
import net.java.truevfs.access.TFileOutputStream;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.plugins.card.constants.Constants;
|
||||
import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
|
||||
import org.mage.plugins.card.utils.CardImageUtils;
|
||||
|
||||
/**
|
||||
* This class stores ALL card images in a cache with soft values. this means
|
||||
* that the images may be garbage collected when they are not needed any more,
|
||||
* but will be kept as long as possible.
|
||||
*
|
||||
* Key format: "<cardname>#<setname>#<type>#<collectorID>#<param>"
|
||||
*
|
||||
* where param is:
|
||||
*
|
||||
* <ul>
|
||||
* <li>#Normal: request for unrotated image</li>
|
||||
* <li>#Tapped: request for rotated image</li>
|
||||
* <li>#Cropped: request for cropped image that is used for Shandalar like card
|
||||
* look</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class ImageCache {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ImageCache.class);
|
||||
|
||||
private static final Map<String, BufferedImage> IMAGE_CACHE;
|
||||
|
||||
/**
|
||||
* Common pattern for keys. Format: "<cardname>#<setname>#<collectorID>"
|
||||
*/
|
||||
private static final Pattern KEY_PATTERN = Pattern.compile("(.*)#(.*)#(.*)#(.*)#(.*)");
|
||||
|
||||
static {
|
||||
IMAGE_CACHE = new MapMaker().softValues().makeComputingMap(new Function<String, BufferedImage>() {
|
||||
@Override
|
||||
public BufferedImage apply(String key) {
|
||||
try {
|
||||
|
||||
boolean usesVariousArt = false;
|
||||
if (key.endsWith("#usesVariousArt")) {
|
||||
usesVariousArt = true;
|
||||
key = key.replace("#usesVariousArt", "");
|
||||
}
|
||||
boolean thumbnail = false;
|
||||
if (key.endsWith("#thumb")) {
|
||||
thumbnail = true;
|
||||
key = key.replace("#thumb", "");
|
||||
}
|
||||
Matcher m = KEY_PATTERN.matcher(key);
|
||||
|
||||
if (m.matches()) {
|
||||
String name = m.group(1);
|
||||
String set = m.group(2);
|
||||
Integer type = Integer.parseInt(m.group(3));
|
||||
Integer collectorId = Integer.parseInt(m.group(4));
|
||||
String tokenSetCode = m.group(5);
|
||||
|
||||
CardDownloadData info = new CardDownloadData(name, set, collectorId, usesVariousArt, type, tokenSetCode);
|
||||
|
||||
String path;
|
||||
if (collectorId == 0) {
|
||||
info.setToken(true);
|
||||
path = CardImageUtils.generateTokenImagePath(info);
|
||||
if (path == null) {
|
||||
path = DirectLinksForDownload.outDir + File.separator + DirectLinksForDownload.cardbackFilename;
|
||||
}
|
||||
} else {
|
||||
path = CardImageUtils.generateImagePath(info);
|
||||
}
|
||||
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
TFile file = getTFile(path);
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (thumbnail && path.endsWith(".jpg")) {
|
||||
String thumbnailPath = buildThumbnailPath(path);
|
||||
TFile thumbnailFile = null;
|
||||
try {
|
||||
thumbnailFile = new TFile(thumbnailPath);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
boolean exists = false;
|
||||
if (thumbnailFile != null) {
|
||||
try {
|
||||
exists = thumbnailFile.exists();
|
||||
} catch (Exception ex) {
|
||||
exists = false;
|
||||
}
|
||||
}
|
||||
if (exists) {
|
||||
LOGGER.debug("loading thumbnail for " + key + ", path=" + thumbnailPath);
|
||||
BufferedImage thumbnailImage = loadImage(thumbnailFile);
|
||||
if (thumbnailImage == null) { // thumbnail exists but broken for some reason
|
||||
LOGGER.warn("failed loading thumbnail for " + key + ", path=" + thumbnailPath
|
||||
+ ", thumbnail file is probably broken, attempting to recreate it...");
|
||||
thumbnailImage = makeThumbnailByFile(key, file, thumbnailPath);
|
||||
}
|
||||
return thumbnailImage;
|
||||
} else {
|
||||
return makeThumbnailByFile(key, file, thumbnailPath);
|
||||
}
|
||||
} else {
|
||||
return getWizardsCard(loadImage(file));
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException(
|
||||
"Requested image doesn't fit the requirement for key (<cardname>#<setname>#<collectorID>): " + key);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
if (ex instanceof ComputationException) {
|
||||
throw (ComputationException) ex;
|
||||
} else {
|
||||
throw new ComputationException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BufferedImage makeThumbnailByFile(String key, TFile file, String thumbnailPath) {
|
||||
BufferedImage image = loadImage(file);
|
||||
image = getWizardsCard(image);
|
||||
if (image == null) {
|
||||
return null;
|
||||
}
|
||||
LOGGER.debug("creating thumbnail for " + key);
|
||||
return makeThumbnail(image, thumbnailPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static BufferedImage getMorphImage() {
|
||||
CardDownloadData info = new CardDownloadData("Morph", "KTK", 0, false, 0, "KTK");
|
||||
info.setToken(true);
|
||||
String path = CardImageUtils.generateTokenImagePath(info);
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
TFile file = getTFile(path);
|
||||
return loadImage(file);
|
||||
}
|
||||
|
||||
public static BufferedImage getManifestImage() {
|
||||
CardDownloadData info = new CardDownloadData("Manifest", "FRF", 0, false, 0, "FRF");
|
||||
info.setToken(true);
|
||||
String path = CardImageUtils.generateTokenImagePath(info);
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
TFile file = getTFile(path);
|
||||
return loadImage(file);
|
||||
}
|
||||
|
||||
private static String buildThumbnailPath(String path) {
|
||||
String thumbnailPath;
|
||||
if (PreferencesDialog.isSaveImagesToZip()) {
|
||||
thumbnailPath = path.replace(".zip", ".thumb.zip");
|
||||
} else {
|
||||
thumbnailPath = path.replace(".jpg", ".thumb.jpg");
|
||||
}
|
||||
return thumbnailPath;
|
||||
}
|
||||
|
||||
public static BufferedImage getWizardsCard(BufferedImage image) {
|
||||
if (image.getWidth() == 265 && image.getHeight() == 370) {
|
||||
BufferedImage crop = new BufferedImage(256, 360, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D graphics2D = crop.createGraphics();
|
||||
graphics2D.drawImage(image, 0, 0, 255, 360, 5, 5, 261, 365, null);
|
||||
graphics2D.dispose();
|
||||
return crop;
|
||||
} else {
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
public static BufferedImage getThumbnail(CardView card) {
|
||||
return getImage(getKey(card, card.getName(), "#thumb"));
|
||||
}
|
||||
|
||||
public static BufferedImage getImageOriginal(CardView card) {
|
||||
return getImage(getKey(card, card.getName(), ""));
|
||||
}
|
||||
|
||||
public static BufferedImage getImageOriginalAlternateName(CardView card) {
|
||||
return getImage(getKey(card, card.getAlternateName(), ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Image corresponding to the key
|
||||
*/
|
||||
private static BufferedImage getImage(String key) {
|
||||
try {
|
||||
BufferedImage image = IMAGE_CACHE.get(key);
|
||||
return image;
|
||||
} catch (NullPointerException ex) {
|
||||
// unfortunately NullOutputException, thrown when apply() returns
|
||||
// null, is not public
|
||||
// NullOutputException is a subclass of NullPointerException
|
||||
// legitimate, happens when a card has no image
|
||||
return null;
|
||||
} catch (ComputationException ex) {
|
||||
if (ex.getCause() instanceof NullPointerException) {
|
||||
return null;
|
||||
}
|
||||
LOGGER.error(ex, ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the map key for a card, without any suffixes for the image size.
|
||||
*/
|
||||
private static String getKey(CardView card, String name, String suffix) {
|
||||
return name + "#" + card.getExpansionSetCode() + "#" + card.getType() + "#" + card.getCardNumber() + "#"
|
||||
+ (card.getTokenSetCode() == null ? "" : card.getTokenSetCode())
|
||||
+ suffix
|
||||
+ (card.getUsesVariousArt() ? "#usesVariousArt" : "");
|
||||
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Returns the map key for the flip image of a card, without any suffixes for the image size.
|
||||
// */
|
||||
// private static String getKeyAlternateName(CardView card, String alternateName) {
|
||||
// return alternateName + "#" + card.getExpansionSetCode() + "#" +card.getType()+ "#" + card.getCardNumber() + "#"
|
||||
// + (card.getTokenSetCode() == null ? "":card.getTokenSetCode());
|
||||
// }
|
||||
/**
|
||||
* Load image from file
|
||||
*
|
||||
* @param file file to load image from
|
||||
* @return {@link BufferedImage}
|
||||
*/
|
||||
public static BufferedImage loadImage(TFile file) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
BufferedImage image = null;
|
||||
if (!file.exists()) {
|
||||
LOGGER.debug("File does not exist: " + file.toString());
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
try (TFileInputStream inputStream = new TFileInputStream(file)) {
|
||||
image = ImageIO.read(inputStream);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e, e);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
public static BufferedImage makeThumbnail(BufferedImage original, String path) {
|
||||
BufferedImage image = getResizedImage(original, Constants.THUMBNAIL_SIZE_FULL);
|
||||
TFile imageFile = getTFile(path);
|
||||
if (imageFile == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
try (TFileOutputStream outputStream = new TFileOutputStream(imageFile)) {
|
||||
String format = image.getColorModel().getNumComponents() > 3 ? "png" : "jpg";
|
||||
ImageIO.write(image, format, outputStream);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e, e);
|
||||
imageFile.delete();
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image scaled to the size given
|
||||
*
|
||||
* @param original
|
||||
* @return
|
||||
*/
|
||||
public static BufferedImage getNormalSizeImage(BufferedImage original) {
|
||||
if (original == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int srcWidth = original.getWidth();
|
||||
int srcHeight = original.getHeight();
|
||||
|
||||
int tgtWidth = Constants.CARD_SIZE_FULL.width;
|
||||
int tgtHeight = Constants.CARD_SIZE_FULL.height;
|
||||
|
||||
if (srcWidth == tgtWidth && srcHeight == tgtHeight) {
|
||||
return original;
|
||||
}
|
||||
|
||||
ResampleOp resampleOp = new ResampleOp(tgtWidth, tgtHeight);
|
||||
BufferedImage image = resampleOp.filter(original, null);
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image scaled to the size appropriate for the card picture
|
||||
* panel For future use.
|
||||
*/
|
||||
private static BufferedImage getFullSizeImage(BufferedImage original, double scale) {
|
||||
if (scale == 1) {
|
||||
return original;
|
||||
}
|
||||
ResampleOp resampleOp = new ResampleOp((int) (original.getWidth() * scale), (int) (original.getHeight() * scale));
|
||||
BufferedImage image = resampleOp.filter(original, null);
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image scaled to the size appropriate for the card picture
|
||||
* panel
|
||||
*
|
||||
* @param original
|
||||
* @param sizeNeed
|
||||
* @return
|
||||
*/
|
||||
public static BufferedImage getResizedImage(BufferedImage original, Rectangle sizeNeed) {
|
||||
ResampleOp resampleOp = new ResampleOp(sizeNeed.width, sizeNeed.height);
|
||||
BufferedImage image = resampleOp.filter(original, null);
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the image appropriate to display the card in the picture panel
|
||||
*
|
||||
* @param card
|
||||
* @param width
|
||||
* @param height
|
||||
* @return
|
||||
*/
|
||||
public static BufferedImage getImage(CardView card, int width, int height) {
|
||||
if (Constants.THUMBNAIL_SIZE_FULL.width + 10 > width) {
|
||||
return getThumbnail(card);
|
||||
}
|
||||
String key = getKey(card, card.getName(), Integer.toString(width));
|
||||
BufferedImage original = getImage(key);
|
||||
if (original == null) {
|
||||
LOGGER.debug(key + " not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
double scale = Math.min((double) width / original.getWidth(), (double) height / original.getHeight());
|
||||
if (scale > 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
||||
return getFullSizeImage(original, scale);
|
||||
}
|
||||
|
||||
public static TFile getTFile(String path) {
|
||||
try {
|
||||
TFile file = new TFile(path);
|
||||
return file;
|
||||
} catch (NullPointerException ex) {
|
||||
LOGGER.warn("Imagefile does not exist: " + path);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
package org.mage.plugins.card.images;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ComputationException;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import com.mortennobel.imagescaling.ResampleOp;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.imageio.ImageIO;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.view.CardView;
|
||||
import net.java.truevfs.access.TFile;
|
||||
import net.java.truevfs.access.TFileInputStream;
|
||||
import net.java.truevfs.access.TFileOutputStream;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.plugins.card.constants.Constants;
|
||||
import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
|
||||
import org.mage.plugins.card.utils.CardImageUtils;
|
||||
|
||||
/**
|
||||
* This class stores ALL card images in a cache with soft values. this means
|
||||
* that the images may be garbage collected when they are not needed any more,
|
||||
* but will be kept as long as possible.
|
||||
*
|
||||
* Key format: "<cardname>#<setname>#<type>#<collectorID>#<param>"
|
||||
*
|
||||
* where param is:
|
||||
*
|
||||
* <ul>
|
||||
* <li>#Normal: request for unrotated image</li>
|
||||
* <li>#Tapped: request for rotated image</li>
|
||||
* <li>#Cropped: request for cropped image that is used for Shandalar like card
|
||||
* look</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class ImageCache {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ImageCache.class);
|
||||
|
||||
private static final Map<String, BufferedImage> IMAGE_CACHE;
|
||||
|
||||
/**
|
||||
* Common pattern for keys. Format: "<cardname>#<setname>#<collectorID>"
|
||||
*/
|
||||
private static final Pattern KEY_PATTERN = Pattern.compile("(.*)#(.*)#(.*)#(.*)#(.*)");
|
||||
|
||||
static {
|
||||
IMAGE_CACHE = new MapMaker().softValues().makeComputingMap(new Function<String, BufferedImage>() {
|
||||
@Override
|
||||
public BufferedImage apply(String key) {
|
||||
try {
|
||||
|
||||
boolean usesVariousArt = false;
|
||||
if (key.endsWith("#usesVariousArt")) {
|
||||
usesVariousArt = true;
|
||||
key = key.replace("#usesVariousArt", "");
|
||||
}
|
||||
boolean thumbnail = false;
|
||||
if (key.endsWith("#thumb")) {
|
||||
thumbnail = true;
|
||||
key = key.replace("#thumb", "");
|
||||
}
|
||||
Matcher m = KEY_PATTERN.matcher(key);
|
||||
|
||||
if (m.matches()) {
|
||||
String name = m.group(1);
|
||||
String set = m.group(2);
|
||||
Integer type = Integer.parseInt(m.group(3));
|
||||
Integer collectorId = Integer.parseInt(m.group(4));
|
||||
String tokenSetCode = m.group(5);
|
||||
|
||||
CardDownloadData info = new CardDownloadData(name, set, collectorId, usesVariousArt, type, tokenSetCode);
|
||||
|
||||
String path;
|
||||
if (collectorId == 0) {
|
||||
info.setToken(true);
|
||||
path = CardImageUtils.generateTokenImagePath(info);
|
||||
if (path == null) {
|
||||
path = DirectLinksForDownload.outDir + File.separator + DirectLinksForDownload.cardbackFilename;
|
||||
}
|
||||
} else {
|
||||
path = CardImageUtils.generateImagePath(info);
|
||||
}
|
||||
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
TFile file = getTFile(path);
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (thumbnail && path.endsWith(".jpg")) {
|
||||
String thumbnailPath = buildThumbnailPath(path);
|
||||
TFile thumbnailFile = null;
|
||||
try {
|
||||
thumbnailFile = new TFile(thumbnailPath);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
boolean exists = false;
|
||||
if (thumbnailFile != null) {
|
||||
try {
|
||||
exists = thumbnailFile.exists();
|
||||
} catch (Exception ex) {
|
||||
exists = false;
|
||||
}
|
||||
}
|
||||
if (exists) {
|
||||
LOGGER.debug("loading thumbnail for " + key + ", path=" + thumbnailPath);
|
||||
BufferedImage thumbnailImage = loadImage(thumbnailFile);
|
||||
if (thumbnailImage == null) { // thumbnail exists but broken for some reason
|
||||
LOGGER.warn("failed loading thumbnail for " + key + ", path=" + thumbnailPath
|
||||
+ ", thumbnail file is probably broken, attempting to recreate it...");
|
||||
thumbnailImage = makeThumbnailByFile(key, file, thumbnailPath);
|
||||
}
|
||||
return thumbnailImage;
|
||||
} else {
|
||||
return makeThumbnailByFile(key, file, thumbnailPath);
|
||||
}
|
||||
} else {
|
||||
return getWizardsCard(loadImage(file));
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException(
|
||||
"Requested image doesn't fit the requirement for key (<cardname>#<setname>#<collectorID>): " + key);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
if (ex instanceof ComputationException) {
|
||||
throw (ComputationException) ex;
|
||||
} else {
|
||||
throw new ComputationException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BufferedImage makeThumbnailByFile(String key, TFile file, String thumbnailPath) {
|
||||
BufferedImage image = loadImage(file);
|
||||
image = getWizardsCard(image);
|
||||
if (image == null) {
|
||||
return null;
|
||||
}
|
||||
LOGGER.debug("creating thumbnail for " + key);
|
||||
return makeThumbnail(image, thumbnailPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static BufferedImage getMorphImage() {
|
||||
CardDownloadData info = new CardDownloadData("Morph", "KTK", 0, false, 0, "KTK");
|
||||
info.setToken(true);
|
||||
String path = CardImageUtils.generateTokenImagePath(info);
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
TFile file = getTFile(path);
|
||||
return loadImage(file);
|
||||
}
|
||||
|
||||
public static BufferedImage getManifestImage() {
|
||||
CardDownloadData info = new CardDownloadData("Manifest", "FRF", 0, false, 0, "FRF");
|
||||
info.setToken(true);
|
||||
String path = CardImageUtils.generateTokenImagePath(info);
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
TFile file = getTFile(path);
|
||||
return loadImage(file);
|
||||
}
|
||||
|
||||
private static String buildThumbnailPath(String path) {
|
||||
String thumbnailPath;
|
||||
if (PreferencesDialog.isSaveImagesToZip()) {
|
||||
thumbnailPath = path.replace(".zip", ".thumb.zip");
|
||||
} else {
|
||||
thumbnailPath = path.replace(".jpg", ".thumb.jpg");
|
||||
}
|
||||
return thumbnailPath;
|
||||
}
|
||||
|
||||
public static BufferedImage getWizardsCard(BufferedImage image) {
|
||||
if (image.getWidth() == 265 && image.getHeight() == 370) {
|
||||
BufferedImage crop = new BufferedImage(256, 360, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D graphics2D = crop.createGraphics();
|
||||
graphics2D.drawImage(image, 0, 0, 255, 360, 5, 5, 261, 365, null);
|
||||
graphics2D.dispose();
|
||||
return crop;
|
||||
} else {
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
public static BufferedImage getThumbnail(CardView card) {
|
||||
return getImage(getKey(card, card.getName(), "#thumb"));
|
||||
}
|
||||
|
||||
public static BufferedImage getImageOriginal(CardView card) {
|
||||
return getImage(getKey(card, card.getName(), ""));
|
||||
}
|
||||
|
||||
public static BufferedImage getImageOriginalAlternateName(CardView card) {
|
||||
return getImage(getKey(card, card.getAlternateName(), ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Image corresponding to the key
|
||||
*/
|
||||
private static BufferedImage getImage(String key) {
|
||||
try {
|
||||
BufferedImage image = IMAGE_CACHE.get(key);
|
||||
return image;
|
||||
} catch (NullPointerException ex) {
|
||||
// unfortunately NullOutputException, thrown when apply() returns
|
||||
// null, is not public
|
||||
// NullOutputException is a subclass of NullPointerException
|
||||
// legitimate, happens when a card has no image
|
||||
return null;
|
||||
} catch (ComputationException ex) {
|
||||
if (ex.getCause() instanceof NullPointerException) {
|
||||
return null;
|
||||
}
|
||||
LOGGER.error(ex, ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the map key for a card, without any suffixes for the image size.
|
||||
*/
|
||||
private static String getKey(CardView card, String name, String suffix) {
|
||||
return name + "#" + card.getExpansionSetCode() + "#" + card.getType() + "#" + card.getCardNumber() + "#"
|
||||
+ (card.getTokenSetCode() == null ? "" : card.getTokenSetCode())
|
||||
+ suffix
|
||||
+ (card.getUsesVariousArt() ? "#usesVariousArt" : "");
|
||||
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Returns the map key for the flip image of a card, without any suffixes for the image size.
|
||||
// */
|
||||
// private static String getKeyAlternateName(CardView card, String alternateName) {
|
||||
// return alternateName + "#" + card.getExpansionSetCode() + "#" +card.getType()+ "#" + card.getCardNumber() + "#"
|
||||
// + (card.getTokenSetCode() == null ? "":card.getTokenSetCode());
|
||||
// }
|
||||
/**
|
||||
* Load image from file
|
||||
*
|
||||
* @param file file to load image from
|
||||
* @return {@link BufferedImage}
|
||||
*/
|
||||
public static BufferedImage loadImage(TFile file) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
BufferedImage image = null;
|
||||
if (!file.exists()) {
|
||||
LOGGER.debug("File does not exist: " + file.toString());
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
try (TFileInputStream inputStream = new TFileInputStream(file)) {
|
||||
image = ImageIO.read(inputStream);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e, e);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
public static BufferedImage makeThumbnail(BufferedImage original, String path) {
|
||||
BufferedImage image = getResizedImage(original, Constants.THUMBNAIL_SIZE_FULL);
|
||||
TFile imageFile = getTFile(path);
|
||||
if (imageFile == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
try (TFileOutputStream outputStream = new TFileOutputStream(imageFile)) {
|
||||
String format = image.getColorModel().getNumComponents() > 3 ? "png" : "jpg";
|
||||
ImageIO.write(image, format, outputStream);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e, e);
|
||||
imageFile.delete();
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image scaled to the size given
|
||||
*
|
||||
* @param original
|
||||
* @return
|
||||
*/
|
||||
public static BufferedImage getNormalSizeImage(BufferedImage original) {
|
||||
if (original == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int srcWidth = original.getWidth();
|
||||
int srcHeight = original.getHeight();
|
||||
|
||||
int tgtWidth = Constants.CARD_SIZE_FULL.width;
|
||||
int tgtHeight = Constants.CARD_SIZE_FULL.height;
|
||||
|
||||
if (srcWidth == tgtWidth && srcHeight == tgtHeight) {
|
||||
return original;
|
||||
}
|
||||
|
||||
ResampleOp resampleOp = new ResampleOp(tgtWidth, tgtHeight);
|
||||
BufferedImage image = resampleOp.filter(original, null);
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image scaled to the size appropriate for the card picture
|
||||
* panel For future use.
|
||||
*/
|
||||
private static BufferedImage getFullSizeImage(BufferedImage original, double scale) {
|
||||
if (scale == 1) {
|
||||
return original;
|
||||
}
|
||||
ResampleOp resampleOp = new ResampleOp((int) (original.getWidth() * scale), (int) (original.getHeight() * scale));
|
||||
BufferedImage image = resampleOp.filter(original, null);
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image scaled to the size appropriate for the card picture
|
||||
* panel
|
||||
*
|
||||
* @param original
|
||||
* @param sizeNeed
|
||||
* @return
|
||||
*/
|
||||
public static BufferedImage getResizedImage(BufferedImage original, Rectangle sizeNeed) {
|
||||
ResampleOp resampleOp = new ResampleOp(sizeNeed.width, sizeNeed.height);
|
||||
BufferedImage image = resampleOp.filter(original, null);
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the image appropriate to display the card in the picture panel
|
||||
*
|
||||
* @param card
|
||||
* @param width
|
||||
* @param height
|
||||
* @return
|
||||
*/
|
||||
public static BufferedImage getImage(CardView card, int width, int height) {
|
||||
if (Constants.THUMBNAIL_SIZE_FULL.width + 10 > width) {
|
||||
return getThumbnail(card);
|
||||
}
|
||||
String key = getKey(card, card.getName(), Integer.toString(width));
|
||||
BufferedImage original = getImage(key);
|
||||
if (original == null) {
|
||||
LOGGER.debug(key + " not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
double scale = Math.min((double) width / original.getWidth(), (double) height / original.getHeight());
|
||||
if (scale > 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
||||
return getFullSizeImage(original, scale);
|
||||
}
|
||||
|
||||
public static TFile getTFile(String path) {
|
||||
try {
|
||||
TFile file = new TFile(path);
|
||||
return file;
|
||||
} catch (NullPointerException ex) {
|
||||
LOGGER.warn("Imagefile does not exist: " + path);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,120 +1,120 @@
|
|||
package org.mage.plugins.card.info;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
import mage.client.util.gui.GuiDisplayUtil;
|
||||
import mage.client.util.gui.GuiDisplayUtil.TextLines;
|
||||
import mage.components.CardInfoPane;
|
||||
import mage.view.CardView;
|
||||
import org.mage.card.arcane.UI;
|
||||
|
||||
/**
|
||||
* Card info pane for displaying card rules. Supports drawing mana symbols.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
|
||||
|
||||
public static final int TOOLTIP_WIDTH_MIN = 160;
|
||||
|
||||
public static final int TOOLTIP_HEIGHT_MIN = 120;
|
||||
public static final int TOOLTIP_HEIGHT_MAX = 300;
|
||||
|
||||
public static final int TOOLTIP_BORDER_WIDTH = 80;
|
||||
|
||||
private CardView currentCard;
|
||||
private int type;
|
||||
|
||||
private int addWidth;
|
||||
private int addHeight;
|
||||
private boolean setSize = false;
|
||||
|
||||
public CardInfoPaneImpl() {
|
||||
UI.setHTMLEditorKit(this);
|
||||
setEditable(false);
|
||||
setBackground(Color.white);
|
||||
setGUISize();
|
||||
}
|
||||
|
||||
public void changeGUISize() {
|
||||
setGUISize();
|
||||
this.revalidate();
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
private void setGUISize() {
|
||||
addWidth = 20 * GUISizeHelper.cardTooltipFontSize - 50;
|
||||
addHeight = 12 * GUISizeHelper.cardTooltipFontSize - 20;
|
||||
setSize = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCard(final CardView card, final Component container) {
|
||||
if (card == null || isCurrentCard(card)) {
|
||||
return;
|
||||
}
|
||||
currentCard = card;
|
||||
|
||||
try {
|
||||
if (!card.equals(currentCard)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!card.equals(currentCard)) {
|
||||
return;
|
||||
}
|
||||
TextLines textLines = GuiDisplayUtil.getTextLinesfromCardView(card);
|
||||
StringBuilder buffer = GuiDisplayUtil.getRulefromCardView(card, textLines);
|
||||
resizeTooltipIfNeeded(container, textLines.basicTextLength, textLines.lines.size());
|
||||
setText(buffer.toString());
|
||||
setCaretPosition(0);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void resizeTooltipIfNeeded(Component container, int ruleLength, int rules) {
|
||||
if (container == null) {
|
||||
return;
|
||||
}
|
||||
boolean makeBig = (rules > 5 || ruleLength > 350);
|
||||
if (setSize) {
|
||||
if (makeBig) {
|
||||
type = 0;
|
||||
} else {
|
||||
type = 1;
|
||||
}
|
||||
}
|
||||
if (makeBig && type == 0) {
|
||||
type = 1;
|
||||
container.setSize(
|
||||
addWidth + TOOLTIP_WIDTH_MIN + TOOLTIP_BORDER_WIDTH,
|
||||
addHeight + TOOLTIP_HEIGHT_MAX + TOOLTIP_BORDER_WIDTH
|
||||
);
|
||||
this.setSize(addWidth + TOOLTIP_WIDTH_MIN,
|
||||
addHeight + TOOLTIP_HEIGHT_MAX);
|
||||
} else if (!makeBig && type == 1) {
|
||||
type = 0;
|
||||
container.setSize(
|
||||
addWidth + TOOLTIP_WIDTH_MIN + TOOLTIP_BORDER_WIDTH,
|
||||
addHeight + TOOLTIP_HEIGHT_MIN + TOOLTIP_BORDER_WIDTH
|
||||
);
|
||||
this.setSize(addWidth + TOOLTIP_WIDTH_MIN,
|
||||
addHeight + TOOLTIP_HEIGHT_MIN);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurrentCard(CardView card) {
|
||||
return currentCard != null && card.equals(currentCard);
|
||||
}
|
||||
}
|
||||
package org.mage.plugins.card.info;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
import mage.client.util.gui.GuiDisplayUtil;
|
||||
import mage.client.util.gui.GuiDisplayUtil.TextLines;
|
||||
import mage.components.CardInfoPane;
|
||||
import mage.view.CardView;
|
||||
import org.mage.card.arcane.UI;
|
||||
|
||||
/**
|
||||
* Card info pane for displaying card rules. Supports drawing mana symbols.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
|
||||
|
||||
public static final int TOOLTIP_WIDTH_MIN = 160;
|
||||
|
||||
public static final int TOOLTIP_HEIGHT_MIN = 120;
|
||||
public static final int TOOLTIP_HEIGHT_MAX = 300;
|
||||
|
||||
public static final int TOOLTIP_BORDER_WIDTH = 80;
|
||||
|
||||
private CardView currentCard;
|
||||
private int type;
|
||||
|
||||
private int addWidth;
|
||||
private int addHeight;
|
||||
private boolean setSize = false;
|
||||
|
||||
public CardInfoPaneImpl() {
|
||||
UI.setHTMLEditorKit(this);
|
||||
setEditable(false);
|
||||
setBackground(Color.white);
|
||||
setGUISize();
|
||||
}
|
||||
|
||||
public void changeGUISize() {
|
||||
setGUISize();
|
||||
this.revalidate();
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
private void setGUISize() {
|
||||
addWidth = 20 * GUISizeHelper.cardTooltipFontSize - 50;
|
||||
addHeight = 12 * GUISizeHelper.cardTooltipFontSize - 20;
|
||||
setSize = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCard(final CardView card, final Component container) {
|
||||
if (card == null || isCurrentCard(card)) {
|
||||
return;
|
||||
}
|
||||
currentCard = card;
|
||||
|
||||
try {
|
||||
if (!card.equals(currentCard)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!card.equals(currentCard)) {
|
||||
return;
|
||||
}
|
||||
TextLines textLines = GuiDisplayUtil.getTextLinesfromCardView(card);
|
||||
StringBuilder buffer = GuiDisplayUtil.getRulefromCardView(card, textLines);
|
||||
resizeTooltipIfNeeded(container, textLines.basicTextLength, textLines.lines.size());
|
||||
setText(buffer.toString());
|
||||
setCaretPosition(0);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void resizeTooltipIfNeeded(Component container, int ruleLength, int rules) {
|
||||
if (container == null) {
|
||||
return;
|
||||
}
|
||||
boolean makeBig = (rules > 5 || ruleLength > 350);
|
||||
if (setSize) {
|
||||
if (makeBig) {
|
||||
type = 0;
|
||||
} else {
|
||||
type = 1;
|
||||
}
|
||||
}
|
||||
if (makeBig && type == 0) {
|
||||
type = 1;
|
||||
container.setSize(
|
||||
addWidth + TOOLTIP_WIDTH_MIN + TOOLTIP_BORDER_WIDTH,
|
||||
addHeight + TOOLTIP_HEIGHT_MAX + TOOLTIP_BORDER_WIDTH
|
||||
);
|
||||
this.setSize(addWidth + TOOLTIP_WIDTH_MIN,
|
||||
addHeight + TOOLTIP_HEIGHT_MAX);
|
||||
} else if (!makeBig && type == 1) {
|
||||
type = 0;
|
||||
container.setSize(
|
||||
addWidth + TOOLTIP_WIDTH_MIN + TOOLTIP_BORDER_WIDTH,
|
||||
addHeight + TOOLTIP_HEIGHT_MIN + TOOLTIP_BORDER_WIDTH
|
||||
);
|
||||
this.setSize(addWidth + TOOLTIP_WIDTH_MIN,
|
||||
addHeight + TOOLTIP_HEIGHT_MIN);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurrentCard(CardView card) {
|
||||
return currentCard != null && card.equals(currentCard);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,78 +1,78 @@
|
|||
package org.mage.plugins.card.properties;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.mage.plugins.card.constants.Constants;
|
||||
|
||||
public class SettingsManager {
|
||||
|
||||
private static SettingsManager settingsManager = null;
|
||||
|
||||
public static SettingsManager getIntance() {
|
||||
if (settingsManager == null) {
|
||||
synchronized (SettingsManager.class) {
|
||||
if (settingsManager == null) settingsManager = new SettingsManager();
|
||||
}
|
||||
}
|
||||
return settingsManager;
|
||||
}
|
||||
|
||||
private SettingsManager() {
|
||||
loadImageProperties();
|
||||
}
|
||||
|
||||
public void reloadImageProperties() {
|
||||
loadImageProperties();
|
||||
}
|
||||
|
||||
private void loadImageProperties() {
|
||||
imageUrlProperties = new Properties();
|
||||
try {
|
||||
InputStream is = SettingsManager.class.getClassLoader().getResourceAsStream(Constants.IO.IMAGE_PROPERTIES_FILE);
|
||||
if (is == null)
|
||||
throw new RuntimeException("Couldn't load " + Constants.IO.IMAGE_PROPERTIES_FILE);
|
||||
imageUrlProperties.load(is);
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getSetNameReplacement(String setName) {
|
||||
String result = setName;
|
||||
if (imageUrlProperties != null) {
|
||||
result = imageUrlProperties.getProperty(setName, setName);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public HashSet<String> getIgnoreUrls() {
|
||||
HashSet<String> ignoreUrls = new HashSet<String>();
|
||||
if (imageUrlProperties != null) {
|
||||
String result = imageUrlProperties.getProperty("ignore.urls");
|
||||
if (result != null) {
|
||||
String[] ignore = result.split(",");
|
||||
ignoreUrls.addAll(Arrays.asList(ignore));
|
||||
}
|
||||
}
|
||||
return ignoreUrls;
|
||||
}
|
||||
|
||||
public ArrayList<String> getTokenLookupOrder() {
|
||||
ArrayList<String> order = new ArrayList<String>();
|
||||
if (imageUrlProperties != null) {
|
||||
String result = imageUrlProperties.getProperty("token.lookup.order");
|
||||
if (result != null) {
|
||||
String[] sets = result.split(",");
|
||||
order.addAll(Arrays.asList(sets));
|
||||
}
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
private Properties imageUrlProperties;
|
||||
}
|
||||
package org.mage.plugins.card.properties;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.mage.plugins.card.constants.Constants;
|
||||
|
||||
public class SettingsManager {
|
||||
|
||||
private static SettingsManager settingsManager = null;
|
||||
|
||||
public static SettingsManager getIntance() {
|
||||
if (settingsManager == null) {
|
||||
synchronized (SettingsManager.class) {
|
||||
if (settingsManager == null) settingsManager = new SettingsManager();
|
||||
}
|
||||
}
|
||||
return settingsManager;
|
||||
}
|
||||
|
||||
private SettingsManager() {
|
||||
loadImageProperties();
|
||||
}
|
||||
|
||||
public void reloadImageProperties() {
|
||||
loadImageProperties();
|
||||
}
|
||||
|
||||
private void loadImageProperties() {
|
||||
imageUrlProperties = new Properties();
|
||||
try {
|
||||
InputStream is = SettingsManager.class.getClassLoader().getResourceAsStream(Constants.IO.IMAGE_PROPERTIES_FILE);
|
||||
if (is == null)
|
||||
throw new RuntimeException("Couldn't load " + Constants.IO.IMAGE_PROPERTIES_FILE);
|
||||
imageUrlProperties.load(is);
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getSetNameReplacement(String setName) {
|
||||
String result = setName;
|
||||
if (imageUrlProperties != null) {
|
||||
result = imageUrlProperties.getProperty(setName, setName);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public HashSet<String> getIgnoreUrls() {
|
||||
HashSet<String> ignoreUrls = new HashSet<String>();
|
||||
if (imageUrlProperties != null) {
|
||||
String result = imageUrlProperties.getProperty("ignore.urls");
|
||||
if (result != null) {
|
||||
String[] ignore = result.split(",");
|
||||
ignoreUrls.addAll(Arrays.asList(ignore));
|
||||
}
|
||||
}
|
||||
return ignoreUrls;
|
||||
}
|
||||
|
||||
public ArrayList<String> getTokenLookupOrder() {
|
||||
ArrayList<String> order = new ArrayList<String>();
|
||||
if (imageUrlProperties != null) {
|
||||
String result = imageUrlProperties.getProperty("token.lookup.order");
|
||||
if (result != null) {
|
||||
String[] sets = result.split(",");
|
||||
order.addAll(Arrays.asList(sets));
|
||||
}
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
private Properties imageUrlProperties;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,170 +1,170 @@
|
|||
package org.mage.plugins.card.utils;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.prefs.Preferences;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.constants.Constants;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Connection.ProxyType;
|
||||
import net.java.truevfs.access.TFile;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.plugins.card.images.CardDownloadData;
|
||||
import org.mage.plugins.card.properties.SettingsManager;
|
||||
|
||||
public class CardImageUtils {
|
||||
|
||||
private static final HashMap<CardDownloadData, String> pathCache = new HashMap<>();
|
||||
private static final Logger log = Logger.getLogger(CardImageUtils.class);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param card
|
||||
* @return String if image exists, else null
|
||||
*/
|
||||
public static String generateTokenImagePath(CardDownloadData card) {
|
||||
if (card.isToken()) {
|
||||
if (pathCache.containsKey(card)) {
|
||||
return pathCache.get(card);
|
||||
}
|
||||
String filePath = getTokenImagePath(card);
|
||||
TFile file = new TFile(filePath);
|
||||
|
||||
if (!file.exists() && card.getTokenSetCode() != null) {
|
||||
filePath = searchForCardImage(card);
|
||||
file = new TFile(filePath);
|
||||
}
|
||||
|
||||
if (file.exists()) {
|
||||
pathCache.put(card, filePath);
|
||||
return filePath;
|
||||
}
|
||||
}
|
||||
log.warn("Token image file not found: " + card.getTokenSetCode() + " - " + card.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getTokenImagePath(CardDownloadData card) {
|
||||
String filename = generateImagePath(card);
|
||||
|
||||
TFile file = new TFile(filename);
|
||||
if (!file.exists()) {
|
||||
CardDownloadData updated = new CardDownloadData(card);
|
||||
updated.setName(card.getName() + " 1");
|
||||
filename = generateImagePath(updated);
|
||||
file = new TFile(filename);
|
||||
if (!file.exists()) {
|
||||
updated = new CardDownloadData(card);
|
||||
updated.setName(card.getName() + " 2");
|
||||
filename = generateImagePath(updated);
|
||||
}
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
private static String searchForCardImage(CardDownloadData card) {
|
||||
TFile file;
|
||||
String path;
|
||||
CardDownloadData c = new CardDownloadData(card);
|
||||
c.setSet(card.getTokenSetCode());
|
||||
path = getTokenImagePath(c);
|
||||
file = new TFile(path);
|
||||
if (file.exists()) {
|
||||
pathCache.put(card, path);
|
||||
return path;
|
||||
}
|
||||
|
||||
// for (String set : SettingsManager.getIntance().getTokenLookupOrder()) {
|
||||
// c.setSet(set);
|
||||
// path = getTokenImagePath(c);
|
||||
// file = new TFile(path);
|
||||
// if (file.exists()) {
|
||||
// pathCache.put(card, path);
|
||||
// return path;
|
||||
// }
|
||||
// }
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String updateSet(String cardSet, boolean forUrl) {
|
||||
String set = cardSet.toLowerCase();
|
||||
if (set.equals("con")) {
|
||||
set = "cfx";
|
||||
}
|
||||
if (forUrl) {
|
||||
set = SettingsManager.getIntance().getSetNameReplacement(set);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
private static String getImageDir(CardDownloadData card, String imagesPath) {
|
||||
if (card.getSet() == null) {
|
||||
return "";
|
||||
}
|
||||
String set = updateSet(card.getSet(), false).toUpperCase();
|
||||
String imagesDir = (imagesPath != null ? imagesPath : Constants.IO.imageBaseDir);
|
||||
if (card.isToken()) {
|
||||
return buildTokenPath(imagesDir, set);
|
||||
} else {
|
||||
return buildPath(imagesDir, set);
|
||||
}
|
||||
}
|
||||
|
||||
private static String buildTokenPath(String imagesDir, String set) {
|
||||
if (PreferencesDialog.isSaveImagesToZip()) {
|
||||
return imagesDir + TFile.separator + "TOK" + ".zip" + TFile.separator + set;
|
||||
} else {
|
||||
return imagesDir + TFile.separator + "TOK" + TFile.separator + set;
|
||||
}
|
||||
}
|
||||
|
||||
private static String buildPath(String imagesDir, String set) {
|
||||
if (PreferencesDialog.isSaveImagesToZip()) {
|
||||
return imagesDir + TFile.separator + set + ".zip" + TFile.separator + set;
|
||||
} else {
|
||||
return imagesDir + TFile.separator + set;
|
||||
}
|
||||
}
|
||||
|
||||
public static String generateImagePath(CardDownloadData card) {
|
||||
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
||||
String imagesPath = useDefault.equals("true") ? null : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
||||
|
||||
String imageDir = getImageDir(card, imagesPath);
|
||||
String imageName;
|
||||
|
||||
String type = card.getType() != 0 ? " " + Integer.toString(card.getType()) : "";
|
||||
String name = card.getName().replace(":", "").replace("//", "-");
|
||||
|
||||
if (card.getUsesVariousArt()) {
|
||||
imageName = name + "." + card.getCollectorId() + ".full.jpg";
|
||||
} else {
|
||||
imageName = name + type + ".full.jpg";
|
||||
}
|
||||
|
||||
if (new TFile(imageDir).exists() && !new TFile(imageDir + TFile.separator + imageName).exists()) {
|
||||
for (String fileName : new TFile(imageDir).list()) {
|
||||
if (fileName.toLowerCase().equals(imageName.toLowerCase())) {
|
||||
imageName = fileName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return imageDir + TFile.separator + imageName;
|
||||
}
|
||||
|
||||
public static Proxy getProxyFromPreferences() {
|
||||
Preferences prefs = MageFrame.getPreferences();
|
||||
Connection.ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
|
||||
if (!proxyType.equals(ProxyType.NONE)) {
|
||||
String proxyServer = prefs.get("proxyAddress", "");
|
||||
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
|
||||
return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyServer, proxyPort));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
package org.mage.plugins.card.utils;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.prefs.Preferences;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.constants.Constants;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Connection.ProxyType;
|
||||
import net.java.truevfs.access.TFile;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.plugins.card.images.CardDownloadData;
|
||||
import org.mage.plugins.card.properties.SettingsManager;
|
||||
|
||||
public class CardImageUtils {
|
||||
|
||||
private static final HashMap<CardDownloadData, String> pathCache = new HashMap<>();
|
||||
private static final Logger log = Logger.getLogger(CardImageUtils.class);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param card
|
||||
* @return String if image exists, else null
|
||||
*/
|
||||
public static String generateTokenImagePath(CardDownloadData card) {
|
||||
if (card.isToken()) {
|
||||
if (pathCache.containsKey(card)) {
|
||||
return pathCache.get(card);
|
||||
}
|
||||
String filePath = getTokenImagePath(card);
|
||||
TFile file = new TFile(filePath);
|
||||
|
||||
if (!file.exists() && card.getTokenSetCode() != null) {
|
||||
filePath = searchForCardImage(card);
|
||||
file = new TFile(filePath);
|
||||
}
|
||||
|
||||
if (file.exists()) {
|
||||
pathCache.put(card, filePath);
|
||||
return filePath;
|
||||
}
|
||||
}
|
||||
log.warn("Token image file not found: " + card.getTokenSetCode() + " - " + card.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getTokenImagePath(CardDownloadData card) {
|
||||
String filename = generateImagePath(card);
|
||||
|
||||
TFile file = new TFile(filename);
|
||||
if (!file.exists()) {
|
||||
CardDownloadData updated = new CardDownloadData(card);
|
||||
updated.setName(card.getName() + " 1");
|
||||
filename = generateImagePath(updated);
|
||||
file = new TFile(filename);
|
||||
if (!file.exists()) {
|
||||
updated = new CardDownloadData(card);
|
||||
updated.setName(card.getName() + " 2");
|
||||
filename = generateImagePath(updated);
|
||||
}
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
private static String searchForCardImage(CardDownloadData card) {
|
||||
TFile file;
|
||||
String path;
|
||||
CardDownloadData c = new CardDownloadData(card);
|
||||
c.setSet(card.getTokenSetCode());
|
||||
path = getTokenImagePath(c);
|
||||
file = new TFile(path);
|
||||
if (file.exists()) {
|
||||
pathCache.put(card, path);
|
||||
return path;
|
||||
}
|
||||
|
||||
// for (String set : SettingsManager.getIntance().getTokenLookupOrder()) {
|
||||
// c.setSet(set);
|
||||
// path = getTokenImagePath(c);
|
||||
// file = new TFile(path);
|
||||
// if (file.exists()) {
|
||||
// pathCache.put(card, path);
|
||||
// return path;
|
||||
// }
|
||||
// }
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String updateSet(String cardSet, boolean forUrl) {
|
||||
String set = cardSet.toLowerCase();
|
||||
if (set.equals("con")) {
|
||||
set = "cfx";
|
||||
}
|
||||
if (forUrl) {
|
||||
set = SettingsManager.getIntance().getSetNameReplacement(set);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
private static String getImageDir(CardDownloadData card, String imagesPath) {
|
||||
if (card.getSet() == null) {
|
||||
return "";
|
||||
}
|
||||
String set = updateSet(card.getSet(), false).toUpperCase();
|
||||
String imagesDir = (imagesPath != null ? imagesPath : Constants.IO.imageBaseDir);
|
||||
if (card.isToken()) {
|
||||
return buildTokenPath(imagesDir, set);
|
||||
} else {
|
||||
return buildPath(imagesDir, set);
|
||||
}
|
||||
}
|
||||
|
||||
private static String buildTokenPath(String imagesDir, String set) {
|
||||
if (PreferencesDialog.isSaveImagesToZip()) {
|
||||
return imagesDir + TFile.separator + "TOK" + ".zip" + TFile.separator + set;
|
||||
} else {
|
||||
return imagesDir + TFile.separator + "TOK" + TFile.separator + set;
|
||||
}
|
||||
}
|
||||
|
||||
private static String buildPath(String imagesDir, String set) {
|
||||
if (PreferencesDialog.isSaveImagesToZip()) {
|
||||
return imagesDir + TFile.separator + set + ".zip" + TFile.separator + set;
|
||||
} else {
|
||||
return imagesDir + TFile.separator + set;
|
||||
}
|
||||
}
|
||||
|
||||
public static String generateImagePath(CardDownloadData card) {
|
||||
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
||||
String imagesPath = useDefault.equals("true") ? null : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
||||
|
||||
String imageDir = getImageDir(card, imagesPath);
|
||||
String imageName;
|
||||
|
||||
String type = card.getType() != 0 ? " " + Integer.toString(card.getType()) : "";
|
||||
String name = card.getName().replace(":", "").replace("//", "-");
|
||||
|
||||
if (card.getUsesVariousArt()) {
|
||||
imageName = name + "." + card.getCollectorId() + ".full.jpg";
|
||||
} else {
|
||||
imageName = name + type + ".full.jpg";
|
||||
}
|
||||
|
||||
if (new TFile(imageDir).exists() && !new TFile(imageDir + TFile.separator + imageName).exists()) {
|
||||
for (String fileName : new TFile(imageDir).list()) {
|
||||
if (fileName.toLowerCase().equals(imageName.toLowerCase())) {
|
||||
imageName = fileName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return imageDir + TFile.separator + imageName;
|
||||
}
|
||||
|
||||
public static Proxy getProxyFromPreferences() {
|
||||
Preferences prefs = MageFrame.getPreferences();
|
||||
Connection.ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
|
||||
if (!proxyType.equals(ProxyType.NONE)) {
|
||||
String proxyServer = prefs.get("proxyAddress", "");
|
||||
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
|
||||
return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyServer, proxyPort));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,49 +1,49 @@
|
|||
package org.mage.plugins.card.utils;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface ImageManager {
|
||||
|
||||
Image getAppImage();
|
||||
Image getAppSmallImage();
|
||||
Image getAppFlashedImage();
|
||||
|
||||
Image getSicknessImage();
|
||||
Image getDayImage();
|
||||
Image getNightImage();
|
||||
|
||||
Image getTokenIconImage();
|
||||
Image getTriggeredAbilityImage();
|
||||
Image getActivatedAbilityImage();
|
||||
Image getLookedAtImage();
|
||||
Image getRevealedImage();
|
||||
Image getExileImage();
|
||||
Image getCopyInformIconImage();
|
||||
Image getCounterImageViolet();
|
||||
Image getCounterImageRed();
|
||||
Image getCounterImageGreen();
|
||||
Image getCounterImageGrey();
|
||||
|
||||
Image getDlgAcceptButtonImage();
|
||||
Image getDlgActiveAcceptButtonImage();
|
||||
Image getDlgCancelButtonImage();
|
||||
Image getDlgActiveCancelButtonImage();
|
||||
Image getDlgPrevButtonImage();
|
||||
Image getDlgActivePrevButtonImage();
|
||||
Image getDlgNextButtonImage();
|
||||
Image getDlgActiveNextButtonImage();
|
||||
|
||||
Image getSwitchHandsButtonImage();
|
||||
Image getStopWatchButtonImage();
|
||||
Image getConcedeButtonImage();
|
||||
Image getCancelSkipButtonImage();
|
||||
Image getSkipNextTurnButtonImage();
|
||||
Image getSkipEndTurnButtonImage();
|
||||
Image getSkipMainButtonImage();
|
||||
Image getSkipStackButtonImage();
|
||||
Image getSkipEndStepBeforeYourTurnButtonImage();
|
||||
Image getSkipYourNextTurnButtonImage();
|
||||
|
||||
|
||||
Image getPhaseImage(String phase);
|
||||
}
|
||||
package org.mage.plugins.card.utils;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface ImageManager {
|
||||
|
||||
Image getAppImage();
|
||||
Image getAppSmallImage();
|
||||
Image getAppFlashedImage();
|
||||
|
||||
Image getSicknessImage();
|
||||
Image getDayImage();
|
||||
Image getNightImage();
|
||||
|
||||
Image getTokenIconImage();
|
||||
Image getTriggeredAbilityImage();
|
||||
Image getActivatedAbilityImage();
|
||||
Image getLookedAtImage();
|
||||
Image getRevealedImage();
|
||||
Image getExileImage();
|
||||
Image getCopyInformIconImage();
|
||||
Image getCounterImageViolet();
|
||||
Image getCounterImageRed();
|
||||
Image getCounterImageGreen();
|
||||
Image getCounterImageGrey();
|
||||
|
||||
Image getDlgAcceptButtonImage();
|
||||
Image getDlgActiveAcceptButtonImage();
|
||||
Image getDlgCancelButtonImage();
|
||||
Image getDlgActiveCancelButtonImage();
|
||||
Image getDlgPrevButtonImage();
|
||||
Image getDlgActivePrevButtonImage();
|
||||
Image getDlgNextButtonImage();
|
||||
Image getDlgActiveNextButtonImage();
|
||||
|
||||
Image getSwitchHandsButtonImage();
|
||||
Image getStopWatchButtonImage();
|
||||
Image getConcedeButtonImage();
|
||||
Image getCancelSkipButtonImage();
|
||||
Image getSkipNextTurnButtonImage();
|
||||
Image getSkipEndTurnButtonImage();
|
||||
Image getSkipMainButtonImage();
|
||||
Image getSkipStackButtonImage();
|
||||
Image getSkipEndStepBeforeYourTurnButtonImage();
|
||||
Image getSkipYourNextTurnButtonImage();
|
||||
|
||||
|
||||
Image getPhaseImage(String phase);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,52 +1,52 @@
|
|||
package org.mage.plugins.card.utils;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.FilteredImageSource;
|
||||
import java.awt.image.ImageFilter;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.awt.image.RGBImageFilter;
|
||||
|
||||
public class Transparency {
|
||||
public static Image makeColorTransparent(Image im, final Color color) {
|
||||
ImageFilter filter = new RGBImageFilter() {
|
||||
// the color we are looking for... Alpha bits are set to opaque
|
||||
public int markerRGB = color.getRGB() | 0xFF000000;
|
||||
|
||||
@Override
|
||||
public final int filterRGB(int x, int y, int rgb) {
|
||||
if ((rgb | 0xFF000000) == markerRGB) {
|
||||
// Mark the alpha bits as zero - transparent
|
||||
return 0x00FFFFFF & rgb;
|
||||
} else {
|
||||
// nothing to do
|
||||
return rgb;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
|
||||
return Toolkit.getDefaultToolkit().createImage(ip);
|
||||
}
|
||||
|
||||
public static BufferedImage makeImageTranslucent(BufferedImage source,
|
||||
double alpha) {
|
||||
BufferedImage target = new BufferedImage(source.getWidth(), source
|
||||
.getHeight(), java.awt.Transparency.TRANSLUCENT);
|
||||
// Get the images graphics
|
||||
Graphics2D g = target.createGraphics();
|
||||
// Set the Graphics composite to Alpha
|
||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
|
||||
(float) alpha));
|
||||
// Draw the image into the prepared reciver image
|
||||
g.drawImage(source, null, 0, 0);
|
||||
// let go of all system resources in this Graphics
|
||||
g.dispose();
|
||||
// Return the image
|
||||
return target;
|
||||
}
|
||||
}
|
||||
package org.mage.plugins.card.utils;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.FilteredImageSource;
|
||||
import java.awt.image.ImageFilter;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.awt.image.RGBImageFilter;
|
||||
|
||||
public class Transparency {
|
||||
public static Image makeColorTransparent(Image im, final Color color) {
|
||||
ImageFilter filter = new RGBImageFilter() {
|
||||
// the color we are looking for... Alpha bits are set to opaque
|
||||
public int markerRGB = color.getRGB() | 0xFF000000;
|
||||
|
||||
@Override
|
||||
public final int filterRGB(int x, int y, int rgb) {
|
||||
if ((rgb | 0xFF000000) == markerRGB) {
|
||||
// Mark the alpha bits as zero - transparent
|
||||
return 0x00FFFFFF & rgb;
|
||||
} else {
|
||||
// nothing to do
|
||||
return rgb;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
|
||||
return Toolkit.getDefaultToolkit().createImage(ip);
|
||||
}
|
||||
|
||||
public static BufferedImage makeImageTranslucent(BufferedImage source,
|
||||
double alpha) {
|
||||
BufferedImage target = new BufferedImage(source.getWidth(), source
|
||||
.getHeight(), java.awt.Transparency.TRANSLUCENT);
|
||||
// Get the images graphics
|
||||
Graphics2D g = target.createGraphics();
|
||||
// Set the Graphics composite to Alpha
|
||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
|
||||
(float) alpha));
|
||||
// Draw the image into the prepared reciver image
|
||||
g.drawImage(source, null, 0, 0);
|
||||
// let go of all system resources in this Graphics
|
||||
g.dispose();
|
||||
// Return the image
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,442 +1,442 @@
|
|||
package org.mage.plugins.card.utils.impl;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.CropImageFilter;
|
||||
import java.awt.image.FilteredImageSource;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.imageio.ImageIO;
|
||||
import mage.client.util.gui.BufferedImageBuilder;
|
||||
import org.mage.plugins.card.utils.ImageManager;
|
||||
import org.mage.plugins.card.utils.Transparency;
|
||||
|
||||
public class ImageManagerImpl implements ImageManager {
|
||||
|
||||
private static final ImageManagerImpl fInstance = new ImageManagerImpl();
|
||||
|
||||
public static ImageManagerImpl getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
public ImageManagerImpl() {
|
||||
init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
String[] phases = {"Untap", "Upkeep", "Draw", "Main1",
|
||||
"Combat_Start", "Combat_Attack", "Combat_Block", "Combat_Damage", "Combat_End",
|
||||
"Main2", "Cleanup", "Next_Turn"};
|
||||
phasesImages = new HashMap<>();
|
||||
for (String name : phases) {
|
||||
Image image = getImageFromResource("/phases/phase_" + name.toLowerCase() + ".png", new Rectangle(36, 36));
|
||||
phasesImages.put(name, image);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getPhaseImage(String phase) {
|
||||
return phasesImages.get(phase);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getAppImage() {
|
||||
if (appImage == null) {
|
||||
Image image = getBufferedImageFromResource("/icon-mage.png");
|
||||
appImage = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return appImage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getAppSmallImage() {
|
||||
if (appSmallImage == null) {
|
||||
Image image = getImageFromResourceTransparent("/icon-mage.png", Color.WHITE, new Rectangle(16, 16));
|
||||
appSmallImage = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return appSmallImage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getAppFlashedImage() {
|
||||
if (appImageFlashed == null) {
|
||||
Image image = getImageFromResourceTransparent("/icon-mage-flashed.png", Color.WHITE, new Rectangle(16, 16));
|
||||
appImageFlashed = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return appImageFlashed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getSicknessImage() {
|
||||
if (imageSickness == null) {
|
||||
Image image = getImageFromResourceTransparent("/sickness.png", Color.WHITE, new Rectangle(296, 265));
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
image = tk.createImage(new FilteredImageSource(image.getSource(), new CropImageFilter(0, 0, 200, 285)));
|
||||
imageSickness = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageSickness;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getDayImage() {
|
||||
if (imageDay == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/day.png", Color.WHITE, new Rectangle(20, 20));
|
||||
imageDay = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageDay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getNightImage() {
|
||||
if (imageNight == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/night.png", Color.WHITE, new Rectangle(20, 20));
|
||||
imageNight = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageNight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getTokenIconImage() {
|
||||
if (imageTokenIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/token.png", Color.WHITE, new Rectangle(20, 20));
|
||||
imageTokenIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageTokenIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getLookedAtImage() {
|
||||
if (lookedAtIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/game/looked_at.png", Color.WHITE, new Rectangle(20, 20));
|
||||
lookedAtIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return lookedAtIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getRevealedImage() {
|
||||
if (revealedIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/game/revealed.png", Color.WHITE, new Rectangle(20, 20));
|
||||
revealedIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return revealedIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getExileImage() {
|
||||
if (exileIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/info/exile.png", Color.WHITE, new Rectangle(20, 20));
|
||||
exileIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return exileIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getTriggeredAbilityImage() {
|
||||
if (triggeredAbilityIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/triggered_ability.png", Color.WHITE, new Rectangle(20, 20));
|
||||
triggeredAbilityIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return triggeredAbilityIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getActivatedAbilityImage() {
|
||||
if (activatedAbilityIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/activated_ability.png", Color.WHITE, new Rectangle(20, 20));
|
||||
activatedAbilityIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return activatedAbilityIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCopyInformIconImage() {
|
||||
if (imageCopyIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/copy.png", Color.WHITE, new Rectangle(20, 20));
|
||||
imageCopyIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCopyIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCounterImageViolet() {
|
||||
if (imageCounterViolet == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/counter_violet.png", Color.WHITE, new Rectangle(32, 32));
|
||||
imageCounterViolet = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCounterViolet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCounterImageGreen() {
|
||||
if (imageCounterGreen == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/counter_green.png", Color.WHITE, new Rectangle(32, 32));
|
||||
imageCounterGreen = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCounterGreen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCounterImageRed() {
|
||||
if (imageCounterRed == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/counter_red.png", Color.WHITE, new Rectangle(32, 32));
|
||||
imageCounterRed = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCounterRed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCounterImageGrey() {
|
||||
if (imageCounterGrey == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/counter_grey.png", Color.WHITE, new Rectangle(32, 32));
|
||||
imageCounterGrey = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCounterGrey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgCancelButtonImage() {
|
||||
if (imageDlgCancelButton == null) {
|
||||
imageDlgCancelButton = getBufferedImageFromResource("/dlg/dlg.cancel.png");
|
||||
}
|
||||
return imageDlgCancelButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgActiveCancelButtonImage() {
|
||||
if (imageDlgActiveCancelButton == null) {
|
||||
imageDlgActiveCancelButton = getBufferedImageFromResource("/dlg/dlg.cancel.hover.png");
|
||||
}
|
||||
return imageDlgActiveCancelButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgAcceptButtonImage() {
|
||||
if (imageDlgAcceptButton == null) {
|
||||
imageDlgAcceptButton = getBufferedImageFromResource("/dlg/dlg.ok.png");
|
||||
}
|
||||
return imageDlgAcceptButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgActiveAcceptButtonImage() {
|
||||
if (imageDlgActiveAcceptButton == null) {
|
||||
imageDlgActiveAcceptButton = getBufferedImageFromResource("/dlg/dlg.ok.hover.png");
|
||||
}
|
||||
return imageDlgActiveAcceptButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgPrevButtonImage() {
|
||||
if (imageDlgPrevButton == null) {
|
||||
imageDlgPrevButton = getBufferedImageFromResource("/dlg/dlg.prev.png");
|
||||
}
|
||||
return imageDlgPrevButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgActivePrevButtonImage() {
|
||||
if (imageDlgActivePrevButton == null) {
|
||||
imageDlgActivePrevButton = getBufferedImageFromResource("/dlg/dlg.prev.hover.png");
|
||||
}
|
||||
return imageDlgActivePrevButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgNextButtonImage() {
|
||||
if (imageDlgNextButton == null) {
|
||||
imageDlgNextButton = getBufferedImageFromResource("/dlg/dlg.next.png");
|
||||
}
|
||||
return imageDlgNextButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgActiveNextButtonImage() {
|
||||
if (imageDlgActiveNextButton == null) {
|
||||
imageDlgActiveNextButton = getBufferedImageFromResource("/dlg/dlg.next.hover.png");
|
||||
}
|
||||
return imageDlgActiveNextButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getConcedeButtonImage() {
|
||||
if (imageConcedeButton == null) {
|
||||
imageConcedeButton = getBufferedImageFromResource("/buttons/concede.png");
|
||||
}
|
||||
return imageConcedeButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSwitchHandsButtonImage() {
|
||||
if (imageSwitchHandsButton == null) {
|
||||
imageSwitchHandsButton = getBufferedImageFromResource("/buttons/switch_hands.png");
|
||||
}
|
||||
return imageSwitchHandsButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getStopWatchButtonImage() {
|
||||
if (imageStopWatchingButton == null) {
|
||||
imageStopWatchingButton = getBufferedImageFromResource("/buttons/stop_watching.png");
|
||||
}
|
||||
return imageStopWatchingButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getCancelSkipButtonImage() {
|
||||
if (imageCancelSkipButton == null) {
|
||||
imageCancelSkipButton = getBufferedImageFromResource("/buttons/cancel_skip.png");
|
||||
}
|
||||
return imageCancelSkipButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSkipNextTurnButtonImage() {
|
||||
if (imageSkipNextTurnButton == null) {
|
||||
imageSkipNextTurnButton = getBufferedImageFromResource("/buttons/skip_turn.png");
|
||||
}
|
||||
return imageSkipNextTurnButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSkipEndTurnButtonImage() {
|
||||
if (imageSkipToEndTurnButton == null) {
|
||||
imageSkipToEndTurnButton = getBufferedImageFromResource("/buttons/skip_to_end.png");
|
||||
}
|
||||
return imageSkipToEndTurnButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSkipMainButtonImage() {
|
||||
if (imageSkipToMainButton == null) {
|
||||
imageSkipToMainButton = getBufferedImageFromResource("/buttons/skip_to_main.png");
|
||||
}
|
||||
return imageSkipToMainButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSkipStackButtonImage() {
|
||||
if (imageSkipStackButton == null) {
|
||||
imageSkipStackButton = getBufferedImageFromResource("/buttons/skip_stack.png");
|
||||
}
|
||||
return imageSkipStackButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSkipEndStepBeforeYourTurnButtonImage() {
|
||||
if (imageSkipUntilEndStepBeforeYourTurnButton == null) {
|
||||
imageSkipUntilEndStepBeforeYourTurnButton = getBufferedImageFromResource("/buttons/skip_to_previous_end.png");
|
||||
}
|
||||
return imageSkipUntilEndStepBeforeYourTurnButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSkipYourNextTurnButtonImage() {
|
||||
if (imageSkipYourNextTurnButton == null) {
|
||||
imageSkipYourNextTurnButton = getBufferedImageFromResource("/buttons/skip_all.png");
|
||||
}
|
||||
return imageSkipYourNextTurnButton;
|
||||
}
|
||||
|
||||
protected static Image getImageFromResourceTransparent(String path, Color mask, Rectangle rec) {
|
||||
BufferedImage image;
|
||||
Image imageCardTransparent;
|
||||
Image resized = null;
|
||||
|
||||
URL imageURL = ImageManager.class.getResource(path);
|
||||
|
||||
try {
|
||||
image = ImageIO.read(imageURL);
|
||||
imageCardTransparent = Transparency.makeColorTransparent(image, mask);
|
||||
|
||||
resized = imageCardTransparent.getScaledInstance(rec.width, rec.height, java.awt.Image.SCALE_SMOOTH);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return resized;
|
||||
}
|
||||
|
||||
protected static Image getImageFromResource(String path, Rectangle rec) {
|
||||
Image resized = null;
|
||||
|
||||
URL imageURL = ImageManager.class.getResource(path);
|
||||
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(imageURL);
|
||||
resized = image.getScaledInstance(rec.width, rec.height, java.awt.Image.SCALE_SMOOTH);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return resized;
|
||||
}
|
||||
|
||||
protected static BufferedImage getBufferedImageFromResource(String path) {
|
||||
URL imageURL = ImageManager.class.getResource(path);
|
||||
BufferedImage image = null;
|
||||
|
||||
try {
|
||||
image = ImageIO.read(imageURL);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
public static BufferedImage deepCopy(BufferedImage bi) {
|
||||
ColorModel cm = bi.getColorModel();
|
||||
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
|
||||
WritableRaster raster = bi.copyData(null);
|
||||
return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
|
||||
}
|
||||
|
||||
private static BufferedImage appImage;
|
||||
private static BufferedImage appSmallImage;
|
||||
private static BufferedImage appImageFlashed;
|
||||
|
||||
private static BufferedImage imageSickness;
|
||||
private static BufferedImage imageDay;
|
||||
private static BufferedImage imageNight;
|
||||
|
||||
private static BufferedImage imageTokenIcon;
|
||||
private static BufferedImage triggeredAbilityIcon;
|
||||
private static BufferedImage activatedAbilityIcon;
|
||||
private static BufferedImage lookedAtIcon;
|
||||
private static BufferedImage revealedIcon;
|
||||
private static BufferedImage exileIcon;
|
||||
private static BufferedImage imageCopyIcon;
|
||||
private static BufferedImage imageCounterGreen;
|
||||
private static BufferedImage imageCounterGrey;
|
||||
private static BufferedImage imageCounterRed;
|
||||
private static BufferedImage imageCounterViolet;
|
||||
|
||||
private static BufferedImage imageDlgAcceptButton;
|
||||
private static BufferedImage imageDlgActiveAcceptButton;
|
||||
private static BufferedImage imageDlgCancelButton;
|
||||
private static BufferedImage imageDlgActiveCancelButton;
|
||||
private static BufferedImage imageDlgPrevButton;
|
||||
private static BufferedImage imageDlgActivePrevButton;
|
||||
private static BufferedImage imageDlgNextButton;
|
||||
private static BufferedImage imageDlgActiveNextButton;
|
||||
|
||||
private static BufferedImage imageCancelSkipButton;
|
||||
private static BufferedImage imageSwitchHandsButton;
|
||||
private static BufferedImage imageStopWatchingButton;
|
||||
private static BufferedImage imageConcedeButton;
|
||||
private static BufferedImage imageSkipNextTurnButton;
|
||||
private static BufferedImage imageSkipToEndTurnButton;
|
||||
private static BufferedImage imageSkipToMainButton;
|
||||
private static BufferedImage imageSkipStackButton;
|
||||
private static BufferedImage imageSkipUntilEndStepBeforeYourTurnButton;
|
||||
private static BufferedImage imageSkipYourNextTurnButton;
|
||||
|
||||
private static Map<String, Image> phasesImages;
|
||||
}
|
||||
package org.mage.plugins.card.utils.impl;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.CropImageFilter;
|
||||
import java.awt.image.FilteredImageSource;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.imageio.ImageIO;
|
||||
import mage.client.util.gui.BufferedImageBuilder;
|
||||
import org.mage.plugins.card.utils.ImageManager;
|
||||
import org.mage.plugins.card.utils.Transparency;
|
||||
|
||||
public class ImageManagerImpl implements ImageManager {
|
||||
|
||||
private static final ImageManagerImpl fInstance = new ImageManagerImpl();
|
||||
|
||||
public static ImageManagerImpl getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
public ImageManagerImpl() {
|
||||
init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
String[] phases = {"Untap", "Upkeep", "Draw", "Main1",
|
||||
"Combat_Start", "Combat_Attack", "Combat_Block", "Combat_Damage", "Combat_End",
|
||||
"Main2", "Cleanup", "Next_Turn"};
|
||||
phasesImages = new HashMap<>();
|
||||
for (String name : phases) {
|
||||
Image image = getImageFromResource("/phases/phase_" + name.toLowerCase() + ".png", new Rectangle(36, 36));
|
||||
phasesImages.put(name, image);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getPhaseImage(String phase) {
|
||||
return phasesImages.get(phase);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getAppImage() {
|
||||
if (appImage == null) {
|
||||
Image image = getBufferedImageFromResource("/icon-mage.png");
|
||||
appImage = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return appImage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getAppSmallImage() {
|
||||
if (appSmallImage == null) {
|
||||
Image image = getImageFromResourceTransparent("/icon-mage.png", Color.WHITE, new Rectangle(16, 16));
|
||||
appSmallImage = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return appSmallImage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getAppFlashedImage() {
|
||||
if (appImageFlashed == null) {
|
||||
Image image = getImageFromResourceTransparent("/icon-mage-flashed.png", Color.WHITE, new Rectangle(16, 16));
|
||||
appImageFlashed = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return appImageFlashed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getSicknessImage() {
|
||||
if (imageSickness == null) {
|
||||
Image image = getImageFromResourceTransparent("/sickness.png", Color.WHITE, new Rectangle(296, 265));
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
image = tk.createImage(new FilteredImageSource(image.getSource(), new CropImageFilter(0, 0, 200, 285)));
|
||||
imageSickness = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageSickness;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getDayImage() {
|
||||
if (imageDay == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/day.png", Color.WHITE, new Rectangle(20, 20));
|
||||
imageDay = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageDay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getNightImage() {
|
||||
if (imageNight == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/night.png", Color.WHITE, new Rectangle(20, 20));
|
||||
imageNight = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageNight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getTokenIconImage() {
|
||||
if (imageTokenIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/token.png", Color.WHITE, new Rectangle(20, 20));
|
||||
imageTokenIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageTokenIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getLookedAtImage() {
|
||||
if (lookedAtIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/game/looked_at.png", Color.WHITE, new Rectangle(20, 20));
|
||||
lookedAtIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return lookedAtIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getRevealedImage() {
|
||||
if (revealedIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/game/revealed.png", Color.WHITE, new Rectangle(20, 20));
|
||||
revealedIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return revealedIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getExileImage() {
|
||||
if (exileIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/info/exile.png", Color.WHITE, new Rectangle(20, 20));
|
||||
exileIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return exileIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getTriggeredAbilityImage() {
|
||||
if (triggeredAbilityIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/triggered_ability.png", Color.WHITE, new Rectangle(20, 20));
|
||||
triggeredAbilityIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return triggeredAbilityIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getActivatedAbilityImage() {
|
||||
if (activatedAbilityIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/activated_ability.png", Color.WHITE, new Rectangle(20, 20));
|
||||
activatedAbilityIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return activatedAbilityIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCopyInformIconImage() {
|
||||
if (imageCopyIcon == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/copy.png", Color.WHITE, new Rectangle(20, 20));
|
||||
imageCopyIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCopyIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCounterImageViolet() {
|
||||
if (imageCounterViolet == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/counter_violet.png", Color.WHITE, new Rectangle(32, 32));
|
||||
imageCounterViolet = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCounterViolet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCounterImageGreen() {
|
||||
if (imageCounterGreen == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/counter_green.png", Color.WHITE, new Rectangle(32, 32));
|
||||
imageCounterGreen = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCounterGreen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCounterImageRed() {
|
||||
if (imageCounterRed == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/counter_red.png", Color.WHITE, new Rectangle(32, 32));
|
||||
imageCounterRed = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCounterRed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getCounterImageGrey() {
|
||||
if (imageCounterGrey == null) {
|
||||
Image image = getImageFromResourceTransparent("/card/counter_grey.png", Color.WHITE, new Rectangle(32, 32));
|
||||
imageCounterGrey = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
return imageCounterGrey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgCancelButtonImage() {
|
||||
if (imageDlgCancelButton == null) {
|
||||
imageDlgCancelButton = getBufferedImageFromResource("/dlg/dlg.cancel.png");
|
||||
}
|
||||
return imageDlgCancelButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgActiveCancelButtonImage() {
|
||||
if (imageDlgActiveCancelButton == null) {
|
||||
imageDlgActiveCancelButton = getBufferedImageFromResource("/dlg/dlg.cancel.hover.png");
|
||||
}
|
||||
return imageDlgActiveCancelButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgAcceptButtonImage() {
|
||||
if (imageDlgAcceptButton == null) {
|
||||
imageDlgAcceptButton = getBufferedImageFromResource("/dlg/dlg.ok.png");
|
||||
}
|
||||
return imageDlgAcceptButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgActiveAcceptButtonImage() {
|
||||
if (imageDlgActiveAcceptButton == null) {
|
||||
imageDlgActiveAcceptButton = getBufferedImageFromResource("/dlg/dlg.ok.hover.png");
|
||||
}
|
||||
return imageDlgActiveAcceptButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgPrevButtonImage() {
|
||||
if (imageDlgPrevButton == null) {
|
||||
imageDlgPrevButton = getBufferedImageFromResource("/dlg/dlg.prev.png");
|
||||
}
|
||||
return imageDlgPrevButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgActivePrevButtonImage() {
|
||||
if (imageDlgActivePrevButton == null) {
|
||||
imageDlgActivePrevButton = getBufferedImageFromResource("/dlg/dlg.prev.hover.png");
|
||||
}
|
||||
return imageDlgActivePrevButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgNextButtonImage() {
|
||||
if (imageDlgNextButton == null) {
|
||||
imageDlgNextButton = getBufferedImageFromResource("/dlg/dlg.next.png");
|
||||
}
|
||||
return imageDlgNextButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getDlgActiveNextButtonImage() {
|
||||
if (imageDlgActiveNextButton == null) {
|
||||
imageDlgActiveNextButton = getBufferedImageFromResource("/dlg/dlg.next.hover.png");
|
||||
}
|
||||
return imageDlgActiveNextButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getConcedeButtonImage() {
|
||||
if (imageConcedeButton == null) {
|
||||
imageConcedeButton = getBufferedImageFromResource("/buttons/concede.png");
|
||||
}
|
||||
return imageConcedeButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSwitchHandsButtonImage() {
|
||||
if (imageSwitchHandsButton == null) {
|
||||
imageSwitchHandsButton = getBufferedImageFromResource("/buttons/switch_hands.png");
|
||||
}
|
||||
return imageSwitchHandsButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getStopWatchButtonImage() {
|
||||
if (imageStopWatchingButton == null) {
|
||||
imageStopWatchingButton = getBufferedImageFromResource("/buttons/stop_watching.png");
|
||||
}
|
||||
return imageStopWatchingButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getCancelSkipButtonImage() {
|
||||
if (imageCancelSkipButton == null) {
|
||||
imageCancelSkipButton = getBufferedImageFromResource("/buttons/cancel_skip.png");
|
||||
}
|
||||
return imageCancelSkipButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSkipNextTurnButtonImage() {
|
||||
if (imageSkipNextTurnButton == null) {
|
||||
imageSkipNextTurnButton = getBufferedImageFromResource("/buttons/skip_turn.png");
|
||||
}
|
||||
return imageSkipNextTurnButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSkipEndTurnButtonImage() {
|
||||
if (imageSkipToEndTurnButton == null) {
|
||||
imageSkipToEndTurnButton = getBufferedImageFromResource("/buttons/skip_to_end.png");
|
||||
}
|
||||
return imageSkipToEndTurnButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSkipMainButtonImage() {
|
||||
if (imageSkipToMainButton == null) {
|
||||
imageSkipToMainButton = getBufferedImageFromResource("/buttons/skip_to_main.png");
|
||||
}
|
||||
return imageSkipToMainButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSkipStackButtonImage() {
|
||||
if (imageSkipStackButton == null) {
|
||||
imageSkipStackButton = getBufferedImageFromResource("/buttons/skip_stack.png");
|
||||
}
|
||||
return imageSkipStackButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSkipEndStepBeforeYourTurnButtonImage() {
|
||||
if (imageSkipUntilEndStepBeforeYourTurnButton == null) {
|
||||
imageSkipUntilEndStepBeforeYourTurnButton = getBufferedImageFromResource("/buttons/skip_to_previous_end.png");
|
||||
}
|
||||
return imageSkipUntilEndStepBeforeYourTurnButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getSkipYourNextTurnButtonImage() {
|
||||
if (imageSkipYourNextTurnButton == null) {
|
||||
imageSkipYourNextTurnButton = getBufferedImageFromResource("/buttons/skip_all.png");
|
||||
}
|
||||
return imageSkipYourNextTurnButton;
|
||||
}
|
||||
|
||||
protected static Image getImageFromResourceTransparent(String path, Color mask, Rectangle rec) {
|
||||
BufferedImage image;
|
||||
Image imageCardTransparent;
|
||||
Image resized = null;
|
||||
|
||||
URL imageURL = ImageManager.class.getResource(path);
|
||||
|
||||
try {
|
||||
image = ImageIO.read(imageURL);
|
||||
imageCardTransparent = Transparency.makeColorTransparent(image, mask);
|
||||
|
||||
resized = imageCardTransparent.getScaledInstance(rec.width, rec.height, java.awt.Image.SCALE_SMOOTH);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return resized;
|
||||
}
|
||||
|
||||
protected static Image getImageFromResource(String path, Rectangle rec) {
|
||||
Image resized = null;
|
||||
|
||||
URL imageURL = ImageManager.class.getResource(path);
|
||||
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(imageURL);
|
||||
resized = image.getScaledInstance(rec.width, rec.height, java.awt.Image.SCALE_SMOOTH);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return resized;
|
||||
}
|
||||
|
||||
protected static BufferedImage getBufferedImageFromResource(String path) {
|
||||
URL imageURL = ImageManager.class.getResource(path);
|
||||
BufferedImage image = null;
|
||||
|
||||
try {
|
||||
image = ImageIO.read(imageURL);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
public static BufferedImage deepCopy(BufferedImage bi) {
|
||||
ColorModel cm = bi.getColorModel();
|
||||
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
|
||||
WritableRaster raster = bi.copyData(null);
|
||||
return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
|
||||
}
|
||||
|
||||
private static BufferedImage appImage;
|
||||
private static BufferedImage appSmallImage;
|
||||
private static BufferedImage appImageFlashed;
|
||||
|
||||
private static BufferedImage imageSickness;
|
||||
private static BufferedImage imageDay;
|
||||
private static BufferedImage imageNight;
|
||||
|
||||
private static BufferedImage imageTokenIcon;
|
||||
private static BufferedImage triggeredAbilityIcon;
|
||||
private static BufferedImage activatedAbilityIcon;
|
||||
private static BufferedImage lookedAtIcon;
|
||||
private static BufferedImage revealedIcon;
|
||||
private static BufferedImage exileIcon;
|
||||
private static BufferedImage imageCopyIcon;
|
||||
private static BufferedImage imageCounterGreen;
|
||||
private static BufferedImage imageCounterGrey;
|
||||
private static BufferedImage imageCounterRed;
|
||||
private static BufferedImage imageCounterViolet;
|
||||
|
||||
private static BufferedImage imageDlgAcceptButton;
|
||||
private static BufferedImage imageDlgActiveAcceptButton;
|
||||
private static BufferedImage imageDlgCancelButton;
|
||||
private static BufferedImage imageDlgActiveCancelButton;
|
||||
private static BufferedImage imageDlgPrevButton;
|
||||
private static BufferedImage imageDlgActivePrevButton;
|
||||
private static BufferedImage imageDlgNextButton;
|
||||
private static BufferedImage imageDlgActiveNextButton;
|
||||
|
||||
private static BufferedImage imageCancelSkipButton;
|
||||
private static BufferedImage imageSwitchHandsButton;
|
||||
private static BufferedImage imageStopWatchingButton;
|
||||
private static BufferedImage imageConcedeButton;
|
||||
private static BufferedImage imageSkipNextTurnButton;
|
||||
private static BufferedImage imageSkipToEndTurnButton;
|
||||
private static BufferedImage imageSkipToMainButton;
|
||||
private static BufferedImage imageSkipStackButton;
|
||||
private static BufferedImage imageSkipUntilEndStepBeforeYourTurnButton;
|
||||
private static BufferedImage imageSkipYourNextTurnButton;
|
||||
|
||||
private static Map<String, Image> phasesImages;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,204 +1,204 @@
|
|||
package org.mage.plugins.theme;
|
||||
|
||||
import mage.components.ImagePanel;
|
||||
import mage.interfaces.plugin.ThemePlugin;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import net.xeoh.plugins.base.annotations.PluginImplementation;
|
||||
import net.xeoh.plugins.base.annotations.events.Init;
|
||||
import net.xeoh.plugins.base.annotations.events.PluginLoaded;
|
||||
import net.xeoh.plugins.base.annotations.meta.Author;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
@PluginImplementation
|
||||
@Author(name = "nantuko")
|
||||
/* udpated by Noahsark */
|
||||
public class ThemePluginImpl implements ThemePlugin {
|
||||
|
||||
private static final Logger log = Logger.getLogger(ThemePluginImpl.class);
|
||||
private static BufferedImage background;
|
||||
private List flist = new List();
|
||||
private String BackgroundDir = "backgrounds" + File.separator;
|
||||
|
||||
@Init
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@PluginLoaded
|
||||
public void newPlugin(ThemePlugin plugin) {
|
||||
log.info(plugin.toString() + " has been loaded.");
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "[Theme plugin, version 0.5]";
|
||||
}
|
||||
|
||||
public boolean loadimages() {
|
||||
File filedir = new File(BackgroundDir);
|
||||
File[] filelist = filedir.listFiles();
|
||||
if (filelist == null) {
|
||||
return false;
|
||||
}
|
||||
if (filelist.length == 0) {
|
||||
return false;
|
||||
}
|
||||
for (File f : filelist) {
|
||||
String filename = f.getName().toLowerCase();
|
||||
if (filename != null && (filename.endsWith(".png") || filename.endsWith(".jpg")
|
||||
|| filename.endsWith(".bmp"))) {
|
||||
flist.add(filename);
|
||||
}
|
||||
}
|
||||
if (flist.getItemCount() == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyInGame(Map<String, JComponent> ui) {
|
||||
BufferedImage backgroundImage;
|
||||
try {
|
||||
if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE_DEFAULT,"true").equals("true")) {
|
||||
backgroundImage = loadbuffer_default();
|
||||
} else if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE_RANDOM,"true").equals("true")) {
|
||||
backgroundImage = loadbuffer_random();
|
||||
} else if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE, "") != null) {
|
||||
backgroundImage = loadbuffer_selected();
|
||||
} else {
|
||||
backgroundImage = loadbuffer_default();
|
||||
}
|
||||
|
||||
if (backgroundImage == null) {
|
||||
backgroundImage = loadbuffer_default();
|
||||
}
|
||||
if (backgroundImage == null) {
|
||||
throw new FileNotFoundException("Couldn't find in resources.");
|
||||
}
|
||||
|
||||
if (ui.containsKey("gamePanel") && ui.containsKey("jLayeredPane")) {
|
||||
ImagePanel bgPanel = new ImagePanel(backgroundImage, ImagePanel.TILED);
|
||||
|
||||
unsetOpaque(ui.get("jSplitPane1"));
|
||||
unsetOpaque(ui.get("pnlBattlefield"));
|
||||
unsetOpaque(ui.get("jPanel3"));
|
||||
unsetOpaque(ui.get("hand"));
|
||||
unsetOpaque(ui.get("gameChatPanel"));
|
||||
unsetOpaque(ui.get("userChatPanel"));
|
||||
|
||||
ui.get("gamePanel").remove(ui.get("jLayeredPane"));
|
||||
bgPanel.add(ui.get("jLayeredPane"));
|
||||
ui.get("gamePanel").add(bgPanel);
|
||||
} else {
|
||||
log.error("error: no components");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedImage loadbuffer_default() throws IOException {
|
||||
String filename = "/dragon.png";
|
||||
BufferedImage res;
|
||||
InputStream is = this.getClass().getResourceAsStream(filename);
|
||||
res = ImageIO.read(is);
|
||||
return res;
|
||||
}
|
||||
|
||||
private BufferedImage loadbuffer_random() throws IOException {
|
||||
BufferedImage res;
|
||||
if (loadimages()) {
|
||||
int it = (int) Math.abs(Math.random() * (flist.getItemCount()));
|
||||
String filename = BackgroundDir + flist.getItem(it);
|
||||
res = ImageIO.read(new File(filename));
|
||||
return res;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private BufferedImage loadbuffer_selected() throws IOException {
|
||||
BufferedImage res;
|
||||
String path = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE, "");
|
||||
if (path != null && !path.equals("")) {
|
||||
try {
|
||||
res = ImageIO.read(new File(path));
|
||||
return res;
|
||||
} catch (Exception e) {
|
||||
res = null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public JComponent updateTable(Map<String, JComponent> ui) {
|
||||
ImagePanel bgPanel = createImagePanelInstance();
|
||||
|
||||
unsetOpaque(ui.get("jScrollPane1"));
|
||||
unsetOpaque(ui.get("jPanel1"));
|
||||
unsetOpaque(ui.get("tablesPanel"));
|
||||
JComponent viewport = ui.get("jScrollPane1ViewPort");
|
||||
if (viewport != null) {
|
||||
viewport.setBackground(new Color(255, 255, 255, 50));
|
||||
}
|
||||
return bgPanel;
|
||||
}
|
||||
|
||||
private ImagePanel createImagePanelInstance() {
|
||||
if (background == null) {
|
||||
synchronized (ThemePluginImpl.class) {
|
||||
if (background == null) {
|
||||
String filename = "/background.png";
|
||||
try {
|
||||
if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BACKGROUND_IMAGE_DEFAULT, "true").equals("true")) {
|
||||
InputStream is = this.getClass().getResourceAsStream(filename);
|
||||
if (is == null) {
|
||||
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
||||
}
|
||||
background = ImageIO.read(is);
|
||||
} else {
|
||||
String path = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BACKGROUND_IMAGE, "");
|
||||
if (path != null && !path.equals("")) {
|
||||
try {
|
||||
File f = new File(path);
|
||||
if (f != null) {
|
||||
background = ImageIO.read(f);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
background = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (background == null) {
|
||||
InputStream is = this.getClass().getResourceAsStream(filename);
|
||||
if (is == null) {
|
||||
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
||||
}
|
||||
background = ImageIO.read(is);
|
||||
}
|
||||
if (background == null) {
|
||||
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ImagePanel(background, ImagePanel.SCALED);
|
||||
}
|
||||
|
||||
private void unsetOpaque(JComponent c) {
|
||||
if (c != null) {
|
||||
c.setOpaque(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.mage.plugins.theme;
|
||||
|
||||
import mage.components.ImagePanel;
|
||||
import mage.interfaces.plugin.ThemePlugin;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import net.xeoh.plugins.base.annotations.PluginImplementation;
|
||||
import net.xeoh.plugins.base.annotations.events.Init;
|
||||
import net.xeoh.plugins.base.annotations.events.PluginLoaded;
|
||||
import net.xeoh.plugins.base.annotations.meta.Author;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
@PluginImplementation
|
||||
@Author(name = "nantuko")
|
||||
/* udpated by Noahsark */
|
||||
public class ThemePluginImpl implements ThemePlugin {
|
||||
|
||||
private static final Logger log = Logger.getLogger(ThemePluginImpl.class);
|
||||
private static BufferedImage background;
|
||||
private List flist = new List();
|
||||
private String BackgroundDir = "backgrounds" + File.separator;
|
||||
|
||||
@Init
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@PluginLoaded
|
||||
public void newPlugin(ThemePlugin plugin) {
|
||||
log.info(plugin.toString() + " has been loaded.");
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "[Theme plugin, version 0.5]";
|
||||
}
|
||||
|
||||
public boolean loadimages() {
|
||||
File filedir = new File(BackgroundDir);
|
||||
File[] filelist = filedir.listFiles();
|
||||
if (filelist == null) {
|
||||
return false;
|
||||
}
|
||||
if (filelist.length == 0) {
|
||||
return false;
|
||||
}
|
||||
for (File f : filelist) {
|
||||
String filename = f.getName().toLowerCase();
|
||||
if (filename != null && (filename.endsWith(".png") || filename.endsWith(".jpg")
|
||||
|| filename.endsWith(".bmp"))) {
|
||||
flist.add(filename);
|
||||
}
|
||||
}
|
||||
if (flist.getItemCount() == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyInGame(Map<String, JComponent> ui) {
|
||||
BufferedImage backgroundImage;
|
||||
try {
|
||||
if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE_DEFAULT,"true").equals("true")) {
|
||||
backgroundImage = loadbuffer_default();
|
||||
} else if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE_RANDOM,"true").equals("true")) {
|
||||
backgroundImage = loadbuffer_random();
|
||||
} else if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE, "") != null) {
|
||||
backgroundImage = loadbuffer_selected();
|
||||
} else {
|
||||
backgroundImage = loadbuffer_default();
|
||||
}
|
||||
|
||||
if (backgroundImage == null) {
|
||||
backgroundImage = loadbuffer_default();
|
||||
}
|
||||
if (backgroundImage == null) {
|
||||
throw new FileNotFoundException("Couldn't find in resources.");
|
||||
}
|
||||
|
||||
if (ui.containsKey("gamePanel") && ui.containsKey("jLayeredPane")) {
|
||||
ImagePanel bgPanel = new ImagePanel(backgroundImage, ImagePanel.TILED);
|
||||
|
||||
unsetOpaque(ui.get("jSplitPane1"));
|
||||
unsetOpaque(ui.get("pnlBattlefield"));
|
||||
unsetOpaque(ui.get("jPanel3"));
|
||||
unsetOpaque(ui.get("hand"));
|
||||
unsetOpaque(ui.get("gameChatPanel"));
|
||||
unsetOpaque(ui.get("userChatPanel"));
|
||||
|
||||
ui.get("gamePanel").remove(ui.get("jLayeredPane"));
|
||||
bgPanel.add(ui.get("jLayeredPane"));
|
||||
ui.get("gamePanel").add(bgPanel);
|
||||
} else {
|
||||
log.error("error: no components");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedImage loadbuffer_default() throws IOException {
|
||||
String filename = "/dragon.png";
|
||||
BufferedImage res;
|
||||
InputStream is = this.getClass().getResourceAsStream(filename);
|
||||
res = ImageIO.read(is);
|
||||
return res;
|
||||
}
|
||||
|
||||
private BufferedImage loadbuffer_random() throws IOException {
|
||||
BufferedImage res;
|
||||
if (loadimages()) {
|
||||
int it = (int) Math.abs(Math.random() * (flist.getItemCount()));
|
||||
String filename = BackgroundDir + flist.getItem(it);
|
||||
res = ImageIO.read(new File(filename));
|
||||
return res;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private BufferedImage loadbuffer_selected() throws IOException {
|
||||
BufferedImage res;
|
||||
String path = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE, "");
|
||||
if (path != null && !path.equals("")) {
|
||||
try {
|
||||
res = ImageIO.read(new File(path));
|
||||
return res;
|
||||
} catch (Exception e) {
|
||||
res = null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public JComponent updateTable(Map<String, JComponent> ui) {
|
||||
ImagePanel bgPanel = createImagePanelInstance();
|
||||
|
||||
unsetOpaque(ui.get("jScrollPane1"));
|
||||
unsetOpaque(ui.get("jPanel1"));
|
||||
unsetOpaque(ui.get("tablesPanel"));
|
||||
JComponent viewport = ui.get("jScrollPane1ViewPort");
|
||||
if (viewport != null) {
|
||||
viewport.setBackground(new Color(255, 255, 255, 50));
|
||||
}
|
||||
return bgPanel;
|
||||
}
|
||||
|
||||
private ImagePanel createImagePanelInstance() {
|
||||
if (background == null) {
|
||||
synchronized (ThemePluginImpl.class) {
|
||||
if (background == null) {
|
||||
String filename = "/background.png";
|
||||
try {
|
||||
if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BACKGROUND_IMAGE_DEFAULT, "true").equals("true")) {
|
||||
InputStream is = this.getClass().getResourceAsStream(filename);
|
||||
if (is == null) {
|
||||
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
||||
}
|
||||
background = ImageIO.read(is);
|
||||
} else {
|
||||
String path = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BACKGROUND_IMAGE, "");
|
||||
if (path != null && !path.equals("")) {
|
||||
try {
|
||||
File f = new File(path);
|
||||
if (f != null) {
|
||||
background = ImageIO.read(f);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
background = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (background == null) {
|
||||
InputStream is = this.getClass().getResourceAsStream(filename);
|
||||
if (is == null) {
|
||||
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
||||
}
|
||||
background = ImageIO.read(is);
|
||||
}
|
||||
if (background == null) {
|
||||
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ImagePanel(background, ImagePanel.SCALED);
|
||||
}
|
||||
|
||||
private void unsetOpaque(JComponent c) {
|
||||
if (c != null) {
|
||||
c.setOpaque(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue