Removed a couple of duplicate files.

This commit is contained in:
North 2011-09-02 00:18:04 +03:00
parent 8ec8be115c
commit e8426e6e71
13 changed files with 171 additions and 618 deletions

View file

@ -1,8 +1,8 @@
package mage.client.components; package mage.client.components;
import mage.client.components.arcane.ManaSymbols;
import mage.client.components.arcane.UI;
import mage.view.CardView; import mage.view.CardView;
import org.mage.card.arcane.ManaSymbols;
import org.mage.card.arcane.UI;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;

View file

@ -1,96 +0,0 @@
package mage.client.components.arcane;
import javax.swing.*;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.font.LineBreakMeasurer;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import java.text.BreakIterator;
import java.util.Locale;
public class GlowText extends JLabel {
private static final long serialVersionUID = 1827677946939348001L;
private int glowSize;
@SuppressWarnings("unused")
private float glowIntensity;
private Color glowColor;
private boolean wrap;
private int lineCount = 0;
public void setGlow (Color glowColor, int size, float intensity) {
this.glowColor = glowColor;
this.glowSize = size;
this.glowIntensity = intensity;
}
public void setWrap (boolean wrap) {
this.wrap = wrap;
}
public Dimension getPreferredSize () {
Dimension size = super.getPreferredSize();
size.width += glowSize;
size.height += glowSize / 2;
return size;
}
public void setText (String text) {
super.setText(text);
}
public void paint (Graphics g) {
if (getText().length() == 0) return;
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
Dimension size = getSize();
int textX = 0, textY = 0;
int wrapWidth = Math.max(0, wrap ? size.width - glowSize : Integer.MAX_VALUE);
AttributedString attributedString = new AttributedString(getText());
attributedString.addAttribute(TextAttribute.FONT, getFont());
AttributedCharacterIterator charIterator = attributedString.getIterator();
FontRenderContext fontContext = g2d.getFontRenderContext();
LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, BreakIterator.getWordInstance(Locale.ENGLISH), fontContext);
lineCount = 0;
while (measurer.getPosition() < charIterator.getEndIndex()) {
//TextLayout textLayout = measurer.nextLayout(wrapWidth);
lineCount++;
if (lineCount > 2) break;
}
charIterator.first();
// Use char wrap if word wrap would cause more than two lines of text.
if (lineCount > 2)
measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH), fontContext);
else
measurer.setPosition(0);
while (measurer.getPosition() < charIterator.getEndIndex()) {
TextLayout textLayout = measurer.nextLayout(wrapWidth);
float ascent = textLayout.getAscent();
textY += ascent; // Move down to baseline.
g2d.setColor(glowColor);
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
textLayout.draw(g2d, textX + glowSize / 2 + 1, textY + glowSize / 2 - 1);
textLayout.draw(g2d, textX + glowSize / 2 + 1, textY + glowSize / 2 + 1);
textLayout.draw(g2d, textX + glowSize / 2 - 1, textY + glowSize / 2 - 1);
textLayout.draw(g2d, textX + glowSize / 2 - 1, textY + glowSize / 2 + 1);
g2d.setColor(getForeground());
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
textLayout.draw(g2d, textX + glowSize / 2, textY + glowSize / 2);
textY += textLayout.getDescent() + textLayout.getLeading(); // Move down to top of next line.
}
}
public int getLineCount() {
return this.lineCount;
}
}

View file

