New tooltips (support delayed displaying, mana and tap symbols, styled text).

This commit is contained in:
magenoxx 2010-12-15 07:14:35 +03:00
parent 1a945de4de
commit 94d883b5ba
7 changed files with 95 additions and 38 deletions

View file

@ -43,11 +43,14 @@ import mage.client.util.Event;
import mage.client.util.Listener;
import mage.components.CardInfoPane;
import mage.game.GameException;
import mage.view.CardView;
import mage.view.CardsView;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
@ -98,7 +101,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
cardSelector.getCardsList().removeCard(card.getId());
}
if (cardInfoPane instanceof CardInfoPane) {
((CardInfoPane)cardInfoPane).setCard(card);
((CardInfoPane)cardInfoPane).setCard(new CardView(card));
}
break;
}
@ -178,7 +181,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
cardInfoPane = Plugins.getInstance().getCardInfoPane();
if (cardInfoPane != null && System.getProperty("testCardInfo") != null) {
cardInfoPane.setPreferredSize(new Dimension(170,230));
cardInfoPane.setPreferredSize(new Dimension(170,150));
cardInfoPane.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
isShowCardInfo = true;
} else {
@ -456,4 +459,6 @@ class ImportFilter extends FileFilter {
public String getDescription() {
return "*.dec | *.mwDeck | *.txt";
}
}

View file

@ -1,16 +1,13 @@
package mage.client.plugins.adapters;
import java.awt.Color;
import java.awt.Image;
import java.awt.Point;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.util.List;
import java.util.UUID;
import javax.swing.Popup;
import javax.swing.PopupFactory;
import javax.swing.SwingUtilities;
import javax.swing.*;
import mage.cards.MageCard;
import mage.cards.MagePermanent;
@ -25,6 +22,8 @@ import mage.client.util.DefaultActionCallback;
import mage.client.util.ImageHelper;
import mage.client.util.gui.ArrowBuilder;
import mage.client.util.gui.GuiDisplayUtil;
import mage.components.CardInfoPane;
import mage.utils.ThreadUtils;
import mage.view.CardView;
import org.jdesktop.swingx.JXPanel;
@ -32,12 +31,14 @@ import org.jdesktop.swingx.JXPanel;
public class MageActionCallback implements ActionCallback {
private Popup popup;
private JPopupMenu jPopupMenu;
private BigCard bigCard;
protected static DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance();
protected static Session session = MageFrame.getSession();
private CardView popupCard;
private Thread t;
private int state = 0;
private JComponent cardInfoPane;
public MageActionCallback() {
}
@ -50,6 +51,9 @@ public class MageActionCallback implements ActionCallback {
if (session == null) {
session = MageFrame.getSession();
}
if (cardInfoPane == null) {
cardInfoPane = Plugins.getInstance().getCardInfoPane();
}
}
@Override
@ -126,6 +130,7 @@ public class MageActionCallback implements ActionCallback {
ie.printStackTrace();
}*/
if (cardInfoPane == null) {
PopupFactory factory = PopupFactory.getSharedInstance();
popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
popup.show();
@ -133,6 +138,34 @@ public class MageActionCallback implements ActionCallback {
popup.hide();
popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
popup.show();
} else {
ThreadUtils.threadPool2.submit(new Runnable() {
@Override
public void run() {
ThreadUtils.threadPool2.submit(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(900);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
if (!popupCard.equals(data.card)) {
return;
}
PopupFactory factory = PopupFactory.getSharedInstance();
((CardInfoPane)cardInfoPane).setCard(data.card);
cardInfoPane.setSize(161, 221);
cardInfoPane.setPreferredSize(new Dimension(161, 221));
popup = factory.getPopup(data.component, cardInfoPane, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
popup.show();
}
});
}
});
}
}
@Override
@ -172,6 +205,9 @@ public class MageActionCallback implements ActionCallback {
if (popup != null) {
popup.hide();
}
if (jPopupMenu != null) {
jPopupMenu.setVisible(false);
}
ArrowBuilder.removeAllArrows();
}

View file

@ -1,6 +1,7 @@
package mage.components;
import mage.cards.Card;
import mage.view.CardView;
/**
* Card info pane for displaying card rules.
@ -9,6 +10,6 @@ import mage.cards.Card;
* @author nantuko
*/
public interface CardInfoPane {
public void setCard (final Card card);
public boolean isCurrentCard (Card card);
public void setCard (final CardView card);
public boolean isCurrentCard (CardView card);
}

View file

@ -1,4 +1,4 @@
package org.mage.card.arcane;
package mage.utils;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
@ -13,6 +13,7 @@ import java.util.concurrent.TimeUnit;
public class ThreadUtils {
static public ThreadPoolExecutor threadPool;
static public ThreadPoolExecutor threadPool2;
static private int threadCount;
static {
threadPool = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new ThreadFactory() {
@ -24,6 +25,15 @@ public class ThreadUtils {
}
});
threadPool.prestartAllCoreThreads();
threadPool2 = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new ThreadFactory() {
public Thread newThread (Runnable runnable) {
threadCount++;
Thread thread = new Thread(runnable, "TP2" + threadCount);
thread.setDaemon(true);
return thread;
}
});
threadPool2.prestartAllCoreThreads();
}
static public void sleep (int millis) {

View file

@ -84,10 +84,10 @@ public class ManaSymbols {
static public synchronized String replaceSymbolsWithHTML (String value, boolean small) {
if (small)
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/small/$1$2.jpg' 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 {
value = value.replace("{slash}", "<img src='file:plugins/images/symbols/medium/slash.jpg' width=10 height=13>");
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/medium/$1$2.jpg' width=13 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>");
}
}
}

