* Fixed possible null pointer exception in client.

This commit is contained in:
LevelX2 2015-07-12 09:19:43 +02:00
parent 0e3d4b335a
commit 6cf0a59644

View file

@ -1,5 +1,28 @@
package mage.client.plugins.adapters; package mage.client.plugins.adapters;
import java.awt.Component;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.Popup;
import javax.swing.PopupFactory;
import javax.swing.SwingUtilities;
import mage.cards.MageCard; import mage.cards.MageCard;
import mage.cards.action.ActionCallback; import mage.cards.action.ActionCallback;
import mage.cards.action.TransferData; import mage.cards.action.TransferData;
@ -24,21 +47,10 @@ import org.jdesktop.swingx.JXPanel;
import org.mage.card.arcane.CardPanel; import org.mage.card.arcane.CardPanel;
import org.mage.plugins.card.images.ImageCache; import org.mage.plugins.card.images.ImageCache;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.image.BufferedImage;
import java.util.*;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/** /**
* Class that handles the callbacks from the card panels to mage to display big card * Class that handles the callbacks from the card panels to mage to display big
* images from the cards the mouse hovers on. Also handles tooltip text window. * card images from the cards the mouse hovers on. Also handles tooltip text
* window.
* *
* @author Nantuko, noxx * @author Nantuko, noxx
*/ */
@ -62,7 +74,9 @@ public class MageActionCallback implements ActionCallback {
private TransferData popupData; private TransferData popupData;
private JComponent cardInfoPane; private JComponent cardInfoPane;
private volatile boolean popupTextWindowOpen = false; private volatile boolean popupTextWindowOpen = false;
enum EnlargedWindowState { enum EnlargedWindowState {
CLOSED, NORMAL, ROTATED CLOSED, NORMAL, ROTATED
} }
private volatile EnlargedWindowState enlargedWindowState = EnlargedWindowState.CLOSED; private volatile EnlargedWindowState enlargedWindowState = EnlargedWindowState.CLOSED;
@ -458,7 +472,8 @@ public class MageActionCallback implements ActionCallback {
/** /**
* Show the big card image on mouse position while hovering over a card * Show the big card image on mouse position while hovering over a card
* *
* @param showAlternative defines if the original image (if it's a copied card) or the opposite side of a transformable card will be shown * @param showAlternative defines if the original image (if it's a copied
* card) or the opposite side of a transformable card will be shown
*/ */
public void enlargeCard(EnlargeMode showAlternative) { public void enlargeCard(EnlargeMode showAlternative) {
if (enlargedWindowState.equals(EnlargedWindowState.CLOSED)) { if (enlargedWindowState.equals(EnlargedWindowState.CLOSED)) {
@ -496,8 +511,6 @@ public class MageActionCallback implements ActionCallback {
} }
} }
private void displayEnlargedCard(final CardView cardView, final TransferData transferData) { private void displayEnlargedCard(final CardView cardView, final TransferData transferData) {
ThreadUtils.threadPool2.submit(new Runnable() { ThreadUtils.threadPool2.submit(new Runnable() {
@Override @Override
@ -509,8 +522,6 @@ public class MageActionCallback implements ActionCallback {
if (enlargedWindowState.equals(EnlargedWindowState.CLOSED)) { if (enlargedWindowState.equals(EnlargedWindowState.CLOSED)) {
return; return;
} }
Component parentComponent = SwingUtilities.getRoot(transferData.component);
Point parentPoint = parentComponent.getLocationOnScreen();
MageComponents mageComponentCardPreviewContainer; MageComponents mageComponentCardPreviewContainer;
MageComponents mageComponentCardPreviewPane; MageComponents mageComponentCardPreviewPane;
@ -531,7 +542,9 @@ public class MageActionCallback implements ActionCallback {
} }
final Component popupContainer = MageFrame.getUI().getComponent(mageComponentCardPreviewContainer); final Component popupContainer = MageFrame.getUI().getComponent(mageComponentCardPreviewContainer);
Component cardPreviewPane = MageFrame.getUI().getComponent(mageComponentCardPreviewPane); Component cardPreviewPane = MageFrame.getUI().getComponent(mageComponentCardPreviewPane);
if (cardPreviewPane != null) { Component parentComponent = SwingUtilities.getRoot(transferData.component);
if (cardPreviewPane != null && parentComponent != null) {
Point parentPoint = parentComponent.getLocationOnScreen();
transferData.locationOnScreen = transferData.component.getLocationOnScreen(); transferData.locationOnScreen = transferData.component.getLocationOnScreen();
Point location = new Point((int) transferData.locationOnScreen.getX() + transferData.popupOffsetX - 40, (int) transferData.locationOnScreen.getY() + transferData.popupOffsetY - 40); Point location = new Point((int) transferData.locationOnScreen.getX() + transferData.popupOffsetX - 40, (int) transferData.locationOnScreen.getY() + transferData.popupOffsetY - 40);
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, cardPreviewPane, parentComponent); location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, cardPreviewPane, parentComponent);
@ -564,7 +577,6 @@ public class MageActionCallback implements ActionCallback {
BigCard bigCard = (BigCard) cardPreviewPane; BigCard bigCard = (BigCard) cardPreviewPane;
displayCardInfo(mageCard, image, bigCard); displayCardInfo(mageCard, image, bigCard);
} else { } else {
logger.warn("No Card preview Pane in Mage Frame defined. Card: " + cardView.getName()); logger.warn("No Card preview Pane in Mage Frame defined. Card: " + cardView.getName());
} }