@ -1,167 +0,0 @@
package mage.client.components.arcane;
import mage.client.cards.CardsStorage;
import mage.client.constants.Constants;
import mage.client.util.gui.BufferedImageBuilder;
import org.apache.log4j.Logger;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
import mage.client.util.ImageHelper;
public class ManaSymbols {
private static final Logger log = Logger.getLogger(ManaSymbols.class);
static private final Map<String, BufferedImage> manaImages = new HashMap<String, BufferedImage>();
static private final Map<String, Image> manaImagesOriginal = new HashMap<String, Image>();
static private final Map<String, Image> setImages = new HashMap<String, Image>();
static private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
static private boolean noManaSymbols = false;
static public void loadImages() {
String[] symbols = new String[]{"0", "1", "10", "11", "12", "15", "16", "2", "3", "4", "5", "6", "7", "8", "9", "B", "BG",
"BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", "U", "UB", "UR", "W", "WB", "WU",
"WP", "UP", "BP", "RP", "GP", "X" /*, "Y", "Z", "slash"*/};
for (String symbol : symbols) {
File file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg");
Rectangle r = new Rectangle(11, 11);
try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
manaImages.put(symbol, resized);
} catch (Exception e) {
log.error("Error for symbol:" + symbol);
//e.printStackTrace();
noManaSymbols = true;
}
file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg");
try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
manaImagesOriginal.put(symbol, image);
} catch (Exception e) {
}
}
for (String set : CardsStorage.getSetCodes()) {
String _set = set.equals("CON") ? "CFX" : set;
File file = new File(Constants.RESOURCE_PATH_SET + _set + "-C.jpg");
try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
int width = image.getWidth(null);
if (width > 21) {
int h = image.getHeight(null);
if (h > 0) {
Rectangle r = new Rectangle(21, (int) (h * 21.0f / width));
BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
setImages.put(set, resized);
}
} else {
setImages.put(set, image);
}
} catch (Exception e) {
}
String[] codes = new String[]{"C", "U", "R", "M"};
try {
file = new File(Constants.RESOURCE_PATH_SET_SMALL);
if (!file.exists()) {
file.mkdirs();
}
for (String code : codes) {
file = new File(Constants.RESOURCE_PATH_SET_SMALL + set + "-" + code + ".png");
if (file.exists()) {
continue;
}
file = new File(Constants.RESOURCE_PATH_SET + _set + "-" + code + ".jpg");
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
try {
int width = image.getWidth(null);
int height = image.getHeight(null);
if (height > 0) {
int dx = 0;
if (set.equals("M10") || set.equals("M11")) {
dx = 6;
}
Rectangle r = new Rectangle(15 + dx, (int) (height * (15.0f + dx) / width));
BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
File newFile = new File(Constants.RESOURCE_PATH_SET_SMALL + File.separator + _set + "-" + code + ".png");
ImageIO.write(resized, "png", newFile);
}
} catch (Exception e) {
if (file != null && file.exists()) {
file.delete();
}
}
}
} catch (Exception e) {
}
}
}
static public Image getManaSymbolImage(String symbol) {
return manaImagesOriginal.get(symbol);
}
static public BufferedImage getManaSymbolImageSmall(String symbol) {
return manaImages.get(symbol);
}
static public Image getSetSymbolImage(String set) {
return setImages.get(set);
}
static public void draw(Graphics g, String manaCost, int x, int y) {
if (manaCost.length() == 0) return;
manaCost = manaCost.replace("\\", "");
manaCost = UI.getDisplayManaCost(manaCost);
StringTokenizer tok = new StringTokenizer(manaCost, " ");
while (tok.hasMoreTokens()) {
String symbol = tok.nextToken().substring(0);
Image image = manaImages.get(symbol);
if (image == null) {
//log.error("Symbol not recognized \"" + symbol + "\" in mana cost: " + manaCost);
continue;
}
g.drawImage(image, x, y, null);
x += symbol.length() > 2 ? 10 : 12; // slash.png is only 10 pixels wide.
}
}
static public String getStringManaCost(List<String> manaCost) {
StringBuilder sb = new StringBuilder();
for (String s : manaCost) {
sb.append(s);
}
return sb.toString().replace("{", "").replace("}", " ").trim();
}
static public int getWidth(String manaCost) {
int width = 0;
manaCost = manaCost.replace("\\", "");
StringTokenizer tok = new StringTokenizer(manaCost, " ");
while (tok.hasMoreTokens()) {
String symbol = tok.nextToken().substring(0);
width += symbol.length() > 2 ? 10 : 12; // slash.png is only 10 pixels wide.
}
return width;
}
static public synchronized String replaceSymbolsWithHTML(String value, boolean small) {
if (noManaSymbols) {
return value;
} else {
if (small)
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/small/$1$2.jpg' alt='$1$2' width=11 height=11>");
else {
value = value.replace("{slash}", "<img src='file:plugins/images/symbols/medium/slash.jpg' alt='slash' width=10 height=13>");
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/medium/$1$2.jpg' alt='$1$2' width=18 height=18>");
}
}
}
}

