* UI: fixed non closeable card popup hints, fixed memory leaks (#4983, #2803);

This commit is contained in:
Oleg Agafonov 2019-04-12 17:55:25 +04:00
parent eafd28ca6d
commit ee2741c7a7
2 changed files with 58 additions and 48 deletions

View file

@ -72,7 +72,7 @@ import java.util.concurrent.TimeUnit;
import java.util.prefs.Preferences; import java.util.prefs.Preferences;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com, JayDi85
*/ */
public class MageFrame extends javax.swing.JFrame implements MageClient { public class MageFrame extends javax.swing.JFrame implements MageClient {
@ -353,61 +353,76 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
+ ((SessionHandler.getSession() != null && SessionHandler.isConnected()) ? SessionHandler.getVersionInfo() : NOT_CONNECTED_TEXT)); + ((SessionHandler.getSession() != null && SessionHandler.isConnected()) ? SessionHandler.getVersionInfo() : NOT_CONNECTED_TEXT));
} }
private void updateTooltipContainerSizes() {
JPanel cardPreviewContainer;
BigCard bigCard;
JPanel cardPreviewContainerRotated;
BigCard bigCardRotated;
try {
cardPreviewContainer = (JPanel) UI.getComponent(MageComponents.CARD_PREVIEW_CONTAINER);
bigCard = (BigCard) UI.getComponent(MageComponents.CARD_PREVIEW_PANE);
cardPreviewContainerRotated = (JPanel) UI.getComponent(MageComponents.CARD_PREVIEW_CONTAINER_ROTATED);
bigCardRotated = (BigCard) UI.getComponent(MageComponents.CARD_PREVIEW_PANE_ROTATED);
} catch (InterruptedException e) {
LOGGER.fatal("Can't update tooltip panel sizes");
Thread.currentThread().interrupt();
return;
}
int height = GUISizeHelper.enlargedImageHeight;
int width = (int) ((float) height * (float) 0.64);
bigCard.setSize(width, height);
cardPreviewContainer.setBounds(0, 0, width + 80, height + 30);
bigCardRotated.setSize(height, width + 30);
cardPreviewContainerRotated.setBounds(0, 0, height + 80, width + 100 + 30);
}
private void addTooltipContainer() { private void addTooltipContainer() {
final JEditorPane cardInfoPane = (JEditorPane) Plugins.instance.getCardInfoPane(); JEditorPane cardInfoPane = (JEditorPane) Plugins.instance.getCardInfoPane();
if (cardInfoPane == null) { if (cardInfoPane == null) {
LOGGER.fatal("Can't find card tooltip plugin");
return; return;
} }
cardInfoPane.setLocation(40, 40); cardInfoPane.setLocation(40, 40);
cardInfoPane.setBackground(new Color(0, 0, 0, 0)); cardInfoPane.setBackground(new Color(0, 0, 0, 0));
UI.addComponent(MageComponents.CARD_INFO_PANE, cardInfoPane);
MageRoundPane popupContainer = new MageRoundPane(); MageRoundPane popupContainer = new MageRoundPane();
popupContainer.setLayout(null); popupContainer.setLayout(null);
popupContainer.add(cardInfoPane); popupContainer.add(cardInfoPane);
popupContainer.setVisible(false); popupContainer.setVisible(false);
desktopPane.add(popupContainer, JLayeredPane.POPUP_LAYER); desktopPane.add(popupContainer, JLayeredPane.POPUP_LAYER);
UI.addComponent(MageComponents.CARD_INFO_PANE, cardInfoPane);
UI.addComponent(MageComponents.POPUP_CONTAINER, popupContainer); UI.addComponent(MageComponents.POPUP_CONTAINER, popupContainer);
// preview panel normal
JPanel cardPreviewContainer = new JPanel(); JPanel cardPreviewContainer = new JPanel();
cardPreviewContainer.setOpaque(false); cardPreviewContainer.setOpaque(false);
cardPreviewContainer.setLayout(null); cardPreviewContainer.setLayout(null);
BigCard bigCard = new BigCard();
int height = GUISizeHelper.enlargedImageHeight;
int width = (int) ((float) height * (float) 0.64);
bigCard.setSize(width, height);
bigCard.setLocation(40, 40);
bigCard.setBackground(new Color(0, 0, 0, 0));
cardPreviewContainer.add(bigCard);
cardPreviewContainer.setVisible(false); cardPreviewContainer.setVisible(false);
cardPreviewContainer.setBounds(0, 0, width + 80, height + 30); desktopPane.add(cardPreviewContainer, JLayeredPane.POPUP_LAYER);
UI.addComponent(MageComponents.CARD_PREVIEW_PANE, bigCard);
UI.addComponent(MageComponents.CARD_PREVIEW_CONTAINER, cardPreviewContainer); UI.addComponent(MageComponents.CARD_PREVIEW_CONTAINER, cardPreviewContainer);
desktopPane.add(cardPreviewContainer, JLayeredPane.POPUP_LAYER); BigCard bigCard = new BigCard();
bigCard.setLocation(40, 40);
bigCard.setBackground(new Color(0, 0, 0, 0));
cardPreviewContainer.add(bigCard);
UI.addComponent(MageComponents.CARD_PREVIEW_PANE, bigCard);
// preview panel rotated
JPanel cardPreviewContainerRotated = new JPanel(); JPanel cardPreviewContainerRotated = new JPanel();
cardPreviewContainerRotated.setOpaque(false); cardPreviewContainerRotated.setOpaque(false);
cardPreviewContainerRotated.setLayout(null); cardPreviewContainerRotated.setLayout(null);
bigCard = new BigCard(true);
bigCard.setSize(height, width + 30);
bigCard.setLocation(40, 40);
bigCard.setBackground(new Color(0, 0, 0, 0));
cardPreviewContainerRotated.add(bigCard);
cardPreviewContainerRotated.setVisible(false); cardPreviewContainerRotated.setVisible(false);
cardPreviewContainerRotated.setBounds(0, 0, height + 80, width + 100 + 30); desktopPane.add(cardPreviewContainerRotated, JLayeredPane.POPUP_LAYER);
UI.addComponent(MageComponents.CARD_PREVIEW_PANE_ROTATED, bigCard);
UI.addComponent(MageComponents.CARD_PREVIEW_CONTAINER_ROTATED, cardPreviewContainerRotated); UI.addComponent(MageComponents.CARD_PREVIEW_CONTAINER_ROTATED, cardPreviewContainerRotated);
desktopPane.add(cardPreviewContainerRotated, JLayeredPane.POPUP_LAYER);
BigCard bigCardRotated = new BigCard(true);
bigCardRotated.setLocation(40, 40);
bigCardRotated.setBackground(new Color(0, 0, 0, 0));
cardPreviewContainerRotated.add(bigCardRotated);
UI.addComponent(MageComponents.CARD_PREVIEW_PANE_ROTATED, bigCardRotated);
updateTooltipContainerSizes();
} }
private void setGUISizeTooltipContainer() { private void setGUISizeTooltipContainer() {
@ -1586,7 +1601,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} }
balloonTip.setFont(GUISizeHelper.balloonTooltipFont); balloonTip.setFont(GUISizeHelper.balloonTooltipFont);
addTooltipContainer(); updateTooltipContainerSizes();
} }
public void showWhatsNewDialog(boolean forceToShowPage) { public void showWhatsNewDialog(boolean forceToShowPage) {

View file

@ -30,8 +30,8 @@ import java.awt.*;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.*;
import java.util.List; import java.util.List;
import java.util.*;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
@ -154,24 +154,22 @@ public class MageActionCallback implements ActionCallback {
try { try {
final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER); final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
Component popup2 = MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE); Component popupInfo = MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE);
((CardInfoPane) popupInfo).setCard(data.getCard(), popupContainer);
((CardInfoPane) popup2).setCard(data.getCard(), popupContainer); showPopup(popupContainer, popupInfo);
showPopup(popupContainer, popup2);
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOGGER.warn(e.getMessage()); LOGGER.error("Can't show card tooltip", e);
Thread.currentThread().interrupt();
} }
} }
public void showPopup(final Component popupContainer, final Component infoPane) throws InterruptedException { public void showPopup(final Component popupContainer, final Component infoPane) throws InterruptedException {
final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE); final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
if (!popupTextWindowOpen if (!popupTextWindowOpen || enlargedWindowState != EnlargedWindowState.CLOSED) {
|| enlargedWindowState != EnlargedWindowState.CLOSED) {
return; return;
} }
if (data.getLocationOnScreen() == null) { if (data.getLocationOnScreen() == null) {
data.setLocationOnScreen(data.getComponent().getLocationOnScreen()); data.setLocationOnScreen(data.getComponent().getLocationOnScreen());
} }
@ -383,6 +381,7 @@ public class MageActionCallback implements ActionCallback {
ArrowUtil.drawArrowsForPairedCards(data, parentPoint); ArrowUtil.drawArrowsForPairedCards(data, parentPoint);
ArrowUtil.drawArrowsForBandedCards(data, parentPoint); ArrowUtil.drawArrowsForBandedCards(data, parentPoint);
ArrowUtil.drawArrowsForEnchantPlayers(data, parentPoint); ArrowUtil.drawArrowsForEnchantPlayers(data, parentPoint);
tooltipCard = data.getCard(); tooltipCard = data.getCard();
showTooltipPopup(data, parentComponent, parentPoint); showTooltipPopup(data, parentComponent, parentPoint);
} }
@ -414,13 +413,9 @@ public class MageActionCallback implements ActionCallback {
@Override @Override
public void hideOpenComponents() { public void hideOpenComponents() {
this.hideTooltipPopup(); hideAll(null);
this.hideEnlargedCard();
} }
/**
* Hides the text popup window
*/
public void hideTooltipPopup() { public void hideTooltipPopup() {
this.tooltipCard = null; this.tooltipCard = null;
if (tooltipPopup != null) { if (tooltipPopup != null) {
@ -433,11 +428,11 @@ public class MageActionCallback implements ActionCallback {
if (SessionHandler.getSession() == null) { if (SessionHandler.getSession() == null) {
return; return;
} }
// set enlarged card display to visible = false
Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER); Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
popupContainer.setVisible(false); popupContainer.setVisible(false);
} catch (Exception e2) { } catch (InterruptedException e) {
LOGGER.warn("Can't set tooltip to visible = false", e2); LOGGER.error("Can't hide card tooltip", e);
Thread.currentThread().interrupt();
} }
} }