Added "transform on click" capability to card picture and detail.

This commit is contained in:
Doublestrike
2012-05-27 06:41:39 +00:00
parent 3e8c5f9956
commit 22d899aeee
7 changed files with 74 additions and 5 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 579 KiB

After

Width:  |  Height:  |  Size: 585 KiB

View File

@@ -51,7 +51,7 @@ public final class CardPicturePanel extends JPanel implements CardContainer {
// private JLabel label;
// private ImageIcon icon;
private final ScaledImagePanel panel;
private Image currentImange;
private Image currentImage;
/**
* <p>
@@ -82,6 +82,8 @@ public final class CardPicturePanel extends JPanel implements CardContainer {
}
});
this.setCard(c);
}
@@ -118,7 +120,8 @@ public final class CardPicturePanel extends JPanel implements CardContainer {
this.setImage();
}
private void setImage() {
/** */
public void setImage() {
final Insets i = this.getInsets();
Image image = null;
if (this.inventoryItem != null) {
@@ -130,8 +133,8 @@ public final class CardPicturePanel extends JPanel implements CardContainer {
- i.bottom - 2);
}
if (image != this.currentImange) {
this.currentImange = image;
if (image != this.currentImage) {
this.currentImage = image;
this.panel.setImage(image, null);
this.panel.repaint();
}

View File

@@ -17,6 +17,9 @@
*/
package forge.gui.match.controllers;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import forge.Card;
import forge.Command;
import forge.gui.framework.ICDoc;
@@ -41,7 +44,9 @@ public enum CDetail implements ICDoc {
*/
public void showCard(final Card c) {
this.currentCard = c;
VDetail.SINGLETON_INSTANCE.getLblFlipcard().setVisible(c.isDoubleFaced() ? true : false);
VDetail.SINGLETON_INSTANCE.getPnlDetail().setCard(c);
VDetail.SINGLETON_INSTANCE.getParentCell().repaintSelf();
}
/**
@@ -66,6 +71,14 @@ public enum CDetail implements ICDoc {
*/
@Override
public void initialize() {
VDetail.SINGLETON_INSTANCE.getPnlDetail().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
if (VDetail.SINGLETON_INSTANCE.getPnlDetail().getCard().isDoubleFaced()) {
CPicture.SINGLETON_INSTANCE.flipCard();
}
}
});
}
/* (non-Javadoc)

View File

@@ -16,7 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.gui.match.controllers;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import forge.Card;
import forge.CardCharactersticName;
import forge.Command;
import forge.gui.framework.ICDoc;
import forge.gui.match.views.VPicture;
@@ -31,6 +35,7 @@ public enum CPicture implements ICDoc {
SINGLETON_INSTANCE;
private Card currentCard = null;
private boolean flipped = false;
/**
* Shows card details and/or picture in sidebar cardview tabber.
@@ -40,6 +45,7 @@ public enum CPicture implements ICDoc {
*/
public void showCard(final Card c) {
this.currentCard = c;
VPicture.SINGLETON_INSTANCE.getLblFlipcard().setVisible(c.isDoubleFaced() ? true : false);
VPicture.SINGLETON_INSTANCE.getPnlPicture().setCard(c);
}
@@ -65,6 +71,14 @@ public enum CPicture implements ICDoc {
*/
@Override
public void initialize() {
VPicture.SINGLETON_INSTANCE.getPnlPicture().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
if (VPicture.SINGLETON_INSTANCE.getPnlPicture().getCard().isDoubleFaced()) {
flipCard();
}
}
});
}
/* (non-Javadoc)
@@ -73,4 +87,19 @@ public enum CPicture implements ICDoc {
@Override
public void update() {
}
/** */
public void flipCard() {
if (flipped) {
flipped = false;
VPicture.SINGLETON_INSTANCE.getPnlPicture().getCard().setState(CardCharactersticName.Original);
CDetail.SINGLETON_INSTANCE.showCard(this.currentCard);
}
else {
flipped = true;
VPicture.SINGLETON_INSTANCE.getPnlPicture().getCard().setState(CardCharactersticName.Transformed);
CDetail.SINGLETON_INSTANCE.showCard(this.currentCard);
}
VPicture.SINGLETON_INSTANCE.getPnlPicture().setImage();
}
}

View File

@@ -17,6 +17,8 @@
*/
package forge.gui.match.views;
import javax.swing.JLabel;
import net.miginfocom.swing.MigLayout;
import forge.gui.CardDetailPanel;
import forge.gui.framework.DragCell;
@@ -25,6 +27,7 @@ import forge.gui.framework.EDocID;
import forge.gui.framework.ICDoc;
import forge.gui.framework.IVDoc;
import forge.gui.match.controllers.CDetail;
import forge.gui.toolbox.FSkin;
/**
* Assembles Swing components of card detail area.
@@ -41,6 +44,8 @@ public enum VDetail implements IVDoc {
// Top-level containers
private final CardDetailPanel pnlDetail = new CardDetailPanel(null);
private final JLabel lblFlipcard = new JLabel(
FSkin.getIcon(FSkin.InterfaceIcons.ICO_FLIPCARD));
//========= Overridden methods
/* (non-Javadoc)
@@ -48,7 +53,8 @@ public enum VDetail implements IVDoc {
*/
@Override
public void populate() {
parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0"));
parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0, center"));
parentCell.getBody().add(lblFlipcard, "pos (50% - 40px) (50% - 60px)");
parentCell.getBody().add(pnlDetail, "w 100%!, h 100%!");
}
@@ -98,4 +104,9 @@ public enum VDetail implements IVDoc {
public CardDetailPanel getPnlDetail() {
return pnlDetail;
}
/** @return {@link javax.swing.JLabel} */
public JLabel getLblFlipcard() {
return lblFlipcard;
}
}

View File

@@ -17,6 +17,8 @@
*/
package forge.gui.match.views;
import javax.swing.JLabel;
import net.miginfocom.swing.MigLayout;
import forge.gui.CardPicturePanel;
import forge.gui.framework.DragCell;
@@ -25,6 +27,7 @@ import forge.gui.framework.EDocID;
import forge.gui.framework.ICDoc;
import forge.gui.framework.IVDoc;
import forge.gui.match.controllers.CPicture;
import forge.gui.toolbox.FSkin;
/**
* Assembles Swing components of card picture area.
@@ -41,10 +44,13 @@ public enum VPicture implements IVDoc {
// Top-level containers
private final CardPicturePanel pnlPicture = new CardPicturePanel(null);
private final JLabel lblFlipcard = new JLabel(
FSkin.getIcon(FSkin.InterfaceIcons.ICO_FLIPCARD));
//========= Constructor
private VPicture() {
pnlPicture.setOpaque(false);
lblFlipcard.setVisible(false);
}
//========== Overridden methods
@@ -55,6 +61,7 @@ public enum VPicture implements IVDoc {
@Override
public void populate() {
parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0, center"));
parentCell.getBody().add(lblFlipcard, "pos (50% - 40px) (50% - 60px)");
parentCell.getBody().add(pnlPicture, "w 100%!, h 100%!");
}
@@ -104,4 +111,9 @@ public enum VPicture implements IVDoc {
public CardPicturePanel getPnlPicture() {
return pnlPicture;
}
/** @return {@link javax.swing.JLabel} */
public JLabel getLblFlipcard() {
return lblFlipcard;
}
}

View File

@@ -273,6 +273,7 @@ public enum FSkin {
ICO_SAVEAS (new int[] {660, 580, 20, 20}), /** */
ICO_UNKNOWN (new int[] {0, 720, 80, 80}), /** */
ICO_LOGO (new int[] {480, 0, 200, 200}), /** */
ICO_FLIPCARD (new int[] {400, 0, 80, 120}), /** */
ICO_FAVICON (new int[] {0, 640, 80, 80});
private int[] coords;