View file

@ -1,163 +0,0 @@
package mage.client.components.arcane;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.text.Element;
import javax.swing.text.StyleConstants;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.ImageView;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.Hashtable;
/**
* UI utility functions.
*/
public class UI {
static private Hashtable<URL, Image> imageCache = new Hashtable<URL, Image>();
static public JToggleButton getToggleButton () {
JToggleButton button = new JToggleButton();
button.setMargin(new Insets(2, 4, 2, 4));
return button;
}
static public JButton getButton () {
JButton button = new JButton();
button.setMargin(new Insets(2, 4, 2, 4));
return button;
}
static public void setTitle (JPanel panel, String title) {
Border border = panel.getBorder();
if (border instanceof TitledBorder) {
((TitledBorder)panel.getBorder()).setTitle(title);
panel.repaint();
} else
panel.setBorder(BorderFactory.createTitledBorder(title));
}
@SuppressWarnings("deprecation")
static public URL getFileURL (String path) {
File file = new File(path);
if (file.exists()) {
try {
return file.toURL();
} catch (MalformedURLException ignored) {
}
}
return UI.class.getResource(path);
}
static public ImageIcon getImageIcon (String path) {
try {
InputStream stream;
stream = UI.class.getResourceAsStream(path);
if (stream == null && new File(path).exists()) stream = new FileInputStream(path);
if (stream == null) throw new RuntimeException("Image not found: " + path);
byte[] data = new byte[stream.available()];
stream.read(data);
return new ImageIcon(data);
} catch (IOException ex) {
throw new RuntimeException("Error reading image: " + path);
}
}
static public void setHTMLEditorKit (JEditorPane editorPane) {
editorPane.getDocument().putProperty("imageCache", imageCache); // Read internally by ImageView, but never written.
// Extend all this shit to cache images.
editorPane.setEditorKit(new HTMLEditorKit() {
private static final long serialVersionUID = -54602188235105448L;
public ViewFactory getViewFactory () {
return new HTMLFactory() {
public View create (Element elem) {
Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute);
if (o instanceof HTML.Tag) {
HTML.Tag kind = (HTML.Tag)o;
if (kind == HTML.Tag.IMG) return new ImageView(elem) {
public URL getImageURL () {
URL url = super.getImageURL();
// Put an image into the cache to be read by other ImageView methods.
if (url != null && imageCache.get(url) == null)
imageCache.put(url, Toolkit.getDefaultToolkit().createImage(url));
return url;
}
};
}
return super.create(elem);
}
};
}
});
}
static public void setVerticalScrollingView (JScrollPane scrollPane, final Component view) {
final JViewport viewport = new JViewport();
viewport.setLayout(new ViewportLayout() {
private static final long serialVersionUID = 7701568740313788935L;
public void layoutContainer (Container parent) {
viewport.setViewPosition(new Point(0, 0));
Dimension viewportSize = viewport.getSize();
int width = viewportSize.width;
int height = Math.max(view.getPreferredSize().height, viewportSize.height);
viewport.setViewSize(new Dimension(width, height));
}
});
viewport.setView(view);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setViewport(viewport);
}
static public String getDisplayManaCost (String manaCost) {
manaCost = manaCost.replace("/", "{slash}");
// A pipe in the cost means "process left of the pipe as the card color, but display right of the pipe as the cost".
int pipePosition = manaCost.indexOf("{|}");
if (pipePosition != -1) manaCost = manaCost.substring(pipePosition + 3);
return manaCost;
}
static public void invokeLater (Runnable runnable) {
EventQueue.invokeLater(runnable);
}
static public void invokeAndWait (Runnable runnable) {
if (EventQueue.isDispatchThread()) {
runnable.run();
return;
}
try {
EventQueue.invokeAndWait(runnable);
} catch (InterruptedException ex) {
} catch (InvocationTargetException ex) {
throw new RuntimeException(ex);
}
}
static public void setSystemLookAndFeel () {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {
System.err.println("Error setting look and feel:");
ex.printStackTrace();
}
}
static public void setDefaultFont (Font font) {
for (Object key : Collections.list(UIManager.getDefaults().keys())) {
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) UIManager.put(key, font);
}
}
}

