+
+
+
-
+
+
+
+
+
@@ -42,7 +49,7 @@
-
+
@@ -50,9 +57,7 @@
-
-
diff --git a/Mage.Client/src/main/java/mage/client/cards/BigCard.java b/Mage.Client/src/main/java/mage/client/cards/BigCard.java
index 5bfe612dab..267bd68f1c 100644
--- a/Mage.Client/src/main/java/mage/client/cards/BigCard.java
+++ b/Mage.Client/src/main/java/mage/client/cards/BigCard.java
@@ -8,6 +8,7 @@
package mage.client.cards;
+import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
@@ -15,9 +16,10 @@ import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.List;
import java.util.UUID;
+import javax.swing.BorderFactory;
import javax.swing.JComponent;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.StyledDocument;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
import static mage.client.constants.Constants.CONTENT_MAX_XOFFSET;
import static mage.client.constants.Constants.FRAME_MAX_HEIGHT;
import static mage.client.constants.Constants.FRAME_MAX_WIDTH;
@@ -29,6 +31,7 @@ import mage.client.util.ImageHelper;
import mage.constants.EnlargeMode;
import org.jdesktop.swingx.JXPanel;
import mage.client.util.TransformedImageCache;
+import org.mage.card.arcane.UI;
/**
* Class for displaying big image of the card
@@ -62,6 +65,9 @@ public class BigCard extends JComponent {
setOpaque(true);
this.scrollPane.setOpaque(true);
this.scrollPane.setVisible(false);
+
+ UI.setHTMLEditorKit(text);
+ text.setEditable(false);
}
private void initBounds(boolean rotated) {
@@ -69,8 +75,8 @@ public class BigCard extends JComponent {
if (rotated) {
scrollPane.setBounds(50, 50, 100, 100);
} else {
- scrollPane.setBounds(this.getWidth()*1000/17777,this.getWidth()*1000/1100,
- this.getWidth()*1000/1142,this.getWidth()*1000/2539);
+ scrollPane.setBounds(this.getWidth()*1000/17777,this.getWidth()*1000/1150,
+ this.getWidth()*1000/1130,this.getWidth()*1000/2100);
}
}
@@ -95,8 +101,14 @@ public class BigCard extends JComponent {
synchronized (this) {
source = null;
hue = 0.000f;
- }
- drawText(strings);
+ }
+ StringBuilder displayedText = new StringBuilder();
+ for (String textLine: strings) {
+ if (textLine != null && !textLine.replace(".", "").trim().isEmpty()) {
+ displayedText.append("").append(textLine).append("
");
+ }
+ }
+ this.text.setText(displayedText.toString());
repaint();
}
}
@@ -109,19 +121,6 @@ public class BigCard extends JComponent {
this.cardId = null;
}
- private void drawText(java.util.List strings) {
- text.setText("");
- StyledDocument doc = text.getStyledDocument();
-
- try {
- for (String line : strings) {
- doc.insertString(doc.getLength(), line + '\n', doc.getStyle("regular"));
- }
- } catch (BadLocationException ble) {
- }
- text.setCaretPosition(0);
- }
-
@Override
public void paintComponent(Graphics graphics) {
if (bigImage != null) {
@@ -169,21 +168,19 @@ public class BigCard extends JComponent {
setFocusable(false);
setMinimumSize(new Dimension(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT));
setName("bigCardPanel"); // NOI18N
- setOpaque(false);
setPreferredSize(getMinimumSize());
setLayout(null);
+ scrollPane.setBackground(new java.awt.Color(220, 220, 220));
scrollPane.setBorder(null);
scrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
- scrollPane.setOpaque(false);
+ scrollPane.setViewportBorder(javax.swing.BorderFactory.createEtchedBorder());
- text.setEditable(false);
text.setFocusable(false);
- text.setOpaque(false);
scrollPane.setViewportView(text);
add(scrollPane);
- scrollPane.setBounds(20, 230, 210, 120);
+ scrollPane.setBounds(20, 220, 210, 130);
scrollPane.setBounds(new Rectangle(CONTENT_MAX_XOFFSET, TEXT_MAX_YOFFSET, TEXT_MAX_WIDTH, TEXT_MAX_HEIGHT));
}// //GEN-END:initComponents
diff --git a/Mage.Client/src/main/java/mage/client/cards/Card.java b/Mage.Client/src/main/java/mage/client/cards/Card.java
index f9bce9e92e..05443a4d1e 100644
--- a/Mage.Client/src/main/java/mage/client/cards/Card.java
+++ b/Mage.Client/src/main/java/mage/client/cards/Card.java
@@ -321,7 +321,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
@Override
public void mouseMoved(MouseEvent arg0) {
- this.bigCard.showTextComponent();
+ // this.bigCard.showTextComponent();
this.bigCard.setCard(card.getId(), EnlargeMode.NORMAL, image, getRules(), false);
}
diff --git a/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java b/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java
index 80fbe14523..b98fadfe5e 100644
--- a/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java
+++ b/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java
@@ -73,8 +73,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
}
trimGrid();
layoutGrid();
- cardScroll.revalidate();
- cardScroll.repaint();
+ repaintGrid();
}
}
@@ -315,8 +314,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
// Remove empty rows / cols / spaces in stacks
trimGrid();
layoutGrid();
- cardScroll.revalidate();
- cardScroll.repaint();
+ repaintGrid();
} else {
// Add new cards to grid
for (CardView card : cards) {
@@ -325,14 +323,14 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
eventSource.fireEvent(card, ClientEventType.ADD_SPECIFIC_CARD);
}
layoutGrid();
- cardContent.repaint();
+ repaintGrid();
}
}
public void changeGUISize() {
layoutGrid();
cardScroll.getVerticalScrollBar().setUnitIncrement(CardRenderer.getCardTopHeight(getCardWidth()));
- cardContent.repaint();
+ repaintGrid();
}
public void cleanUp() {
@@ -386,7 +384,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
}
trimGrid();
layoutGrid();
- cardContent.repaint();
+ repaintGrid();
}
public DeckCardLayout getCardLayout() {
@@ -562,6 +560,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
JButton selectByButton;
JButton analyseButton;
JButton blingButton;
+ JButton oldVersionButton;
// Popup for toolbar
final JPopupMenu filterPopup;
@@ -709,60 +708,6 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
// Editting mode
this.mode = Constants.DeckEditorMode.LIMITED_BUILDING;
- // Toolbar
- sortButton = new JButton("Sort");
- filterButton = new JButton("Filter");
- visibilityButton = new JButton("V"); // "Visibility" button
- selectByButton = new JButton("Select By");
- analyseButton = new JButton("M"); // "Mana" button
- blingButton = new JButton("B"); // "Bling" button
-
- // Name and count label
- deckNameAndCountLabel = new JLabel();
-
- // Count labels
- landCountLabel = new JLabel("", new ImageIcon(getClass().getResource("/buttons/type_land.png")), SwingConstants.LEFT);
- landCountLabel.setToolTipText("Number of lands in deck");
- creatureCountLabel = new JLabel("", new ImageIcon(getClass().getResource("/buttons/type_creatures.png")), SwingConstants.LEFT);
- creatureCountLabel.setToolTipText("Number of creatures in deck");
-
- JPanel toolbar = new JPanel(new BorderLayout());
- JPanel toolbarInner = new JPanel();
- toolbar.setBackground(new Color(250, 250, 250, 150));
- toolbar.setOpaque(true);
- toolbarInner.setOpaque(false);
- toolbarInner.add(deckNameAndCountLabel);
- toolbarInner.add(landCountLabel);
- toolbarInner.add(creatureCountLabel);
- toolbarInner.add(sortButton);
- toolbarInner.add(filterButton);
- toolbarInner.add(selectByButton);
- toolbarInner.add(visibilityButton);
- toolbarInner.add(analyseButton);
- toolbarInner.add(blingButton);
- toolbar.add(toolbarInner, BorderLayout.WEST);
- JPanel sliderPanel = new JPanel(new GridBagLayout());
- sliderPanel.setOpaque(false);
- cardSizeSlider = new JSlider(SwingConstants.HORIZONTAL, 0, 100, 50);
- cardSizeSlider.setOpaque(false);
- cardSizeSlider.setPreferredSize(new Dimension(100, (int) cardSizeSlider.getPreferredSize().getHeight()));
- cardSizeSlider.addChangeListener(e -> {
- if (!cardSizeSlider.getValueIsAdjusting()) {
- // Fraction in [-1, 1]
- float sliderFrac = ((float) (cardSizeSlider.getValue() - 50)) / 50;
- // Convert to frac in [0.5, 2.0] exponentially
- cardSizeMod = (float) Math.pow(2, sliderFrac);
- // Update grid
- layoutGrid();
- cardContent.repaint();
- }
- });
- cardSizeSliderLabel = new JLabel("Card Size:");
- sliderPanel.add(cardSizeSliderLabel);
- sliderPanel.add(cardSizeSlider);
- toolbar.add(sliderPanel, BorderLayout.EAST);
- this.add(toolbar, BorderLayout.NORTH);
-
// Content
cardContent = new JLayeredPane();
cardContent.setLayout(null);
@@ -804,6 +749,62 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
cardScroll.getVerticalScrollBar().setUnitIncrement(CardRenderer.getCardTopHeight(getCardWidth()));
this.add(cardScroll, BorderLayout.CENTER);
+ // Toolbar
+ sortButton = new JButton("Sort");
+ filterButton = new JButton("Filter");
+ visibilityButton = new JButton("V"); // "Visibility" button
+ selectByButton = new JButton("Select By");
+ analyseButton = new JButton("M"); // "Mana" button
+ blingButton = new JButton("B"); // "Bling" button
+ oldVersionButton = new JButton("O"); // "Old version" button
+
+ // Name and count label
+ deckNameAndCountLabel = new JLabel();
+
+ // Count labels
+ landCountLabel = new JLabel("", new ImageIcon(getClass().getResource("/buttons/type_land.png")), SwingConstants.LEFT);
+ landCountLabel.setToolTipText("Number of lands in deck");
+ creatureCountLabel = new JLabel("", new ImageIcon(getClass().getResource("/buttons/type_creatures.png")), SwingConstants.LEFT);
+ creatureCountLabel.setToolTipText("Number of creatures in deck");
+
+ JPanel toolbar = new JPanel(new BorderLayout());
+ JPanel toolbarInner = new JPanel();
+ toolbar.setBackground(new Color(250, 250, 250, 150));
+ toolbar.setOpaque(true);
+ toolbarInner.setOpaque(false);
+ toolbarInner.add(deckNameAndCountLabel);
+ toolbarInner.add(landCountLabel);
+ toolbarInner.add(creatureCountLabel);
+ toolbarInner.add(sortButton);
+ toolbarInner.add(filterButton);
+ toolbarInner.add(selectByButton);
+ toolbarInner.add(visibilityButton);
+ toolbarInner.add(analyseButton);
+ toolbarInner.add(blingButton);
+ toolbarInner.add(oldVersionButton);
+ toolbar.add(toolbarInner, BorderLayout.WEST);
+ JPanel sliderPanel = new JPanel(new GridBagLayout());
+ sliderPanel.setOpaque(false);
+ cardSizeSlider = new JSlider(SwingConstants.HORIZONTAL, 0, 100, 50);
+ cardSizeSlider.setOpaque(false);
+ cardSizeSlider.setPreferredSize(new Dimension(100, (int) cardSizeSlider.getPreferredSize().getHeight()));
+ cardSizeSlider.addChangeListener(e -> {
+ if (!cardSizeSlider.getValueIsAdjusting()) {
+ // Fraction in [-1, 1]
+ float sliderFrac = ((float) (cardSizeSlider.getValue() - 50)) / 50;
+ // Convert to frac in [0.5, 2.0] exponentially
+ cardSizeMod = (float) Math.pow(2, sliderFrac);
+ // Update grid
+ layoutGrid();
+ repaintGrid();
+ }
+ });
+ cardSizeSliderLabel = new JLabel("Card size:");
+ sliderPanel.add(cardSizeSliderLabel);
+ sliderPanel.add(cardSizeSlider);
+ toolbar.add(sliderPanel, BorderLayout.EAST);
+ this.add(toolbar, BorderLayout.NORTH);
+
// Insert arrow
insertArrow = new JLabel();
insertArrow.setSize(20, 20);
@@ -982,6 +983,11 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
blingButton.addActionListener(evt -> blingDeck());
+ // Old version button - Switch cards to the oldest non-promo printing. In case of multiples in a set, take the lowest card number.
+ oldVersionButton.setToolTipText("Switch cards to the oldest non-promo printing");
+
+ oldVersionButton.addActionListener(evt -> oldVersionDeck());
+
// Filter popup
filterPopup = new JPopupMenu();
filterPopup.setPreferredSize(new Dimension(300, 300));
@@ -1222,7 +1228,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
// And finally rerender
layoutGrid();
- repaint();
+ repaintGrid();
}
public void reselectBy() {
@@ -1332,7 +1338,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
// And finally rerender
layoutGrid();
- repaint();
+ repaintGrid();
}
private static final Pattern pattern = Pattern.compile(".*Add(.*)(\\{[WUBRGXC]\\})");
@@ -1633,13 +1639,49 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
}
layoutGrid();
- cardScroll.revalidate();
- repaint();
+ repaintGrid();
JOptionPane.showMessageDialog(null, "Added " + pimpedCards.size() + " cards. You can select them and the originals by choosing 'Multiples'");
}
}
}
+ private void oldVersionDeck() {
+ if (this.mode != Constants.DeckEditorMode.FREE_BUILDING) {
+ return;
+ }
+
+ if (JOptionPane.showConfirmDialog(null, "Are you sure you want to switch your card versions to the oldest ones?", "WARNING",
+ JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
+ return;
+ }
+
+ List>> newCardGrid = new ArrayList<>();
+ for (List> gridRow : cardGrid) {
+ List> newGridRow = new ArrayList<>();
+ for (List stack : gridRow) {
+ List newStack = new ArrayList<>();
+ for (CardView card : stack) {
+ CardInfo oldestCardInfo = CardRepository.instance.findOldestNonPromoVersionCard(card.getName());
+ if (oldestCardInfo != null) {
+ CardView oldestCardView = new CardView(oldestCardInfo.getMockCard());
+ this.removeCardView(card);
+ eventSource.fireEvent(card, ClientEventType.REMOVE_SPECIFIC_CARD);
+ this.addCardView(oldestCardView, false);
+ eventSource.fireEvent(oldestCardView, ClientEventType.ADD_SPECIFIC_CARD);
+ newStack.add(oldestCardView);
+ } else {
+ newStack.add(card);
+ }
+ }
+ newGridRow.add(newStack);
+ }
+ newCardGrid.add(newGridRow);
+ }
+ cardGrid = newCardGrid;
+ layoutGrid();
+ repaintGrid();
+ }
+
// Update the contents of the card grid
public void setCards(CardsView cardsView, DeckCardLayout layout, BigCard bigCard) {
if (bigCard != null) {
@@ -1761,10 +1803,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
if (didModify) {
// Update layout
layoutGrid();
-
- // Update draw
- cardScroll.revalidate();
- repaint();
+ repaintGrid();
}
}
@@ -1904,9 +1943,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
eventSource.fireEvent(card, ClientEventType.ADD_SPECIFIC_CARD);
// Update layout
layoutGrid();
- // Update draw
- cardScroll.revalidate();
- repaint();
+ repaintGrid();
}
}
@@ -2110,6 +2147,12 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
return (int) (1.4 * getCardWidth());
}
+ private void repaintGrid() {
+ cardScroll.revalidate();
+ cardScroll.repaint();
+ repaint();
+ }
+
/**
* Position all of the card views correctly
*/
diff --git a/Mage.Client/src/main/java/mage/client/combat/CombatManager.java b/Mage.Client/src/main/java/mage/client/combat/CombatManager.java
index 6c80cbd74a..4e121976c9 100644
--- a/Mage.Client/src/main/java/mage/client/combat/CombatManager.java
+++ b/Mage.Client/src/main/java/mage/client/combat/CombatManager.java
@@ -27,6 +27,9 @@ public enum CombatManager {
private final Map combatBlockers = new HashMap<>();
private int globalBlockersCount; // we need global counter as there are several combat groups
+ private static Color ARROW_COLOR_ATTACKER = Color.red;
+ private static Color ARROW_COLOR_BLOCKED_ATTACKER = Color.gray;
+
private Point parentPoint;
@@ -79,15 +82,19 @@ public enum CombatManager {
private void drawDefender(CombatGroupView group, MagePermanent attackerCard, UUID gameId) {
UUID defenderId = group.getDefenderId();
if (defenderId != null) {
+ // if attacker was blocked then use another arrow color
+ Color attackColor = group.getBlockers().isEmpty() ? ARROW_COLOR_ATTACKER : ARROW_COLOR_BLOCKED_ATTACKER;
parentPoint = getParentPoint(attackerCard);
PlayAreaPanel p = MageFrame.getGamePlayers(gameId).get(defenderId);
if (p != null) {
+ // attack to player
Point target = p.getLocationOnScreen();
target.translate(-parentPoint.x, -parentPoint.y);
Point attackerPoint = attackerCard.getLocationOnScreen();
attackerPoint.translate(-parentPoint.x, -parentPoint.y);
- ArrowBuilder.getBuilder().addArrow(gameId, (int) attackerPoint.getX() + 45, (int) attackerPoint.getY() + 25, (int) target.getX() + 40, (int) target.getY() - 20, Color.red, ArrowBuilder.Type.COMBAT);
+ ArrowBuilder.getBuilder().addArrow(gameId, (int) attackerPoint.getX() + 45, (int) attackerPoint.getY() + 25, (int) target.getX() + 40, (int) target.getY() - 20, attackColor, ArrowBuilder.Type.COMBAT);
} else {
+ // attack to planeswalker
for (PlayAreaPanel pa : MageFrame.getGamePlayers(gameId).values()) {
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(defenderId);
if (permanent != null) {
@@ -95,7 +102,7 @@ public enum CombatManager {
target.translate(-parentPoint.x, -parentPoint.y);
Point attackerPoint = attackerCard.getLocationOnScreen();
attackerPoint.translate(-parentPoint.x, -parentPoint.y);
- ArrowBuilder.getBuilder().addArrow(gameId, (int) attackerPoint.getX() + 45, (int) attackerPoint.getY() + 25, (int) target.getX() + 40, (int) target.getY() + 10, Color.red, ArrowBuilder.Type.COMBAT);
+ ArrowBuilder.getBuilder().addArrow(gameId, (int) attackerPoint.getX() + 45, (int) attackerPoint.getY() + 25, (int) target.getX() + 40, (int) target.getY() + 10, attackColor, ArrowBuilder.Type.COMBAT);
}
}
}
diff --git a/Mage.Client/src/main/java/mage/client/components/ColorPane.java b/Mage.Client/src/main/java/mage/client/components/ColorPane.java
index 09996a47bd..0592e31e3d 100644
--- a/Mage.Client/src/main/java/mage/client/components/ColorPane.java
+++ b/Mage.Client/src/main/java/mage/client/components/ColorPane.java
@@ -6,9 +6,11 @@ import mage.client.MageFrame;
import mage.client.dialog.PreferencesDialog;
import mage.client.util.gui.GuiDisplayUtil;
import mage.components.CardInfoPane;
+import mage.game.command.Plane;
import mage.util.CardUtil;
import mage.utils.ThreadUtils;
import mage.view.CardView;
+import mage.view.PlaneView;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent.EventType;
@@ -75,17 +77,24 @@ public class ColorPane extends JEditorPane {
if (!alternativeName.isEmpty()) {
cardName = alternativeName;
}
-
- CardInfo card = CardRepository.instance.findCard(cardName);
try {
final Component container = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
if (e.getEventType() == EventType.EXITED) {
setPopupVisibility(container, false);
}
- if (e.getEventType() == EventType.ENTERED && card != null) {
+ if (e.getEventType() == EventType.ENTERED) {
CardInfoPane cardInfoPane = (CardInfoPane) MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE);
- cardInfoPane.setCard(new CardView(card.getMockCard()), container);
- setPopupVisibility(container, true);
+
+ // card
+ CardInfo card = CardRepository.instance.findCard(cardName);
+ Plane plane = Plane.createPlaneByFullName(cardName);
+ if (card != null) {
+ cardInfoPane.setCard(new CardView(card.getMockCard()), container);
+ setPopupVisibility(container, true);
+ } else if (plane != null) {
+ cardInfoPane.setCard(new CardView(new PlaneView(plane)), container);
+ setPopupVisibility(container, true);
+ }
}
} catch (InterruptedException e1) {
e1.printStackTrace();
diff --git a/Mage.Client/src/main/java/mage/client/components/KeyboundButton.java b/Mage.Client/src/main/java/mage/client/components/KeyboundButton.java
index c58ae3cad2..0054cb51d7 100644
--- a/Mage.Client/src/main/java/mage/client/components/KeyboundButton.java
+++ b/Mage.Client/src/main/java/mage/client/components/KeyboundButton.java
@@ -12,41 +12,48 @@ import mage.client.dialog.PreferencesDialog;
*/
public class KeyboundButton extends JButton {
- private final String text;
- private static final Font keyFont = new Font(Font.SANS_SERIF, Font.BOLD, 13);
+ private final String text;
+ private static final Font keyFont = new Font(Font.SANS_SERIF, Font.BOLD, 13);
- private boolean tinting = false;
+ private boolean tinting = false;
- public KeyboundButton(String key) {
- text = PreferencesDialog.getCachedKeyText(key);
- }
+ public KeyboundButton(String key, boolean drawText) {
+ if (drawText) {
+ text = PreferencesDialog.getCachedKeyText(key);
+ } else {
+ text = "";
+ }
+ }
- @Override
- protected void paintComponent(Graphics g) {
- if (ui != null && g != null) {
- Graphics sg = g.create();
- try {
- ui.update(sg, this);
- if (tinting) {
- sg.setColor(new Color(0, 0, 0, 32));
- sg.fillRoundRect(2, 2, getWidth() - 4 , getHeight() - 4, 6, 6);
- }
- sg.setColor(tinting ? Color.lightGray : Color.white);
- sg.setFont(keyFont);
+ @Override
+ protected void paintComponent(Graphics g) {
+ if (ui != null && g != null) {
+ Graphics sg = g.create();
+ try {
+ ui.update(sg, this);
- int textWidth = sg.getFontMetrics(keyFont).stringWidth(text);
- int centerX = (getWidth() - textWidth) / 2;
+ if (tinting) {
+ sg.setColor(new Color(0, 0, 0, 32));
+ sg.fillRoundRect(2, 2, getWidth() - 4 , getHeight() - 4, 6, 6);
+ }
+ sg.setColor(tinting ? Color.lightGray : Color.white);
- sg.drawString(text, centerX, 28);
- } finally {
- sg.dispose();
- }
- }
- }
+ if (!text.isEmpty()) {
+ sg.setFont(keyFont);
- public void setTint(boolean tinting) {
- this.tinting = tinting;
- repaint();
- }
+ int textWidth = sg.getFontMetrics(keyFont).stringWidth(text);
+ int centerX = (getWidth() - textWidth) / 2;
+ sg.drawString(text, centerX, 28);
+ }
+ } finally {
+ sg.dispose();
+ }
+ }
+ }
+
+ public void setTint(boolean tinting) {
+ this.tinting = tinting;
+ repaint();
+ }
}
diff --git a/Mage.Client/src/main/java/mage/client/components/LegalityLabel.java b/Mage.Client/src/main/java/mage/client/components/LegalityLabel.java
new file mode 100644
index 0000000000..9d0a70b4bb
--- /dev/null
+++ b/Mage.Client/src/main/java/mage/client/components/LegalityLabel.java
@@ -0,0 +1,205 @@
+package mage.client.components;
+
+import mage.cards.decks.Deck;
+import mage.cards.decks.DeckValidator;
+import mage.cards.decks.DeckValidatorError;
+import mage.cards.decks.importer.DeckImporter;
+import org.unbescape.html.HtmlEscape;
+import org.unbescape.html.HtmlEscapeLevel;
+import org.unbescape.html.HtmlEscapeType;
+
+import javax.swing.*;
+import java.awt.*;
+import java.io.File;
+
+/**
+ * @author Elandril
+ */
+public class LegalityLabel extends JLabel {
+
+ protected static final Color COLOR_UNKNOWN = new Color(174, 174, 174);
+ protected static final Color COLOR_LEGAL = new Color(117, 152, 110);
+ protected static final Color COLOR_PARTLY_LEGAL = new Color(191, 176, 80);
+ protected static final Color COLOR_NOT_LEGAL = new Color(191, 84, 74);
+ protected static final Color COLOR_TEXT = new Color(255, 255, 255);
+ protected static final Dimension DIM_MINIMUM = new Dimension(75, 25);
+ protected static final Dimension DIM_MAXIMUM = new Dimension(150, 75);
+ protected static final Dimension DIM_PREFERRED = new Dimension(75, 25);
+
+ protected Deck currentDeck;
+ protected String errorMessage;
+ protected DeckValidator validator;
+
+ /**
+ * Creates a LegalityLabel
instance with the specified text
+ * and the given DeckValidator.
+ *
+ * @param text The text to be displayed by the label.
+ * @param validator The DeckValidator to check against.
+ */
+ public LegalityLabel(String text, DeckValidator validator) {
+ super(text);
+ this.validator = validator;
+
+ setBackground(COLOR_UNKNOWN);
+ setForeground(COLOR_TEXT);
+ setHorizontalAlignment(SwingConstants.CENTER);
+ setMinimumSize(DIM_MINIMUM);
+ setMaximumSize(DIM_MAXIMUM);
+ setName(text); // NOI18N
+ setOpaque(true);
+ setPreferredSize(DIM_PREFERRED);
+ }
+
+ /**
+ * Creates a LegalityLabel
instance with the given DeckValidator and uses its
+ * shortName as the text.
+ *
+ * @param validator The DeckValidator to check against.
+ */
+ public LegalityLabel(DeckValidator validator) {
+ this(validator.getShortName(), validator);
+ }
+
+ /**
+ * Creates a LegalityLabel
instance with no DeckValidator or text.
+ * This is used by the Netbeans GUI Editor.
+ */
+ public LegalityLabel() {
+ super();
+
+ setBackground(COLOR_UNKNOWN);
+ setForeground(COLOR_TEXT);
+ setHorizontalAlignment(SwingConstants.CENTER);
+ setMinimumSize(DIM_MINIMUM);
+ setMaximumSize(DIM_MAXIMUM);
+ setOpaque(true);
+ setPreferredSize(DIM_PREFERRED);
+ }
+
+ /**
+ * Creates hide button to close legality panel (must be same size as label)
+ */
+ public static JButton createHideButton() {
+ JButton button = new JButton("Hide");
+ button.setHorizontalAlignment(SwingConstants.CENTER);
+ button.setMinimumSize(DIM_MINIMUM);
+ button.setMaximumSize(DIM_MAXIMUM);
+ button.setPreferredSize(DIM_PREFERRED);
+ return button;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ public DeckValidator getValidator() {
+ return validator;
+ }
+
+ public void setValidator(DeckValidator validator) {
+ this.validator = validator;
+ revalidateDeck();
+ }
+
+ protected String escapeHtml(String string) {
+ return HtmlEscape.escapeHtml(string, HtmlEscapeType.HTML4_NAMED_REFERENCES_DEFAULT_TO_HEXA, HtmlEscapeLevel.LEVEL_0_ONLY_MARKUP_SIGNIFICANT_EXCEPT_APOS);
+ }
+
+ protected String formatInvalidTooltip(java.util.List sortedErrorsList) {
+ return sortedErrorsList.stream()
+ .reduce("Deck is INVALID
The following problems have been found:
",
+ (str, error) -> String.format("%s%s | %s |
", str, escapeHtml(error.getGroup()), escapeHtml(error.getMessage())), String::concat)
+ + "
";
+ }
+
+ protected String formatPartlyValidTooltip(java.util.List sortedErrorsList) {
+ return sortedErrorsList.stream()
+ .reduce("Deck is PARTLY VALID
The following problems have been found:
",
+ (str, error) -> String.format("%s%s | %s |
", str, escapeHtml(error.getGroup()), escapeHtml(error.getMessage())), String::concat)
+ + "
";
+ }
+
+ private String appendErrorMessage(String string) {
+ if (errorMessage.isEmpty())
+ return string;
+ if (string.contains("")) {
+ return string.replaceFirst("(()?