ensure the card image gets refreshed when the panel is resized or a dual-sided card is flipped

This commit is contained in:
myk
2013-02-23 07:01:04 +00:00
parent cb163eaeb4
commit 20d0b5122a

View File

@@ -45,24 +45,13 @@ public final class CardPicturePanel extends JPanel implements CardContainer {
private static final long serialVersionUID = -3160874016387273383L; private static final long serialVersionUID = -3160874016387273383L;
private Object displayed; private Object displayed;
private Object imageShownFor = null;
// private JLabel label;
// private ImageIcon icon;
private final ScaledImagePanel panel; private final ScaledImagePanel panel;
private BufferedImage currentImage; private BufferedImage currentImage;
/**
* <p>
* Constructor for CardPicturePanel.
* </p>
*
* @param c
* a {@link forge.Card} object.
*/
public CardPicturePanel(final Card c) { public CardPicturePanel(final Card c) {
super(new BorderLayout()); super(new BorderLayout());
// add(label = new JLabel(icon = new ImageIcon()));
this.panel = new ScaledImagePanel(); this.panel = new ScaledImagePanel();
this.add(this.panel); this.add(this.panel);
this.addComponentListener(new ComponentAdapter() { this.addComponentListener(new ComponentAdapter() {
@@ -77,46 +66,27 @@ public final class CardPicturePanel extends JPanel implements CardContainer {
} }
}); });
this.setCard(c); this.setCard(c);
} }
/**
* <p>
* update.
* </p>
*/
public void update() { public void update() {
// if (!this.isShowing()) return; -- does this work or not?
this.setImage(); this.setImage();
} }
/**
* Sets the card.
*
* @param cp
* the new card
*/
public void setCard(final InventoryItem cp) { public void setCard(final InventoryItem cp) {
this.displayed = cp; this.displayed = cp;
update(); update();
} }
/** {@inheritDoc} */
@Override @Override
public void setCard(final Card c) { public void setCard(final Card c) {
this.displayed = c; this.displayed = c;
update(); update();
} }
/** */
public void setImage() { public void setImage() {
final Insets i = this.getInsets(); final Insets i = this.getInsets();
BufferedImage image = null; BufferedImage image = null;
if ( displayed == imageShownFor )
return;
if (displayed instanceof InventoryItem) { if (displayed instanceof InventoryItem) {
image = ImageCache.getImage((InventoryItem)this.displayed, this.getWidth() - i.left - i.right, this.getHeight() image = ImageCache.getImage((InventoryItem)this.displayed, this.getWidth() - i.left - i.right, this.getHeight()
- i.top - i.bottom); - i.top - i.bottom);
@@ -126,29 +96,12 @@ public final class CardPicturePanel extends JPanel implements CardContainer {
} }
if (image != this.currentImage) { if (image != this.currentImage) {
imageShownFor = displayed;
this.currentImage = image; this.currentImage = image;
this.panel.setImage(image); this.panel.setImage(image);
this.panel.repaint(); this.panel.repaint();
} }
// if(image == null) {
// label.setIcon(null);
// //avoid a hard reference to the image while not needed
// icon.setImage(null);
// label.setText(card.isFaceDown()? "Morph":card.getName());
// } else if(image != icon.getImage()) {
// icon.setImage(image);
// label.setIcon(icon);
// }
} }
/**
* <p>
* Getter for the field <code>card</code>.
* </p>
*
* @return a {@link forge.Card} object.
*/
@Override @Override
public Card getCard() { public Card getCard() {
if ( displayed instanceof Card ) if ( displayed instanceof Card )