mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
Removed a couple of duplicate files.
This commit is contained in:
parent
8ec8be115c
commit
e8426e6e71
13 changed files with 171 additions and 618 deletions
|
@ -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.*;
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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.
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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,40 +11,36 @@ 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>();
|
|
||||||
|
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> manaImagesOriginal = new HashMap<String, Image>();
|
||||||
|
static private final Map<String, Image> setImages = new HashMap<String, Image>();
|
||||||
static private final Map<String, Dimension> setImagesExist = new HashMap<String, Dimension>();
|
static private final Map<String, Dimension> setImagesExist = new HashMap<String, Dimension>();
|
||||||
static private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
|
static private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
|
||||||
|
|
||||||
private static final String[] sets = {
|
|
||||||
"10E", "M10", "M11", "M12",
|
|
||||||
"HOP", "DDF",
|
|
||||||
"TMP", "INV", "PLS", "APC",
|
|
||||||
"MRD", "DST", "5DN", "CHK", "RAV", "GPT", "DIS",
|
|
||||||
"LRW", "MOR", "SHM", "EVE", "ALA", "CFX", "ARB",
|
|
||||||
"ZEN", "WWK", "ROE", "SOM", "MBS", "NPH"
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static public void loadImages() {
|
static public void loadImages() {
|
||||||
String[] symbols = new String[]{"0", "1", "10", "11", "12", "15", "16", "2", "3", "4", "5", "6", "7", "8", "9",
|
String[] symbols = new String[]{"0", "1", "10", "11", "12", "15", "16", "2", "3", "4", "5", "6", "7", "8", "9", "B", "BG",
|
||||||
"B", "BG", "BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", "U", "UB", "UR", "W", "WB", "WU",
|
"BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", "U", "UB", "UR", "W", "WB", "WU",
|
||||||
"WP", "UP", "BP", "RP", "GP", "X", "Y", "Z", "slash"};
|
"WP", "UP", "BP", "RP", "GP", "X" /*, "Y", "Z", "slash"*/};
|
||||||
for (String symbol : symbols) {
|
for (String symbol : symbols) {
|
||||||
File file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg");
|
File file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg");
|
||||||
Rectangle r = new Rectangle(11, 11);
|
Rectangle r = new Rectangle(11, 11);
|
||||||
try {
|
try {
|
||||||
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
|
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
|
||||||
BufferedImage resized = ImageCache.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
|
BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
|
||||||
manaImages.put(symbol, resized);
|
manaImages.put(symbol, resized);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
log.error("Error for symbol:" + symbol);
|
||||||
|
//e.printStackTrace();
|
||||||
}
|
}
|
||||||
file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg");
|
file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg");
|
||||||
try {
|
try {
|
||||||
|
@ -50,18 +49,58 @@ public class ManaSymbols {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File file;
|
for (String set : CardsStorage.getSetCodes()) {
|
||||||
for (String set : sets) {
|
String _set = set.equals("CON") ? "CFX" : set;
|
||||||
file = new File(Constants.RESOURCE_PATH_SET_SMALL);
|
File file = new File(Constants.RESOURCE_PATH_SET + _set + "-C.jpg");
|
||||||
if (!file.exists()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
file = new File(Constants.RESOURCE_PATH_SET_SMALL + set + "-C.png");
|
|
||||||
try {
|
try {
|
||||||
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
|
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 width = image.getWidth(null);
|
||||||
int height = image.getHeight(null);
|
int height = image.getHeight(null);
|
||||||
setImagesExist.put(set, new Dimension(width, height));
|
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) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +111,9 @@ public class ManaSymbols {
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void draw(Graphics g, String manaCost, int x, int y) {
|
static public void draw(Graphics g, String manaCost, int x, int y) {
|
||||||
if (manaCost.length() == 0) return;
|
if (manaCost.length() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
manaCost = manaCost.replace("\\", "");
|
manaCost = manaCost.replace("\\", "");
|
||||||
manaCost = UI.getDisplayManaCost(manaCost);
|
manaCost = UI.getDisplayManaCost(manaCost);
|
||||||
StringTokenizer tok = new StringTokenizer(manaCost, " ");
|
StringTokenizer tok = new StringTokenizer(manaCost, " ");
|
||||||
|
@ -108,9 +149,9 @@ public class ManaSymbols {
|
||||||
}
|
}
|
||||||
|
|
||||||
static public synchronized String replaceSymbolsWithHTML(String value, boolean small) {
|
static public synchronized String replaceSymbolsWithHTML(String value, boolean small) {
|
||||||
if (small)
|
if (small) {
|
||||||
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/small/$1$2.jpg' alt='$1$2' width=11 height=11>");
|
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/small/$1$2.jpg' alt='$1$2' width=11 height=11>");
|
||||||
else {
|
} else {
|
||||||
value = value.replace("{slash}", "<img src='file:plugins/images/symbols/medium/slash.jpg' alt='slash' width=10 height=13>");
|
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=13 height=13>");
|
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/medium/$1$2.jpg' alt='$1$2' width=13 height=13>");
|
||||||
}
|
}
|
||||||
|
@ -129,4 +170,12 @@ public class ManaSymbols {
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public Image getSetSymbolImage(String set) {
|
||||||
|
return setImages.get(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public BufferedImage getManaSymbolImageSmall(String symbol) {
|
||||||
|
return manaImages.get(symbol);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue