diff --git a/Mage.Client/src/main/java/mage/client/components/MageTextArea.java b/Mage.Client/src/main/java/mage/client/components/MageTextArea.java index 923315b7f0..c589fe32cc 100644 --- a/Mage.Client/src/main/java/mage/client/components/MageTextArea.java +++ b/Mage.Client/src/main/java/mage/client/components/MageTextArea.java @@ -30,9 +30,9 @@ public class MageTextArea extends JEditorPane { public void setText(String text, int fontSize) { if (text == null) return; - String fontFamily = "arial"; + String fontFamily = "times"; - final StringBuffer buffer = new StringBuffer(512); + final StringBuilder buffer = new StringBuilder(512); buffer.append("<html><body style='font-family:"); buffer.append(fontFamily); buffer.append(";font-size:"); diff --git a/Mage.Client/src/main/java/mage/client/components/ability/AbilityPicker.java b/Mage.Client/src/main/java/mage/client/components/ability/AbilityPicker.java index 73c20878f7..21cf371125 100644 --- a/Mage.Client/src/main/java/mage/client/components/ability/AbilityPicker.java +++ b/Mage.Client/src/main/java/mage/client/components/ability/AbilityPicker.java @@ -9,14 +9,14 @@ import org.apache.log4j.Logger; import org.jdesktop.layout.GroupLayout; import org.jdesktop.layout.LayoutStyle; import org.jdesktop.swingx.JXPanel; +import org.mage.card.arcane.ManaSymbols; +import org.mage.card.arcane.UI; import javax.swing.*; import java.awt.*; import java.awt.event.*; -import java.util.ArrayList; +import java.util.*; import java.util.List; -import java.util.Map; -import java.util.UUID; /** * Dialog for choosing abilities. @@ -226,12 +226,87 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener { action.actionPerformed(null); } + public class ImageRenderer2 extends JEditorPane implements ListCellRenderer { + + public final Map<String, String> cache = new HashMap<String, String>(); + + public Component getListCellRendererComponent( + javax.swing.JList list, + Object value, + int index, + boolean isSelected, + boolean cellHasFocus + ) { + + setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 6)); + + UI.setHTMLEditorKit(this); + + setOpaque(false); + setBackground(new Color(0,0,0,0)); + + String text = value.toString(); + + if (cache.containsKey(text)) { + text = cache.get(text); + } else { + StringBuilder buffer = getHtmlForText(isSelected, text); + String rendered = buffer.toString(); + cache.put(text, rendered); + text = rendered; + } + + final String finalText = text; + System.out.println(finalText); + + ImageRenderer2.super.setText(finalText); + setCaretPosition(0); + + return this; + } + + private StringBuilder getHtmlForText(boolean isSelected, String text) { + int fontSize = 16; + + String fontFamily = "arial"; + + final StringBuilder buffer = new StringBuilder(512); + buffer.append("<html><body style='font-family:"); + buffer.append(fontFamily); + buffer.append(";font-size:"); + buffer.append(fontSize); + buffer.append("pt;margin:3px 3px 3px 3px;"); + if (isSelected) { + buffer.append("color: #4093D0'>"); + } else { + buffer.append("color: #FFFFFF'>"); + } + buffer.append("<b>"); + + text = text.replaceAll("#([^#]+)#", "<i>$1</i>"); + text = text.replaceAll("\\s*//\\s*", "<hr width='50%'>"); + text = text.replace("\r\n", "<div style='font-size:5pt'></div>"); + //text += "<br>"; + + if (text.length() > 0) { + buffer.append(ManaSymbols.replaceSymbolsWithHTML(text, ManaSymbols.Type.PAY)); + } + + buffer.append("</b></body></html>"); + return buffer; + } + + + } + + class ImageRenderer extends DefaultListCellRenderer { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); JLabel label = ((JLabel) c); + label.setOpaque(false); label.setForeground(Color.white); @@ -316,8 +391,8 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener { List<Object> objectList = new ArrayList<Object>(); objectList.add("T: add {R} to your mana pool. 111111111111111111111111111"); - objectList.add("T: add {B} to your mana pool"); - objectList.add("T: add {B} to your mana pool"); + objectList.add("T: add {B} to your mana pool. {source} deals 1 damage to you."); + objectList.add("{T}: add {B} to your mana pool"); objectList.add("T: add {B} to your mana pool"); objectList.add("T: add {B} to your mana pool"); objectList.add("T: add {B} to your mana pool"); diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java b/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java index 99f6a8565a..b5c6f8210c 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java @@ -1,9 +1,13 @@ package org.mage.card.arcane; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Image; -import java.awt.Rectangle; +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 javax.imageio.ImageIO; +import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.util.HashMap; @@ -11,12 +15,6 @@ import java.util.List; import java.util.Map; import java.util.StringTokenizer; 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; public class ManaSymbols { @@ -171,16 +169,23 @@ public class ManaSymbols { } static public synchronized String replaceSymbolsWithHTML(String value, Type type) { - if (type.equals(Type.TOOLTIP)) { - return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/small/$1$2.jpg' alt='$1$2' width=11 height=11>"); - } else if (type.equals(Type.CARD)) { - 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=12 height=12>"); - } else if (type.equals(Type.PAY)) { - 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=15 height=15>"); + value = value.replace("{source}", "|source|"); + value = value.replace("{this}", "|this|"); + String replaced = value; + if (!manaImages.isEmpty()) { + if (type.equals(Type.TOOLTIP)) { + replaced = replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/small/$1$2.jpg' alt='$1$2' width=11 height=11>"); + } else if (type.equals(Type.CARD)) { + value = value.replace("{slash}", "<img src='file:plugins/images/symbols/medium/slash.jpg' alt='slash' width=10 height=13>"); + replaced = replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/medium/$1$2.jpg' alt='$1$2' width=12 height=12>"); + } else if (type.equals(Type.PAY)) { + value = value.replace("{slash}", "<img src='file:plugins/images/symbols/medium/slash.jpg' alt='slash' width=10 height=13>"); + replaced = replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/medium/$1$2.jpg' alt='$1$2' width=15 height=15>"); + } } - return value; + replaced = replaced.replace("|source|", "{source}"); + replaced = replaced.replace("|this|", "{this}"); + return replaced; } static public String replaceSetCodeWithHTML(String set, String rarity) {