forked from External/mage
Fix race condition on tooltip resize in EDT.
CardInfoPane.setCard() performs the tooltip resize, initially it's of zero width and height. The resize happens in the EDT but location is calculated in the thread pool's thread, i.e. before the first resize. Because of that the first time the tooltip appears it may be partially off-screen, nothing fatal but looks ugly. Now all calculations are moved to EDT as well and they're guaranteed to happen after the resize.
This commit is contained in:
parent
98c291be7b
commit
768b004d3e
2 changed files with 18 additions and 30 deletions
|
|
@ -182,24 +182,14 @@ public class MageActionCallback implements ActionCallback {
|
|||
|
||||
((CardInfoPane) popup2).setCard(data.card, popupContainer);
|
||||
|
||||
if (data.locationOnScreen == null) {
|
||||
data.locationOnScreen = data.component.getLocationOnScreen();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
ThreadUtils.sleep(200);
|
||||
|
||||
showPopup(popupContainer, location);
|
||||
showPopup(popupContainer, popup2);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.warn(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void showPopup(final Component popupContainer, final Point location) throws InterruptedException {
|
||||
public void showPopup(final Component popupContainer, final Component infoPane) throws InterruptedException {
|
||||
final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
|
|
@ -207,6 +197,13 @@ public class MageActionCallback implements ActionCallback {
|
|||
if (!popupTextWindowOpen || !enlargedWindowState.equals(EnlargedWindowState.CLOSED)) {
|
||||
return;
|
||||
}
|
||||
if (data.locationOnScreen == null) {
|
||||
data.locationOnScreen = data.component.getLocationOnScreen();
|
||||
}
|
||||
|
||||
Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40);
|
||||
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, infoPane, parentComponent);
|
||||
location.translate(-parentPoint.x, -parentPoint.y);
|
||||
popupContainer.setLocation(location);
|
||||
popupContainer.setVisible(true);
|
||||
c.repaint();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue