Merge pull request #1579 from rkfg/master

Fix first card tooltip show.
This commit is contained in:
LevelX2 2016-03-02 13:19:00 +01:00
commit afe0819549
3 changed files with 76 additions and 60 deletions

View file

@ -22,6 +22,7 @@ import mage.client.MageFrame;
import mage.client.dialog.PreferencesDialog;
import mage.client.util.gui.GuiDisplayUtil;
import mage.components.CardInfoPane;
import mage.utils.ThreadUtils;
import mage.view.CardView;
/**
@ -42,6 +43,10 @@ public class ColorPane extends JEditorPane {
@Override
public void hyperlinkUpdate(final HyperlinkEvent e) {
ThreadUtils.threadPool2.submit(new Runnable() {
@Override
public void run() {
tooltipDelay = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_DELAY, 300);
if (tooltipDelay == 0) {
return;
@ -51,28 +56,40 @@ public class ColorPane extends JEditorPane {
try {
final Component container = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
if (e.getEventType() == EventType.EXITED) {
setPopupVisibility(container, false);
setPopupVisibility(null, container, false);
} else {
CardInfoPane cardInfoPane = (CardInfoPane) MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE);
cardInfoPane.setCard(new CardView(card.getMockCard()), container);
Point location = new Point(getLocationOnScreen().x - container.getWidth(), (int) MageFrame.getDesktop()
.getMousePosition().getY());
Point mousePosition = MageFrame.getDesktop().getMousePosition();
int popupY = 0;
if (mousePosition == null) { // switched to another window
popupY = getLocationOnScreen().y;
} else {
popupY = mousePosition.y;
}
Point location = new Point(getLocationOnScreen().x - container.getWidth(), popupY);
Component parentComponent = MageFrame.getInstance();
location = GuiDisplayUtil.keepComponentInsideParent(location, parentComponent.getLocationOnScreen(), container,
parentComponent);
container.setLocation(location);
setPopupVisibility(container, true);
location = GuiDisplayUtil.keepComponentInsideParent(location, parentComponent.getLocationOnScreen(),
container, parentComponent);
setPopupVisibility(location, container, true);
}
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
}
private void setPopupVisibility(final Component container, final boolean show) throws InterruptedException {
private void setPopupVisibility(final Point location, final Component container, final boolean show)
throws InterruptedException {
final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (location != null) {
container.setLocation(location);
}
container.setVisible(show);
c.repaint();
}

View file

@ -189,10 +189,17 @@ public class MageActionCallback implements ActionCallback {
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);
location.translate(-parentPoint.x, -parentPoint.y);
popupContainer.setLocation(location);
ThreadUtils.sleep(200);
showPopup(popupContainer, location);
} catch (InterruptedException e) {
LOGGER.warn(e.getMessage());
}
}
public void showPopup(final Component popupContainer, final Point location) throws InterruptedException {
final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
SwingUtilities.invokeLater(new Runnable() {
@Override
@ -200,15 +207,12 @@ public class MageActionCallback implements ActionCallback {
if (!popupTextWindowOpen || !enlargedWindowState.equals(EnlargedWindowState.CLOSED)) {
return;
}
popupContainer.setLocation(location);
popupContainer.setVisible(true);
c.repaint();
}
}
);
} catch (InterruptedException e) {
LOGGER.warn(e.getMessage());
}
}
});
}

View file

@ -59,9 +59,6 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
}
currentCard = card;
ThreadUtils.threadPool.submit(new Runnable() {
@Override
public void run() {
try {
if (!card.equals(currentCard)) {
return;
@ -85,8 +82,6 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
e.printStackTrace();
}
}
});
}
private void resizeTooltipIfNeeded(Component container, int ruleLength, int rules) {
if (container == null) {