mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Fixed Issue#45: Textbox for tooltip is sometimes too small to show all the text
This commit is contained in:
parent
c203705535
commit
78e1bb99d9
6 changed files with 56 additions and 22 deletions
|
|
@ -44,7 +44,10 @@ import mage.cards.repository.CardRepository;
|
|||
import mage.cards.repository.CardScanner;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.chat.ChatPanel;
|
||||
import mage.client.components.*;
|
||||
import mage.client.components.MageComponents;
|
||||
import mage.client.components.MageJDesktop;
|
||||
import mage.client.components.MageRoundPane;
|
||||
import mage.client.components.MageUI;
|
||||
import mage.client.components.ext.dlg.DialogManager;
|
||||
import mage.client.components.tray.MageTray;
|
||||
import mage.client.constants.Constants.DeckEditorMode;
|
||||
|
|
@ -76,6 +79,7 @@ import mage.server.Main;
|
|||
import mage.utils.MageVersion;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.card.arcane.ManaSymbols;
|
||||
import org.mage.plugins.card.constants.Constants;
|
||||
import org.mage.plugins.card.images.DownloadPictures;
|
||||
import org.mage.plugins.card.utils.impl.ImageManagerImpl;
|
||||
|
||||
|
|
@ -84,23 +88,14 @@ import javax.swing.*;
|
|||
import javax.swing.JToolBar.Separator;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.SplashScreen;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -342,7 +337,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
if (cardInfoPane == null) {
|
||||
return;
|
||||
}
|
||||
cardInfoPane.setSize(320, 201);
|
||||
cardInfoPane.setSize(Constants.TOOLTIP_WIDTH_MIN, Constants.TOOLTIP_HEIGHT_MIN);
|
||||
cardInfoPane.setLocation(40, 40);
|
||||
cardInfoPane.setBackground(new Color(0, 0, 0, 0));
|
||||
|
||||
|
|
@ -351,7 +346,9 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
|
||||
popupContainer.add(cardInfoPane);
|
||||
popupContainer.setVisible(false);
|
||||
popupContainer.setBounds(0, 0, 320 + 80, 201 + 80);
|
||||
popupContainer.setBounds(0, 0,
|
||||
Constants.TOOLTIP_WIDTH_MIN + Constants.TOOLTIP_BORDER_WIDTH,
|
||||
Constants.TOOLTIP_HEIGHT_MIN + Constants.TOOLTIP_BORDER_WIDTH);
|
||||
|
||||
desktopPane.add(popupContainer, JLayeredPane.POPUP_LAYER);
|
||||
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
cardSelector.refresh();
|
||||
}
|
||||
if (cardInfoPane instanceof CardInfoPane) {
|
||||
((CardInfoPane)cardInfoPane).setCard(new CardView(card));
|
||||
((CardInfoPane)cardInfoPane).setCard(new CardView(card), null);
|
||||
}
|
||||
hidePopup();
|
||||
}
|
||||
|
|
@ -206,7 +206,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
deck.getSideboard().add(CardImpl.createCard(card.getClass()));
|
||||
}
|
||||
if (cardInfoPane instanceof CardInfoPane) {
|
||||
((CardInfoPane)cardInfoPane).setCard(new CardView(card));
|
||||
((CardInfoPane)cardInfoPane).setCard(new CardView(card), null);
|
||||
}
|
||||
hidePopup();
|
||||
} else if (event.getEventName().equals("remove-main")) {
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
|
||||
Component popup2 = MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE);
|
||||
|
||||
((CardInfoPane) popup2).setCard(data.card);
|
||||
((CardInfoPane) popup2).setCard(data.card, popupContainer);
|
||||
|
||||
Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40);
|
||||
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, popup2, parentComponent);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,12 @@ public class Constants {
|
|||
|
||||
public static final Rectangle CARD_SIZE_FULL = new Rectangle(101, 149);
|
||||
public static final Rectangle THUMBNAIL_SIZE_FULL = new Rectangle(102, 146);
|
||||
|
||||
public static final int TOOLTIP_WIDTH_MIN = 320;
|
||||
public static final int TOOLTIP_HEIGHT_MIN = 201;
|
||||
|
||||
public static final int TOOLTIP_HEIGHT_MAX = 401;
|
||||
public static final int TOOLTIP_BORDER_WIDTH = 80;
|
||||
|
||||
public interface IO {
|
||||
public static final String imageBaseDir = "plugins" + File.separator + "images";
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.util.List;
|
|||
public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
|
||||
|
||||
private CardView currentCard;
|
||||
private int type;
|
||||
|
||||
public CardInfoPaneImpl() {
|
||||
UI.setHTMLEditorKit(this);
|
||||
|
|
@ -31,7 +32,7 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
|
|||
setBackground(Color.white);
|
||||
}
|
||||
|
||||
public void setCard(final CardView card) {
|
||||
public void setCard(final CardView card, final Component container) {
|
||||
if (card == null) return;
|
||||
if (isCurrentCard(card)) return;
|
||||
currentCard = card;
|
||||
|
|
@ -171,11 +172,12 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
|
|||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (!card.equals(currentCard)) return;
|
||||
if (!card.equals(currentCard)) {
|
||||
return;
|
||||
}
|
||||
resizeTooltipIfNeeded(buffer, container);
|
||||
setText(buffer.toString());
|
||||
//System.out.println(buffer.toString());
|
||||
setCaretPosition(0);
|
||||
//ThreadUtils.sleep(300);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -186,6 +188,33 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
|
|||
});
|
||||
}
|
||||
|
||||
private void resizeTooltipIfNeeded(StringBuilder buffer, Component container) {
|
||||
if (container == null) {
|
||||
return;
|
||||
}
|
||||
int i = buffer.indexOf("</p>");
|
||||
int count = 0;
|
||||
while (i != -1) {
|
||||
count++;
|
||||
i = buffer.indexOf("</p>", i+1);
|
||||
}
|
||||
if (count > 5 && this.type == 0) {
|
||||
type = 1;
|
||||
container.setSize(
|
||||
org.mage.plugins.card.constants.Constants.TOOLTIP_WIDTH_MIN + org.mage.plugins.card.constants.Constants.TOOLTIP_BORDER_WIDTH,
|
||||
org.mage.plugins.card.constants.Constants.TOOLTIP_HEIGHT_MAX + org.mage.plugins.card.constants.Constants.TOOLTIP_BORDER_WIDTH
|
||||
);
|
||||
this.setSize(org.mage.plugins.card.constants.Constants.TOOLTIP_WIDTH_MIN, org.mage.plugins.card.constants.Constants.TOOLTIP_HEIGHT_MAX);
|
||||
} else if (type == 1) {
|
||||
type = 0;
|
||||
container.setSize(
|
||||
org.mage.plugins.card.constants.Constants.TOOLTIP_WIDTH_MIN + org.mage.plugins.card.constants.Constants.TOOLTIP_BORDER_WIDTH,
|
||||
org.mage.plugins.card.constants.Constants.TOOLTIP_HEIGHT_MIN + org.mage.plugins.card.constants.Constants.TOOLTIP_BORDER_WIDTH
|
||||
);
|
||||
this.setSize(org.mage.plugins.card.constants.Constants.TOOLTIP_WIDTH_MIN, org.mage.plugins.card.constants.Constants.TOOLTIP_HEIGHT_MIN);
|
||||
}
|
||||
}
|
||||
|
||||
private String getTypes(CardView card) {
|
||||
String types = "";
|
||||
for (String superType : card.getSuperTypes()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue