From 5b9a38bf228537f56bc2d9104c101a1a7dd6b5d0 Mon Sep 17 00:00:00 2001 From: rkfg Date: Wed, 2 Mar 2016 14:48:44 +0300 Subject: [PATCH] Fix first card tooltip show. --- .../mage/client/components/ColorPane.java | 65 ++++++++++++------- .../plugins/adapters/MageActionCallback.java | 30 +++++---- .../plugins/card/info/CardInfoPaneImpl.java | 41 +++++------- 3 files changed, 76 insertions(+), 60 deletions(-) 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 aa6d5be1aa..43a402ae0c 100644 --- a/Mage.Client/src/main/java/mage/client/components/ColorPane.java +++ b/Mage.Client/src/main/java/mage/client/components/ColorPane.java @@ -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,37 +43,53 @@ public class ColorPane extends JEditorPane { @Override public void hyperlinkUpdate(final HyperlinkEvent e) { - tooltipDelay = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_DELAY, 300); - if (tooltipDelay == 0) { - return; - } - String name = e.getDescription().substring(1); - CardInfo card = CardRepository.instance.findCard(name); - try { - final Component container = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER); - if (e.getEventType() == EventType.EXITED) { - setPopupVisibility(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()); - Component parentComponent = MageFrame.getInstance(); - location = GuiDisplayUtil.keepComponentInsideParent(location, parentComponent.getLocationOnScreen(), container, - parentComponent); - container.setLocation(location); - setPopupVisibility(container, true); + ThreadUtils.threadPool2.submit(new Runnable() { + + @Override + public void run() { + tooltipDelay = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_DELAY, 300); + if (tooltipDelay == 0) { + return; + } + String name = e.getDescription().substring(1); + CardInfo card = CardRepository.instance.findCard(name); + try { + final Component container = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER); + if (e.getEventType() == EventType.EXITED) { + setPopupVisibility(null, container, false); + } else { + CardInfoPane cardInfoPane = (CardInfoPane) MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE); + cardInfoPane.setCard(new CardView(card.getMockCard()), container); + 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); + setPopupVisibility(location, container, true); + } + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + } - } 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(); } diff --git a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java index 069d3a8a8e..015280b3d3 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java +++ b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java @@ -189,27 +189,31 @@ 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); - final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if (!popupTextWindowOpen || !enlargedWindowState.equals(EnlargedWindowState.CLOSED)) { - return; - } - popupContainer.setVisible(true); - c.repaint(); - } - } - ); + 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 + public void run() { + if (!popupTextWindowOpen || !enlargedWindowState.equals(EnlargedWindowState.CLOSED)) { + return; + } + popupContainer.setLocation(location); + popupContainer.setVisible(true); + c.repaint(); + } + } + ); + } }); } diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/info/CardInfoPaneImpl.java b/Mage.Client/src/main/java/org/mage/plugins/card/info/CardInfoPaneImpl.java index 19a33bed51..1d2e242aa2 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/info/CardInfoPaneImpl.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/info/CardInfoPaneImpl.java @@ -59,33 +59,28 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane { } currentCard = card; - ThreadUtils.threadPool.submit(new Runnable() { - @Override - public void run() { - try { + try { + if (!card.equals(currentCard)) { + return; + } + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { if (!card.equals(currentCard)) { return; } - - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if (!card.equals(currentCard)) { - return; - } - TextLines textLines = GuiDisplayUtil.getTextLinesfromCardView(card); - StringBuilder buffer = GuiDisplayUtil.getRulefromCardView(card, textLines); - resizeTooltipIfNeeded(container, textLines.basicTextLength, textLines.lines.size()); - setText(buffer.toString()); - setCaretPosition(0); - } - }); - - } catch (Exception e) { - e.printStackTrace(); + TextLines textLines = GuiDisplayUtil.getTextLinesfromCardView(card); + StringBuilder buffer = GuiDisplayUtil.getRulefromCardView(card, textLines); + resizeTooltipIfNeeded(container, textLines.basicTextLength, textLines.lines.size()); + setText(buffer.toString()); + setCaretPosition(0); } - } - }); + }); + + } catch (Exception e) { + e.printStackTrace(); + } } private void resizeTooltipIfNeeded(Component container, int ruleLength, int rules) {