diff --git a/.gitattributes b/.gitattributes index a9fff40ab5a..08b8629f007 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/src/main/java/forge/ImageCache.java b/src/main/java/forge/ImageCache.java index 26101b3e824..3afc749601b 100644 --- a/src/main/java/forge/ImageCache.java +++ b/src/main/java/forge/ImageCache.java @@ -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 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. @@ -120,16 +134,16 @@ 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 (original == emptyImage) { // the found image is a placeholder for missing picture? return null; } - + double scale = Math.min( -1 == width ? 1 : (double)width / original.getWidth(), -1 == height? 1 : (double)height / original.getHeight()); diff --git a/src/main/resources/no_card.jpg b/src/main/resources/no_card.jpg new file mode 100644 index 00000000000..6e2ca0b5a03 Binary files /dev/null and b/src/main/resources/no_card.jpg differ