Changed handling of tooltip size calculation.

This commit is contained in:
LevelX2 2014-11-06 23:13:34 +01:00
parent 17a9a8edc7
commit a835c19533
3 changed files with 18 additions and 14 deletions

View file

@ -1,13 +1,14 @@
package mage.client.components;
import static com.sun.glass.ui.Cursor.setVisible;
import org.jdesktop.swingx.graphics.GraphicsUtilities;
import org.jdesktop.swingx.graphics.ShadowRenderer;
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
/**
* Mage round pane with transparency.
* Used for tooltips.
@ -19,8 +20,8 @@ public class MageRoundPane extends JPanel {
private int X_OFFSET = 30;
private int Y_OFFSET = 30;
private BufferedImage shadow = null;
private Color backgroundColor = new Color(255, 255, 255, 200);
private int alpha = 0;
private final Color backgroundColor = new Color(255, 255, 255, 200);
private final int alpha = 0;
@Override
protected void paintComponent(Graphics g) {

View file

@ -1,7 +1,9 @@
package org.mage.plugins.card.info;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JEditorPane;
import javax.swing.SwingUtilities;
import mage.client.util.gui.GuiDisplayUtil;
@ -49,7 +51,13 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
return;
}
StringBuilder buffer = GuiDisplayUtil.getRulefromCardView(card);
resizeTooltipIfNeeded(buffer, container);
int ruleLength = 0;
int rules = 0;
for (String rule :card.getRules()) {
ruleLength += rule.length();
rules++;
}
resizeTooltipIfNeeded(container, ruleLength, rules);
setText(buffer.toString());
setCaretPosition(0);
}
@ -62,24 +70,19 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
});
}
private void resizeTooltipIfNeeded(StringBuilder buffer, Component container) {
private void resizeTooltipIfNeeded(Component container, int ruleLength, int rules) {
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) {
boolean makeBig = (rules > 5 || ruleLength > 450);
if (makeBig && 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 (count < 6 && type == 1) {
} else if (!makeBig && type == 1) {
type = 0;
container.setSize(
org.mage.plugins.card.constants.Constants.TOOLTIP_WIDTH_MIN + org.mage.plugins.card.constants.Constants.TOOLTIP_BORDER_WIDTH,

View file

@ -77,7 +77,7 @@ public class CardInfo {
protected String supertypes;
@DatabaseField
protected String manaCosts;
@DatabaseField(dataType = DataType.STRING, width = 500)
@DatabaseField(dataType = DataType.STRING, width = 800)
protected String rules;
@DatabaseField
protected boolean black;