View file

@ -34,8 +34,6 @@ import mage.cards.MageCard;
import mage.client.cards.BigCard; import mage.client.cards.BigCard;
import mage.client.cards.CardsStorage; import mage.client.cards.CardsStorage;
import mage.client.components.HoverButton; import mage.client.components.HoverButton;
import mage.client.components.arcane.GlowText;
import mage.client.components.arcane.ManaSymbols;
import mage.client.plugins.impl.Plugins; import mage.client.plugins.impl.Plugins;
import mage.client.util.AudioManager; import mage.client.util.AudioManager;
import mage.client.util.Command; import mage.client.util.Command;
@ -43,6 +41,7 @@ import mage.client.util.Config;
import mage.client.util.ImageHelper; import mage.client.util.ImageHelper;
import mage.components.ImagePanel; import mage.components.ImagePanel;
import mage.view.CardView; import mage.view.CardView;
import org.mage.card.arcane.GlowText;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
@ -52,6 +51,7 @@ import java.awt.image.BufferedImage;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.InputStream; import java.io.InputStream;
import java.util.UUID; import java.util.UUID;
import org.mage.card.arcane.ManaSymbols;
/** /**
* Mage book with cards and page flipping. * Mage book with cards and page flipping.

View file

@ -1,9 +1,9 @@
package mage.client.deckeditor.collection.viewer; package mage.client.deckeditor.collection.viewer;
import mage.client.components.arcane.ManaSymbols;
import mage.client.plugins.impl.Plugins; import mage.client.plugins.impl.Plugins;
import javax.swing.*; import javax.swing.*;
import org.mage.card.arcane.ManaSymbols;
/** /**
* @author nantuko * @author nantuko

View file

@ -45,7 +45,6 @@ import javax.swing.*;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.components.MageTextArea; import mage.client.components.MageTextArea;
import mage.client.components.arcane.GlowText;
import mage.client.dialog.MageDialog; import mage.client.dialog.MageDialog;
import mage.remote.Session; import mage.remote.Session;

View file

@ -40,7 +40,6 @@ import mage.client.MageFrame;
import mage.client.cards.BigCard; import mage.client.cards.BigCard;
import mage.client.components.HoverButton; import mage.client.components.HoverButton;
import mage.client.components.MageRoundPane; import mage.client.components.MageRoundPane;
import mage.client.components.arcane.ManaSymbols;
import mage.client.dialog.ShowCardsDialog; import mage.client.dialog.ShowCardsDialog;
import mage.client.plugins.adapters.MageActionCallback; import mage.client.plugins.adapters.MageActionCallback;
import mage.client.plugins.impl.Plugins; import mage.client.plugins.impl.Plugins;
@ -54,7 +53,7 @@ import mage.sets.Sets;
import mage.view.CardView; import mage.view.CardView;
import mage.view.ManaPoolView; import mage.view.ManaPoolView;
import mage.view.PlayerView; import mage.view.PlayerView;
import org.mage.card.arcane.CardPanel; import org.mage.card.arcane.ManaSymbols;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;

View file

@ -45,8 +45,8 @@ import java.util.List;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import mage.cards.CardDimensions; import mage.cards.CardDimensions;
import mage.client.components.arcane.UI;
import mage.view.CardView; import mage.view.CardView;
import org.mage.card.arcane.UI;
import com.mortennobel.imagescaling.ResampleOp; import com.mortennobel.imagescaling.ResampleOp;
import java.awt.Rectangle; import java.awt.Rectangle;

View file

@ -1,6 +1,7 @@
package mage.client.util.gui; package mage.client.util.gui;
import java.awt.*; import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver; import java.awt.image.ImageObserver;
@ -38,6 +39,7 @@ public class BufferedImageBuilder {
private void waitForImage(BufferedImage bufferedImage) { private void waitForImage(BufferedImage bufferedImage) {
final ImageLoadStatus imageLoadStatus = new ImageLoadStatus(); final ImageLoadStatus imageLoadStatus = new ImageLoadStatus();
bufferedImage.getHeight(new ImageObserver() { bufferedImage.getHeight(new ImageObserver() {
@Override
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
if (infoflags == ALLBITS) { if (infoflags == ALLBITS) {
imageLoadStatus.heightDone = true; imageLoadStatus.heightDone = true;
@ -47,6 +49,7 @@ public class BufferedImageBuilder {
} }
}); });
bufferedImage.getWidth(new ImageObserver() { bufferedImage.getWidth(new ImageObserver() {
@Override
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
if (infoflags == ALLBITS) { if (infoflags == ALLBITS) {
imageLoadStatus.widthDone = true; imageLoadStatus.widthDone = true;

View file

@ -1,6 +1,9 @@
package org.mage.card.arcane; package org.mage.card.arcane;
import java.awt.*; import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
@ -8,125 +11,171 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import mage.client.cards.CardsStorage;
import mage.client.util.ImageHelper;
import mage.client.util.gui.BufferedImageBuilder;
import org.apache.log4j.Logger;
import org.mage.plugins.card.constants.Constants; import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.images.ImageCache;
import org.mage.plugins.card.utils.BufferedImageBuilder;
public class ManaSymbols { public class ManaSymbols {
static private final Map<String, Image> manaImages = new HashMap<String, Image>();
static private final Map<String, Image> manaImagesOriginal = new HashMap<String, Image>();
static private final Map<String, Dimension> setImagesExist = new HashMap<String, Dimension>();
static private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
private static final String[] sets = { private static final Logger log = Logger.getLogger(ManaSymbols.class);
"10E", "M10", "M11", "M12", static private final Map<String, BufferedImage> manaImages = new HashMap<String, BufferedImage>();
"HOP", "DDF", static private final Map<String, Image> manaImagesOriginal = new HashMap<String, Image>();
"TMP", "INV", "PLS", "APC", static private final Map<String, Image> setImages = new HashMap<String, Image>();
"MRD", "DST", "5DN", "CHK", "RAV", "GPT", "DIS", static private final Map<String, Dimension> setImagesExist = new HashMap<String, Dimension>();
"LRW", "MOR", "SHM", "EVE", "ALA", "CFX", "ARB", static private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
"ZEN", "WWK", "ROE", "SOM", "MBS", "NPH"
};
static public void loadImages() {
String[] symbols = new String[]{"0", "1", "10", "11", "12", "15", "16", "2", "3", "4", "5", "6", "7", "8", "9", "B", "BG",
"BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", "U", "UB", "UR", "W", "WB", "WU",
"WP", "UP", "BP", "RP", "GP", "X" /*, "Y", "Z", "slash"*/};
for (String symbol : symbols) {
File file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg");
Rectangle r = new Rectangle(11, 11);
try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
manaImages.put(symbol, resized);
} catch (Exception e) {
log.error("Error for symbol:" + symbol);
//e.printStackTrace();
}
file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg");
try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
manaImagesOriginal.put(symbol, image);
} catch (Exception e) {
}
}
for (String set : CardsStorage.getSetCodes()) {
String _set = set.equals("CON") ? "CFX" : set;
File file = new File(Constants.RESOURCE_PATH_SET + _set + "-C.jpg");
try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
int width = image.getWidth(null);
if (width > 21) {
int h = image.getHeight(null);
if (h > 0) {
Rectangle r = new Rectangle(21, (int) (h * 21.0f / width));
BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
setImages.put(set, resized);
}
} else {
setImages.put(set, image);
}
} catch (Exception e) {
}
String[] codes = new String[]{"C", "U", "R", "M"};
try {
file = new File(Constants.RESOURCE_PATH_SET_SMALL);
if (!file.exists()) {
file.mkdirs();
}
static public void loadImages() { for (String code : codes) {
String[] symbols = new String[]{"0", "1", "10", "11", "12", "15", "16", "2", "3", "4", "5", "6", "7", "8", "9", file = new File(Constants.RESOURCE_PATH_SET_SMALL + set + "-" + code + ".png");
"B", "BG", "BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", "U", "UB", "UR", "W", "WB", "WU", if (file.exists()) {
"WP", "UP", "BP", "RP", "GP", "X", "Y", "Z", "slash"}; continue;
for (String symbol : symbols) { }
File file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg"); file = new File(Constants.RESOURCE_PATH_SET + _set + "-" + code + ".jpg");
Rectangle r = new Rectangle(11, 11); Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
try { try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage(); int width = image.getWidth(null);
BufferedImage resized = ImageCache.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r); int height = image.getHeight(null);
manaImages.put(symbol, resized); if (height > 0) {
} catch (Exception e) { int dx = 0;
} if (set.equals("M10") || set.equals("M11")) {
file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg"); dx = 6;
try { }
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage(); Rectangle r = new Rectangle(15 + dx, (int) (height * (15.0f + dx) / width));
manaImagesOriginal.put(symbol, image); BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
} catch (Exception e) { File newFile = new File(Constants.RESOURCE_PATH_SET_SMALL + File.separator + _set + "-" + code + ".png");
} ImageIO.write(resized, "png", newFile);
} }
File file; } catch (Exception e) {
for (String set : sets) { if (file != null && file.exists()) {
file = new File(Constants.RESOURCE_PATH_SET_SMALL); file.delete();
if (!file.exists()) { }
break; }
} }
file = new File(Constants.RESOURCE_PATH_SET_SMALL + set + "-C.png");
try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
int width = image.getWidth(null);
int height = image.getHeight(null);
setImagesExist.put(set, new Dimension(width, height));
} catch (Exception e) {
}
}
}
static public Image getManaSymbolImage(String symbol) { } catch (Exception e) {
return manaImagesOriginal.get(symbol); }
} }
}
static public void draw(Graphics g, String manaCost, int x, int y) { static public Image getManaSymbolImage(String symbol) {
if (manaCost.length() == 0) return; return manaImagesOriginal.get(symbol);
manaCost = manaCost.replace("\\", ""); }
manaCost = UI.getDisplayManaCost(manaCost);
StringTokenizer tok = new StringTokenizer(manaCost, " ");
while (tok.hasMoreTokens()) {
String symbol = tok.nextToken().substring(0);
Image image = manaImages.get(symbol);
if (image == null) {
//log.error("Symbol not recognized \"" + symbol + "\" in mana cost: " + manaCost);
continue;
}
g.drawImage(image, x, y, null);
x += symbol.length() > 2 ? 10 : 12; // slash.png is only 10 pixels wide.
}
}
static public String getStringManaCost(List<String> manaCost) { static public void draw(Graphics g, String manaCost, int x, int y) {
StringBuilder sb = new StringBuilder(); if (manaCost.length() == 0) {
for (String s : manaCost) { return;
sb.append(s); }
} manaCost = manaCost.replace("\\", "");
return sb.toString().replace("{", "").replace("}", " ").trim(); manaCost = UI.getDisplayManaCost(manaCost);
} StringTokenizer tok = new StringTokenizer(manaCost, " ");
while (tok.hasMoreTokens()) {
String symbol = tok.nextToken().substring(0);
Image image = manaImages.get(symbol);
if (image == null) {
//log.error("Symbol not recognized \"" + symbol + "\" in mana cost: " + manaCost);
continue;
}
g.drawImage(image, x, y, null);
x += symbol.length() > 2 ? 10 : 12; // slash.png is only 10 pixels wide.
}
}
static public int getWidth(String manaCost) { static public String getStringManaCost(List<String> manaCost) {
int width = 0; StringBuilder sb = new StringBuilder();
manaCost = manaCost.replace("\\", ""); for (String s : manaCost) {
StringTokenizer tok = new StringTokenizer(manaCost, " "); sb.append(s);
while (tok.hasMoreTokens()) { }
String symbol = tok.nextToken().substring(0); return sb.toString().replace("{", "").replace("}", " ").trim();
width += symbol.length() > 2 ? 10 : 12; // slash.png is only 10 pixels wide. }
}
return width;
}
static public synchronized String replaceSymbolsWithHTML(String value, boolean small) { static public int getWidth(String manaCost) {
if (small) int width = 0;
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/small/$1$2.jpg' alt='$1$2' width=11 height=11>"); manaCost = manaCost.replace("\\", "");
else { StringTokenizer tok = new StringTokenizer(manaCost, " ");
value = value.replace("{slash}", "<img src='file:plugins/images/symbols/medium/slash.jpg' alt='slash' width=10 height=13>"); while (tok.hasMoreTokens()) {
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/medium/$1$2.jpg' alt='$1$2' width=13 height=13>"); String symbol = tok.nextToken().substring(0);
} width += symbol.length() > 2 ? 10 : 12; // slash.png is only 10 pixels wide.
} }
return width;
}
static public String replaceSetCodeWithHTML(String set, String rarity) { static public synchronized String replaceSymbolsWithHTML(String value, boolean small) {
String _set = set; if (small) {
if (_set.equals("CON")) { return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/small/$1$2.jpg' alt='$1$2' width=11 height=11>");
_set = "CFX"; } else {
} value = value.replace("{slash}", "<img src='file:plugins/images/symbols/medium/slash.jpg' alt='slash' width=10 height=13>");
if (setImagesExist.containsKey(_set)) { return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/medium/$1$2.jpg' alt='$1$2' width=13 height=13>");
Integer width = setImagesExist.get(_set).width; }
Integer height = setImagesExist.get(_set).height; }
return "<img src='file:plugins/images/sets/small/" + _set + "-" + rarity + ".png' alt='" + rarity + " ' width=" + width + " height=" + height + ">";
} else { static public String replaceSetCodeWithHTML(String set, String rarity) {
return set; String _set = set;
} if (_set.equals("CON")) {
} _set = "CFX";
}
if (setImagesExist.containsKey(_set)) {
Integer width = setImagesExist.get(_set).width;
Integer height = setImagesExist.get(_set).height;
return "<img src='file:plugins/images/sets/small/" + _set + "-" + rarity + ".png' alt='" + rarity + " ' width=" + width + " height=" + height + ">";
} else {
return set;
}
}
static public Image getSetSymbolImage(String set) {
return setImages.get(set);
}
static public BufferedImage getManaSymbolImageSmall(String symbol) {
return manaImages.get(symbol);
}
} }

View file

@ -1,71 +0,0 @@
package org.mage.plugins.card.utils;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
/**
* Utility class for creating BufferedImage object from Image instance.
*
* @author nantuko
*/
public class BufferedImageBuilder {
private static final int DEFAULT_IMAGE_TYPE = BufferedImage.TYPE_INT_RGB;
/**
* Hide constructor
*/
private BufferedImageBuilder() {
}
public static BufferedImage bufferImage(Image image) {
return bufferImage(image, DEFAULT_IMAGE_TYPE);
}
public static BufferedImage bufferImage(Image image, int type) {
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
Graphics2D g = bufferedImage.createGraphics();
g.drawImage(image, null, null);
//waitForImage(bufferedImage);
return bufferedImage;
}
private void waitForImage(BufferedImage bufferedImage) {
final ImageLoadStatus imageLoadStatus = new ImageLoadStatus();
bufferedImage.getHeight(new ImageObserver() {
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
if (infoflags == ALLBITS) {
imageLoadStatus.heightDone = true;
return true;
}
return false;
}
});
bufferedImage.getWidth(new ImageObserver() {
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
if (infoflags == ALLBITS) {
imageLoadStatus.widthDone = true;
return true;
}
return false;
}
});
while (!imageLoadStatus.widthDone && !imageLoadStatus.heightDone) {
try {
Thread.sleep(300);
} catch (InterruptedException e) {
}
}
}
class ImageLoadStatus {
public boolean widthDone = false;
public boolean heightDone = false;
}
}

View file

@ -11,7 +11,7 @@ import java.net.URL;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.mage.plugins.card.utils.BufferedImageBuilder; import mage.client.util.gui.BufferedImageBuilder;
import org.mage.plugins.card.utils.ImageManager; import org.mage.plugins.card.utils.ImageManager;
import org.mage.plugins.card.utils.Transparency; import org.mage.plugins.card.utils.Transparency;