mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
a default picture will be embedded into jar file to be used when a card image is missing
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -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/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/arcane/util/package-info.java svneol=native#text/plain
|
||||||
src/main/java/forge/view/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/main/resources/proxy-template.ftl -text
|
||||||
src/site/apt/index.apt -text
|
src/site/apt/index.apt -text
|
||||||
src/test/java/forge/BoosterDraft1Test.java svneol=native#text/plain
|
src/test/java/forge/BoosterDraft1Test.java svneol=native#text/plain
|
||||||
|
|||||||
@@ -18,8 +18,11 @@
|
|||||||
package forge;
|
package forge;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -68,7 +71,18 @@ public class ImageCache {
|
|||||||
public static final String TOURNAMENTPACK_PREFIX = "o:";
|
public static final String TOURNAMENTPACK_PREFIX = "o:";
|
||||||
|
|
||||||
static private final LoadingCache<String, BufferedImage> CACHE = CacheBuilder.newBuilder().softValues().build(new ImageLoader());
|
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
|
* 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.
|
* 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);
|
boolean mayEnlarge = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_SCALE_LARGER);
|
||||||
BufferedImage original = getImage(key);
|
BufferedImage original = getImage(key);
|
||||||
|
|
||||||
if (original == defaultImage) { // the found image is a placeholder for missing picture?
|
if (null == original) {
|
||||||
return null;
|
original = defaultImage;
|
||||||
|
CACHE.put(key, defaultImage); // This instructs cache to give up finding a picture if it was not found once
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null == original) {
|
if (original == emptyImage) { // the found image is a placeholder for missing picture?
|
||||||
CACHE.put(key, defaultImage); // This instructs cache to give up finding a picture if it was not found once
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
src/main/resources/no_card.jpg
Normal file
BIN
src/main/resources/no_card.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
Reference in New Issue
Block a user