mirror of
https://github.com/correl/mage.git
synced 2024-11-14 19:19:32 +00:00
Advanced card image loading: thumbnails (slow on first run). Updated mage-card-plugin. Disabled foil cards.
This commit is contained in:
parent
539cf2552f
commit
6e3a7ede39
6 changed files with 52 additions and 9 deletions
Binary file not shown.
|
@ -126,7 +126,7 @@ public class BigCard extends JComponent {
|
|||
@Override
|
||||
public void paintComponent(Graphics graphics) {
|
||||
|
||||
if (foilState) {
|
||||
/*if (foilState) {
|
||||
if (source != null) {
|
||||
synchronized (BigCard.class) {
|
||||
if (source != null) {
|
||||
|
@ -138,6 +138,9 @@ public class BigCard extends JComponent {
|
|||
if (bigImage != null) {
|
||||
graphics.drawImage(bigImage, 0, 0, this);
|
||||
}
|
||||
}*/
|
||||
if (bigImage != null) {
|
||||
graphics.drawImage(bigImage, 0, 0, this);
|
||||
}
|
||||
super.paintComponent(graphics);
|
||||
}
|
||||
|
@ -154,7 +157,7 @@ public class BigCard extends JComponent {
|
|||
}
|
||||
|
||||
public void setFoil(boolean foil) {
|
||||
if (foilThread == null) {
|
||||
/*if (foilThread == null) {
|
||||
synchronized (this) {
|
||||
if (foilThread == null) {
|
||||
foilThread = getFoilThread();
|
||||
|
@ -171,7 +174,8 @@ public class BigCard extends JComponent {
|
|||
}
|
||||
}
|
||||
}
|
||||
repaint();
|
||||
*/
|
||||
repaint();
|
||||
}
|
||||
|
||||
private Thread getFoilThread() {
|
||||
|
|
|
@ -90,6 +90,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
|
|||
i.remove();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
drawCards(sortBy, piles);
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
@ -189,10 +190,12 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
|
|||
if (comp instanceof Card) {
|
||||
if (((Card)comp).getCardId().equals(cardId)) {
|
||||
remove(comp);
|
||||
comp = null;
|
||||
}
|
||||
} else if (comp instanceof MageCard) {
|
||||
if (((MageCard)comp).getOriginal().getId().equals(cardId)) {
|
||||
remove(comp);
|
||||
comp = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,8 +149,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
|||
public void run() {
|
||||
try {
|
||||
tappedAngle = isTapped() ? CardPanel.TAPPED_ANGLE : 0;
|
||||
BufferedImage srcImage = ImageCache.getImageOriginal(gameCard);
|
||||
srcImage = ImageCache.getNormalSizeImage(srcImage);
|
||||
BufferedImage srcImage = ImageCache.getThumbnail(gameCard);
|
||||
if (srcImage != null) {
|
||||
hasImage = true;
|
||||
setText(gameCard);
|
||||
|
@ -199,12 +198,12 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
|||
public void setFoil(boolean foil) {
|
||||
this.isFoil = foil;
|
||||
if (foil) {
|
||||
BufferedImage source = BufferedImageBuilder.bufferImage(imagePanel.getSrcImage());
|
||||
/*BufferedImage source = BufferedImageBuilder.bufferImage(imagePanel.getSrcImage());
|
||||
HueFilter filter = FilterFactory.getHueFilter();
|
||||
filter.setHue(0.1f);
|
||||
BufferedImage dest = filter.filter(source, null);
|
||||
imagePanel.setImage(dest);
|
||||
imagePanel.repaint();
|
||||
imagePanel.repaint();*/
|
||||
|
||||
/*
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
|
|
|
@ -11,6 +11,7 @@ public class Constants {
|
|||
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 {
|
||||
public static final String imageBaseDir = "plugins" + File.separator + "images" + File.separator;
|
||||
|
|
|
@ -52,6 +52,11 @@ public class ImageCache {
|
|||
imageCache = new MapMaker().softValues().makeComputingMap(new Function<String, BufferedImage>() {
|
||||
public BufferedImage apply(String key) {
|
||||
try {
|
||||
boolean thumbnail = false;
|
||||
if (key.endsWith("#thumb")) {
|
||||
thumbnail = true;
|
||||
key = key.replace("#thumb", "");
|
||||
}
|
||||
Matcher m = KEY_PATTERN.matcher(key);
|
||||
|
||||
if (m.matches()) {
|
||||
|
@ -66,8 +71,21 @@ public class ImageCache {
|
|||
if (path == null) return null;
|
||||
File file = new File(path);
|
||||
|
||||
BufferedImage image = loadImage(file);
|
||||
return image;
|
||||
if (thumbnail && path.endsWith(".jpg")) {
|
||||
String thumbnailPath = path.replace(".jpg", ".thumb.jpg");
|
||||
File thumbnailFile = new File(thumbnailPath);
|
||||
if (thumbnailFile.exists()) {
|
||||
log.info("loading thumbnail for " + key + ", path="+thumbnailPath);
|
||||
return loadImage(thumbnailFile);
|
||||
} else {
|
||||
BufferedImage image = loadImage(file);
|
||||
if (image == null) return null;
|
||||
log.info("creating thumbnail for " + key);
|
||||
return makeThumbnail(image, thumbnailPath);
|
||||
}
|
||||
} else {
|
||||
return loadImage(file);
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException(
|
||||
"Requested image doesn't fit the requirement for key (<cardname>#<setname>#<collectorID>): " + key);
|
||||
|
@ -82,6 +100,12 @@ public class ImageCache {
|
|||
});
|
||||
}
|
||||
|
||||
public static BufferedImage getThumbnail(CardView card) {
|
||||
String key = getKey(card) + "#thumb";
|
||||
//log.debug("#key: " + key);
|
||||
return getImage(key);
|
||||
}
|
||||
|
||||
public static BufferedImage getImageOriginal(CardView card) {
|
||||
String key = getKey(card);
|
||||
//log.debug("#key: " + key);
|
||||
|
@ -139,6 +163,18 @@ public class ImageCache {
|
|||
|
||||
return image;
|
||||
}
|
||||
|
||||
public static BufferedImage makeThumbnail(BufferedImage original, String path) {
|
||||
BufferedImage image = getResizedImage(original, Constants.THUMBNAIL_SIZE_FULL);
|
||||
File imagePath = new File(path);
|
||||
try {
|
||||
log.info("thumbnail path:"+path);
|
||||
ImageIO.write(image, "jpg", imagePath);
|
||||
} catch (Exception e) {
|
||||
log.error(e,e);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image scaled to the size given
|
||||
|
|
Loading…
Reference in a new issue