forked from External/mage
Please test! Some changes to the display of user choices, showing also a longer text in tooltip window.
This commit is contained in:
parent
cac04616f3
commit
df3e6db569
352 changed files with 2277 additions and 2034 deletions
|
|
@ -1,12 +1,17 @@
|
|||
package mage.client.components;
|
||||
|
||||
import mage.client.util.Command;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import javax.swing.JPanel;
|
||||
import mage.client.util.Command;
|
||||
|
||||
/**
|
||||
* Image button with hover.
|
||||
|
|
@ -48,6 +53,8 @@ public class HoverButton extends JPanel implements MouseListener {
|
|||
static final Font textSetFontBold = new Font("Arial", Font.BOLD, 14);
|
||||
private boolean useMiniFont = false;
|
||||
|
||||
private boolean alignTextLeft = false;
|
||||
|
||||
public HoverButton(String text, Image image, Rectangle size) {
|
||||
this(text, image, image, null, image, size);
|
||||
if (image == null) {
|
||||
|
|
@ -113,7 +120,7 @@ public class HoverButton extends JPanel implements MouseListener {
|
|||
}
|
||||
topTextOffsetX = calculateOffsetForTop(g2d, topText);
|
||||
g2d.setColor(textBGColor);
|
||||
g2d.drawString(topText, topTextOffsetX+1, 13);
|
||||
g2d.drawString(topText, topTextOffsetX + 1, 13);
|
||||
g2d.setColor(textColor);
|
||||
g2d.drawString(topText, topTextOffsetX, 12);
|
||||
}
|
||||
|
|
@ -148,7 +155,11 @@ public class HoverButton extends JPanel implements MouseListener {
|
|||
frc = g2d.getFontRenderContext();
|
||||
textWidth = (int) textFontMini.getStringBounds(text, frc).getWidth();
|
||||
}
|
||||
textOffsetX = (imageSize.width - textWidth) / 2;
|
||||
if (alignTextLeft) {
|
||||
textOffsetX = 0;
|
||||
} else {
|
||||
textOffsetX = (imageSize.width - textWidth) / 2;
|
||||
}
|
||||
}
|
||||
return textOffsetX;
|
||||
}
|
||||
|
|
@ -277,4 +288,8 @@ public class HoverButton extends JPanel implements MouseListener {
|
|||
this.textAlwaysVisible = textAlwaysVisible;
|
||||
}
|
||||
|
||||
public void setAlignTextLeft(boolean alignTextLeft) {
|
||||
this.alignTextLeft = alignTextLeft;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,16 @@
|
|||
package mage.client.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import org.mage.card.arcane.ManaSymbols;
|
||||
import org.mage.card.arcane.UI;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
/**
|
||||
* Component for displaying text in mage.
|
||||
* Supports drawing mana symbols.
|
||||
* Component for displaying text in mage. Supports drawing mana symbols.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
|
||||
public class MageTextArea extends JEditorPane {
|
||||
|
||||
public MageTextArea() {
|
||||
|
|
@ -27,10 +24,10 @@ public class MageTextArea extends JEditorPane {
|
|||
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
setText(text, 16);
|
||||
setText(text, 0);
|
||||
}
|
||||
|
||||
public void setText(String text, int fontSize) {
|
||||
public void setText(String text, final int panelWidth) {
|
||||
if (text == null) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -38,23 +35,36 @@ public class MageTextArea extends JEditorPane {
|
|||
final StringBuilder buffer = new StringBuilder(512);
|
||||
// Dialog is a java logical font family, so it should work on all systems
|
||||
buffer.append("<html><body style='font-family:Dialog;font-size:");
|
||||
buffer.append(fontSize);
|
||||
buffer.append(16);
|
||||
buffer.append("pt;margin:3px 3px 3px 3px;color: #FFFFFF'><b><center>");
|
||||
|
||||
text = text.replaceAll("#([^#]+)#", "<i>$1</i>");
|
||||
// Don't know what it does (easy italc?) but it bugs with multiple #HTML color codes (LevelX2)
|
||||
//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>");
|
||||
|
||||
final String basicText = ManaSymbols.replaceSymbolsWithHTML(text, ManaSymbols.Type.PAY);
|
||||
if (text.length() > 0) {
|
||||
buffer.append(ManaSymbols.replaceSymbolsWithHTML(text, ManaSymbols.Type.PAY));
|
||||
buffer.append(basicText);
|
||||
}
|
||||
|
||||
buffer.append("</b></center></body></html>");
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MageTextArea.super.setText(buffer.toString());
|
||||
//System.out.println(buffer.toString());
|
||||
String promptText = buffer.toString();
|
||||
MageTextArea.super.setText(promptText);
|
||||
// in case the text don't fit in the panel a tooltip with the text is added
|
||||
if (panelWidth > 0 && MageTextArea.this.getPreferredSize().getWidth() > panelWidth) {
|
||||
// String tooltip = promptText
|
||||
// .replace("color: #FFFFFF'>", "color: #111111'><p width='400'>")
|
||||
// .replace("</body>", "</p></body>");
|
||||
String tooltip = "<html><center><body style='font-family:Dialog;font-size:14;color: #FFFFFF'><p width='500'>" + basicText + "</p></body></html>";
|
||||
MageTextArea.super.setToolTipText(tooltip);
|
||||
} else {
|
||||
MageTextArea.super.setToolTipText(null);
|
||||
}
|
||||
setCaretPosition(0);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue