a default picture will be embedded into jar file to be used when a card image is missing

This commit is contained in:
Maxmtg
2013-03-20 05:38:06 +00:00
parent 10389722dc
commit 5c14793d48
3 changed files with 22 additions and 7 deletions

1
.gitattributes vendored
View File

@@ -14544,6 +14544,7 @@ src/main/java/forge/view/arcane/util/CardPanelMouseListener.java svneol=native#t
src/main/java/forge/view/arcane/util/GlowText.java svneol=native#text/plain
src/main/java/forge/view/arcane/util/package-info.java svneol=native#text/plain
src/main/java/forge/view/package-info.java svneol=native#text/plain
src/main/resources/no_card.jpg -text
src/main/resources/proxy-template.ftl -text
src/site/apt/index.apt -text
src/test/java/forge/BoosterDraft1Test.java svneol=native#text/plain

View File

@@ -18,8 +18,11 @@
package forge;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ExecutionException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import org.apache.commons.lang3.StringUtils;
@@ -68,7 +71,18 @@ public class ImageCache {
public static final String TOURNAMENTPACK_PREFIX = "o:";
static private final LoadingCache<String, BufferedImage> CACHE = CacheBuilder.newBuilder().softValues().build(new ImageLoader());
private static final BufferedImage defaultImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
private static final BufferedImage emptyImage = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
private static BufferedImage defaultImage = emptyImage;
static {
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream isNoCardJpg = cl.getResourceAsStream("no_card.jpg");
defaultImage = ImageIO.read(isNoCardJpg);
} catch (IOException e) {
// TODO Auto-generated catch block ignores the exception, but sends it to System.err and probably forge.log.
e.printStackTrace();
}
}
/**
* retrieve an image from the cache. returns null if the image is not found in the cache
* and cannot be loaded from disk. pass -1 for width and/or height to avoid resizing in that dimension.
@@ -121,12 +135,12 @@ public class ImageCache {
boolean mayEnlarge = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_SCALE_LARGER);
BufferedImage original = getImage(key);
if (original == defaultImage) { // the found image is a placeholder for missing picture?
return null;
if (null == original) {
original = defaultImage;
CACHE.put(key, defaultImage); // This instructs cache to give up finding a picture if it was not found once
}
if (null == original) {
CACHE.put(key, defaultImage); // This instructs cache to give up finding a picture if it was not found once
if (original == emptyImage) { // the found image is a placeholder for missing picture?
return null;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB