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.dialog.PreferencesDialog;
import mage.client.util.gui.GuiDisplayUtil; import mage.client.util.gui.GuiDisplayUtil;
import mage.components.CardInfoPane; import mage.components.CardInfoPane;
import mage.utils.ThreadUtils;
import mage.view.CardView; import mage.view.CardView;
/** /**
@ -42,37 +43,53 @@ public class ColorPane extends JEditorPane {
@Override @Override
public void hyperlinkUpdate(final HyperlinkEvent e) { public void hyperlinkUpdate(final HyperlinkEvent e) {
tooltipDelay = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_DELAY, 300); ThreadUtils.threadPool2.submit(new Runnable() {
if (tooltipDelay == 0) {
return; @Override
} public void run() {
String name = e.getDescription().substring(1); tooltipDelay = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_DELAY, 300);
CardInfo card = CardRepository.instance.findCard(name); if (tooltipDelay == 0) {
try { return;
final Component container = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER); }
if (e.getEventType() == EventType.EXITED) { String name = e.getDescription().substring(1);
setPopupVisibility(container, false); CardInfo card = CardRepository.instance.findCard(name);
} else { try {
CardInfoPane cardInfoPane = (CardInfoPane) MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE); final Component container = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
cardInfoPane.setCard(new CardView(card.getMockCard()), container); if (e.getEventType() == EventType.EXITED) {
Point location = new Point(getLocationOnScreen().x - container.getWidth(), (int) MageFrame.getDesktop() setPopupVisibility(null, container, false);
.getMousePosition().getY()); } else {
Component parentComponent = MageFrame.getInstance(); CardInfoPane cardInfoPane = (CardInfoPane) MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE);
location = GuiDisplayUtil.keepComponentInsideParent(location, parentComponent.getLocationOnScreen(), container, cardInfoPane.setCard(new CardView(card.getMockCard()), container);
parentComponent); Point mousePosition = MageFrame.getDesktop().getMousePosition();
container.setLocation(location); int popupY = 0;
setPopupVisibility(container, true); 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); final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
if (location != null) {
container.setLocation(location);
}
container.setVisible(show); container.setVisible(show);
c.repaint(); c.repaint();
} }

View file

@ -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); 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 = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, popup2, parentComponent);
location.translate(-parentPoint.x, -parentPoint.y); location.translate(-parentPoint.x, -parentPoint.y);
popupContainer.setLocation(location);
ThreadUtils.sleep(200); ThreadUtils.sleep(200);
final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE); showPopup(popupContainer, location);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (!popupTextWindowOpen || !enlargedWindowState.equals(EnlargedWindowState.CLOSED)) {
return;
}
popupContainer.setVisible(true);
c.repaint();
}
}
);
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOGGER.warn(e.getMessage()); 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();
}
}
);
}
}); });
} }

View file

@ -59,33 +59,28 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
} }
currentCard = card; currentCard = card;
ThreadUtils.threadPool.submit(new Runnable() { try {
@Override if (!card.equals(currentCard)) {
public void run() { return;
try { }
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (!card.equals(currentCard)) { if (!card.equals(currentCard)) {
return; return;
} }
TextLines textLines = GuiDisplayUtil.getTextLinesfromCardView(card);
SwingUtilities.invokeLater(new Runnable() { StringBuilder buffer = GuiDisplayUtil.getRulefromCardView(card, textLines);
@Override resizeTooltipIfNeeded(container, textLines.basicTextLength, textLines.lines.size());
public void run() { setText(buffer.toString());
if (!card.equals(currentCard)) { setCaretPosition(0);
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();
} }
} });
});
} catch (Exception e) {
e.printStackTrace();
}
} }
private void resizeTooltipIfNeeded(Component container, int ruleLength, int rules) { private void resizeTooltipIfNeeded(Component container, int ruleLength, int rules) {