View file

@ -1,11 +1,11 @@
package org.mage.plugins.card.info;
import mage.Constants;
import mage.cards.Card;
import mage.components.CardInfoPane;
import mage.utils.CardUtil;
import mage.utils.ThreadUtils;
import mage.view.CardView;
import org.mage.card.arcane.ManaSymbols;
import org.mage.card.arcane.ThreadUtils;
import org.mage.card.arcane.UI;
import javax.swing.*;
@ -20,15 +20,16 @@ import java.util.List;
*/
public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
private Card currentCard;
private CardView currentCard;
public CardInfoPaneImpl() {
UI.setHTMLEditorKit(this);
setEditable(false);
setBackground(Color.white);
setSize(170, Integer.MAX_VALUE);
}
public void setCard (final Card card) {
public void setCard (final CardView card) {
if (card == null) return;
if (isCurrentCard(card)) return;
currentCard = card;
@ -37,7 +38,11 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
public void run () {
if (!card.equals(currentCard)) return;
String castingCost = UI.getDisplayManaCost(card.getManaCost().getText());
String manaCost = "";
for (String m : card.getManaCost()) {
manaCost += m;
}
String castingCost = UI.getDisplayManaCost(manaCost);
castingCost = ManaSymbols.replaceSymbolsWithHTML(castingCost, false);
int symbolCount = 0;
@ -111,13 +116,13 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
}
String pt = "";
if (card.getCardType().contains(Constants.CardType.CREATURE)) {
if (CardUtil.isCreature(card)) {
pt = card.getPower() + "/" + card.getToughness();
} else if (card.getCardType().contains(Constants.CardType.PLANESWALKER)) {
} else if (CardUtil.isPlaneswalker(card)) {
pt = card.getLoyalty().toString();
}
if (pt.length() > 0) {
buffer.append("<table cellspacing=0 cellpadding=0 border=0 width='100%'><tr><td>");
buffer.append("<table cellspacing=0 cellpadding=0 border=0 width='100%' valign='bottom'><tr><td>");
buffer.append("</td><td align='right'>");
buffer.append("<b>");
buffer.append(pt);
@ -131,7 +136,7 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
public void run () {
if (!card.equals(currentCard)) return;
setText(buffer.toString());
System.out.println(buffer.toString());
//System.out.println(buffer.toString());
setCaretPosition(0);
}
});
@ -139,24 +144,24 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
});
}
private String getTypes(Card card) {
private String getTypes(CardView card) {
String types = "";
for (String superType : card.getSupertype()) {
for (String superType : card.getSuperTypes()) {
types += superType + " ";
}
for (Constants.CardType cardType : card.getCardType()) {
for (Constants.CardType cardType : card.getCardTypes()) {
types += cardType.toString() + " ";
}
if (card.getSubtype().size() > 0) {
if (card.getSubTypes().size() > 0) {
types += "- ";
}
for (String subType : card.getSubtype()) {
for (String subType : card.getSubTypes()) {
types += subType + " ";
}
return types.trim();
}
public boolean isCurrentCard (Card card) {
public boolean isCurrentCard (CardView card) {
return currentCard != null && card.equals(currentCard);
}
}