mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
Merge pull request #2028 from draxdyn/cardpanel_threading
Fix broken threading in CardPanel
This commit is contained in:
commit
facd5ffa2c
1 changed files with 36 additions and 40 deletions
|
@ -416,37 +416,19 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
||||||
String cardType = getType(newGameCard);
|
String cardType = getType(newGameCard);
|
||||||
tooltipText.setText(getText(cardType, newGameCard));
|
tooltipText.setText(getText(cardType, newGameCard));
|
||||||
|
|
||||||
Util.threadPool.submit(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
tappedAngle = isTapped() ? CardPanel.TAPPED_ANGLE : 0;
|
tappedAngle = isTapped() ? CardPanel.TAPPED_ANGLE : 0;
|
||||||
flippedAngle = isFlipped() ? CardPanel.FLIPPED_ANGLE : 0;
|
flippedAngle = isFlipped() ? CardPanel.FLIPPED_ANGLE : 0;
|
||||||
|
|
||||||
if (!loadImage) {
|
if (!loadImage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BufferedImage srcImage;
|
|
||||||
if (gameCard.isFaceDown()) {
|
|
||||||
srcImage = getFaceDownImage();
|
|
||||||
} else {
|
|
||||||
srcImage = ImageCache.getImage(gameCard, getCardWidth(), getCardHeight());
|
|
||||||
}
|
|
||||||
if (srcImage != null) {
|
|
||||||
hasImage = true;
|
|
||||||
setText(gameCard);
|
|
||||||
setImage(srcImage);
|
|
||||||
}
|
|
||||||
if (gameCard.isTransformed()) {
|
if (gameCard.isTransformed()) {
|
||||||
|
// this calls updateImage
|
||||||
toggleTransformed();
|
toggleTransformed();
|
||||||
|
} else {
|
||||||
|
updateImage();
|
||||||
}
|
}
|
||||||
setText(gameCard);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOGGER.fatal("Problem during image animation", e);
|
|
||||||
} catch (Error err) {
|
|
||||||
LOGGER.error("Problem during image animation", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTypeIcon(BufferedImage bufferedImage, String toolTipText) {
|
private void setTypeIcon(BufferedImage bufferedImage, String toolTipText) {
|
||||||
|
@ -494,7 +476,10 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
||||||
|
|
||||||
private void setImage(BufferedImage srcImage) {
|
private void setImage(BufferedImage srcImage) {
|
||||||
synchronized (imagePanel) {
|
synchronized (imagePanel) {
|
||||||
|
if(srcImage != null)
|
||||||
imagePanel.setImage(srcImage);
|
imagePanel.setImage(srcImage);
|
||||||
|
else
|
||||||
|
imagePanel.clearImage();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
doLayout();
|
doLayout();
|
||||||
|
@ -852,15 +837,21 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
||||||
return cardYOffset;
|
return cardYOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int updateImageStamp;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateImage() {
|
public void updateImage() {
|
||||||
|
tappedAngle = isTapped() ? CardPanel.TAPPED_ANGLE : 0;
|
||||||
|
flippedAngle = isFlipped() ? CardPanel.FLIPPED_ANGLE : 0;
|
||||||
|
|
||||||
|
final CardView gameCard = this.gameCard;
|
||||||
|
final int stamp = ++updateImageStamp;
|
||||||
|
|
||||||
Util.threadPool.submit(new Runnable() {
|
Util.threadPool.submit(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
tappedAngle = isTapped() ? CardPanel.TAPPED_ANGLE : 0;
|
final BufferedImage srcImage;
|
||||||
flippedAngle = isFlipped() ? CardPanel.FLIPPED_ANGLE : 0;
|
|
||||||
BufferedImage srcImage;
|
|
||||||
if (gameCard.isFaceDown()) {
|
if (gameCard.isFaceDown()) {
|
||||||
srcImage = getFaceDownImage();
|
srcImage = getFaceDownImage();
|
||||||
} else if (cardWidth > THUMBNAIL_SIZE_FULL.width) {
|
} else if (cardWidth > THUMBNAIL_SIZE_FULL.width) {
|
||||||
|
@ -868,11 +859,16 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
||||||
} else {
|
} else {
|
||||||
srcImage = ImageCache.getThumbnail(gameCard);
|
srcImage = ImageCache.getThumbnail(gameCard);
|
||||||
}
|
}
|
||||||
if (srcImage != null) {
|
UI.invokeLater(new Runnable() {
|
||||||
hasImage = true;
|
@Override
|
||||||
|
public void run () {
|
||||||
|
if(stamp == updateImageStamp) {
|
||||||
|
hasImage = srcImage != null;
|
||||||
setText(gameCard);
|
setText(gameCard);
|
||||||
setImage(srcImage);
|
setImage(srcImage);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (Error err) {
|
} catch (Error err) {
|
||||||
|
|
Loading…
Reference in a new issue