checkstyle

This commit is contained in:
jendave
2011-10-26 22:08:28 +00:00
parent 082c821db8
commit 063c3e987e
24 changed files with 2089 additions and 967 deletions

View File

@@ -6,7 +6,7 @@ import forge.item.InventoryItem;
/** /**
* Base class for any cardView panel. * Base class for any cardView panel.
* *
*/ */
public abstract class CardPanelBase extends JPanel { public abstract class CardPanelBase extends JPanel {
private static final long serialVersionUID = -2230733670423143126L; private static final long serialVersionUID = -2230733670423143126L;
@@ -14,7 +14,9 @@ public abstract class CardPanelBase extends JPanel {
/** /**
* *
* showCard. * showCard.
* @param card an InventoryItem *
* @param card
* an InventoryItem
*/ */
public abstract void showCard(InventoryItem card); public abstract void showCard(InventoryItem card);

View File

@@ -10,10 +10,8 @@ import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import arcane.ui.CardPanel; import arcane.ui.CardPanel;
import arcane.ui.ViewPanel; import arcane.ui.ViewPanel;
import forge.Card; import forge.Card;
import forge.GuiDisplayUtil; import forge.GuiDisplayUtil;
import forge.ImagePreviewPanel; import forge.ImagePreviewPanel;
@@ -24,105 +22,121 @@ import forge.item.InventoryItem;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
/**
/** * This panel is to be placed in the right part of a deck editor.
* This panel is to be placed in the right part of a deck editor
*
*/ */
public class CardPanelHeavy extends CardPanelBase { public class CardPanelHeavy extends CardPanelBase {
private static final long serialVersionUID = -7134546689397508597L; private static final long serialVersionUID = -7134546689397508597L;
private JButton changeStateButton = new JButton(); private JButton changeStateButton = new JButton();
/* /*
* Removed Oct 25 2011 - Hellfish * Removed Oct 25 2011 - Hellfish private JButton changePictureButton = new
private JButton changePictureButton = new JButton(); * JButton(); private JButton removePictureButton = new JButton();
private JButton removePictureButton = new JButton();
*/ */
// Controls to show card details // Controls to show card details
/** The detail. */
protected CardDetailPanel detail = new CardDetailPanel(null); protected CardDetailPanel detail = new CardDetailPanel(null);
/** The picture. */
protected CardPanel picture = new CardPanel(null); protected CardPanel picture = new CardPanel(null);
/** The picture view panel. */
protected ViewPanel pictureViewPanel = new ViewPanel(); protected ViewPanel pictureViewPanel = new ViewPanel();
// fake card to allow picture changes // fake card to allow picture changes
/** The c card hq. */
public Card cCardHQ; public Card cCardHQ;
/** Constant <code>previousDirectory</code> */
/** Constant <code>previousDirectory</code>. */
protected static File previousDirectory = null; protected static File previousDirectory = null;
/**
* Instantiates a new card panel heavy.
*/
public CardPanelHeavy() { public CardPanelHeavy() {
changeStateButton.setVisible(false); changeStateButton.setVisible(false);
changeStateButton.addActionListener(new java.awt.event.ActionListener() { changeStateButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(final ActionEvent e) {
changeStateButton_actionPerformed(e); changeStateButton_actionPerformed(e);
} }
}); });
if (!Singletons.getModel().getPreferences().lafFonts) if (!Singletons.getModel().getPreferences().lafFonts) {
changeStateButton.setFont(new java.awt.Font("Dialog", 0, 10)); changeStateButton.setFont(new java.awt.Font("Dialog", 0, 10));
}
/* /*
* Removed Oct 25 2011 - Hellfish * Removed Oct 25 2011 - Hellfish
changePictureButton.setText("Change picture..."); * changePictureButton.setText("Change picture...");
changePictureButton.addActionListener(new java.awt.event.ActionListener() { * changePictureButton.addActionListener(new
public void actionPerformed(ActionEvent e) { * java.awt.event.ActionListener() { public void
changePictureButton_actionPerformed(e); * actionPerformed(ActionEvent e) {
} * changePictureButton_actionPerformed(e); } }); if
}); * (!Singletons.getModel().getPreferences().lafFonts)
if (!Singletons.getModel().getPreferences().lafFonts) * changePictureButton.setFont(new java.awt.Font("Dialog", 0, 10));
changePictureButton.setFont(new java.awt.Font("Dialog", 0, 10)); *
* removePictureButton.setText("Remove picture...");
removePictureButton.setText("Remove picture..."); * removePictureButton.addActionListener(new
removePictureButton.addActionListener(new java.awt.event.ActionListener() { * java.awt.event.ActionListener() { public void
public void actionPerformed(ActionEvent e) { * actionPerformed(ActionEvent e) {
removePictureButton_actionPerformed(e); * removePictureButton_actionPerformed(e); } }); if
} * (!Singletons.getModel().getPreferences().lafFonts)
}); * removePictureButton.setFont(new java.awt.Font("Dialog", 0, 10));
if (!Singletons.getModel().getPreferences().lafFonts)
removePictureButton.setFont(new java.awt.Font("Dialog", 0, 10));
*/ */
pictureViewPanel.setCardPanel(picture); pictureViewPanel.setCardPanel(picture);
this.setLayout(new MigLayout("fill, ins 0")); this.setLayout(new MigLayout("fill, ins 0"));
this.add(detail, "w 239, h 323, grow, flowy, wrap"); this.add(detail, "w 239, h 323, grow, flowy, wrap");
/* /*
* Removed Oct 25 2011 - Hellfish * Removed Oct 25 2011 - Hellfish this.add(changeStateButton,
this.add(changeStateButton, "align 50% 0%, split 3, flowx"); * "align 50% 0%, split 3, flowx"); this.add(changePictureButton,
this.add(changePictureButton, "align 50% 0%"); * "align 50% 0%"); this.add(removePictureButton, "align 50% 0%, wrap");
this.add(removePictureButton, "align 50% 0%, wrap");
*/ */
this.add(changeStateButton, "align 50% 0%, flowx, wrap"); this.add(changeStateButton, "align 50% 0%, flowx, wrap");
this.add(pictureViewPanel, "wmin 239, hmin 323, grow"); this.add(pictureViewPanel, "wmin 239, hmin 323, grow");
} }
public void showCard(InventoryItem card) { /*
* (non-Javadoc)
*
* @see
* forge.gui.deckeditor.CardPanelBase#showCard(forge.item.InventoryItem)
*/
public final void showCard(final InventoryItem card) {
Card card2 = card instanceof CardPrinted ? ((CardPrinted) card).toForgeCard() : null; Card card2 = card instanceof CardPrinted ? ((CardPrinted) card).toForgeCard() : null;
detail.setCard(card2); detail.setCard(card2);
setCard(card2); setCard(card2);
} }
public void setCard(Card c) {
if(picture.getCard() != null) { /**
if(picture.getCard().isInAlternateState()) { * Sets the card.
*
* @param c
* the new card
*/
public final void setCard(final Card c) {
if (picture.getCard() != null) {
if (picture.getCard().isInAlternateState()) {
picture.getCard().changeState(); picture.getCard().changeState();
} }
} }
picture.setCard(c); picture.setCard(c);
if(c.hasAlternateState()) { if (c.hasAlternateState()) {
changeStateButton.setVisible(true); changeStateButton.setVisible(true);
if(c.isFlip()) { if (c.isFlip()) {
changeStateButton.setText("Flip"); changeStateButton.setText("Flip");
} } else {
else {
changeStateButton.setText("Transform"); changeStateButton.setText("Transform");
} }
} } else {
else {
changeStateButton.setVisible(false); changeStateButton.setVisible(false);
} }
} }
/** /**
* <p> * <p>
* changeStateButton_actionPerformed. * changeStateButton_actionPerformed.
@@ -131,7 +145,7 @@ public class CardPanelHeavy extends CardPanelBase {
* @param e * @param e
* a {@link java.awt.event.ActionEvent} object. * a {@link java.awt.event.ActionEvent} object.
*/ */
void changeStateButton_actionPerformed(ActionEvent e) { final void changeStateButton_actionPerformed(final ActionEvent e) {
Card cur = picture.getCard(); Card cur = picture.getCard();
cur.changeState(); cur.changeState();
@@ -147,7 +161,7 @@ public class CardPanelHeavy extends CardPanelBase {
* @param e * @param e
* a {@link java.awt.event.ActionEvent} object. * a {@link java.awt.event.ActionEvent} object.
*/ */
void changePictureButton_actionPerformed(ActionEvent e) { final void changePictureButton_actionPerformed(final ActionEvent e) {
if (cCardHQ != null) { if (cCardHQ != null) {
File file = getImportFilename(); File file = getImportFilename();
if (file != null) { if (file != null) {
@@ -159,7 +173,8 @@ public class CardPanelHeavy extends CardPanelBase {
try { try {
org.apache.commons.io.FileUtils.copyFile(file, f); org.apache.commons.io.FileUtils.copyFile(file, f);
} catch (IOException e1) { } catch (IOException e1) {
// TODO Auto-generated catch block ignores the exception, but sends it to System.err and probably forge.log. // TODO Auto-generated catch block ignores the exception,
// but sends it to System.err and probably forge.log.
e1.printStackTrace(); e1.printStackTrace();
} }
setCard(cCardHQ); setCard(cCardHQ);
@@ -192,10 +207,11 @@ public class CardPanelHeavy extends CardPanelBase {
} }
/** The dck filter. */
protected FileFilter dckFilter = new FileFilter() { protected FileFilter dckFilter = new FileFilter() {
@Override @Override
public boolean accept(File f) { public boolean accept(final File f) {
return f.getName().endsWith(".jpg") || f.isDirectory(); return f.getName().endsWith(".jpg") || f.isDirectory();
} }
@@ -207,11 +223,15 @@ public class CardPanelHeavy extends CardPanelBase {
}; };
/** /**
* <p>
* removePictureButton_actionPerformed
* </p>
* . Removed Oct 25 2011 - Hellfish
* *
* <p>removePictureButton_actionPerformed</p>. Removed Oct 25 2011 - Hellfish
* @param e * @param e
* the e
*/ */
void removePictureButton_actionPerformed(ActionEvent e) { final void removePictureButton_actionPerformed(final ActionEvent e) {
if (cCardHQ != null) { if (cCardHQ != null) {
String options[] = { "Yes", "No" }; String options[] = { "Yes", "No" };
int value = JOptionPane.showOptionDialog(null, "Do you want delete " + cCardHQ.getName() + " picture?", int value = JOptionPane.showOptionDialog(null, "Do you want delete " + cCardHQ.getName() + " picture?",
@@ -229,6 +249,13 @@ public class CardPanelHeavy extends CardPanelBase {
} }
} }
public Card getCard() { return detail.getCard(); } /**
* Gets the card.
*
* @return the card
*/
public final Card getCard() {
return detail.getCard();
}
} }

View File

@@ -6,7 +6,6 @@ import java.awt.event.ActionListener;
import javax.swing.JButton; import javax.swing.JButton;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import forge.Card; import forge.Card;
import forge.Singletons; import forge.Singletons;
import forge.gui.game.CardDetailPanel; import forge.gui.game.CardDetailPanel;
@@ -23,6 +22,7 @@ public class CardPanelLite extends CardPanelBase {
private static final long serialVersionUID = -7134546689397508597L; private static final long serialVersionUID = -7134546689397508597L;
// Controls to show card details // Controls to show card details
/** The detail. */
protected CardDetailPanel detail = new CardDetailPanel(null); protected CardDetailPanel detail = new CardDetailPanel(null);
private CardPicturePanel picture = new CardPicturePanel(null); private CardPicturePanel picture = new CardPicturePanel(null);
private JButton bChangeState = new JButton(); private JButton bChangeState = new JButton();
@@ -34,13 +34,14 @@ public class CardPanelLite extends CardPanelBase {
public CardPanelLite() { public CardPanelLite() {
bChangeState.setVisible(false); bChangeState.setVisible(false);
bChangeState.addActionListener(new ActionListener() { bChangeState.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(final ActionEvent e) {
bChangeState_actionPerformed(e); bChangeState_actionPerformed(e);
} }
}); });
if (!Singletons.getModel().getPreferences().lafFonts) if (!Singletons.getModel().getPreferences().lafFonts) {
bChangeState.setFont(new java.awt.Font("Dialog", 0, 10)); bChangeState.setFont(new java.awt.Font("Dialog", 0, 10));
}
this.setLayout(new MigLayout("fill, ins 0")); this.setLayout(new MigLayout("fill, ins 0"));
this.add(detail, "w 239, h 303, grow, flowy, wrap"); this.add(detail, "w 239, h 303, grow, flowy, wrap");
this.add(bChangeState, "align 50% 0%, wrap"); this.add(bChangeState, "align 50% 0%, wrap");
@@ -58,32 +59,36 @@ public class CardPanelLite extends CardPanelBase {
picture.setCard(card); picture.setCard(card);
boolean isCard = card != null && card instanceof CardPrinted; boolean isCard = card != null && card instanceof CardPrinted;
detail.setVisible(isCard); detail.setVisible(isCard);
if (isCard) { if (isCard) {
Card toSet = ((CardPrinted) card).toForgeCard(); Card toSet = ((CardPrinted) card).toForgeCard();
detail.setCard(toSet); detail.setCard(toSet);
if(toSet.hasAlternateState()) { if (toSet.hasAlternateState()) {
bChangeState.setVisible(true); bChangeState.setVisible(true);
if(toSet.isFlip()) { if (toSet.isFlip()) {
bChangeState.setText("Flip"); bChangeState.setText("Flip");
} } else {
else {
bChangeState.setText("Transform"); bChangeState.setText("Transform");
} }
} }
} }
} }
public void setCard(Card c) { /**
* Sets the card.
*
* @param c
* the new card
*/
public final void setCard(final Card c) {
picture.setCard(c); picture.setCard(c);
if(c != null) { if (c != null) {
detail.setCard(c); detail.setCard(c);
if(c.hasAlternateState()) { if (c.hasAlternateState()) {
bChangeState.setVisible(true); bChangeState.setVisible(true);
if(c.isFlip()) { if (c.isFlip()) {
bChangeState.setText("Flip"); bChangeState.setText("Flip");
} } else {
else {
bChangeState.setText("Transform"); bChangeState.setText("Transform");
} }
} }
@@ -99,12 +104,12 @@ public class CardPanelLite extends CardPanelBase {
public final Card getCard() { public final Card getCard() {
return detail.getCard(); return detail.getCard();
} }
private void bChangeState_actionPerformed(ActionEvent e) { private void bChangeState_actionPerformed(final ActionEvent e) {
Card cur = detail.getCard(); Card cur = detail.getCard();
if(cur != null) { if (cur != null) {
cur.changeState(); cur.changeState();
setCard(cur); setCard(cur);
} }
} }

View File

@@ -7,8 +7,7 @@ import javax.swing.ImageIcon;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
/** /**
* Custom check box class for filter icon * Custom check box class for filter icon.
*
*/ */
public class CheckBoxWithIcon extends JCheckBox { public class CheckBoxWithIcon extends JCheckBox {
/* CHOPPIC */ /* CHOPPIC */
@@ -20,7 +19,15 @@ public class CheckBoxWithIcon extends JCheckBox {
private String iconNo; private String iconNo;
private CheckBoxWithIcon cb; private CheckBoxWithIcon cb;
CheckBoxWithIcon(String filterName, String toolTip) { /**
* Instantiates a new check box with icon.
*
* @param filterName
* the filter name
* @param toolTip
* the tool tip
*/
CheckBoxWithIcon(final String filterName, final String toolTip) {
super("", true); super("", true);
cb = this; cb = this;
iconYes = imagePath + "filter_" + filterName + "_y.png"; iconYes = imagePath + "filter_" + filterName + "_y.png";
@@ -28,7 +35,7 @@ public class CheckBoxWithIcon extends JCheckBox {
this.setIcon(new ImageIcon(iconYes)); this.setIcon(new ImageIcon(iconYes));
this.setToolTipText(toolTip); this.setToolTipText(toolTip);
this.addActionListener(new ActionListener() { this.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
if (cb.isSelected()) { if (cb.isSelected()) {
cb.setIcon(new ImageIcon(iconYes)); cb.setIcon(new ImageIcon(iconYes));
} else { } else {

View File

@@ -28,6 +28,7 @@ import javax.swing.border.BevelBorder;
import javax.swing.event.MouseInputAdapter; import javax.swing.event.MouseInputAdapter;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import net.miginfocom.swing.MigLayout;
import forge.CardList; import forge.CardList;
import forge.MyRandom; import forge.MyRandom;
import forge.card.CardRules; import forge.card.CardRules;
@@ -35,8 +36,6 @@ import forge.card.CardType;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
import net.miginfocom.swing.MigLayout;
/** /**
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
* Builder, which is free for non-commercial use. If Jigloo is being used * Builder, which is free for non-commercial use. If Jigloo is being used
@@ -99,7 +98,10 @@ public class DeckAnalysis extends javax.swing.JDialog {
private JFrame jF; private JFrame jF;
// private ButtonGroup buttonGroup1; // private ButtonGroup buttonGroup1;
/** The filter card list. */
public CardList filterCardList; public CardList filterCardList;
/** The deck. */
public ItemPoolView<CardPrinted> deck; public ItemPoolView<CardPrinted> deck;
/** /**
@@ -109,10 +111,10 @@ public class DeckAnalysis extends javax.swing.JDialog {
* *
* @param g * @param g
* a {@link javax.swing.JFrame} object. * a {@link javax.swing.JFrame} object.
* @param tb * @param deckView
* a {@link forge.gui.deckeditor.TableModel} object. * the deck view
*/ */
public DeckAnalysis(JFrame g, ItemPoolView<CardPrinted> deckView) { public DeckAnalysis(final JFrame g, final ItemPoolView<CardPrinted> deckView) {
super(g); super(g);
deck = deckView; deck = deckView;
@@ -145,12 +147,12 @@ public class DeckAnalysis extends javax.swing.JDialog {
this.addWindowListener(new WindowAdapter() { this.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing(WindowEvent arg0) { public void windowClosing(final WindowEvent arg0) {
jF.setEnabled(true); jF.setEnabled(true);
} }
@Override @Override
public void windowOpened(WindowEvent arg0) { public void windowOpened(final WindowEvent arg0) {
int cBlack, cBlue, cGreen, cRed, cWhite, cMulticolor, cColorless, cLand; int cBlack, cBlue, cGreen, cRed, cWhite, cMulticolor, cColorless, cLand;
int cArtifact, cCreature, cEnchant, cInstant, cLandType, cPlaneswalker, cSorcery; int cArtifact, cCreature, cEnchant, cInstant, cLandType, cPlaneswalker, cSorcery;
@@ -188,36 +190,69 @@ public class DeckAnalysis extends javax.swing.JDialog {
if (c.getColor().isMulticolor()) { if (c.getColor().isMulticolor()) {
cMulticolor = cMulticolor + cnt; cMulticolor = cMulticolor + cnt;
} else { } else {
if (c.getColor().isBlack()) { cBlack = cBlack + cnt; } if (c.getColor().isBlack()) {
if (c.getColor().isBlue()) { cBlue = cBlue + cnt; } cBlack = cBlack + cnt;
if (c.getColor().isGreen()) { cGreen = cGreen + cnt; } }
if (c.getColor().isRed()) { cRed = cRed + cnt; } if (c.getColor().isBlue()) {
if (c.getColor().isWhite()) { cWhite = cWhite + cnt; } cBlue = cBlue + cnt;
}
if (c.getColor().isGreen()) {
cGreen = cGreen + cnt;
}
if (c.getColor().isRed()) {
cRed = cRed + cnt;
}
if (c.getColor().isWhite()) {
cWhite = cWhite + cnt;
}
if (c.getColor().isColorless()) { if (c.getColor().isColorless()) {
if (c.getType().isLand()) { cLand = cLand + cnt; } if (c.getType().isLand()) {
else { cColorless = cColorless + cnt; } cLand = cLand + cnt;
} else {
cColorless = cColorless + cnt;
}
} }
} }
// count card types // count card types
CardType cType = c.getType(); CardType cType = c.getType();
if (cType.isArtifact()) { cArtifact = cArtifact + cnt; } if (cType.isArtifact()) {
if (cType.isCreature()) { cCreature = cCreature + cnt; } cArtifact = cArtifact + cnt;
if (cType.isEnchantment()) { cEnchant = cEnchant + cnt; } }
if (cType.isInstant()) { cInstant = cInstant + cnt; } if (cType.isCreature()) {
if (cType.isLand()) { cLandType = cLandType + cnt; } cCreature = cCreature + cnt;
if (cType.isPlaneswalker()) { cPlaneswalker = cPlaneswalker + cnt; } }
if (cType.isSorcery()) { cSorcery = cSorcery + cnt; } if (cType.isEnchantment()) {
cEnchant = cEnchant + cnt;
}
if (cType.isInstant()) {
cInstant = cInstant + cnt;
}
if (cType.isLand()) {
cLandType = cLandType + cnt;
}
if (cType.isPlaneswalker()) {
cPlaneswalker = cPlaneswalker + cnt;
}
if (cType.isSorcery()) {
cSorcery = cSorcery + cnt;
}
int cmc = c.getManaCost().getCMC(); int cmc = c.getManaCost().getCMC();
if (cmc == 0) { mZero = mZero + cnt; if (cmc == 0) {
} else if (cmc == 1) { mOne = mOne + cnt; mZero = mZero + cnt;
} else if (cmc == 2) { mTwo = mTwo + cnt; } else if (cmc == 1) {
} else if (cmc == 3) { mThree = mThree + cnt; mOne = mOne + cnt;
} else if (cmc == 4) { mFour = mFour + cnt; } else if (cmc == 2) {
} else if (cmc == 5) { mFive = mFive + 1; mTwo = mTwo + cnt;
} else if (cmc >= 6) { mSixMore = mSixMore + 1; } else if (cmc == 3) {
mThree = mThree + cnt;
} else if (cmc == 4) {
mFour = mFour + cnt;
} else if (cmc == 5) {
mFive = mFive + 1;
} else if (cmc >= 6) {
mSixMore = mSixMore + 1;
} }
tManaCost = tManaCost + cmc * cnt; tManaCost = tManaCost + cmc * cnt;
@@ -230,51 +265,95 @@ public class DeckAnalysis extends javax.swing.JDialog {
jLabelManaCost.setText("Mana cost (ACC:" + aManaCost + ")"); jLabelManaCost.setText("Mana cost (ACC:" + aManaCost + ")");
Color cr = new Color(100, 100, 100); Color cr = new Color(100, 100, 100);
if (cBlack == 0) { jLabelBlack.setForeground(cr); } if (cBlack == 0) {
jLabelBlack.setForeground(cr);
}
jLabelBlack.setText(formatStat("Black", cBlack, total)); jLabelBlack.setText(formatStat("Black", cBlack, total));
if (cBlue == 0) { jLabelBlue.setForeground(cr); } if (cBlue == 0) {
jLabelBlue.setForeground(cr);
}
jLabelBlue.setText(formatStat("Blue", cBlue, total)); jLabelBlue.setText(formatStat("Blue", cBlue, total));
if (cGreen == 0) { jLabelGreen.setForeground(cr); } if (cGreen == 0) {
jLabelGreen.setForeground(cr);
}
jLabelGreen.setText(formatStat("Green", cGreen, total)); jLabelGreen.setText(formatStat("Green", cGreen, total));
if (cRed == 0) { jLabelRed.setForeground(cr); } if (cRed == 0) {
jLabelRed.setForeground(cr);
}
jLabelRed.setText(formatStat("Red", cRed, total)); jLabelRed.setText(formatStat("Red", cRed, total));
if (cWhite == 0) { jLabelWhite.setForeground(cr); } if (cWhite == 0) {
jLabelWhite.setForeground(cr);
}
jLabelWhite.setText(formatStat("White", cWhite, total)); jLabelWhite.setText(formatStat("White", cWhite, total));
if (cMulticolor == 0) { jLabelMultiColor.setForeground(cr); } if (cMulticolor == 0) {
jLabelMultiColor.setForeground(cr);
}
jLabelMultiColor.setText(formatStat("Multicolor", cMulticolor, total)); jLabelMultiColor.setText(formatStat("Multicolor", cMulticolor, total));
if (cColorless == 0) { jLabelColorless.setForeground(cr); } if (cColorless == 0) {
jLabelColorless.setForeground(cr);
}
jLabelColorless.setText(formatStat("Colorless", cColorless, total)); jLabelColorless.setText(formatStat("Colorless", cColorless, total));
if (cLand == 0) { jLabelLand.setForeground(cr); } if (cLand == 0) {
jLabelLand.setForeground(cr);
}
jLabelLand.setText(formatStat("Land", cLand, total)); jLabelLand.setText(formatStat("Land", cLand, total));
if (cArtifact == 0) { jLabelArtifact.setForeground(cr); } if (cArtifact == 0) {
jLabelArtifact.setForeground(cr);
}
jLabelArtifact.setText(formatStat("Artifact", cArtifact, total)); jLabelArtifact.setText(formatStat("Artifact", cArtifact, total));
if (cCreature == 0) { jLabelCreature.setForeground(cr); } if (cCreature == 0) {
jLabelCreature.setForeground(cr);
}
jLabelCreature.setText(formatStat("Creature", cCreature, total)); jLabelCreature.setText(formatStat("Creature", cCreature, total));
if (cEnchant == 0) { jLabelEnchant.setForeground(cr); } if (cEnchant == 0) {
jLabelEnchant.setForeground(cr);
}
jLabelEnchant.setText(formatStat("Enchant", cEnchant, total)); jLabelEnchant.setText(formatStat("Enchant", cEnchant, total));
if (cInstant == 0) { jLabelInstant.setForeground(cr); } if (cInstant == 0) {
jLabelInstant.setForeground(cr);
}
jLabelInstant.setText(formatStat("Instant", cInstant, total)); jLabelInstant.setText(formatStat("Instant", cInstant, total));
if (cLandType == 0) { jLabelLandType.setForeground(cr); } if (cLandType == 0) {
jLabelLandType.setForeground(cr);
}
jLabelLandType.setText(formatStat("Land", cLandType, total)); jLabelLandType.setText(formatStat("Land", cLandType, total));
if (cPlaneswalker == 0) { jLabelPlaneswalker.setForeground(cr); } if (cPlaneswalker == 0) {
jLabelPlaneswalker.setForeground(cr);
}
jLabelPlaneswalker.setText(formatStat("Planeswalker", cPlaneswalker, total)); jLabelPlaneswalker.setText(formatStat("Planeswalker", cPlaneswalker, total));
if (cSorcery == 0) { jLabelSorcery.setForeground(cr); } if (cSorcery == 0) {
jLabelSorcery.setForeground(cr);
}
jLabelSorcery.setText(formatStat("Sorcery", cSorcery, total)); jLabelSorcery.setText(formatStat("Sorcery", cSorcery, total));
if (mZero == 0) { jLabelZeroMana.setForeground(cr); } if (mZero == 0) {
jLabelZeroMana.setForeground(cr);
}
jLabelZeroMana.setText(formatStat("Zero mana", mZero, total)); jLabelZeroMana.setText(formatStat("Zero mana", mZero, total));
if (mOne == 0) { jLabelOneMana.setForeground(cr); } if (mOne == 0) {
jLabelOneMana.setForeground(cr);
}
jLabelOneMana.setText(formatStat("One mana", mOne, total)); jLabelOneMana.setText(formatStat("One mana", mOne, total));
if (mTwo == 0) { jLabelTwoMana.setForeground(cr); } if (mTwo == 0) {
jLabelTwoMana.setForeground(cr);
}
jLabelTwoMana.setText(formatStat("Two mana", mTwo, total)); jLabelTwoMana.setText(formatStat("Two mana", mTwo, total));
if (mThree == 0) { jLabelThreeMana.setForeground(cr); } if (mThree == 0) {
jLabelThreeMana.setForeground(cr);
}
jLabelThreeMana.setText(formatStat("Three mana", mThree, total)); jLabelThreeMana.setText(formatStat("Three mana", mThree, total));
if (mFour == 0) { jLabelFourMana.setForeground(cr); } if (mFour == 0) {
jLabelFourMana.setForeground(cr);
}
jLabelFourMana.setText(formatStat("Four mana", mFour, total)); jLabelFourMana.setText(formatStat("Four mana", mFour, total));
if (mFive == 0) { jLabelFiveMana.setForeground(cr); } if (mFive == 0) {
jLabelFiveMana.setForeground(cr);
}
jLabelFiveMana.setText(formatStat("Five mana", mFive, total)); jLabelFiveMana.setText(formatStat("Five mana", mFive, total));
if (mSixMore == 0) { jLabelSixMana.setForeground(cr); } if (mSixMore == 0) {
jLabelSixMana.setForeground(cr);
}
jLabelSixMana.setText(formatStat("Six and more", mSixMore, total)); jLabelSixMana.setText(formatStat("Six and more", mSixMore, total));
} }
}); });
@@ -293,9 +372,8 @@ public class DeckAnalysis extends javax.swing.JDialog {
e.printStackTrace(); e.printStackTrace();
} }
} }
private String formatStat(String statName, int value, int deckSize ) private String formatStat(final String statName, final int value, final int deckSize) {
{
return String.format("%s: %d (%f%%)", statName, value, 100f * value / deckSize); return String.format("%s: %d (%f%%)", statName, value, 100f * value / deckSize);
} }
@@ -380,7 +458,7 @@ public class DeckAnalysis extends javax.swing.JDialog {
jButtonOk.setBounds(206, 536, 168, 31); jButtonOk.setBounds(206, 536, 168, 31);
jButtonOk.addMouseListener(new MouseInputAdapter() { jButtonOk.addMouseListener(new MouseInputAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(final MouseEvent e) {
jF.setEnabled(true); jF.setEnabled(true);
dispose(); dispose();
} }
@@ -929,12 +1007,12 @@ public class DeckAnalysis extends javax.swing.JDialog {
if (jListFirstHand == null) { if (jListFirstHand == null) {
jListFirstHand = new JList(); jListFirstHand = new JList();
} }
if (rList.size() >= 40) { if (rList.size() >= 40) {
jList1Model = new DefaultComboBoxModel(new String[] { rList.get(0).getName(), jList1Model = new DefaultComboBoxModel(new String[] { rList.get(0).getName(), rList.get(1).getName(),
rList.get(1).getName(), rList.get(2).getName(), rList.get(3).getName(), rList.get(2).getName(), rList.get(3).getName(), rList.get(4).getName(), rList.get(5).getName(),
rList.get(4).getName(), rList.get(5).getName(), rList.get(6).getName() }); rList.get(6).getName() });
} else { } else {
jList1Model = new DefaultComboBoxModel(new String[] { "Few cards." }); jList1Model = new DefaultComboBoxModel(new String[] { "Few cards." });
} }
@@ -1038,7 +1116,7 @@ public class DeckAnalysis extends javax.swing.JDialog {
jButtonRegenerate.setPreferredSize(new java.awt.Dimension(139, 21)); jButtonRegenerate.setPreferredSize(new java.awt.Dimension(139, 21));
jButtonRegenerate.setBounds(2, 189, 133, 13); jButtonRegenerate.setBounds(2, 189, 133, 13);
jButtonRegenerate.addActionListener(new java.awt.event.ActionListener() { jButtonRegenerate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(final ActionEvent e) {
jButtonRegenerate_actionPerformed(e); jButtonRegenerate_actionPerformed(e);
} }
}); });
@@ -1059,7 +1137,7 @@ public class DeckAnalysis extends javax.swing.JDialog {
* @param e * @param e
* a {@link java.awt.event.ActionEvent} object. * a {@link java.awt.event.ActionEvent} object.
*/ */
void jButtonRegenerate_actionPerformed(ActionEvent e) { final void jButtonRegenerate_actionPerformed(final ActionEvent e) {
getContentPane().removeAll(); getContentPane().removeAll();
getContentPane().add(getJPanel5()); getContentPane().add(getJPanel5());
getContentPane().add(getJLabel1xx()); getContentPane().add(getJLabel1xx());

View File

@@ -7,10 +7,8 @@ import forge.item.InventoryItem;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
/** /**
* Created by IntelliJ IDEA. * Created by IntelliJ IDEA. User: dhudson Date: 6/24/11
* User: dhudson *
* Date: 6/24/11
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
@@ -18,27 +16,37 @@ public interface DeckDisplay {
/** /**
* *
* setDeck. * setDeck.
* @param top ItemPoolView<CardPrinted> *
* @param bottom ItemPoolView<CardPrinted> * @param top
* @param gameType GameType * ItemPoolView<CardPrinted>
* @param bottom
* ItemPoolView<CardPrinted>
* @param gameType
* GameType
*/ */
void setDeck(ItemPoolView<CardPrinted> top, ItemPoolView<CardPrinted> bottom, GameType gameType); void setDeck(ItemPoolView<CardPrinted> top, ItemPoolView<CardPrinted> bottom, GameType gameType);
/** /**
* *
* setItems. * setItems.
* @param <T> InventoryItem *
* @param topParam ItemPoolView<T> * @param <T>
* @param bottomParam ItemPoolView<T> * InventoryItem
* @param gt GameType * @param topParam
* ItemPoolView<T>
* @param bottomParam
* ItemPoolView<T>
* @param gt
* GameType
*/ */
<T extends InventoryItem> void setItems(ItemPoolView<T> topParam, ItemPoolView<T> bottomParam, GameType gt); <T extends InventoryItem> void setItems(ItemPoolView<T> topParam, ItemPoolView<T> bottomParam, GameType gt);
/** /**
* *
* Top shows available card pool. * Top shows available card pool. if constructed, top shows all cards if
* if constructed, top shows all cards * sealed, top shows 5 booster packs if draft, top shows cards that were
* if sealed, top shows 5 booster packs * chosen
* if draft, top shows cards that were chosen *
* @return ItemPoolView<InventoryItem> * @return ItemPoolView<InventoryItem>
*/ */
ItemPoolView<InventoryItem> getTop(); ItemPoolView<InventoryItem> getTop();
@@ -47,6 +55,7 @@ public interface DeckDisplay {
/** /**
* *
* Bottom shows cards that the user has chosen for his library. * Bottom shows cards that the user has chosen for his library.
*
* @return ItemPoolView<InventoryItem> * @return ItemPoolView<InventoryItem>
*/ */
ItemPoolView<InventoryItem> getBottom(); ItemPoolView<InventoryItem> getBottom();
@@ -54,19 +63,24 @@ public interface DeckDisplay {
/** /**
* *
* Set title. * Set title.
* @param message String *
* @param message
* String
*/ */
void setTitle(String message); void setTitle(String message);
/** /**
* *
* Get deck. * Get deck.
*
* @return Deck * @return Deck
*/ */
Deck getDeck(); Deck getDeck();
/** /**
* *
* Get game type. * Get game type.
*
* @return GameType * @return GameType
*/ */
GameType getGameType(); GameType getGameType();

View File

@@ -10,7 +10,6 @@ import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import net.slightlymagic.maxmtg.Predicate; import net.slightlymagic.maxmtg.Predicate;
import forge.deck.Deck; import forge.deck.Deck;
import forge.game.GameType; import forge.game.GameType;
import forge.item.CardPrinted; import forge.item.CardPrinted;
@@ -18,39 +17,90 @@ import forge.item.InventoryItem;
import forge.item.ItemPool; import forge.item.ItemPool;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
public abstract class DeckEditorBase extends JFrame implements DeckDisplay { /**
* The Class DeckEditorBase.
*/
public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
private static final long serialVersionUID = -401223933343539977L; private static final long serialVersionUID = -401223933343539977L;
/** The filter boxes. */
protected FilterCheckBoxes filterBoxes; protected FilterCheckBoxes filterBoxes;
// set this to false when resetting filter from code (like "clearFiltersPressed"), reset when done. // set this to false when resetting filter from code (like
// "clearFiltersPressed"), reset when done.
/** The is filters change firing update. */
protected boolean isFiltersChangeFiringUpdate = true; protected boolean isFiltersChangeFiringUpdate = true;
/** The card view. */
protected CardPanelBase cardView; protected CardPanelBase cardView;
// CardPools and Table data for top and bottom lists // CardPools and Table data for top and bottom lists
/** The top. */
protected TableWithCards top; protected TableWithCards top;
/** The bottom. */
protected TableWithCards bottom; protected TableWithCards bottom;
private GameType gameType; private GameType gameType;
public GameType getGameType() { return gameType; }
/*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckDisplay#getGameType()
*/
public final GameType getGameType() {
return gameType;
}
// top shows available card pool // top shows available card pool
// if constructed, top shows all cards // if constructed, top shows all cards
// if sealed, top shows N booster packs // if sealed, top shows N booster packs
// if draft, top shows cards that were chosen // if draft, top shows cards that were chosen
public final TableWithCards getTopTableModel() { return top; } /**
public final ItemPoolView<InventoryItem> getTop() { return top.getCards(); } * Gets the top table model.
*
* @return the top table model
*/
public final TableWithCards getTopTableModel() {
return top;
}
/*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckDisplay#getTop()
*/
public final ItemPoolView<InventoryItem> getTop() {
return top.getCards();
}
// bottom shows player's choice - be it deck or draft // bottom shows player's choice - be it deck or draft
public final ItemPoolView<InventoryItem> getBottom() { return bottom.getCards(); } /*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckDisplay#getBottom()
*/
public final ItemPoolView<InventoryItem> getBottom() {
return bottom.getCards();
}
// THIS IS HERE FOR OVERLOADING!!!1 // THIS IS HERE FOR OVERLOADING!!!1
// or may be return abstract getFilter from derived class + this filter ... virtual protected member, but later // or may be return abstract getFilter from derived class + this filter ...
// virtual protected member, but later
/**
* Builds the filter.
*
* @return the predicate
*/
protected abstract Predicate<InventoryItem> buildFilter(); protected abstract Predicate<InventoryItem> buildFilter();
void analysisButton_actionPerformed(ActionEvent e) { /**
ItemPoolView<CardPrinted> deck = ItemPool.createFrom(bottom.getCards(), CardPrinted.class); * Analysis button_action performed.
*
* @param e
* the e
*/
final void analysisButton_actionPerformed(final ActionEvent e) {
ItemPoolView<CardPrinted> deck = ItemPool.createFrom(bottom.getCards(), CardPrinted.class);
if (deck.isEmpty()) { if (deck.isEmpty()) {
JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck", JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck",
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
@@ -62,50 +112,119 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
} }
} }
public DeckEditorBase(GameType gametype) /**
{ * Instantiates a new deck editor base.
*
* @param gametype
* the gametype
*/
public DeckEditorBase(final GameType gametype) {
gameType = gametype; gameType = gametype;
} }
public void setDeck(ItemPoolView<CardPrinted> topParam, ItemPoolView<CardPrinted> bottomParam, GameType gt) { /*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckDisplay#setDeck(forge.item.ItemPoolView,
* forge.item.ItemPoolView, forge.game.GameType)
*/
public void setDeck(final ItemPoolView<CardPrinted> topParam, final ItemPoolView<CardPrinted> bottomParam,
final GameType gt) {
gameType = gt; gameType = gt;
top.setDeck(topParam); top.setDeck(topParam);
bottom.setDeck(bottomParam); bottom.setDeck(bottomParam);
} }
public <T extends InventoryItem> void setItems(ItemPoolView<T> topParam, ItemPoolView<T> bottomParam, GameType gt) { /*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckDisplay#setItems(forge.item.ItemPoolView,
* forge.item.ItemPoolView, forge.game.GameType)
*/
public final <T extends InventoryItem> void setItems(final ItemPoolView<T> topParam,
final ItemPoolView<T> bottomParam, final GameType gt) {
gameType = gt; gameType = gt;
top.setDeck(topParam); top.setDeck(topParam);
bottom.setDeck(bottomParam); bottom.setDeck(bottomParam);
} }
public void updateDisplay() { /**
* Update display.
*/
public final void updateDisplay() {
top.setFilter(buildFilter()); top.setFilter(buildFilter());
} }
/** The item listener updates display. */
protected ItemListener itemListenerUpdatesDisplay = new ItemListener() { protected ItemListener itemListenerUpdatesDisplay = new ItemListener() {
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(final ItemEvent e) {
if (isFiltersChangeFiringUpdate) { updateDisplay(); } if (isFiltersChangeFiringUpdate) {
updateDisplay();
}
} }
}; };
/** This class is used for a feature: when you start typing card name, the list gets auto-filtered. */ /**
* This class is used for a feature: when you start typing card name, the
* list gets auto-filtered.
*/
protected class OnChangeTextUpdateDisplay implements DocumentListener { protected class OnChangeTextUpdateDisplay implements DocumentListener {
private void onChange() { if (isFiltersChangeFiringUpdate) { updateDisplay(); } } private void onChange() {
@Override public void insertUpdate(DocumentEvent e) { onChange(); } if (isFiltersChangeFiringUpdate) {
@Override public void removeUpdate(DocumentEvent e) { onChange(); } updateDisplay();
@Override public void changedUpdate(DocumentEvent e) { } // Happend only on ENTER pressed }
}
/*
* (non-Javadoc)
*
* @see
* javax.swing.event.DocumentListener#insertUpdate(javax.swing.event
* .DocumentEvent)
*/
@Override
public final void insertUpdate(final DocumentEvent e) {
onChange();
}
/*
* (non-Javadoc)
*
* @see
* javax.swing.event.DocumentListener#removeUpdate(javax.swing.event
* .DocumentEvent)
*/
@Override
public final void removeUpdate(final DocumentEvent e) {
onChange();
}
/*
* (non-Javadoc)
*
* @see
* javax.swing.event.DocumentListener#changedUpdate(javax.swing.event
* .DocumentEvent)
*/
@Override
public void changedUpdate(final DocumentEvent e) {
} // Happend only on ENTER pressed
} }
public Deck getDeck() { /*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckDisplay#getDeck()
*/
public final Deck getDeck() {
Deck deck = new Deck(gameType); Deck deck = new Deck(gameType);
deck.addMain(ItemPool.createFrom(getBottom(), CardPrinted.class)); deck.addMain(ItemPool.createFrom(getBottom(), CardPrinted.class));
//if sealed or draft, move "top" to sideboard // if sealed or draft, move "top" to sideboard
if (gameType.isLimited() && gameType != GameType.Quest) { if (gameType.isLimited() && gameType != GameType.Quest) {
deck.addSideboard(ItemPool.createFrom(getTop(), CardPrinted.class)); deck.addSideboard(ItemPool.createFrom(getTop(), CardPrinted.class));
} }
return deck; return deck;
}//getDeck() }// getDeck()
} }

View File

@@ -1,9 +1,9 @@
package forge.gui.deckeditor; package forge.gui.deckeditor;
import java.awt.Container; import java.awt.Container;
import java.awt.Dialog.ModalityType;
import java.awt.Font; import java.awt.Font;
import java.awt.Frame; import java.awt.Frame;
import java.awt.Dialog.ModalityType;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
@@ -17,6 +17,7 @@ import java.util.List;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JLabel; import javax.swing.JLabel;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.slightlymagic.maxmtg.Predicate; import net.slightlymagic.maxmtg.Predicate;
import forge.AllZone; import forge.AllZone;
@@ -42,18 +43,25 @@ public final class DeckEditorCommon extends DeckEditorBase {
/** Constant <code>serialVersionUID=130339644136746796L</code> */ /** Constant <code>serialVersionUID=130339644136746796L</code> */
private static final long serialVersionUID = 130339644136746796L; private static final long serialVersionUID = 130339644136746796L;
/** The custom menu. */
public DeckEditorCommonMenu customMenu; public DeckEditorCommonMenu customMenu;
private JButton removeButton = new JButton(); private JButton removeButton = new JButton();
private JButton addButton = new JButton(); private JButton addButton = new JButton();
private JButton importButton = new JButton(); private JButton importButton = new JButton();
private JButton analysisButton = new JButton(); private JButton analysisButton = new JButton();
private JButton clearFilterButton = new JButton(); private JButton clearFilterButton = new JButton();
private JLabel jLabelAnalysisGap = new JLabel(""); private JLabel jLabelAnalysisGap = new JLabel("");
private FilterNameTypeSetPanel filterNameTypeSet; private FilterNameTypeSetPanel filterNameTypeSet;
/**
* Show.
*
* @param exitCommand
* the exit command
*/
public void show(final Command exitCommand) { public void show(final Command exitCommand) {
final Command exit = new Command() { final Command exit = new Command() {
private static final long serialVersionUID = 5210924838133689758L; private static final long serialVersionUID = 5210924838133689758L;
@@ -77,8 +85,6 @@ public final class DeckEditorCommon extends DeckEditorBase {
setup(); setup();
// show cards, makes this user friendly // show cards, makes this user friendly
if (!getGameType().isLimited()) { if (!getGameType().isLimited()) {
customMenu.newConstructed(false); customMenu.newConstructed(false);
@@ -89,23 +95,28 @@ public final class DeckEditorCommon extends DeckEditorBase {
} // show(Command) } // show(Command)
private void setup() { private void setup() {
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>(); List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.fnQtyCompare, PresetColumns.fnQtyGet)); columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.fnQtyCompare, PresetColumns.fnQtyGet));
columns.add(new TableColumnInfo<InventoryItem>("Name", 175, PresetColumns.fnNameCompare, PresetColumns.fnNameGet)); columns.add(new TableColumnInfo<InventoryItem>("Name", 175, PresetColumns.fnNameCompare,
PresetColumns.fnNameGet));
columns.add(new TableColumnInfo<InventoryItem>("Cost", 75, PresetColumns.fnCostCompare, PresetColumns.fnCostGet)); columns.add(new TableColumnInfo<InventoryItem>("Cost", 75, PresetColumns.fnCostCompare, PresetColumns.fnCostGet));
columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet)); columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.fnColorCompare,
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare, PresetColumns.fnTypeGet)); PresetColumns.fnColorGet));
columns.add(new TableColumnInfo<InventoryItem>("Stats", 40, PresetColumns.fnStatsCompare, PresetColumns.fnStatsGet)); columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare,
columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.fnRarityCompare, PresetColumns.fnRarityGet)); PresetColumns.fnTypeGet));
columns.add(new TableColumnInfo<InventoryItem>("Stats", 40, PresetColumns.fnStatsCompare,
PresetColumns.fnStatsGet));
columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.fnRarityCompare,
PresetColumns.fnRarityGet));
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.fnSetCompare, PresetColumns.fnSetGet)); columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.fnSetCompare, PresetColumns.fnSetGet));
columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.fnAiStatusCompare, PresetColumns.fnAiStatusGet)); columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.fnAiStatusCompare,
PresetColumns.fnAiStatusGet));
columns.get(2).setCellRenderer(new ManaCostRenderer()); columns.get(2).setCellRenderer(new ManaCostRenderer());
top.setup(columns, cardView); top.setup(columns, cardView);
bottom.setup(columns, cardView); bottom.setup(columns, cardView);
filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), itemListenerUpdatesDisplay); filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), itemListenerUpdatesDisplay);
setSize(1024, 740); setSize(1024, 740);
@@ -113,8 +124,13 @@ public final class DeckEditorCommon extends DeckEditorBase {
} }
/**
public DeckEditorCommon(GameType gameType) { * Instantiates a new deck editor common.
*
* @param gameType
* the game type
*/
public DeckEditorCommon(final GameType gameType) {
super(gameType); super(gameType);
try { try {
filterBoxes = new FilterCheckBoxes(true); filterBoxes = new FilterCheckBoxes(true);
@@ -122,14 +138,13 @@ public final class DeckEditorCommon extends DeckEditorBase {
bottom = new TableWithCards("Deck", true); bottom = new TableWithCards("Deck", true);
cardView = new CardPanelHeavy(); cardView = new CardPanelHeavy();
filterNameTypeSet = new FilterNameTypeSetPanel(); filterNameTypeSet = new FilterNameTypeSetPanel();
jbInit(); jbInit();
} catch (Exception ex) { } catch (Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
} }
} }
private void jbInit() { private void jbInit() {
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
@@ -140,28 +155,45 @@ public final class DeckEditorCommon extends DeckEditorBase {
clearFilterButton.setFont(fButtons); clearFilterButton.setFont(fButtons);
analysisButton.setFont(fButtons); analysisButton.setFont(fButtons);
} }
addButton.setText("Add to Deck"); addButton.setText("Add to Deck");
removeButton.setText("Remove from Deck"); removeButton.setText("Remove from Deck");
importButton.setText("Import a Deck"); importButton.setText("Import a Deck");
clearFilterButton.setText("Clear Filter"); clearFilterButton.setText("Clear Filter");
analysisButton.setText("Deck Analysis"); analysisButton.setText("Deck Analysis");
removeButton.addActionListener(new java.awt.event.ActionListener() { removeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(final ActionEvent e) { removeButtonClicked(e); } }); public void actionPerformed(final ActionEvent e) {
removeButtonClicked(e);
}
});
addButton.addActionListener(new java.awt.event.ActionListener() { addButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(final ActionEvent e) { addButton_actionPerformed(e); } }); public void actionPerformed(final ActionEvent e) {
addButton_actionPerformed(e);
}
});
importButton.addActionListener(new java.awt.event.ActionListener() { importButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(final ActionEvent e) { importButton_actionPerformed(e); } }); public void actionPerformed(final ActionEvent e) {
importButton_actionPerformed(e);
}
});
clearFilterButton.addActionListener(new java.awt.event.ActionListener() { clearFilterButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(final ActionEvent e) { clearFilterButton_actionPerformed(e); } }); public void actionPerformed(final ActionEvent e) {
clearFilterButton_actionPerformed(e);
}
});
analysisButton.addActionListener(new java.awt.event.ActionListener() { analysisButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(final ActionEvent e) { analysisButton_actionPerformed(e); } }); public void actionPerformed(final ActionEvent e) {
analysisButton_actionPerformed(e);
}
});
// Type filtering // Type filtering
Font f = new Font("Tahoma", Font.PLAIN, 10); Font f = new Font("Tahoma", Font.PLAIN, 10);
for (JCheckBox box : filterBoxes.allTypes) { for (JCheckBox box : filterBoxes.allTypes) {
if (!Singletons.getModel().getPreferences().lafFonts) { box.setFont(f); } if (!Singletons.getModel().getPreferences().lafFonts) {
box.setFont(f);
}
box.setOpaque(false); box.setOpaque(false);
} }
@@ -203,7 +235,8 @@ public final class DeckEditorCommon extends DeckEditorBase {
content.add(addButton, "w 100, h 49, sg button, cell 0 5, split 5"); content.add(addButton, "w 100, h 49, sg button, cell 0 5, split 5");
content.add(removeButton, "w 100, h 49, sg button"); content.add(removeButton, "w 100, h 49, sg button");
content.add(importButton, "w 100, h 49, sg button, gapleft 40px"); content.add(importButton, "w 100, h 49, sg button, gapleft 40px");
// Label is used to push the analysis button to the right to separate analysis button from add/remove card ones // Label is used to push the analysis button to the right to separate
// analysis button from add/remove card ones
content.add(jLabelAnalysisGap, "wmin 75, growx"); content.add(jLabelAnalysisGap, "wmin 75, growx");
content.add(analysisButton, "w 100, h 49, wrap"); content.add(analysisButton, "w 100, h 49, wrap");
@@ -213,36 +246,76 @@ public final class DeckEditorCommon extends DeckEditorBase {
content.add(cardView, "cell 1 0 1 8, flowy, grow"); content.add(cardView, "cell 1 0 1 8, flowy, grow");
top.getTable().addMouseListener(new MouseAdapter() { top.getTable().addMouseListener(new MouseAdapter() {
@Override public void mouseClicked(final MouseEvent e) { if (e.getClickCount() == 2) { addCardToDeck(); } } }); @Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
addCardToDeck();
}
}
});
top.getTable().addKeyListener(new KeyAdapter() { top.getTable().addKeyListener(new KeyAdapter() {
@Override public void keyPressed(final KeyEvent e) { if (e.getKeyChar() == ' ') { addCardToDeck(); } } }); @Override
public void keyPressed(final KeyEvent e) {
if (e.getKeyChar() == ' ') {
addCardToDeck();
}
}
});
//javax.swing.JRootPane rootPane = this.getRootPane(); // javax.swing.JRootPane rootPane = this.getRootPane();
//rootPane.setDefaultButton(filterButton); // rootPane.setDefaultButton(filterButton);
} }
/*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckEditorBase#buildFilter()
*/
@Override @Override
protected Predicate<InventoryItem> buildFilter() { protected Predicate<InventoryItem> buildFilter() {
Predicate<CardPrinted> cardFilter = Predicate.and(Predicate.and(filterBoxes.buildFilter(), filterNameTypeSet.buildFilter()),CardPrinted.Predicates.Presets.nonAlternate); Predicate<CardPrinted> cardFilter = Predicate.and(
Predicate.and(filterBoxes.buildFilter(), filterNameTypeSet.buildFilter()),
CardPrinted.Predicates.Presets.nonAlternate);
return Predicate.instanceOf(cardFilter, CardPrinted.class); return Predicate.instanceOf(cardFilter, CardPrinted.class);
} }
/*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckEditorBase#setDeck(forge.item.ItemPoolView,
* forge.item.ItemPoolView, forge.game.GameType)
*/
@Override @Override
public void setDeck(ItemPoolView<CardPrinted> topParam, ItemPoolView<CardPrinted> bottomParam, GameType gt) public void setDeck(final ItemPoolView<CardPrinted> topParam, final ItemPoolView<CardPrinted> bottomParam,
{ final GameType gt) {
boolean keepRecievedCards = gt.isLimited() || topParam != null; boolean keepRecievedCards = gt.isLimited() || topParam != null;
// if constructed, can add the all cards above // if constructed, can add the all cards above
ItemPoolView<CardPrinted> top = keepRecievedCards ? topParam : ItemPool.createFrom(CardDb.instance().getAllCards(), CardPrinted.class); ItemPoolView<CardPrinted> top = keepRecievedCards ? topParam : ItemPool.createFrom(CardDb.instance()
.getAllCards(), CardPrinted.class);
importButton.setVisible(!gt.isLimited()); importButton.setVisible(!gt.isLimited());
super.setDeck(top, bottomParam, gt); super.setDeck(top, bottomParam, gt);
} }
void clearFilterButton_actionPerformed(ActionEvent e) { /**
* Clear filter button_action performed.
*
* @param e
* the e
*/
void clearFilterButton_actionPerformed(final ActionEvent e) {
// disable automatic update triggered by listeners // disable automatic update triggered by listeners
isFiltersChangeFiringUpdate = false; isFiltersChangeFiringUpdate = false;
for (JCheckBox box : filterBoxes.allTypes) { if (!box.isSelected()) { box.doClick(); } } for (JCheckBox box : filterBoxes.allTypes) {
for (JCheckBox box : filterBoxes.allColors) { if (!box.isSelected()) { box.doClick(); } } if (!box.isSelected()) {
box.doClick();
}
}
for (JCheckBox box : filterBoxes.allColors) {
if (!box.isSelected()) {
box.doClick();
}
}
filterNameTypeSet.clearFilters(); filterNameTypeSet.clearFilters();
@@ -251,13 +324,24 @@ public final class DeckEditorCommon extends DeckEditorBase {
top.setFilter(null); top.setFilter(null);
} }
void addButton_actionPerformed(ActionEvent e) { /**
* Adds the button_action performed.
*
* @param e
* the e
*/
void addButton_actionPerformed(final ActionEvent e) {
addCardToDeck(); addCardToDeck();
} }
/**
* Adds the card to deck.
*/
void addCardToDeck() { void addCardToDeck() {
InventoryItem item = top.getSelectedCard(); InventoryItem item = top.getSelectedCard();
if (item == null || !( item instanceof CardPrinted )) { return; } if (item == null || !(item instanceof CardPrinted)) {
return;
}
CardPrinted card = (CardPrinted) item; CardPrinted card = (CardPrinted) item;
setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved"); setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved");
@@ -266,13 +350,21 @@ public final class DeckEditorCommon extends DeckEditorBase {
if (getGameType().isLimited()) { if (getGameType().isLimited()) {
top.removeCard(card); top.removeCard(card);
} }
customMenu.notifyDeckChange(); customMenu.notifyDeckChange();
} }
void removeButtonClicked(ActionEvent e) { /**
* Removes the button clicked.
*
* @param e
* the e
*/
void removeButtonClicked(final ActionEvent e) {
InventoryItem item = bottom.getSelectedCard(); InventoryItem item = bottom.getSelectedCard();
if (item == null || !( item instanceof CardPrinted )) { return; } if (item == null || !(item instanceof CardPrinted)) {
return;
}
CardPrinted card = (CardPrinted) item; CardPrinted card = (CardPrinted) item;
@@ -282,11 +374,17 @@ public final class DeckEditorCommon extends DeckEditorBase {
if (getGameType().isLimited()) { if (getGameType().isLimited()) {
top.addCard(card); top.addCard(card);
} }
customMenu.notifyDeckChange(); customMenu.notifyDeckChange();
} }
void importButton_actionPerformed(ActionEvent e) { /**
* Import button_action performed.
*
* @param e
* the e
*/
void importButton_actionPerformed(final ActionEvent e) {
DeckEditorBase g = this; DeckEditorBase g = this;
DeckImport dImport = new DeckImport(g); DeckImport dImport = new DeckImport(g);
dImport.setModalityType(ModalityType.APPLICATION_MODAL); dImport.setModalityType(ModalityType.APPLICATION_MODAL);

View File

@@ -147,7 +147,7 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
} // setupSortMenu() } // setupSortMenu()
/** /**
* * New constructed.
* *
* @param careAboutOldDeck * @param careAboutOldDeck
* a boolean * a boolean

View File

@@ -1,25 +1,5 @@
package forge.gui.deckeditor; package forge.gui.deckeditor;
import forge.AllZone;
import forge.Constant;
import forge.deck.Deck;
import forge.deck.DeckManager;
import forge.error.ErrorViewer;
import forge.game.GameType;
import forge.game.limited.BoosterDraft;
import forge.gui.GuiUtils;
import forge.item.CardDb;
import forge.item.CardPrinted;
import forge.item.InventoryItem;
import forge.item.ItemPool;
import forge.item.ItemPoolView;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.view.swing.Gui_HomeScreen;
import forge.view.swing.OldGuiNewGame;
import net.slightlymagic.maxmtg.Predicate;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@@ -38,10 +18,30 @@ import javax.swing.JButton;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JTable; import javax.swing.JTable;
import net.slightlymagic.maxmtg.Predicate;
import forge.AllZone;
import forge.Constant;
import forge.deck.Deck;
import forge.deck.DeckManager;
import forge.error.ErrorViewer;
import forge.game.GameType;
import forge.game.limited.BoosterDraft;
import forge.gui.GuiUtils;
import forge.item.CardDb;
import forge.item.CardPrinted;
import forge.item.InventoryItem;
import forge.item.ItemPool;
import forge.item.ItemPoolView;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.view.swing.Gui_HomeScreen;
import forge.view.swing.OldGuiNewGame;
/** /**
* <p>Gui_BoosterDraft class.</p> * <p>
* * Gui_BoosterDraft class.
* </p>
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
@@ -57,18 +57,23 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
private CardPanelLite cardView = new CardPanelLite(); private CardPanelLite cardView = new CardPanelLite();
private MouseListener pickWithMouse = new MouseAdapter() { private MouseListener pickWithMouse = new MouseAdapter() {
@Override @Override
public void mouseClicked(final MouseEvent e) { public void mouseClicked(final MouseEvent e) {
// Pick on left-button double click // Pick on left-button double click
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0 && e.getClickCount() == 2) { if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0 && e.getClickCount() == 2) {
jButtonPickClicked(null); jButtonPickClicked(null);
} else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { // pick on right click } else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { // pick
// on
// right
// click
JTable table = top.getTable(); JTable table = top.getTable();
int rowNumber = table.rowAtPoint(e.getPoint()); int rowNumber = table.rowAtPoint(e.getPoint());
// after hittest - if it was outside of rows - discard this click // after hittest - if it was outside of rows - discard this
if (rowNumber == -1) { return; } // click
if (rowNumber == -1) {
return;
}
// if row was not selected, select it. If it was, pick a card // if row was not selected, select it. If it was, pick a card
if (rowNumber != table.getSelectedRow()) { if (rowNumber != table.getSelectedRow()) {
@@ -80,13 +85,19 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
} }
}; };
public void showGui(BoosterDraft in_boosterDraft) { /**
* Show gui.
*
* @param in_boosterDraft
* the in_booster draft
*/
public final void showGui(final BoosterDraft in_boosterDraft) {
boosterDraft = in_boosterDraft; boosterDraft = in_boosterDraft;
setup(); setup();
showChoices(boosterDraft.nextChoice()); showChoices(boosterDraft.nextChoice());
bottom.setDeck((Iterable<InventoryItem>)null); bottom.setDeck((Iterable<InventoryItem>) null);
top.sort(1, true); top.sort(1, true);
bottom.sort(1, true); bottom.sort(1, true);
@@ -94,20 +105,22 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
} }
/** /**
* <p>addListeners.</p> * <p>
* addListeners.
* </p>
*/ */
private void addListeners() { private void addListeners() {
this.addWindowListener(new WindowAdapter() { this.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing(WindowEvent ev) { public void windowClosing(final WindowEvent ev) {
int n = JOptionPane.showConfirmDialog(null, ForgeProps.getLocalized(CLOSE_MESSAGE), "", int n = JOptionPane.showConfirmDialog(null, ForgeProps.getLocalized(CLOSE_MESSAGE), "",
JOptionPane.YES_NO_OPTION); JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) { if (n == JOptionPane.YES_OPTION) {
dispose(); dispose();
if (System.getenv("NG2") != null) { if (System.getenv("NG2") != null) {
if (System.getenv("NG2").equalsIgnoreCase("true")) { if (System.getenv("NG2").equalsIgnoreCase("true")) {
String argz[] = {}; String[] argz = {};
Gui_HomeScreen.main(argz); Gui_HomeScreen.main(argz);
} else { } else {
new OldGuiNewGame(); new OldGuiNewGame();
@@ -117,27 +130,35 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
} }
} }
}//windowClosing() }// windowClosing()
}); });
}//addListeners() }// addListeners()
/** /**
* <p>setup.</p> * <p>
* setup.
* </p>
*/ */
private void setup() { private void setup() {
addListeners(); addListeners();
// setupMenu(); // setupMenu();
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>(); List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.fnQtyCompare, PresetColumns.fnQtyGet)); columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.fnQtyCompare, PresetColumns.fnQtyGet));
columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.fnNameCompare, PresetColumns.fnNameGet)); columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.fnNameCompare,
PresetColumns.fnNameGet));
columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.fnCostCompare, PresetColumns.fnCostGet)); columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.fnCostCompare, PresetColumns.fnCostGet));
columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet)); columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.fnColorCompare,
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare, PresetColumns.fnTypeGet)); PresetColumns.fnColorGet));
columns.add(new TableColumnInfo<InventoryItem>("Stats", 40, PresetColumns.fnStatsCompare, PresetColumns.fnStatsGet)); columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare,
columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.fnRarityCompare, PresetColumns.fnRarityGet)); PresetColumns.fnTypeGet));
columns.add(new TableColumnInfo<InventoryItem>("Stats", 40, PresetColumns.fnStatsCompare,
PresetColumns.fnStatsGet));
columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.fnRarityCompare,
PresetColumns.fnRarityGet));
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.fnSetCompare, PresetColumns.fnSetGet)); columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.fnSetCompare, PresetColumns.fnSetGet));
columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.fnAiStatusCompare, PresetColumns.fnAiStatusGet)); columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.fnAiStatusCompare,
PresetColumns.fnAiStatusGet));
columns.get(2).setCellRenderer(new ManaCostRenderer()); columns.get(2).setCellRenderer(new ManaCostRenderer());
top.setup(columns, cardView); top.setup(columns, cardView);
@@ -149,11 +170,19 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
top.getTable().addMouseListener(pickWithMouse); top.getTable().addMouseListener(pickWithMouse);
top.getTable().addKeyListener(new KeyAdapter() { top.getTable().addKeyListener(new KeyAdapter() {
@Override public void keyPressed(final KeyEvent e) { @Override
if (e.getKeyChar() == ' ') { jButtonPickClicked(null); } } }); public void keyPressed(final KeyEvent e) {
if (e.getKeyChar() == ' ') {
jButtonPickClicked(null);
}
}
});
} }
/**
* Instantiates a new deck editor draft.
*/
public DeckEditorDraft() { public DeckEditorDraft() {
super(GameType.Draft); super(GameType.Draft);
try { try {
@@ -167,11 +196,13 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
} }
} }
/** /**
* <p>jbInit.</p> * <p>
* * jbInit.
* @throws java.lang.Exception if any. * </p>
*
* @throws java.lang.Exception
* if any.
*/ */
private void jbInit() throws Exception { private void jbInit() throws Exception {
this.getContentPane().setLayout(null); this.getContentPane().setLayout(null);
@@ -179,21 +210,21 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
top.getTableDecorated().setBounds(new Rectangle(19, 28, 680, 344)); top.getTableDecorated().setBounds(new Rectangle(19, 28, 680, 344));
bottom.getTableDecorated().setBounds(new Rectangle(19, 478, 680, 184)); bottom.getTableDecorated().setBounds(new Rectangle(19, 478, 680, 184));
bottom.getLabel().setBounds(new Rectangle(19, 680, 665, 31)); bottom.getLabel().setBounds(new Rectangle(19, 680, 665, 31));
cardView.setBounds(new Rectangle(715, 23, 240, 666)); cardView.setBounds(new Rectangle(715, 23, 240, 666));
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
this.setTitle("Booster Draft"); this.setTitle("Booster Draft");
jButtonPick.setBounds(new Rectangle(238, 418, 147, 44)); jButtonPick.setBounds(new Rectangle(238, 418, 147, 44));
jButtonPick.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonPick.setFont(new java.awt.Font("Dialog", 0, 16));
jButtonPick.setText("Choose Card"); jButtonPick.setText("Choose Card");
jButtonPick.addActionListener(new ActionListener() { jButtonPick.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(final ActionEvent e) {
jButtonPickClicked(e); jButtonPickClicked(e);
} }
}); });
this.getContentPane().add(cardView, null); this.getContentPane().add(cardView, null);
this.getContentPane().add(top.getTableDecorated(), null); this.getContentPane().add(top.getTableDecorated(), null);
this.getContentPane().add(bottom.getLabel(), null); this.getContentPane().add(bottom.getLabel(), null);
@@ -202,55 +233,65 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
} }
/** /**
* <p>jButton1_actionPerformed.</p> * <p>
* * jButton1_actionPerformed.
* @param e a {@link java.awt.event.ActionEvent} object. * </p>
*
* @param e
* a {@link java.awt.event.ActionEvent} object.
*/ */
void jButtonPickClicked(final ActionEvent e) { final void jButtonPickClicked(final ActionEvent e) {
InventoryItem item = top.getSelectedCard(); InventoryItem item = top.getSelectedCard();
if (item == null || !( item instanceof CardPrinted )) { return; } if (item == null || !(item instanceof CardPrinted)) {
return;
}
CardPrinted card = (CardPrinted) item; CardPrinted card = (CardPrinted) item;
bottom.addCard(card); bottom.addCard(card);
//get next booster pack // get next booster pack
boosterDraft.setChoice(card); boosterDraft.setChoice(card);
if (boosterDraft.hasNextChoice()) { if (boosterDraft.hasNextChoice()) {
showChoices(boosterDraft.nextChoice()); showChoices(boosterDraft.nextChoice());
} else { } else {
boosterDraft.finishedDrafting(); boosterDraft.finishedDrafting();
//quit // quit
saveDraft(); saveDraft();
dispose(); dispose();
} }
}/*OK Button*/ }/* OK Button */
/** /**
* <p>showChoices.</p> * <p>
* * showChoices.
* @param list a {@link forge.CardList} object. * </p>
*
* @param list
* a {@link forge.CardList} object.
*/ */
private void showChoices(ItemPoolView<CardPrinted> list) { private void showChoices(final ItemPoolView<CardPrinted> list) {
top.setDeck(list); top.setDeck(list);
cardView.showCard(null); cardView.showCard(null);
top.fixSelection(0); top.fixSelection(0);
}//showChoices() }// showChoices()
/** /**
* <p>getPlayersDeck.</p> * <p>
* * getPlayersDeck.
* </p>
*
* @return a {@link forge.deck.Deck} object. * @return a {@link forge.deck.Deck} object.
*/ */
private Deck getPlayersDeck() { private Deck getPlayersDeck() {
Deck deck = new Deck(GameType.Draft); Deck deck = new Deck(GameType.Draft);
Constant.Runtime.HumanDeck[0] = deck; Constant.Runtime.HumanDeck[0] = deck;
//add sideboard to deck // add sideboard to deck
ItemPoolView<CardPrinted> list = ItemPool.createFrom(bottom.getCards(), CardPrinted.class); ItemPoolView<CardPrinted> list = ItemPool.createFrom(bottom.getCards(), CardPrinted.class);
deck.addSideboard(list); deck.addSideboard(list);
String landSet = BoosterDraft.LandSetCode[0]; String landSet = BoosterDraft.LandSetCode[0];
final int LANDS_COUNT = 20; final int LANDS_COUNT = 20;
deck.addSideboard(CardDb.instance().getCard("Forest", landSet), LANDS_COUNT); deck.addSideboard(CardDb.instance().getCard("Forest", landSet), LANDS_COUNT);
@@ -260,10 +301,12 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
deck.addSideboard(CardDb.instance().getCard("Plains", landSet), LANDS_COUNT); deck.addSideboard(CardDb.instance().getCard("Plains", landSet), LANDS_COUNT);
return deck; return deck;
}//getPlayersDeck() }// getPlayersDeck()
/** /**
* <p>saveDraft.</p> * <p>
* saveDraft.
* </p>
*/ */
private void saveDraft() { private void saveDraft() {
String s = ""; String s = "";
@@ -271,35 +314,36 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
s = JOptionPane.showInputDialog(null, ForgeProps.getLocalized(SAVE_DRAFT_MESSAGE), s = JOptionPane.showInputDialog(null, ForgeProps.getLocalized(SAVE_DRAFT_MESSAGE),
ForgeProps.getLocalized(SAVE_DRAFT_TITLE), JOptionPane.QUESTION_MESSAGE); ForgeProps.getLocalized(SAVE_DRAFT_TITLE), JOptionPane.QUESTION_MESSAGE);
} }
//TODO: check if overwriting the same name, and let the user delete old drafts // TODO: check if overwriting the same name, and let the user delete old
// drafts
//construct computer's decks // construct computer's decks
//save draft // save draft
Deck[] computer = boosterDraft.getDecks(); Deck[] computer = boosterDraft.getDecks();
Deck human = getPlayersDeck(); Deck human = getPlayersDeck();
human.setName(s); human.setName(s);
Deck[] all = { Deck[] all = { human, computer[0], computer[1], computer[2], computer[3], computer[4], computer[5], computer[6] };
human, computer[0], computer[1], computer[2], computer[3], computer[4], computer[5], computer[6]};
for(int i = 1; i < all.length; i++) { for (int i = 1; i < all.length; i++) {
all[i].setName(String.format("Draft %s - Computer %d", s, i)); all[i].setName(String.format("Draft %s - Computer %d", s, i));
} }
//DeckManager deckManager = new DeckManager(ForgeProps.getFile(NEW_DECKS)); // DeckManager deckManager = new
// DeckManager(ForgeProps.getFile(NEW_DECKS));
DeckManager deckManager = AllZone.getDeckManager(); DeckManager deckManager = AllZone.getDeckManager();
deckManager.addDraftDeck(all); deckManager.addDraftDeck(all);
//write file // write file
DeckManager.writeDraftDecks(all); DeckManager.writeDraftDecks(all);
//close and open next screen // close and open next screen
dispose(); dispose();
if (System.getenv("NG2") != null) { if (System.getenv("NG2") != null) {
if (System.getenv("NG2").equalsIgnoreCase("true")) { if (System.getenv("NG2").equalsIgnoreCase("true")) {
String argz[] = {}; String[] argz = {};
Gui_HomeScreen.main(argz); Gui_HomeScreen.main(argz);
} else { } else {
new OldGuiNewGame(); new OldGuiNewGame();
@@ -308,11 +352,15 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
new OldGuiNewGame(); new OldGuiNewGame();
} }
}/*saveDraft()*/ }/* saveDraft() */
/*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckEditorBase#buildFilter()
*/
@Override @Override
protected Predicate<InventoryItem> buildFilter() { protected final Predicate<InventoryItem> buildFilter() {
return Predicate.getTrue(InventoryItem.class); return Predicate.getTrue(InventoryItem.class);
} }
} }

View File

@@ -1,5 +1,20 @@
package forge.gui.deckeditor; package forge.gui.deckeditor;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import net.slightlymagic.maxmtg.Predicate;
import forge.Command; import forge.Command;
import forge.Constant; import forge.Constant;
import forge.Singletons; import forge.Singletons;
@@ -14,22 +29,6 @@ import forge.item.ItemPoolView;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.quest.data.QuestData; import forge.quest.data.QuestData;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import net.slightlymagic.maxmtg.Predicate;
//import forge.quest.data.QuestBoosterPack; //import forge.quest.data.QuestBoosterPack;
/** /**
@@ -44,22 +43,27 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
/** Constant <code>serialVersionUID=152061168634545L</code> */ /** Constant <code>serialVersionUID=152061168634545L</code> */
private static final long serialVersionUID = 152061168634545L; private static final long serialVersionUID = 152061168634545L;
/** The custom menu. */
DeckEditorQuestMenu customMenu; DeckEditorQuestMenu customMenu;
// private ImageIcon upIcon = Constant.IO.upIcon; // private ImageIcon upIcon = Constant.IO.upIcon;
// private ImageIcon downIcon = Constant.IO.downIcon; // private ImageIcon downIcon = Constant.IO.downIcon;
//private JLabel labelSortHint = new JLabel(); // private JLabel labelSortHint = new JLabel();
private JButton addButton = new JButton(); private JButton addButton = new JButton();
private JButton removeButton = new JButton(); private JButton removeButton = new JButton();
private JButton analysisButton = new JButton(); private JButton analysisButton = new JButton();
private FilterNameTypeSetPanel filterNameTypeSet; private FilterNameTypeSetPanel filterNameTypeSet;
private QuestData questData; private QuestData questData;
/**
* Show.
*
* @param exitCommand
* the exit command
*/
public void show(final Command exitCommand) { public void show(final Command exitCommand) {
final Command exit = new Command() { final Command exit = new Command() {
private static final long serialVersionUID = -7428793574300520612L; private static final long serialVersionUID = -7428793574300520612L;
@@ -114,7 +118,6 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
bottom.sort(1, true); bottom.sort(1, true);
} // show(Command) } // show(Command)
/** /**
* <p> * <p>
* setup. * setup.
@@ -122,23 +125,29 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
*/ */
public void setup() { public void setup() {
this.setLayout(null); this.setLayout(null);
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>(); List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.fnQtyCompare, PresetColumns.fnQtyGet)); columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.fnQtyCompare, PresetColumns.fnQtyGet));
columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.fnNameCompare, PresetColumns.fnNameGet)); columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.fnNameCompare,
PresetColumns.fnNameGet));
columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.fnCostCompare, PresetColumns.fnCostGet)); columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.fnCostCompare, PresetColumns.fnCostGet));
columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet)); columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.fnColorCompare,
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare, PresetColumns.fnTypeGet)); PresetColumns.fnColorGet));
columns.add(new TableColumnInfo<InventoryItem>("Stats", 40, PresetColumns.fnStatsCompare, PresetColumns.fnStatsGet)); columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare,
columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.fnRarityCompare, PresetColumns.fnRarityGet)); PresetColumns.fnTypeGet));
columns.add(new TableColumnInfo<InventoryItem>("Stats", 40, PresetColumns.fnStatsCompare,
PresetColumns.fnStatsGet));
columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.fnRarityCompare,
PresetColumns.fnRarityGet));
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.fnSetCompare, PresetColumns.fnSetGet)); columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.fnSetCompare, PresetColumns.fnSetGet));
columns.add(new TableColumnInfo<InventoryItem>("New", 30, questData.getCards().fnNewCompare, questData.getCards().fnNewGet)); columns.add(new TableColumnInfo<InventoryItem>("New", 30, questData.getCards().fnNewCompare, questData
.getCards().fnNewGet));
columns.get(2).setCellRenderer(new ManaCostRenderer()); columns.get(2).setCellRenderer(new ManaCostRenderer());
top.setup(columns, cardView); top.setup(columns, cardView);
bottom.setup(columns, cardView); bottom.setup(columns, cardView);
filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), itemListenerUpdatesDisplay); filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), itemListenerUpdatesDisplay);
this.setSize(1024, 768); this.setSize(1024, 768);
@@ -151,7 +160,13 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
// setExtendedState(Frame.MAXIMIZED_BOTH); // setExtendedState(Frame.MAXIMIZED_BOTH);
} // setupAndDisplay() } // setupAndDisplay()
public DeckEditorQuest(QuestData questData2) { /**
* Instantiates a new deck editor quest.
*
* @param questData2
* the quest data2
*/
public DeckEditorQuest(final QuestData questData2) {
super(GameType.Quest); super(GameType.Quest);
questData = questData2; questData = questData2;
try { try {
@@ -166,22 +181,21 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
} }
} }
private void jbInit() throws Exception { private void jbInit() throws Exception {
this.getContentPane().setLayout(null); this.getContentPane().setLayout(null);
//labelSortHint.setText("Click on the column name (like name or color) to sort the cards"); // labelSortHint.setText("Click on the column name (like name or color) to sort the cards");
//labelSortHint.setBounds(new Rectangle(20, 27, 400, 19)); // labelSortHint.setBounds(new Rectangle(20, 27, 400, 19));
filterNameTypeSet.setBounds(new Rectangle(19, 10, 726, 25)); filterNameTypeSet.setBounds(new Rectangle(19, 10, 726, 25));
top.getTableDecorated().setBounds(new Rectangle(19, 40, 726, 316)); top.getTableDecorated().setBounds(new Rectangle(19, 40, 726, 316));
bottom.getTableDecorated().setBounds(new Rectangle(19, 458, 726, 218)); bottom.getTableDecorated().setBounds(new Rectangle(19, 458, 726, 218));
removeButton.setBounds(new Rectangle(180, 403, 146, 49)); removeButton.setBounds(new Rectangle(180, 403, 146, 49));
// removeButton.setIcon(upIcon); // removeButton.setIcon(upIcon);
if (!Singletons.getModel().getPreferences().lafFonts) if (!Singletons.getModel().getPreferences().lafFonts) {
removeButton.setFont(new java.awt.Font("Dialog", 0, 13)); removeButton.setFont(new java.awt.Font("Dialog", 0, 13));
}
removeButton.setText("Remove Card"); removeButton.setText("Remove Card");
removeButton.addActionListener(new ActionListener() { removeButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
@@ -195,8 +209,9 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
} }
}); });
// addButton.setIcon(downIcon); // addButton.setIcon(downIcon);
if (!Singletons.getModel().getPreferences().lafFonts) if (!Singletons.getModel().getPreferences().lafFonts) {
addButton.setFont(new java.awt.Font("Dialog", 0, 13)); addButton.setFont(new java.awt.Font("Dialog", 0, 13));
}
addButton.setBounds(new Rectangle(23, 403, 146, 49)); addButton.setBounds(new Rectangle(23, 403, 146, 49));
analysisButton.setText("Deck Analysis"); analysisButton.setText("Deck Analysis");
@@ -205,8 +220,9 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
analysisButton_actionPerformed(e); analysisButton_actionPerformed(e);
} }
}); });
if (!Singletons.getModel().getPreferences().lafFonts) if (!Singletons.getModel().getPreferences().lafFonts) {
analysisButton.setFont(new java.awt.Font("Dialog", 0, 13)); analysisButton.setFont(new java.awt.Font("Dialog", 0, 13));
}
analysisButton.setBounds(new Rectangle(578, 426, 166, 25)); analysisButton.setBounds(new Rectangle(578, 426, 166, 25));
/** /**
@@ -219,10 +235,12 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
filterBoxes.planeswalker.setBounds(558, 400, 85, 20); filterBoxes.planeswalker.setBounds(558, 400, 85, 20);
filterBoxes.artifact.setBounds(638, 400, 58, 20); filterBoxes.artifact.setBounds(638, 400, 58, 20);
filterBoxes.enchantment.setBounds(692, 400, 80, 20); filterBoxes.enchantment.setBounds(692, 400, 80, 20);
Font f = new Font("Tahoma", Font.PLAIN, 10); Font f = new Font("Tahoma", Font.PLAIN, 10);
for (JCheckBox box : filterBoxes.allTypes) { for (JCheckBox box : filterBoxes.allTypes) {
if (!Singletons.getModel().getPreferences().lafFonts) { box.setFont(f); } if (!Singletons.getModel().getPreferences().lafFonts) {
box.setFont(f);
}
box.setOpaque(false); box.setOpaque(false);
box.addItemListener(itemListenerUpdatesDisplay); box.addItemListener(itemListenerUpdatesDisplay);
} }
@@ -252,7 +270,6 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
// x 768 screen size // x 768 screen size
this.setTitle("Deck Editor"); this.setTitle("Deck Editor");
this.getContentPane().add(filterNameTypeSet, null); this.getContentPane().add(filterNameTypeSet, null);
this.getContentPane().add(top.getTableDecorated(), null); this.getContentPane().add(top.getTableDecorated(), null);
this.getContentPane().add(bottom.getTableDecorated(), null); this.getContentPane().add(bottom.getTableDecorated(), null);
@@ -261,7 +278,7 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
this.getContentPane().add(analysisButton, null); this.getContentPane().add(analysisButton, null);
this.getContentPane().add(bottom.getLabel(), null); this.getContentPane().add(bottom.getLabel(), null);
this.getContentPane().add(top.getLabel(), null); this.getContentPane().add(top.getLabel(), null);
//this.getContentPane().add(labelSortHint, null); // this.getContentPane().add(labelSortHint, null);
this.getContentPane().add(cardView, null); this.getContentPane().add(cardView, null);
for (JCheckBox box : filterBoxes.allTypes) { for (JCheckBox box : filterBoxes.allTypes) {
@@ -275,21 +292,29 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
top.getTable().addKeyListener(new KeyAdapter() { top.getTable().addKeyListener(new KeyAdapter() {
@Override @Override
public void keyPressed(final KeyEvent e) { public void keyPressed(final KeyEvent e) {
if (e.getKeyChar() == ' ') { addButtonActionPerformed(null); } if (e.getKeyChar() == ' ') {
addButtonActionPerformed(null);
}
} }
}); });
} }
/*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckEditorBase#buildFilter()
*/
@Override @Override
protected Predicate<InventoryItem> buildFilter() { protected Predicate<InventoryItem> buildFilter() {
Predicate<CardPrinted> cardFilter = Predicate.and(filterBoxes.buildFilter(), filterNameTypeSet.buildFilter()); Predicate<CardPrinted> cardFilter = Predicate.and(filterBoxes.buildFilter(), filterNameTypeSet.buildFilter());
return Predicate.instanceOf(cardFilter, CardPrinted.class); return Predicate.instanceOf(cardFilter, CardPrinted.class);
} }
private void addButtonActionPerformed(final ActionEvent e) { private void addButtonActionPerformed(final ActionEvent e) {
InventoryItem item = top.getSelectedCard(); InventoryItem item = top.getSelectedCard();
if (item == null || !( item instanceof CardPrinted )) { return; } if (item == null || !(item instanceof CardPrinted)) {
return;
}
CardPrinted card = (CardPrinted) item; CardPrinted card = (CardPrinted) item;
@@ -299,10 +324,11 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
bottom.addCard(card); bottom.addCard(card);
} }
private void removeButtonActionPerformed(final ActionEvent e) { private void removeButtonActionPerformed(final ActionEvent e) {
InventoryItem item = bottom.getSelectedCard(); InventoryItem item = bottom.getSelectedCard();
if (item == null || !( item instanceof CardPrinted )) { return; } if (item == null || !(item instanceof CardPrinted)) {
return;
}
CardPrinted card = (CardPrinted) item; CardPrinted card = (CardPrinted) item;
@@ -312,7 +338,12 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
bottom.removeCard(card); bottom.removeCard(card);
} }
/**
* Adds the cheat card.
*
* @param card
* the card
*/
public void addCheatCard(final CardPrinted card) { public void addCheatCard(final CardPrinted card) {
top.addCard(card); top.addCard(card);
questData.getCards().getCardpool().add(card); questData.getCards().getCardpool().add(card);

View File

@@ -1,5 +1,25 @@
package forge.gui.deckeditor; package forge.gui.deckeditor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import javax.swing.JFileChooser;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import org.apache.commons.lang3.StringUtils;
import forge.Command; import forge.Command;
import forge.Constant; import forge.Constant;
@@ -17,28 +37,12 @@ import forge.item.ItemPool;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
import forge.quest.data.QuestData; import forge.quest.data.QuestData;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import org.apache.commons.lang3.StringUtils;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
//presumes AllZone.getQuestData() is not null //presumes AllZone.getQuestData() is not null
/** /**
* <p>Gui_Quest_DeckEditor_Menu class.</p> * <p>
* * Gui_Quest_DeckEditor_Menu class.
* </p>
*
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
@@ -49,7 +53,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
/** Constant <code>deckEditorName="Deck Editor"</code>. */ /** Constant <code>deckEditorName="Deck Editor"</code>. */
private static final String deckEditorName = "Deck Editor"; private static final String deckEditorName = "Deck Editor";
//used for import and export, try to made the gui user friendly // used for import and export, try to made the gui user friendly
/** Constant <code>previousDirectory</code>. */ /** Constant <code>previousDirectory</code>. */
private static File previousDirectory = null; private static File previousDirectory = null;
@@ -57,17 +61,22 @@ public class DeckEditorQuestMenu extends JMenuBar {
private forge.quest.data.QuestData questData; private forge.quest.data.QuestData questData;
private Deck currentDeck; private Deck currentDeck;
//the class DeckDisplay is in the file "Gui_DeckEditor_Menu.java" // the class DeckDisplay is in the file "Gui_DeckEditor_Menu.java"
private DeckDisplay deckDisplay; private DeckDisplay deckDisplay;
/** /**
* <p>Constructor for Gui_Quest_DeckEditor_Menu.</p> * <p>
* * Constructor for Gui_Quest_DeckEditor_Menu.
* @param d a {@link forge.gui.deckeditor.DeckDisplay} object. * </p>
* @param exit a {@link forge.Command} object. *
* @param q
* the q
* @param d
* a {@link forge.gui.deckeditor.DeckDisplay} object.
* @param exit
* a {@link forge.Command} object.
*/ */
public DeckEditorQuestMenu(QuestData q, final DeckDisplay d, final Command exit) { public DeckEditorQuestMenu(final QuestData q, final DeckDisplay d, final Command exit) {
deckDisplay = d; deckDisplay = d;
questData = q; questData = q;
@@ -79,13 +88,15 @@ public class DeckEditorQuestMenu extends JMenuBar {
setupMenu(); setupMenu();
} }
/** /**
* <p>addImportExport.</p> * <p>
* * addImportExport.
* @param menu a {@link javax.swing.JMenu} object. * </p>
* @param isHumanMenu a boolean. *
* @param menu
* a {@link javax.swing.JMenu} object.
* @param isHumanMenu
* a boolean.
*/ */
private void addImportExport(final JMenu menu, final boolean isHumanMenu) { private void addImportExport(final JMenu menu, final boolean isHumanMenu) {
JMenuItem import2 = new JMenuItem("Import"); JMenuItem import2 = new JMenuItem("Import");
@@ -93,23 +104,25 @@ public class DeckEditorQuestMenu extends JMenuBar {
import2.addActionListener(new ActionListener() { import2.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
importDeck(); //importDeck(isHumanMenu); importDeck(); // importDeck(isHumanMenu);
} }
}); //import }); // import
export.addActionListener(new ActionListener() { export.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
exportDeck(); exportDeck();
} }
}); //export }); // export
menu.add(import2); menu.add(import2);
menu.add(export); menu.add(export);
} //addImportExport() } // addImportExport()
/** /**
* <p>exportDeck.</p> * <p>
* exportDeck.
* </p>
*/ */
private void exportDeck() { private void exportDeck() {
File filename = getExportFilename(); File filename = getExportFilename();
@@ -118,8 +131,8 @@ public class DeckEditorQuestMenu extends JMenuBar {
return; return;
} }
//write is an Object variable because you might just // write is an Object variable because you might just
//write one Deck object // write one Deck object
Deck deck = cardPoolToDeck(deckDisplay.getBottom()); Deck deck = cardPoolToDeck(deckDisplay.getBottom());
deck.setName(filename.getName()); deck.setName(filename.getName());
@@ -136,17 +149,21 @@ public class DeckEditorQuestMenu extends JMenuBar {
exportDeckText(getExportDeckText(deck), filename.getAbsolutePath()); exportDeckText(getExportDeckText(deck), filename.getAbsolutePath());
} //exportDeck() } // exportDeck()
/** /**
* <p>exportDeckText.</p> * <p>
* * exportDeckText.
* @param deckText a {@link java.lang.String} object. * </p>
* @param filename a {@link java.lang.String} object. *
* @param deckText
* a {@link java.lang.String} object.
* @param filename
* a {@link java.lang.String} object.
*/ */
private void exportDeckText(final String deckText, String filename) { private void exportDeckText(final String deckText, String filename) {
//remove ".deck" extension // remove ".deck" extension
int cut = filename.indexOf("."); int cut = filename.indexOf(".");
filename = filename.substring(0, cut); filename = filename.substring(0, cut);
@@ -158,21 +175,24 @@ public class DeckEditorQuestMenu extends JMenuBar {
writer.close(); writer.close();
} catch (Exception ex) { } catch (Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeckText() error, " + ex.getMessage() throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeckText() error, " + ex.getMessage() + " : "
+ " : " + Arrays.toString(ex.getStackTrace())); + Arrays.toString(ex.getStackTrace()));
} }
} //exportDeckText() } // exportDeckText()
/** /**
* <p>getExportDeckText.</p> * <p>
* * getExportDeckText.
* @param aDeck a {@link forge.deck.Deck} object. * </p>
*
* @param aDeck
* a {@link forge.deck.Deck} object.
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private String getExportDeckText(final Deck aDeck) { private String getExportDeckText(final Deck aDeck) {
//convert Deck into CardList // convert Deck into CardList
ItemPoolView<CardPrinted> all = aDeck.getMain(); ItemPoolView<CardPrinted> all = aDeck.getMain();
//sort by card name // sort by card name
Collections.sort(all.getOrderedList(), TableSorter.byNameThenSet); Collections.sort(all.getOrderedList(), TableSorter.byNameThenSet);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
@@ -180,21 +200,24 @@ public class DeckEditorQuestMenu extends JMenuBar {
sb.append(String.format("%d Total Cards%n%n", all.countAll())); sb.append(String.format("%d Total Cards%n%n", all.countAll()));
//creatures // creatures
sb.append(String.format("%d Creatures%n-------------%n", CardRules.Predicates.Presets.isCreature.aggregate(all, all.fnToCard, all.fnToCount))); sb.append(String.format("%d Creatures%n-------------%n",
CardRules.Predicates.Presets.isCreature.aggregate(all, all.fnToCard, all.fnToCount)));
for (Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.isCreature.select(all, all.fnToCard)) { for (Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.isCreature.select(all, all.fnToCard)) {
sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName())); sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName()));
} }
//spells // spells
sb.append(String.format("%d Spells%n----------%n", CardRules.Predicates.Presets.isNonCreatureSpell.aggregate(all, all.fnToCard, all.fnToCount))); sb.append(String.format("%d Spells%n----------%n",
CardRules.Predicates.Presets.isNonCreatureSpell.aggregate(all, all.fnToCard, all.fnToCount)));
for (Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.isNonCreatureSpell.select(all, all.fnToCard)) { for (Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.isNonCreatureSpell.select(all, all.fnToCard)) {
sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName())); sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName()));
} }
//lands // lands
sb.append(String.format("%d Land%n--------%n", CardRules.Predicates.Presets.isLand.aggregate(all, all.fnToCard, all.fnToCount))); sb.append(String.format("%d Land%n--------%n",
CardRules.Predicates.Presets.isLand.aggregate(all, all.fnToCard, all.fnToCount)));
for (Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.isLand.select(all, all.fnToCard)) { for (Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.isLand.select(all, all.fnToCard)) {
sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName())); sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName()));
} }
@@ -202,11 +225,13 @@ public class DeckEditorQuestMenu extends JMenuBar {
sb.append(newLine); sb.append(newLine);
return sb.toString(); return sb.toString();
} //getExportDeckText } // getExportDeckText
/** /**
* <p>getFileFilter.</p> * <p>
* * getFileFilter.
* </p>
*
* @return a {@link javax.swing.filechooser.FileFilter} object. * @return a {@link javax.swing.filechooser.FileFilter} object.
*/ */
private FileFilter getFileFilter() { private FileFilter getFileFilter() {
@@ -223,15 +248,17 @@ public class DeckEditorQuestMenu extends JMenuBar {
}; };
return filter; return filter;
} //getFileFilter() } // getFileFilter()
/** /**
* <p>getExportFilename.</p> * <p>
* * getExportFilename.
* </p>
*
* @return a {@link java.io.File} object. * @return a {@link java.io.File} object.
*/ */
private File getExportFilename() { private File getExportFilename() {
//Object o = null; // unused // Object o = null; // unused
JFileChooser save = new JFileChooser(previousDirectory); JFileChooser save = new JFileChooser(previousDirectory);
@@ -256,10 +283,12 @@ public class DeckEditorQuestMenu extends JMenuBar {
} }
return null; return null;
} //getExportFilename() } // getExportFilename()
/** /**
* <p>importDeck.</p> * <p>
* importDeck.
* </p>
*/ */
private void importDeck() { private void importDeck() {
File file = getImportFilename(); File file = getImportFilename();
@@ -270,7 +299,8 @@ public class DeckEditorQuestMenu extends JMenuBar {
Deck newDeck = DeckManager.readDeck(file); Deck newDeck = DeckManager.readDeck(file);
questData.addDeck(newDeck); questData.addDeck(newDeck);
ItemPool<CardPrinted> cardpool = ItemPool.createFrom(questData.getCards().getCardpool(), CardPrinted.class); ItemPool<CardPrinted> cardpool = ItemPool.createFrom(questData.getCards().getCardpool(),
CardPrinted.class);
ItemPool<CardPrinted> decklist = new ItemPool<CardPrinted>(CardPrinted.class); ItemPool<CardPrinted> decklist = new ItemPool<CardPrinted>(CardPrinted.class);
for (Entry<CardPrinted, Integer> s : newDeck.getMain()) { for (Entry<CardPrinted, Integer> s : newDeck.getMain()) {
CardPrinted cp = s.getKey(); CardPrinted cp = s.getKey();
@@ -286,11 +316,13 @@ public class DeckEditorQuestMenu extends JMenuBar {
} }
} }
} //importDeck() } // importDeck()
/** /**
* <p>getImportFilename.</p> * <p>
* * getImportFilename.
* </p>
*
* @return a {@link java.io.File} object. * @return a {@link java.io.File} object.
*/ */
private File getImportFilename() { private File getImportFilename() {
@@ -306,17 +338,18 @@ public class DeckEditorQuestMenu extends JMenuBar {
} }
return null; return null;
} //openFileDialog() } // openFileDialog()
private final ActionListener addCardActionListener = new ActionListener() { private final ActionListener addCardActionListener = new ActionListener() {
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
// Provide a model here: all unique cards to be displayed by only name (unlike default toString) // Provide a model here: all unique cards to be displayed by only
// name (unlike default toString)
Iterable<CardPrinted> uniqueCards = CardDb.instance().getAllUniqueCards(); Iterable<CardPrinted> uniqueCards = CardDb.instance().getAllUniqueCards();
List<String> cards = new ArrayList<String>(); List<String> cards = new ArrayList<String>();
for (CardPrinted c : uniqueCards) { cards.add(c.getName()); } for (CardPrinted c : uniqueCards) {
cards.add(c.getName());
}
Collections.sort(cards); Collections.sort(cards);
// use standard forge's list selection dialog // use standard forge's list selection dialog
@@ -333,11 +366,14 @@ public class DeckEditorQuestMenu extends JMenuBar {
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
String deckName = getUserInput_OpenDeck(questData.getDeckNames()); String deckName = getUserInput_OpenDeck(questData.getDeckNames());
//check if user selected "cancel" // check if user selected "cancel"
if (StringUtils.isBlank(deckName)) { return; } if (StringUtils.isBlank(deckName)) {
return;
}
setPlayerDeckName(deckName); setPlayerDeckName(deckName);
ItemPool<CardPrinted> cards = ItemPool.createFrom(questData.getCards().getCardpool().getView(), CardPrinted.class); ItemPool<CardPrinted> cards = ItemPool.createFrom(questData.getCards().getCardpool().getView(),
CardPrinted.class);
ItemPoolView<CardPrinted> deck = questData.getDeck(deckName).getMain(); ItemPoolView<CardPrinted> deck = questData.getDeck(deckName).getMain();
// show in pool all cards except ones used in deck // show in pool all cards except ones used in deck
@@ -357,10 +393,12 @@ public class DeckEditorQuestMenu extends JMenuBar {
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
String deckName = getUserInput_GetDeckName(questData.getDeckNames()); String deckName = getUserInput_GetDeckName(questData.getDeckNames());
//check if user cancels // check if user cancels
if (StringUtils.isBlank(deckName)) { return; } if (StringUtils.isBlank(deckName)) {
return;
}
//is the current deck already saved and in QuestData? // is the current deck already saved and in QuestData?
if (questData.getDeckNames().contains(currentDeck.getName())) { if (questData.getDeckNames().contains(currentDeck.getName())) {
questData.removeDeck(currentDeck.getName()); questData.removeDeck(currentDeck.getName());
} }
@@ -379,11 +417,11 @@ public class DeckEditorQuestMenu extends JMenuBar {
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
String name = currentDeck.getName(); String name = currentDeck.getName();
//check to see if name is set // check to see if name is set
if (name.equals("")) { if (name.equals("")) {
name = getUserInput_GetDeckName(questData.getDeckNames()); name = getUserInput_GetDeckName(questData.getDeckNames());
//check if user cancels // check if user cancels
if (name.equals("")) { if (name.equals("")) {
return; return;
} }
@@ -402,7 +440,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
String name = getUserInput_GetDeckName(questData.getDeckNames()); String name = getUserInput_GetDeckName(questData.getDeckNames());
//check if user cancels // check if user cancels
if (name.equals("")) { if (name.equals("")) {
return; return;
} }
@@ -422,24 +460,26 @@ public class DeckEditorQuestMenu extends JMenuBar {
return; return;
} }
int check = JOptionPane.showConfirmDialog(null, "Do you really want to delete this deck?", int check = JOptionPane.showConfirmDialog(null, "Do you really want to delete this deck?", "Delete",
"Delete", JOptionPane.YES_NO_OPTION); JOptionPane.YES_NO_OPTION);
if (check == JOptionPane.NO_OPTION) { if (check == JOptionPane.NO_OPTION) {
return; //stop here return; // stop here
} }
questData.removeDeck(currentDeck.getName()); questData.removeDeck(currentDeck.getName());
//show card pool // show card pool
deckDisplay.setItems(questData.getCards().getCardpool().getView(), null, GameType.Quest); deckDisplay.setItems(questData.getCards().getCardpool().getView(), null, GameType.Quest);
setPlayerDeckName(""); setPlayerDeckName("");
} }
}; };
//the usual menu options that will be used // the usual menu options that will be used
/** /**
* <p>setupMenu.</p> * <p>
* setupMenu.
* </p>
*/ */
private void setupMenu() { private void setupMenu() {
JMenuItem openDeck = new JMenuItem("Open"); JMenuItem openDeck = new JMenuItem("Open");
@@ -452,7 +492,6 @@ public class DeckEditorQuestMenu extends JMenuBar {
JMenuItem addCard = new JMenuItem("Cheat - Add Card"); JMenuItem addCard = new JMenuItem("Cheat - Add Card");
addCard.addActionListener(addCardActionListener); addCard.addActionListener(addCardActionListener);
openDeck.addActionListener(openDeckActionListener); openDeck.addActionListener(openDeckActionListener);
newDeck.addActionListener(newDeckActionListener); newDeck.addActionListener(newDeckActionListener);
@@ -461,8 +500,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
copy.addActionListener(copyDeckActionListener); copy.addActionListener(copyDeckActionListener);
delete.addActionListener(deleteDeckActionListener); delete.addActionListener(deleteDeckActionListener);
// human
//human
exit.addActionListener(new ActionListener() { exit.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
DeckEditorQuestMenu.this.close(); DeckEditorQuestMenu.this.close();
@@ -494,37 +532,46 @@ public class DeckEditorQuestMenu extends JMenuBar {
} }
/** /**
* <p>convertCardPoolToDeck.</p> * <p>
* * convertCardPoolToDeck.
* @param list a {@link forge.CardPool} object. * </p>
*
* @param list
* a {@link forge.CardPool} object.
* @return a {@link forge.deck.Deck} object. * @return a {@link forge.deck.Deck} object.
*/ */
private Deck cardPoolToDeck(final ItemPoolView<InventoryItem> list) { private Deck cardPoolToDeck(final ItemPoolView<InventoryItem> list) {
//put CardPool into Deck main // put CardPool into Deck main
Deck deck = new Deck(GameType.Sealed); Deck deck = new Deck(GameType.Sealed);
deck.addMain(ItemPool.createFrom(list, CardPrinted.class)); deck.addMain(ItemPool.createFrom(list, CardPrinted.class));
return deck; return deck;
} }
//needs to be public because Gui_Quest_DeckEditor.show(Command) uses it // needs to be public because Gui_Quest_DeckEditor.show(Command) uses it
/** /**
* <p>setHumanPlayer.</p> * <p>
* * setHumanPlayer.
* @param deckName a {@link java.lang.String} object. * </p>
*
* @param deckName
* a {@link java.lang.String} object.
*/ */
public final void setPlayerDeckName(final String deckName) { public final void setPlayerDeckName(final String deckName) {
//the gui uses this, Gui_Quest_DeckEditor // the gui uses this, Gui_Quest_DeckEditor
currentDeck = new Deck(GameType.Sealed); currentDeck = new Deck(GameType.Sealed);
currentDeck.setName(deckName); currentDeck.setName(deckName);
deckDisplay.setTitle(deckEditorName + " - " + deckName); deckDisplay.setTitle(deckEditorName + " - " + deckName);
} }
//only accepts numbers, letters or dashes up to 20 characters in length // only accepts numbers, letters or dashes up to 20 characters in length
/** /**
* <p>cleanString.</p> * <p>
* * cleanString.
* @param in a {@link java.lang.String} object. * </p>
*
* @param in
* a {@link java.lang.String} object.
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private String cleanString(final String in) { private String cleanString(final String in) {
@@ -532,17 +579,22 @@ public class DeckEditorQuestMenu extends JMenuBar {
char[] c = in.toCharArray(); char[] c = in.toCharArray();
for (int i = 0; i < c.length && i < 20; i++) { for (int i = 0; i < c.length && i < 20; i++) {
if (Character.isLetterOrDigit(c[i]) || c[i] == '-' || c[i] == '_' || c[i] == ' ') { out.append(c[i]); } if (Character.isLetterOrDigit(c[i]) || c[i] == '-' || c[i] == '_' || c[i] == ' ') {
out.append(c[i]);
}
} }
return out.toString(); return out.toString();
} }
//if user cancels, returns "" // if user cancels, returns ""
/** /**
* <p>getUserInput_GetDeckName.</p> * <p>
* * getUserInput_GetDeckName.
* @param nameList a {@link java.util.List} object. * </p>
*
* @param nameList
* a {@link java.util.List} object.
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private String getUserInput_GetDeckName(final List<String> nameList) { private String getUserInput_GetDeckName(final List<String> nameList) {
@@ -560,14 +612,16 @@ public class DeckEditorQuestMenu extends JMenuBar {
} }
return deckName; return deckName;
} //getUserInput_GetDeckName() } // getUserInput_GetDeckName()
// if user cancels, it will return ""
//if user cancels, it will return ""
/** /**
* <p>getUserInput_OpenDeck.</p> * <p>
* * getUserInput_OpenDeck.
* @param deckNameList a {@link java.util.List} object. * </p>
*
* @param deckNameList
* a {@link java.util.List} object.
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private String getUserInput_OpenDeck(final List<String> deckNameList) { private String getUserInput_OpenDeck(final List<String> deckNameList) {
@@ -577,8 +631,9 @@ public class DeckEditorQuestMenu extends JMenuBar {
return ""; return "";
} }
//Object o = JOptionPane.showInputDialog(null, "Deck Name", "Open Deck", JOptionPane.OK_CANCEL_OPTION, null, // Object o = JOptionPane.showInputDialog(null, "Deck Name",
// choices.toArray(), choices.toArray()[0]); // "Open Deck", JOptionPane.OK_CANCEL_OPTION, null,
// choices.toArray(), choices.toArray()[0]);
Object o = GuiUtils.getChoiceOptional("Select Deck", choices.toArray()); Object o = GuiUtils.getChoiceOptional("Select Deck", choices.toArray());
if (o == null) { if (o == null) {
@@ -586,20 +641,24 @@ public class DeckEditorQuestMenu extends JMenuBar {
} }
return o.toString(); return o.toString();
} //getUserInput_OpenDeck() } // getUserInput_OpenDeck()
//used by Gui_Quest_DeckEditor // used by Gui_Quest_DeckEditor
/** /**
* <p>close.</p> * <p>
* close.
* </p>
*/ */
public final void close() { public final void close() {
exitCommand.execute(); exitCommand.execute();
} }
//used by Gui_Quest_DeckEditor // used by Gui_Quest_DeckEditor
/** /**
* <p>getDeckName.</p> * <p>
* * getDeckName.
* </p>
*
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public final String getDeckName() { public final String getDeckName() {

View File

@@ -18,7 +18,6 @@ import javax.swing.JOptionPane;
import net.slightlymagic.braids.util.lambda.Lambda1; import net.slightlymagic.braids.util.lambda.Lambda1;
import net.slightlymagic.maxmtg.Predicate; import net.slightlymagic.maxmtg.Predicate;
import forge.Command; import forge.Command;
import forge.Singletons; import forge.Singletons;
import forge.deck.Deck; import forge.deck.Deck;
@@ -56,15 +55,19 @@ public final class DeckEditorShop extends DeckEditorBase {
private double multiplier; private double multiplier;
private QuestData questData; private QuestData questData;
//private CardPoolView newCardsList; // private CardPoolView newCardsList;
// get pricelist: // get pricelist:
private ReadPriceList r = new ReadPriceList(); private ReadPriceList r = new ReadPriceList();
private Map<String, Integer> mapPrices = r.getPriceList(); private Map<String, Integer> mapPrices = r.getPriceList();
private Map<CardPrinted, Integer> decksUsingMyCards; private Map<CardPrinted, Integer> decksUsingMyCards;
/**
* Show.
*
* @param exitCommand
* the exit command
*/
public void show(final Command exitCommand) { public void show(final Command exitCommand) {
final Command exit = new Command() { final Command exit = new Command() {
private static final long serialVersionUID = -7428793574300520612L; private static final long serialVersionUID = -7428793574300520612L;
@@ -74,11 +77,11 @@ public final class DeckEditorShop extends DeckEditorBase {
exitCommand.execute(); exitCommand.execute();
} }
}; };
// do not change this!!!! // do not change this!!!!
this.addWindowListener(new WindowAdapter() { this.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing(WindowEvent ev) { public void windowClosing(final WindowEvent ev) {
exit.execute(); exit.execute();
} }
}); });
@@ -95,7 +98,7 @@ public final class DeckEditorShop extends DeckEditorBase {
forSale = questData.getCards().getShopList(); forSale = questData.getCards().getShopList();
} }
ItemPoolView<InventoryItem> owned = questData.getCards().getCardpool().getView(); ItemPoolView<InventoryItem> owned = questData.getCards().getCardpool().getView();
//newCardsList = questData.getCards().getNewCards(); // newCardsList = questData.getCards().getNewCards();
setItems(forSale, owned, GameType.Quest); setItems(forSale, owned, GameType.Quest);
@@ -104,8 +107,11 @@ public final class DeckEditorShop extends DeckEditorBase {
String maxSellingPrice = ""; String maxSellingPrice = "";
int maxSellPrice = questData.getCards().getSellPriceLimit(); int maxSellPrice = questData.getCards().getSellPriceLimit();
if (maxSellPrice < Integer.MAX_VALUE) { maxSellingPrice = String.format("Max selling price: %d", maxSellPrice); } if (maxSellPrice < Integer.MAX_VALUE) {
sellPercentageLabel.setText("<html>(You can sell cards at " + formatter.format(multiPercent) + "% of their value)<br>" + maxSellingPrice + "</html>"); maxSellingPrice = String.format("Max selling price: %d", maxSellPrice);
}
sellPercentageLabel.setText("<html>(You can sell cards at " + formatter.format(multiPercent)
+ "% of their value)<br>" + maxSellingPrice + "</html>");
top.sort(1, true); top.sort(1, true);
bottom.sort(1, true); bottom.sort(1, true);
@@ -125,7 +131,7 @@ public final class DeckEditorShop extends DeckEditorBase {
} }
return result; return result;
} }
/** /**
* <p> * <p>
* setup. * setup.
@@ -134,21 +140,27 @@ public final class DeckEditorShop extends DeckEditorBase {
private void setup() { private void setup() {
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>(); List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.fnQtyCompare, PresetColumns.fnQtyGet)); columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.fnQtyCompare, PresetColumns.fnQtyGet));
columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.fnNameCompare, PresetColumns.fnNameGet)); columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.fnNameCompare,
PresetColumns.fnNameGet));
columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.fnCostCompare, PresetColumns.fnCostGet)); columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.fnCostCompare, PresetColumns.fnCostGet));
columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet)); columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.fnColorCompare,
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare, PresetColumns.fnTypeGet)); PresetColumns.fnColorGet));
columns.add(new TableColumnInfo<InventoryItem>("Stats", 40, PresetColumns.fnStatsCompare, PresetColumns.fnStatsGet)); columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare,
columns.add(new TableColumnInfo<InventoryItem>("R", 30, PresetColumns.fnRarityCompare, PresetColumns.fnRarityGet)); PresetColumns.fnTypeGet));
columns.add(new TableColumnInfo<InventoryItem>("Stats", 40, PresetColumns.fnStatsCompare,
PresetColumns.fnStatsGet));
columns.add(new TableColumnInfo<InventoryItem>("R", 30, PresetColumns.fnRarityCompare,
PresetColumns.fnRarityGet));
columns.add(new TableColumnInfo<InventoryItem>("Set", 35, PresetColumns.fnSetCompare, PresetColumns.fnSetGet)); columns.add(new TableColumnInfo<InventoryItem>("Set", 35, PresetColumns.fnSetCompare, PresetColumns.fnSetGet));
columns.get(2).setCellRenderer(new ManaCostRenderer()); columns.get(2).setCellRenderer(new ManaCostRenderer());
List<TableColumnInfo<InventoryItem>> columnsBelow = new ArrayList<TableColumnInfo<InventoryItem>>(columns); List<TableColumnInfo<InventoryItem>> columnsBelow = new ArrayList<TableColumnInfo<InventoryItem>>(columns);
columns.add(new TableColumnInfo<InventoryItem>("Price", 36, fnPriceCompare, fnPriceGet)); columns.add(new TableColumnInfo<InventoryItem>("Price", 36, fnPriceCompare, fnPriceGet));
top.setup(columns, cardView); top.setup(columns, cardView);
columnsBelow.add(new TableColumnInfo<InventoryItem>("Dks", 30, fnDeckCompare, fnDeckGet)); columnsBelow.add(new TableColumnInfo<InventoryItem>("Dks", 30, fnDeckCompare, fnDeckGet));
columnsBelow.add(new TableColumnInfo<InventoryItem>("New", 35, questData.getCards().fnNewCompare, questData.getCards().fnNewGet)); columnsBelow.add(new TableColumnInfo<InventoryItem>("New", 35, questData.getCards().fnNewCompare, questData
.getCards().fnNewGet));
columnsBelow.add(new TableColumnInfo<InventoryItem>("Price", 36, fnPriceCompare, fnPriceSellGet)); columnsBelow.add(new TableColumnInfo<InventoryItem>("Price", 36, fnPriceCompare, fnPriceSellGet));
bottom.setup(columnsBelow, cardView); bottom.setup(columnsBelow, cardView);
@@ -179,7 +191,6 @@ public final class DeckEditorShop extends DeckEditorBase {
} }
} }
/** /**
* <p> * <p>
* jbInit. * jbInit.
@@ -196,23 +207,25 @@ public final class DeckEditorShop extends DeckEditorBase {
sellButton.setBounds(new Rectangle(180, 403, 146, 49)); sellButton.setBounds(new Rectangle(180, 403, 146, 49));
// removeButton.setIcon(upIcon); // removeButton.setIcon(upIcon);
if (!Singletons.getModel().getPreferences().lafFonts) if (!Singletons.getModel().getPreferences().lafFonts) {
sellButton.setFont(new java.awt.Font("Dialog", 0, 13)); sellButton.setFont(new java.awt.Font("Dialog", 0, 13));
}
sellButton.setText("Sell Card"); sellButton.setText("Sell Card");
sellButton.addActionListener(new java.awt.event.ActionListener() { sellButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(final ActionEvent e) {
sellButton_actionPerformed(e); sellButton_actionPerformed(e);
} }
}); });
buyButton.setText("Buy Card"); buyButton.setText("Buy Card");
buyButton.addActionListener(new java.awt.event.ActionListener() { buyButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(final ActionEvent e) {
buyButton_actionPerformed(e); buyButton_actionPerformed(e);
} }
}); });
if (!Singletons.getModel().getPreferences().lafFonts) if (!Singletons.getModel().getPreferences().lafFonts) {
buyButton.setFont(new java.awt.Font("Dialog", 0, 13)); buyButton.setFont(new java.awt.Font("Dialog", 0, 13));
}
buyButton.setBounds(new Rectangle(23, 403, 146, 49)); buyButton.setBounds(new Rectangle(23, 403, 146, 49));
cardView.setBounds(new Rectangle(765, 23, 239, 710)); cardView.setBounds(new Rectangle(765, 23, 239, 710));
@@ -222,15 +235,17 @@ public final class DeckEditorShop extends DeckEditorBase {
creditsLabel.setBounds(new Rectangle(19, 365, 720, 31)); creditsLabel.setBounds(new Rectangle(19, 365, 720, 31));
creditsLabel.setText("Total credits: " + questData.getCredits()); creditsLabel.setText("Total credits: " + questData.getCredits());
if (!Singletons.getModel().getPreferences().lafFonts) if (!Singletons.getModel().getPreferences().lafFonts) {
creditsLabel.setFont(new java.awt.Font("Dialog", 0, 14)); creditsLabel.setFont(new java.awt.Font("Dialog", 0, 14));
}
sellPercentageLabel.setBounds(new Rectangle(350, 403, 450, 31)); sellPercentageLabel.setBounds(new Rectangle(350, 403, 450, 31));
sellPercentageLabel.setText("(Sell percentage: " + multiplier + ")"); sellPercentageLabel.setText("(Sell percentage: " + multiplier + ")");
if (!Singletons.getModel().getPreferences().lafFonts) if (!Singletons.getModel().getPreferences().lafFonts) {
sellPercentageLabel.setFont(new java.awt.Font("Dialog", 0, 14)); sellPercentageLabel.setFont(new java.awt.Font("Dialog", 0, 14));
}
jLabel1.setText("Click on the column name (like name or color) to sort the cards"); jLabel1.setText("Click on the column name (like name or color) to sort the cards");
jLabel1.setBounds(new Rectangle(20, 1, 400, 19)); jLabel1.setBounds(new Rectangle(20, 1, 400, 19));
this.getContentPane().add(cardView, null); this.getContentPane().add(cardView, null);
this.getContentPane().add(top.getTableDecorated(), null); this.getContentPane().add(top.getTableDecorated(), null);
this.getContentPane().add(bottom.getTableDecorated(), null); this.getContentPane().add(bottom.getTableDecorated(), null);
@@ -245,14 +260,20 @@ public final class DeckEditorShop extends DeckEditorBase {
private Integer getCardValue(final InventoryItem card) { private Integer getCardValue(final InventoryItem card) {
if (mapPrices.containsKey(card.getName())) { if (mapPrices.containsKey(card.getName())) {
return mapPrices.get(card.getName()); return mapPrices.get(card.getName());
} else if (card instanceof CardPrinted) { } else if (card instanceof CardPrinted) {
switch (((CardPrinted) card).getRarity()) { switch (((CardPrinted) card).getRarity()) {
case BasicLand: return Integer.valueOf(4); case BasicLand:
case Common: return Integer.valueOf(6); return Integer.valueOf(4);
case Uncommon: return Integer.valueOf(40); case Common:
case Rare: return Integer.valueOf(120); return Integer.valueOf(6);
case MythicRare: return Integer.valueOf(600); case Uncommon:
default: return Integer.valueOf(15); return Integer.valueOf(40);
case Rare:
return Integer.valueOf(120);
case MythicRare:
return Integer.valueOf(600);
default:
return Integer.valueOf(15);
} }
} else if (card instanceof BoosterPack) { } else if (card instanceof BoosterPack) {
return 395; return 395;
@@ -260,9 +281,11 @@ public final class DeckEditorShop extends DeckEditorBase {
return 1337; return 1337;
} }
private void buyButton_actionPerformed(ActionEvent e) { private void buyButton_actionPerformed(final ActionEvent e) {
InventoryItem item = top.getSelectedCard(); InventoryItem item = top.getSelectedCard();
if (item == null ) { return; } if (item == null) {
return;
}
int value = getCardValue(item); int value = getCardValue(item);
@@ -278,8 +301,11 @@ public final class DeckEditorShop extends DeckEditorBase {
BoosterPack booster = (BoosterPack) ((BoosterPack) item).clone(); BoosterPack booster = (BoosterPack) ((BoosterPack) item).clone();
questData.getCards().buyBooster(booster, value); questData.getCards().buyBooster(booster, value);
List<CardPrinted> newCards = booster.getCards(); List<CardPrinted> newCards = booster.getCards();
for (CardPrinted card : newCards) { bottom.addCard(card); } for (CardPrinted card : newCards) {
CardListViewer c = new CardListViewer(booster.getName(), "You have found the following cards inside:", newCards); bottom.addCard(card);
}
CardListViewer c = new CardListViewer(booster.getName(), "You have found the following cards inside:",
newCards);
c.show(); c.show();
} }
@@ -289,14 +315,21 @@ public final class DeckEditorShop extends DeckEditorBase {
} }
} }
/*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckEditorBase#buildFilter()
*/
@Override @Override
protected Predicate<InventoryItem> buildFilter() { protected Predicate<InventoryItem> buildFilter() {
return Predicate.getTrue(InventoryItem.class); return Predicate.getTrue(InventoryItem.class);
} }
private void sellButton_actionPerformed(ActionEvent e) { private void sellButton_actionPerformed(final ActionEvent e) {
InventoryItem item = bottom.getSelectedCard(); InventoryItem item = bottom.getSelectedCard();
if (item == null || !( item instanceof CardPrinted )) { return; } if (item == null || !(item instanceof CardPrinted)) {
return;
}
CardPrinted card = (CardPrinted) item; CardPrinted card = (CardPrinted) item;
bottom.removeCard(card); bottom.removeCard(card);
@@ -309,29 +342,39 @@ public final class DeckEditorShop extends DeckEditorBase {
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnPriceCompare = private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnPriceCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { @Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { return getCardValue(from.getKey()); } }; public Comparable apply(final Entry<InventoryItem, Integer> from) {
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceGet = return getCardValue(from.getKey());
new Lambda1<Object, Entry<InventoryItem, Integer>>() { @Override }
public Object apply(final Entry<InventoryItem, Integer> from) { return getCardValue(from.getKey()); } }; };
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceSellGet = private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
new Lambda1<Object, Entry<InventoryItem, Integer>>() { @Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { return (int) (multiplier * getCardValue(from.getKey())); } }; public Object apply(final Entry<InventoryItem, Integer> from) {
return getCardValue(from.getKey());
@SuppressWarnings("rawtypes") }
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnDeckCompare = };
new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { @Override private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceSellGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
public Comparable apply(final Entry<InventoryItem, Integer> from) { @Override
Integer iValue = decksUsingMyCards.get(from.getKey()); public Object apply(final Entry<InventoryItem, Integer> from) {
return iValue == null ? Integer.valueOf(0) : iValue; return (int) (multiplier * getCardValue(from.getKey()));
} }; }
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnDeckGet = };
new Lambda1<Object, Entry<InventoryItem, Integer>>() { @Override
public Object apply(final Entry<InventoryItem, Integer> from) {
Integer iValue = decksUsingMyCards.get(from.getKey());
return iValue == null ? "" : iValue.toString();
} };
@SuppressWarnings("rawtypes")
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnDeckCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
@Override
public Comparable apply(final Entry<InventoryItem, Integer> from) {
Integer iValue = decksUsingMyCards.get(from.getKey());
return iValue == null ? Integer.valueOf(0) : iValue;
}
};
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnDeckGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override
public Object apply(final Entry<InventoryItem, Integer> from) {
Integer iValue = decksUsingMyCards.get(from.getKey());
return iValue == null ? "" : iValue.toString();
}
};
} }

View File

@@ -23,7 +23,6 @@ import javax.swing.text.Element;
import javax.swing.text.ElementIterator; import javax.swing.text.ElementIterator;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import forge.Singletons; import forge.Singletons;
import forge.deck.Deck; import forge.deck.Deck;
import forge.deck.DeckRecognizer; import forge.deck.DeckRecognizer;
@@ -32,33 +31,32 @@ import forge.game.GameType;
import forge.gui.GuiUtils; import forge.gui.GuiUtils;
import forge.item.CardPrinted; import forge.item.CardPrinted;
/** /**
* Dialog for quick import of decks * Dialog for quick import of decks.
*
*/ */
public class DeckImport extends JDialog { public class DeckImport extends JDialog {
private static final long serialVersionUID = -5837776824284093004L; private static final long serialVersionUID = -5837776824284093004L;
private JTextArea txtInput = new JTextArea(); private JTextArea txtInput = new JTextArea();
private static final String stylesheet = "<style>" + private static final String stylesheet = "<style>"
"body, h1, h2, h3, h4, h5, h6, table, tr, td, p {margin: 1px; padding: 0; font-weight: normal; font-style: normal; text-decoration: none; font-family: Arial; font-size: 10px;} " + + "body, h1, h2, h3, h4, h5, h6, table, tr, td, p {margin: 1px; padding: 0; font-weight: normal; font-style: normal; text-decoration: none; font-family: Arial; font-size: 10px;} "
//"h1 {border-bottom: solid 1px black; color: blue; font-size: 12px; margin: 3px 0 9px 0; } " + +
".comment {color: #666666;} " + // "h1 {border-bottom: solid 1px black; color: blue; font-size: 12px; margin: 3px 0 9px 0; } "
".knowncard {color: #009900;} " + // +
".unknowncard {color: #990000;} " + ".comment {color: #666666;} " + ".knowncard {color: #009900;} " + ".unknowncard {color: #990000;} "
".section {padding: 3px 10px; margin: 3px 0; font-weight: 700; background-color: #DDDDDD; } " + + ".section {padding: 3px 10px; margin: 3px 0; font-weight: 700; background-color: #DDDDDD; } "
"</style>"; + "</style>";
private static final String htmlWelcomeText = "<html>"+stylesheet+"<h3>You'll see recognized cards here</h3>" + private static final String htmlWelcomeText = "<html>"
"<div class='section'>Legend</div>" + + stylesheet
"<ul>" + + "<h3>You'll see recognized cards here</h3>"
"<li class='knowncard'>Recognized cards will be shown in green. These cards will be auto-imported into a new deck<BR></li>" + + "<div class='section'>Legend</div>"
"<li class='unknowncard'>Lines which seem to be cards but are either misspelled or unsupported by Forge, are shown in dark-red<BR></li>" + + "<ul>"
"<li class='comment'>Lines that appear unsignificant will be shown in gray<BR><BR></li>" + + "<li class='knowncard'>Recognized cards will be shown in green. These cards will be auto-imported into a new deck<BR></li>"
"</ul>" + + "<li class='unknowncard'>Lines which seem to be cards but are either misspelled or unsupported by Forge, are shown in dark-red<BR></li>"
"<div class='comment'>Submit feedback to Max mtg on slightlymagic.net forum</div>" + + "<li class='comment'>Lines that appear unsignificant will be shown in gray<BR><BR></li>" + "</ul>"
"<div class='comment'>Post bug-reports to http://cardforge.org/bugz/</div>" + + "<div class='comment'>Submit feedback to Max mtg on slightlymagic.net forum</div>"
"</html>"; + "<div class='comment'>Post bug-reports to http://cardforge.org/bugz/</div>" + "</html>";
private JEditorPane htmlOutput = new JEditorPane("text/html", htmlWelcomeText); private JEditorPane htmlOutput = new JEditorPane("text/html", htmlWelcomeText);
private JScrollPane scrollInput = new JScrollPane(txtInput); private JScrollPane scrollInput = new JScrollPane(txtInput);
private JScrollPane scrollOutput = new JScrollPane(htmlOutput); private JScrollPane scrollOutput = new JScrollPane(htmlOutput);
@@ -66,40 +64,47 @@ public class DeckImport extends JDialog {
private JLabel summarySide = new JLabel("This is second line"); private JLabel summarySide = new JLabel("This is second line");
private JButton cmdAccept = new JButton("Import Deck"); private JButton cmdAccept = new JButton("Import Deck");
private JButton cmdCancel = new JButton("Cancel"); private JButton cmdCancel = new JButton("Cancel");
/** The tokens. */
List<DeckRecognizer.Token> tokens = new ArrayList<DeckRecognizer.Token>(); List<DeckRecognizer.Token> tokens = new ArrayList<DeckRecognizer.Token>();
private final DeckEditorBase host; private final DeckEditorBase host;
public DeckImport(DeckEditorBase g) { /**
* Instantiates a new deck import.
*
* @param g
* the g
*/
public DeckImport(final DeckEditorBase g) {
host = g; host = g;
int wWidth = 600; int wWidth = 600;
int wHeight = 600; int wHeight = 600;
setPreferredSize(new java.awt.Dimension(wWidth, wHeight)); setPreferredSize(new java.awt.Dimension(wWidth, wHeight));
setSize(wWidth, wHeight); setSize(wWidth, wHeight);
GuiUtils.centerFrame(this); GuiUtils.centerFrame(this);
setResizable(false); setResizable(false);
setTitle("Deck Import (wip)"); setTitle("Deck Import (wip)");
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
Font fButtons = new java.awt.Font("Dialog", 0, 13); Font fButtons = new java.awt.Font("Dialog", 0, 13);
cmdAccept.setFont(fButtons); cmdAccept.setFont(fButtons);
cmdCancel.setFont(fButtons); cmdCancel.setFont(fButtons);
txtInput.setFont(fButtons); txtInput.setFont(fButtons);
//htmlOutput.setFont(fButtons); // htmlOutput.setFont(fButtons);
} }
htmlOutput.setEditable(false); htmlOutput.setEditable(false);
scrollInput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(), "Paste or type a decklist")); scrollInput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(), "Paste or type a decklist"));
scrollOutput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(), "Expect the recognized lines to appear")); scrollOutput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(),
"Expect the recognized lines to appear"));
scrollInput.setViewportBorder(BorderFactory.createLoweredBevelBorder()); scrollInput.setViewportBorder(BorderFactory.createLoweredBevelBorder());
scrollOutput.setViewportBorder(BorderFactory.createLoweredBevelBorder()); scrollOutput.setViewportBorder(BorderFactory.createLoweredBevelBorder());
getContentPane().setLayout(new MigLayout("fill")); getContentPane().setLayout(new MigLayout("fill"));
getContentPane().add(scrollInput, "cell 0 0, w 50%, sy 4, growy, pushy"); getContentPane().add(scrollInput, "cell 0 0, w 50%, sy 4, growy, pushy");
getContentPane().add(scrollOutput, "cell 1 0, w 50%, growy, pushy"); getContentPane().add(scrollOutput, "cell 1 0, w 50%, growy, pushy");
@@ -110,42 +115,50 @@ public class DeckImport extends JDialog {
getContentPane().add(cmdAccept, "cell 1 3, split 2, w 100, align c"); getContentPane().add(cmdAccept, "cell 1 3, split 2, w 100, align c");
getContentPane().add(cmdCancel, "w 100"); getContentPane().add(cmdCancel, "w 100");
cmdCancel.addActionListener(new ActionListener() { cmdCancel.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) { @Override
processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING)); } }); public void actionPerformed(final ActionEvent e) {
processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING));
}
});
cmdAccept.addActionListener(new ActionListener() { cmdAccept.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) { @Override
public void actionPerformed(final ActionEvent e) {
String warning = "This will replace contents of your currently open deck with whatever you are importing. Proceed?"; String warning = "This will replace contents of your currently open deck with whatever you are importing. Proceed?";
int answer = JOptionPane.showConfirmDialog(DeckImport.this, warning, "Replacing old deck", JOptionPane.YES_NO_OPTION); int answer = JOptionPane.showConfirmDialog(DeckImport.this, warning, "Replacing old deck",
if (JOptionPane.NO_OPTION == answer) { return; } JOptionPane.YES_NO_OPTION);
if (JOptionPane.NO_OPTION == answer) {
return;
}
Deck toSet = buildDeck(); Deck toSet = buildDeck();
host.setDeck(null, toSet.getMain(), toSet.getDeckType()); host.setDeck(null, toSet.getMain(), toSet.getDeckType());
processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING)); } }); processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING));
}
});
txtInput.getDocument().addDocumentListener(new OnChangeTextUpdate()); txtInput.getDocument().addDocumentListener(new OnChangeTextUpdate());
cmdAccept.setEnabled(false); cmdAccept.setEnabled(false);
} }
private void readInput() private void readInput() {
{
tokens.clear(); tokens.clear();
ElementIterator it = new ElementIterator(txtInput.getDocument().getDefaultRootElement()); ElementIterator it = new ElementIterator(txtInput.getDocument().getDefaultRootElement());
Element e; Element e;
while ((e=it.next()) != null) { while ((e = it.next()) != null) {
if (!e.isLeaf()) { continue; } if (!e.isLeaf()) {
continue;
}
int rangeStart = e.getStartOffset(); int rangeStart = e.getStartOffset();
int rangeEnd = e.getEndOffset(); int rangeEnd = e.getEndOffset();
try { try {
String line = txtInput.getText(rangeStart, rangeEnd-rangeStart); String line = txtInput.getText(rangeStart, rangeEnd - rangeStart);
tokens.add(DeckRecognizer.recognizeLine(line)); tokens.add(DeckRecognizer.recognizeLine(line));
} catch (BadLocationException ex) { } catch (BadLocationException ex) {
} }
} }
} }
private void displayTokens() { private void displayTokens() {
StringBuilder sbOut = new StringBuilder("<html>"); StringBuilder sbOut = new StringBuilder("<html>");
sbOut.append(stylesheet); sbOut.append(stylesheet);
@@ -155,30 +168,41 @@ public class DeckImport extends JDialog {
sbOut.append("</html>"); sbOut.append("</html>");
htmlOutput.setText(sbOut.toString()); htmlOutput.setText(sbOut.toString());
} }
private void updateSummaries() { private void updateSummaries() {
int[] cardsOk = new int[2]; int[] cardsOk = new int[2];
int[] cardsUnknown = new int[2]; int[] cardsUnknown = new int[2];
int idx = 0; int idx = 0;
for (DeckRecognizer.Token t : tokens) { for (DeckRecognizer.Token t : tokens) {
if (t.getType() == TokenType.KnownCard) { cardsOk[idx] += t.getNumber(); } if (t.getType() == TokenType.KnownCard) {
if (t.getType() == TokenType.UnknownCard) { cardsUnknown[idx] += t.getNumber(); } cardsOk[idx] += t.getNumber();
if (t.getType() == TokenType.SectionName && t.getText().toLowerCase().contains("side") ) { idx = 1; } }
if (t.getType() == TokenType.UnknownCard) {
cardsUnknown[idx] += t.getNumber();
}
if (t.getType() == TokenType.SectionName && t.getText().toLowerCase().contains("side")) {
idx = 1;
}
} }
summaryMain.setText(String.format("Main: %d cards recognized, %d unknown cards", cardsOk[0], cardsUnknown[0])); summaryMain.setText(String.format("Main: %d cards recognized, %d unknown cards", cardsOk[0], cardsUnknown[0]));
summarySide.setText(String.format("Sideboard: %d cards recognized, %d unknown cards", cardsOk[1], cardsUnknown[1])); summarySide.setText(String.format("Sideboard: %d cards recognized, %d unknown cards", cardsOk[1],
cardsUnknown[1]));
cmdAccept.setEnabled(cardsOk[0] > 0); cmdAccept.setEnabled(cardsOk[0] > 0);
} }
private Deck buildDeck(){ private Deck buildDeck() {
Deck result = new Deck(GameType.Constructed); Deck result = new Deck(GameType.Constructed);
boolean isMain = true; boolean isMain = true;
for (DeckRecognizer.Token t : tokens) { for (DeckRecognizer.Token t : tokens) {
DeckRecognizer.TokenType type = t.getType(); DeckRecognizer.TokenType type = t.getType();
if (type == DeckRecognizer.TokenType.SectionName && t.getText().toLowerCase().contains("side") ) { isMain = false; } if (type == DeckRecognizer.TokenType.SectionName && t.getText().toLowerCase().contains("side")) {
if (type != DeckRecognizer.TokenType.KnownCard) { continue; } isMain = false;
}
if (type != DeckRecognizer.TokenType.KnownCard) {
continue;
}
CardPrinted crd = t.getCard(); CardPrinted crd = t.getCard();
if(crd.isAlternate()) { if (crd.isAlternate()) {
continue; continue;
} }
if (isMain) { if (isMain) {
@@ -190,27 +214,68 @@ public class DeckImport extends JDialog {
return result; return result;
} }
/**
* The Class OnChangeTextUpdate.
*/
protected class OnChangeTextUpdate implements DocumentListener { protected class OnChangeTextUpdate implements DocumentListener {
private void onChange() { readInput(); displayTokens(); updateSummaries(); } private void onChange() {
@Override public void insertUpdate(DocumentEvent e) { onChange(); } readInput();
@Override public void removeUpdate(DocumentEvent e) { onChange(); } displayTokens();
@Override public void changedUpdate(DocumentEvent e) { } // Happend only on ENTER pressed updateSummaries();
} }
private String makeHtmlViewOfToken(DeckRecognizer.Token token) { /*
switch(token.getType()) * (non-Javadoc)
{ *
case KnownCard: * @see
return String.format("<div class='knowncard'>%s * %s [%s]</div>", token.getNumber(), token.getCard().getName(), token.getCard().getSet()); * javax.swing.event.DocumentListener#insertUpdate(javax.swing.event
case UnknownCard: * .DocumentEvent)
*/
@Override
public final void insertUpdate(final DocumentEvent e) {
onChange();
}
/*
* (non-Javadoc)
*
* @see
* javax.swing.event.DocumentListener#removeUpdate(javax.swing.event
* .DocumentEvent)
*/
@Override
public final void removeUpdate(final DocumentEvent e) {
onChange();
}
/*
* (non-Javadoc)
*
* @see
* javax.swing.event.DocumentListener#changedUpdate(javax.swing.event
* .DocumentEvent)
*/
@Override
public void changedUpdate(final DocumentEvent e) {
} // Happend only on ENTER pressed
}
private String makeHtmlViewOfToken(final DeckRecognizer.Token token) {
switch (token.getType()) {
case KnownCard:
return String.format("<div class='knowncard'>%s * %s [%s]</div>", token.getNumber(), token.getCard()
.getName(), token.getCard().getSet());
case UnknownCard:
return String.format("<div class='unknowncard'>%s * %s</div>", token.getNumber(), token.getText()); return String.format("<div class='unknowncard'>%s * %s</div>", token.getNumber(), token.getText());
case SectionName: case SectionName:
return String.format("<div class='section'>%s</div>", token.getText()); return String.format("<div class='section'>%s</div>", token.getText());
case UnknownText: case UnknownText:
case Comment: case Comment:
return String.format("<div class='comment'>%s</div>", token.getText()); return String.format("<div class='comment'>%s</div>", token.getText());
default:
break;
} }
return ""; return "";
} }
} }

View File

@@ -10,30 +10,65 @@ import net.slightlymagic.maxmtg.Predicate;
import forge.card.CardRules; import forge.card.CardRules;
import forge.item.CardPrinted; import forge.item.CardPrinted;
/** /**
* A structural class for some checkboxes need for a deck editor, contains no JPanel to store boxes on * A structural class for some checkboxes need for a deck editor, contains no
* Checkboxes are public so the using class should place them in some container. * JPanel to store boxes on Checkboxes are public so the using class should
* place them in some container.
*/ */
class FilterCheckBoxes { class FilterCheckBoxes {
/** The white. */
public final JCheckBox white; public final JCheckBox white;
/** The blue. */
public final JCheckBox blue; public final JCheckBox blue;
/** The black. */
public final JCheckBox black; public final JCheckBox black;
/** The red. */
public final JCheckBox red; public final JCheckBox red;
/** The green. */
public final JCheckBox green; public final JCheckBox green;
/** The colorless. */
public final JCheckBox colorless; public final JCheckBox colorless;
/** The land. */
public final JCheckBox land; public final JCheckBox land;
/** The creature. */
public final JCheckBox creature; public final JCheckBox creature;
/** The sorcery. */
public final JCheckBox sorcery; public final JCheckBox sorcery;
/** The instant. */
public final JCheckBox instant; public final JCheckBox instant;
/** The planeswalker. */
public final JCheckBox planeswalker; public final JCheckBox planeswalker;
/** The artifact. */
public final JCheckBox artifact; public final JCheckBox artifact;
/** The enchantment. */
public final JCheckBox enchantment; public final JCheckBox enchantment;
// Very handy for classes using mass operations on an array of checkboxes // Very handy for classes using mass operations on an array of checkboxes
/** The all colors. */
public final List<JCheckBox> allColors; public final List<JCheckBox> allColors;
/** The all types. */
public final List<JCheckBox> allTypes; public final List<JCheckBox> allTypes;
/**
* Instantiates a new filter check boxes.
*
* @param useGraphicalBoxes
* the use graphical boxes
*/
public FilterCheckBoxes(final boolean useGraphicalBoxes) { public FilterCheckBoxes(final boolean useGraphicalBoxes) {
if (useGraphicalBoxes) { if (useGraphicalBoxes) {
white = new CheckBoxWithIcon("white", "White"); white = new CheckBoxWithIcon("white", "White");
@@ -51,48 +86,81 @@ class FilterCheckBoxes {
artifact = new CheckBoxWithIcon("artifact", "Artifact"); artifact = new CheckBoxWithIcon("artifact", "Artifact");
enchantment = new CheckBoxWithIcon("enchant", "Enchantment"); enchantment = new CheckBoxWithIcon("enchant", "Enchantment");
} else { } else {
white = new JCheckBox("W", true); white = new JCheckBox("W", true);
blue = new JCheckBox("U", true); blue = new JCheckBox("U", true);
black = new JCheckBox("B", true); black = new JCheckBox("B", true);
red = new JCheckBox("R", true); red = new JCheckBox("R", true);
green = new JCheckBox("G", true); green = new JCheckBox("G", true);
colorless = new JCheckBox("C", true); colorless = new JCheckBox("C", true);
land = new JCheckBox("Land", true); land = new JCheckBox("Land", true);
creature = new JCheckBox("Creature", true); creature = new JCheckBox("Creature", true);
sorcery = new JCheckBox("Sorcery", true); sorcery = new JCheckBox("Sorcery", true);
instant = new JCheckBox("Instant", true); instant = new JCheckBox("Instant", true);
planeswalker = new JCheckBox("Planeswalker", true); planeswalker = new JCheckBox("Planeswalker", true);
artifact = new JCheckBox("Artifact", true); artifact = new JCheckBox("Artifact", true);
enchantment = new JCheckBox("Enchant", true); enchantment = new JCheckBox("Enchant", true);
} }
allColors = Arrays.asList(new JCheckBox[]{ white, blue, black, red, green, colorless}); allColors = Arrays.asList(new JCheckBox[] { white, blue, black, red, green, colorless });
allTypes = Arrays.asList(new JCheckBox[]{ land, creature, sorcery, instant, planeswalker, artifact, enchantment }); allTypes = Arrays.asList(new JCheckBox[] { land, creature, sorcery, instant, planeswalker, artifact,
enchantment });
} }
/**
* Builds the filter.
*
* @return the predicate
*/
public final Predicate<CardPrinted> buildFilter() { public final Predicate<CardPrinted> buildFilter() {
List<Predicate<CardRules>> colors = new ArrayList<Predicate<CardRules>>(); List<Predicate<CardRules>> colors = new ArrayList<Predicate<CardRules>>();
if (white.isSelected()) { colors.add(CardRules.Predicates.Presets.isWhite); } if (white.isSelected()) {
if (blue.isSelected()) { colors.add(CardRules.Predicates.Presets.isBlue); } colors.add(CardRules.Predicates.Presets.isWhite);
if (black.isSelected()) { colors.add(CardRules.Predicates.Presets.isBlack); } }
if (red.isSelected()) { colors.add(CardRules.Predicates.Presets.isRed); } if (blue.isSelected()) {
if (green.isSelected()) { colors.add(CardRules.Predicates.Presets.isGreen); } colors.add(CardRules.Predicates.Presets.isBlue);
if (colorless.isSelected()) { colors.add(CardRules.Predicates.Presets.isColorless); } }
Predicate<CardRules> filterByColor = colors.size() == 6 ? CardRules.Predicates.Presets.constantTrue : Predicate.or(colors); if (black.isSelected()) {
colors.add(CardRules.Predicates.Presets.isBlack);
}
if (red.isSelected()) {
colors.add(CardRules.Predicates.Presets.isRed);
}
if (green.isSelected()) {
colors.add(CardRules.Predicates.Presets.isGreen);
}
if (colorless.isSelected()) {
colors.add(CardRules.Predicates.Presets.isColorless);
}
Predicate<CardRules> filterByColor = colors.size() == 6 ? CardRules.Predicates.Presets.constantTrue : Predicate
.or(colors);
List<Predicate<CardRules>> types = new ArrayList<Predicate<CardRules>>(); List<Predicate<CardRules>> types = new ArrayList<Predicate<CardRules>>();
if (land.isSelected()) { types.add(CardRules.Predicates.Presets.isLand); } if (land.isSelected()) {
if (creature.isSelected()) { types.add(CardRules.Predicates.Presets.isCreature); } types.add(CardRules.Predicates.Presets.isLand);
if (sorcery.isSelected()) { types.add(CardRules.Predicates.Presets.isSorcery); } }
if (instant.isSelected()) { types.add(CardRules.Predicates.Presets.isInstant); } if (creature.isSelected()) {
if (planeswalker.isSelected()) { types.add(CardRules.Predicates.Presets.isPlaneswalker); } types.add(CardRules.Predicates.Presets.isCreature);
if (artifact.isSelected()) { types.add(CardRules.Predicates.Presets.isArtifact); } }
if (enchantment.isSelected()) { types.add(CardRules.Predicates.Presets.isEnchantment); } if (sorcery.isSelected()) {
Predicate<CardRules> filterByType = types.size() == 7 ? CardRules.Predicates.Presets.constantTrue : Predicate.or(types); types.add(CardRules.Predicates.Presets.isSorcery);
}
if (instant.isSelected()) {
types.add(CardRules.Predicates.Presets.isInstant);
}
if (planeswalker.isSelected()) {
types.add(CardRules.Predicates.Presets.isPlaneswalker);
}
if (artifact.isSelected()) {
types.add(CardRules.Predicates.Presets.isArtifact);
}
if (enchantment.isSelected()) {
types.add(CardRules.Predicates.Presets.isEnchantment);
}
Predicate<CardRules> filterByType = types.size() == 7 ? CardRules.Predicates.Presets.constantTrue : Predicate
.or(types);
return Predicate.brigde(Predicate.and(filterByColor, filterByType), CardPrinted.fnGetRules); return Predicate.brigde(Predicate.and(filterByColor, filterByType), CardPrinted.fnGetRules);
} }
} }

View File

@@ -22,27 +22,41 @@ import forge.card.CardSet;
import forge.game.GameFormat; import forge.game.GameFormat;
import forge.item.CardPrinted; import forge.item.CardPrinted;
/** /**
* A panel that holds Name, Type, Rules text fields aligned horizontally together with set filter * A panel that holds Name, Type, Rules text fields aligned horizontally
* together with set filter.
*/ */
public class FilterNameTypeSetPanel extends JComponent{ public class FilterNameTypeSetPanel extends JComponent {
private static final long serialVersionUID = -6409564625432765430L; private static final long serialVersionUID = -6409564625432765430L;
/** The label filter name. */
public final JLabel labelFilterName = new JLabel(); public final JLabel labelFilterName = new JLabel();
/** The label filter type. */
public final JLabel labelFilterType = new JLabel(); public final JLabel labelFilterType = new JLabel();
/** The label filter rules. */
public final JLabel labelFilterRules = new JLabel(); public final JLabel labelFilterRules = new JLabel();
/** The txt card name. */
public final JTextField txtCardName = new JTextField(); public final JTextField txtCardName = new JTextField();
/** The txt card type. */
public final JTextField txtCardType = new JTextField(); public final JTextField txtCardType = new JTextField();
/** The txt card rules. */
public final JTextField txtCardRules = new JTextField(); public final JTextField txtCardRules = new JTextField();
/** The search set combo. */
public final JComboBox searchSetCombo = new JComboBox(); public final JComboBox searchSetCombo = new JComboBox();
/**
public FilterNameTypeSetPanel() * Instantiates a new filter name type set panel.
{ */
public FilterNameTypeSetPanel() {
this.setLayout(new MigLayout("fill, ins 0")); this.setLayout(new MigLayout("fill, ins 0"));
labelFilterName.setText("Name:"); labelFilterName.setText("Name:");
labelFilterName.setToolTipText("Card names must include the text in this field"); labelFilterName.setToolTipText("Card names must include the text in this field");
this.add(labelFilterName, "cell 0 1, split 7"); this.add(labelFilterName, "cell 0 1, split 7");
@@ -52,18 +66,17 @@ public class FilterNameTypeSetPanel extends JComponent{
labelFilterType.setToolTipText("Card types must include the text in this field"); labelFilterType.setToolTipText("Card types must include the text in this field");
this.add(labelFilterType, ""); this.add(labelFilterType, "");
this.add(txtCardType, "wmin 100, grow"); this.add(txtCardType, "wmin 100, grow");
labelFilterRules.setText("Text:"); labelFilterRules.setText("Text:");
labelFilterRules.setToolTipText("Card descriptions must include the text in this field"); labelFilterRules.setToolTipText("Card descriptions must include the text in this field");
this.add(labelFilterRules, ""); this.add(labelFilterRules, "");
this.add(txtCardRules, "wmin 200, grow"); this.add(txtCardRules, "wmin 200, grow");
searchSetCombo.removeAllItems(); searchSetCombo.removeAllItems();
searchSetCombo.addItem("(all sets and formats)"); searchSetCombo.addItem("(all sets and formats)");
for (GameFormat s : SetUtils.getFormats()) { for (GameFormat s : SetUtils.getFormats()) {
searchSetCombo.addItem(s); searchSetCombo.addItem(s);
} }
for (CardSet s : SetUtils.getAllSets()) { for (CardSet s : SetUtils.getAllSets()) {
searchSetCombo.addItem(s); searchSetCombo.addItem(s);
} }
@@ -71,28 +84,42 @@ public class FilterNameTypeSetPanel extends JComponent{
this.add(searchSetCombo, "wmin 150, grow"); this.add(searchSetCombo, "wmin 150, grow");
} }
public void setListeners(DocumentListener onTextChange, ItemListener onComboChange) /**
{ * Sets the listeners.
*
* @param onTextChange
* the on text change
* @param onComboChange
* the on combo change
*/
public final void setListeners(final DocumentListener onTextChange, final ItemListener onComboChange) {
txtCardType.getDocument().addDocumentListener(onTextChange); txtCardType.getDocument().addDocumentListener(onTextChange);
txtCardRules.getDocument().addDocumentListener(onTextChange); txtCardRules.getDocument().addDocumentListener(onTextChange);
txtCardName.getDocument().addDocumentListener(onTextChange); txtCardName.getDocument().addDocumentListener(onTextChange);
searchSetCombo.addItemListener(onComboChange); searchSetCombo.addItemListener(onComboChange);
} }
public Predicate<CardPrinted> buildFilter() { /**
* Builds the filter.
*
* @return the predicate
*/
public final Predicate<CardPrinted> buildFilter() {
List<Predicate<CardPrinted>> rules = new ArrayList<Predicate<CardPrinted>>(4); List<Predicate<CardPrinted>> rules = new ArrayList<Predicate<CardPrinted>>(4);
if (StringUtils.isNotBlank(txtCardName.getText())) { if (StringUtils.isNotBlank(txtCardName.getText())) {
rules.add(CardPrinted.Predicates.name(StringOp.CONTAINS, txtCardName.getText())); rules.add(CardPrinted.Predicates.name(StringOp.CONTAINS, txtCardName.getText()));
} }
if (StringUtils.isNotBlank(txtCardType.getText())) { if (StringUtils.isNotBlank(txtCardType.getText())) {
rules.add(Predicate.brigde(CardRules.Predicates.joinedType(StringOp.CONTAINS, txtCardType.getText()), CardPrinted.fnGetRules)); rules.add(Predicate.brigde(CardRules.Predicates.joinedType(StringOp.CONTAINS, txtCardType.getText()),
CardPrinted.fnGetRules));
} }
if (StringUtils.isNotBlank(txtCardRules.getText())) { if (StringUtils.isNotBlank(txtCardRules.getText())) {
rules.add(Predicate.brigde(CardRules.Predicates.rules(StringOp.CONTAINS, txtCardRules.getText()), CardPrinted.fnGetRules)); rules.add(Predicate.brigde(CardRules.Predicates.rules(StringOp.CONTAINS, txtCardRules.getText()),
CardPrinted.fnGetRules));
} }
if (searchSetCombo.getSelectedIndex() != 0) { if (searchSetCombo.getSelectedIndex() != 0) {
Object selected = searchSetCombo.getSelectedItem(); Object selected = searchSetCombo.getSelectedItem();
if (selected instanceof CardSet) { if (selected instanceof CardSet) {
@@ -102,18 +129,22 @@ public class FilterNameTypeSetPanel extends JComponent{
} }
} }
switch (rules.size()){ switch (rules.size()) {
case 0: return Predicate.getTrue(CardPrinted.class); case 0:
case 1: return rules.get(0); return Predicate.getTrue(CardPrinted.class);
case 2: return Predicate.and(rules.get(0), rules.get(1)); case 1:
default: return Predicate.and(rules); return rules.get(0);
case 2:
return Predicate.and(rules.get(0), rules.get(1));
default:
return Predicate.and(rules);
} }
} }
/** /**
* TODO: Write javadoc for this method. * TODO: Write javadoc for this method.
*/ */
public void clearFilters() { public final void clearFilters() {
txtCardName.setText(""); txtCardName.setText("");
txtCardType.setText(""); txtCardType.setText("");
txtCardRules.setText(""); txtCardRules.setText("");

View File

@@ -6,12 +6,12 @@ import java.util.List;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableCellRenderer;
import arcane.ui.util.ManaSymbols; import arcane.ui.util.ManaSymbols;
import forge.card.CardManaCostShard;
import forge.card.CardManaCost; import forge.card.CardManaCost;
import forge.card.CardManaCostShard;
/** /**
* Displays mana cost as symbols. * Displays mana cost as symbols.
*/ */
public class ManaCostRenderer extends DefaultTableCellRenderer { public class ManaCostRenderer extends DefaultTableCellRenderer {
@@ -19,17 +19,28 @@ public class ManaCostRenderer extends DefaultTableCellRenderer {
private CardManaCost value; private CardManaCost value;
/*
* (non-Javadoc)
*
* @see
* javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent
* (javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
*/
@Override @Override
public Component getTableCellRendererComponent(final JTable table, final Object value, public final Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected,
final boolean isSelected, final boolean hasFocus, final int row, final int column) final boolean hasFocus, final int row, final int column) {
{
this.value = (CardManaCost) value; this.value = (CardManaCost) value;
setToolTipText(this.value.toString()); setToolTipText(this.value.toString());
return super.getTableCellRendererComponent(table, "", isSelected, hasFocus, row, column); return super.getTableCellRendererComponent(table, "", isSelected, hasFocus, row, column);
} }
/*
* (non-Javadoc)
*
* @see javax.swing.JComponent#paint(java.awt.Graphics)
*/
@Override @Override
public void paint(final Graphics g) { public final void paint(final Graphics g) {
super.paint(g); super.paint(g);
final int elemtWidth = 13; final int elemtWidth = 13;
@@ -44,7 +55,8 @@ public class ManaCostRenderer extends DefaultTableCellRenderer {
int cellWidth = getWidth(); int cellWidth = getWidth();
int cntGlyphs = hasGeneric ? shards.size() + 1 : shards.size(); int cntGlyphs = hasGeneric ? shards.size() + 1 : shards.size();
float offsetIfNoSpace = cntGlyphs > 1 ? (cellWidth - padding - elemtWidth) / (cntGlyphs - 1f) : elemtWidth + elemtGap; float offsetIfNoSpace = cntGlyphs > 1 ? (cellWidth - padding - elemtWidth) / (cntGlyphs - 1f) : elemtWidth
+ elemtGap;
float offset = Math.min(elemtWidth + elemtGap, offsetIfNoSpace); float offset = Math.min(elemtWidth + elemtGap, offsetIfNoSpace);
if (hasGeneric) { if (hasGeneric) {

View File

@@ -12,90 +12,195 @@ import forge.item.CardPrinted;
import forge.item.InventoryItem; import forge.item.InventoryItem;
import forge.item.InventoryItemFromSet; import forge.item.InventoryItemFromSet;
/** /**
* TODO: Write javadoc for this type. * TODO: Write javadoc for this type.
* *
*/ */
public abstract class PresetColumns { public abstract class PresetColumns {
private static CardManaCost toManaCost(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getManaCost() : CardManaCost.empty; } private static CardManaCost toManaCost(final InventoryItem i) {
private static CardColor toColor(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getColor() : CardColor.nullColor; } return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getManaCost() : CardManaCost.empty;
private static String toPTL(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getPTorLoyalty() : ""; } }
private static CardRarity toRarity(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getRarity() : CardRarity.Unknown; }
private static CardSet toSetCmp(InventoryItem i) { return i instanceof InventoryItemFromSet ? SetUtils.getSetByCode(((InventoryItemFromSet) i).getSet()) : CardSet.unknown; }
private static String toSetStr(InventoryItem i) { return i instanceof InventoryItemFromSet ? ((InventoryItemFromSet) i).getSet() : "n/a"; }
private static Integer toAiCmp(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatusComparable() : Integer.valueOf(-1); }
private static String toAiStr(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatus() : "n/a"; }
@SuppressWarnings("rawtypes")
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnQtyCompare =
new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { return from.getValue(); } };
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnQtyGet =
new Lambda1<Object, Entry<InventoryItem, Integer>>() { @Override
public Object apply(final Entry<InventoryItem, Integer> from) { return from.getValue(); } };
@SuppressWarnings("rawtypes") private static CardColor toColor(final InventoryItem i) {
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnNameCompare = return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getColor() : CardColor.nullColor;
new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { @Override }
public Comparable apply(final Entry<InventoryItem, Integer> from) { return from.getKey().getName(); } };
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnNameGet =
new Lambda1<Object, Entry<InventoryItem, Integer>>() { @Override
public Object apply(final Entry<InventoryItem, Integer> from) { return from.getKey().getName(); } };
@SuppressWarnings("rawtypes") private static String toPTL(final InventoryItem i) {
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnCostCompare = return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getPTorLoyalty() : "";
new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { @Override }
public Comparable apply(final Entry<InventoryItem, Integer> from) { return toManaCost(from.getKey()); } };
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnCostGet =
new Lambda1<Object, Entry<InventoryItem, Integer>>() { @Override
public Object apply(final Entry<InventoryItem, Integer> from) { return toManaCost(from.getKey()); } };
@SuppressWarnings("rawtypes") private static CardRarity toRarity(final InventoryItem i) {
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnColorCompare = return i instanceof CardPrinted ? ((CardPrinted) i).getRarity() : CardRarity.Unknown;
new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { @Override }
public Comparable apply(final Entry<InventoryItem, Integer> from) { return toColor(from.getKey()); } };
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnColorGet =
new Lambda1<Object, Entry<InventoryItem, Integer>>() { @Override
public Object apply(final Entry<InventoryItem, Integer> from) { return toColor(from.getKey()); } };
@SuppressWarnings("rawtypes") private static CardSet toSetCmp(final InventoryItem i) {
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnTypeCompare = return i instanceof InventoryItemFromSet ? SetUtils.getSetByCode(((InventoryItemFromSet) i).getSet())
new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { @Override : CardSet.unknown;
public Comparable apply(final Entry<InventoryItem, Integer> from) { return from.getKey().getType(); } }; }
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnTypeGet =
new Lambda1<Object, Entry<InventoryItem, Integer>>() { @Override
public Object apply(final Entry<InventoryItem, Integer> from) { return from.getKey().getType(); } };
@SuppressWarnings("rawtypes") private static String toSetStr(final InventoryItem i) {
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnStatsCompare = return i instanceof InventoryItemFromSet ? ((InventoryItemFromSet) i).getSet() : "n/a";
new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { @Override }
public Comparable apply(final Entry<InventoryItem, Integer> from) { return toPTL(from.getKey()); } };
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnStatsGet =
new Lambda1<Object, Entry<InventoryItem, Integer>>() { @Override
public Object apply(final Entry<InventoryItem, Integer> from) { return toPTL(from.getKey()); } };
@SuppressWarnings("rawtypes") private static Integer toAiCmp(final InventoryItem i) {
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnRarityCompare = return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatusComparable() : Integer.valueOf(-1);
new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { @Override }
public Comparable apply(final Entry<InventoryItem, Integer> from) { return toRarity(from.getKey()); } };
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnRarityGet =
new Lambda1<Object, Entry<InventoryItem, Integer>>() { @Override
public Object apply(final Entry<InventoryItem, Integer> from) { return toRarity(from.getKey()); } };
@SuppressWarnings("rawtypes") private static String toAiStr(final InventoryItem i) {
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnSetCompare = return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatus() : "n/a";
new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { @Override }
public Comparable apply(final Entry<InventoryItem, Integer> from) { return toSetCmp(from.getKey()); } };
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnSetGet =
new Lambda1<Object, Entry<InventoryItem, Integer>>() { @Override
public Object apply(final Entry<InventoryItem, Integer> from) { return toSetStr(from.getKey()); } };
/** The Constant fnQtyCompare. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnAiStatusCompare = public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnQtyCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { @Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { return toAiCmp(from.getKey()); } }; public Comparable apply(final Entry<InventoryItem, Integer> from) {
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnAiStatusGet = return from.getValue();
new Lambda1<Object, Entry<InventoryItem, Integer>>() { @Override }
public Object apply(final Entry<InventoryItem, Integer> from) { return toAiStr(from.getKey()); } }; };
/** The Constant fnQtyGet. */
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnQtyGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override
public Object apply(final Entry<InventoryItem, Integer> from) {
return from.getValue();
}
};
/** The Constant fnNameCompare. */
@SuppressWarnings("rawtypes")
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnNameCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
@Override
public Comparable apply(final Entry<InventoryItem, Integer> from) {
return from.getKey().getName();
}
};
/** The Constant fnNameGet. */
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnNameGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override
public Object apply(final Entry<InventoryItem, Integer> from) {
return from.getKey().getName();
}
};
/** The Constant fnCostCompare. */
@SuppressWarnings("rawtypes")
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnCostCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
@Override
public Comparable apply(final Entry<InventoryItem, Integer> from) {
return toManaCost(from.getKey());
}
};
/** The Constant fnCostGet. */
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnCostGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override
public Object apply(final Entry<InventoryItem, Integer> from) {
return toManaCost(from.getKey());
}
};
/** The Constant fnColorCompare. */
@SuppressWarnings("rawtypes")
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnColorCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
@Override
public Comparable apply(final Entry<InventoryItem, Integer> from) {
return toColor(from.getKey());
}
};
/** The Constant fnColorGet. */
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnColorGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override
public Object apply(final Entry<InventoryItem, Integer> from) {
return toColor(from.getKey());
}
};
/** The Constant fnTypeCompare. */
@SuppressWarnings("rawtypes")
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnTypeCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
@Override
public Comparable apply(final Entry<InventoryItem, Integer> from) {
return from.getKey().getType();
}
};
/** The Constant fnTypeGet. */
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnTypeGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override
public Object apply(final Entry<InventoryItem, Integer> from) {
return from.getKey().getType();
}
};
/** The Constant fnStatsCompare. */
@SuppressWarnings("rawtypes")
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnStatsCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
@Override
public Comparable apply(final Entry<InventoryItem, Integer> from) {
return toPTL(from.getKey());
}
};
/** The Constant fnStatsGet. */
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnStatsGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override
public Object apply(final Entry<InventoryItem, Integer> from) {
return toPTL(from.getKey());
}
};
/** The Constant fnRarityCompare. */
@SuppressWarnings("rawtypes")
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnRarityCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
@Override
public Comparable apply(final Entry<InventoryItem, Integer> from) {
return toRarity(from.getKey());
}
};
/** The Constant fnRarityGet. */
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnRarityGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override
public Object apply(final Entry<InventoryItem, Integer> from) {
return toRarity(from.getKey());
}
};
/** The Constant fnSetCompare. */
@SuppressWarnings("rawtypes")
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnSetCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
@Override
public Comparable apply(final Entry<InventoryItem, Integer> from) {
return toSetCmp(from.getKey());
}
};
/** The Constant fnSetGet. */
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnSetGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override
public Object apply(final Entry<InventoryItem, Integer> from) {
return toSetStr(from.getKey());
}
};
/** The Constant fnAiStatusCompare. */
@SuppressWarnings("rawtypes")
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnAiStatusCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
@Override
public Comparable apply(final Entry<InventoryItem, Integer> from) {
return toAiCmp(from.getKey());
}
};
/** The Constant fnAiStatusGet. */
public static final Lambda1<Object, Entry<InventoryItem, Integer>> fnAiStatusGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override
public Object apply(final Entry<InventoryItem, Integer> from) {
return toAiStr(from.getKey());
}
};
} }

View File

@@ -6,61 +6,130 @@ import javax.swing.table.TableCellRenderer;
import net.slightlymagic.braids.util.lambda.Lambda1; import net.slightlymagic.braids.util.lambda.Lambda1;
/** /**
* Holds single column set up for TableModel. * Holds single column set up for TableModel. Contains name, width + functions
* Contains name, width + functions to retrieve column's value for compare and for display * to retrieve column's value for compare and for display (they are different,
* (they are different, in case of sets for instance) * in case of sets for instance)
*
* @param <T>
* the generic type
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public class TableColumnInfo<T> { public class TableColumnInfo<T> {
private final String name; private final String name;
public int minWidth; /** The min width. */
public int maxWidth; public int minWidth;
public int nominalWidth;
public boolean isMinMaxApplied = true; /** The max width. */
public int maxWidth;
public final Lambda1<Comparable, Entry<T, Integer>> fnSort; // this will be used for sorting /** The nominal width. */
public final Lambda1<Object, Entry<T, Integer>> fnDisplay; // this is used to display public int nominalWidth;
private TableCellRenderer cellRenderer = null; /** The is min max applied. */
public boolean isMinMaxApplied = true;
public final String getName() { return name; } /** The fn sort. */
public final Lambda1<Comparable, Entry<T, Integer>> fnSort; // this will be
// used for
// sorting
public TableColumnInfo(final String colName, /** The fn display. */
final Lambda1<Comparable, Entry<T, Integer>> fieldSort, public final Lambda1<Object, Entry<T, Integer>> fnDisplay; // this is used
final Lambda1<Object, Entry<T, Integer>> fieldDisplay) { // to display
fnSort = fieldSort;
fnDisplay = fieldDisplay;
this.name = colName;
}
public TableColumnInfo(final String colName, final int width, private TableCellRenderer cellRenderer = null;
final Lambda1<Comparable, Entry<T, Integer>> fieldSort,
final Lambda1<Object, Entry<T, Integer>> fieldDisplay) {
this(colName, fieldSort, fieldDisplay);
this.maxWidth = width;
this.minWidth = width;
this.nominalWidth = width;
}
public TableColumnInfo(final String colName, final int wMin, final int width, final int wMax,
final Lambda1<Comparable, Entry<T, Integer>> fieldSort,
final Lambda1<Object, Entry<T, Integer>> fieldDisplay) {
this(colName, fieldSort, fieldDisplay);
this.maxWidth = wMax;
this.minWidth = wMin;
this.nominalWidth = width;
}
/**
public void setCellRenderer(final TableCellRenderer renderer) { * Gets the name.
cellRenderer = renderer; *
} * @return the name
*/
public final TableCellRenderer getCellRenderer() { public final String getName() {
return cellRenderer; return name;
}
} }
/**
* Instantiates a new table column info.
*
* @param colName
* the col name
* @param fieldSort
* the field sort
* @param fieldDisplay
* the field display
*/
public TableColumnInfo(final String colName, final Lambda1<Comparable, Entry<T, Integer>> fieldSort,
final Lambda1<Object, Entry<T, Integer>> fieldDisplay) {
fnSort = fieldSort;
fnDisplay = fieldDisplay;
this.name = colName;
}
/**
* Instantiates a new table column info.
*
* @param colName
* the col name
* @param width
* the width
* @param fieldSort
* the field sort
* @param fieldDisplay
* the field display
*/
public TableColumnInfo(final String colName, final int width,
final Lambda1<Comparable, Entry<T, Integer>> fieldSort,
final Lambda1<Object, Entry<T, Integer>> fieldDisplay) {
this(colName, fieldSort, fieldDisplay);
this.maxWidth = width;
this.minWidth = width;
this.nominalWidth = width;
}
/**
* Instantiates a new table column info.
*
* @param colName
* the col name
* @param wMin
* the w min
* @param width
* the width
* @param wMax
* the w max
* @param fieldSort
* the field sort
* @param fieldDisplay
* the field display
*/
public TableColumnInfo(final String colName, final int wMin, final int width, final int wMax,
final Lambda1<Comparable, Entry<T, Integer>> fieldSort,
final Lambda1<Object, Entry<T, Integer>> fieldDisplay) {
this(colName, fieldSort, fieldDisplay);
this.maxWidth = wMax;
this.minWidth = wMin;
this.nominalWidth = width;
}
/**
* Sets the cell renderer.
*
* @param renderer
* the new cell renderer
*/
public final void setCellRenderer(final TableCellRenderer renderer) {
cellRenderer = renderer;
}
/**
* Gets the cell renderer.
*
* @return the cell renderer
*/
public final TableCellRenderer getCellRenderer() {
return cellRenderer;
}
}

View File

@@ -1,7 +1,15 @@
package forge.gui.deckeditor; package forge.gui.deckeditor;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import javax.swing.*; import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelEvent;
@@ -13,16 +21,13 @@ import forge.item.InventoryItem;
import forge.item.ItemPool; import forge.item.ItemPool;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
/** /**
* <p>TableModel class.</p> * <p>
* * TableModel class.
* </p>
*
* @param <T>
* the generic type
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
@@ -36,13 +41,17 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
private class Order { private class Order {
public final int sortColumn; public final int sortColumn;
public boolean isSortAsc = true; public boolean isSortAsc = true;
public Order(final int col) { sortColumn = col; }
public Order(final int col) {
sortColumn = col;
}
}; };
private final int MAX_DEPTH = 3; private final int MAX_DEPTH = 3;
private List<Order> orders = new ArrayList<Order>(3); private List<Order> orders = new ArrayList<Order>(3);
private TableSorterCascade<T> sorter = null; private TableSorterCascade<T> sorter = null;
private boolean isSorterReady = false; private boolean isSorterReady = false;
private int indexOfColumn(final int column) { private int indexOfColumn(final int column) {
int posColumn = orders.size() - 1; int posColumn = orders.size() - 1;
for (; posColumn >= 0; posColumn--) { for (; posColumn >= 0; posColumn--) {
@@ -60,22 +69,26 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
isSorterReady = false; isSorterReady = false;
} }
// puts desired direction on top, set "asc"; if already was on top, inverts direction; // puts desired direction on top, set "asc"; if already was on top,
// inverts direction;
public void add(final int column) { public void add(final int column) {
int posColumn = indexOfColumn(column); int posColumn = indexOfColumn(column);
switch (posColumn) { switch (posColumn) {
case -1: // no such column here - let's add then case -1: // no such column here - let's add then
orders.add(0, new Order(column)); orders.add(0, new Order(column));
break; break;
case 0: // found at top-level, should invert case 0: // found at top-level, should invert
orders.get(0).isSortAsc ^= true; // invert orders.get(0).isSortAsc ^= true; // invert
break; break;
default: // found somewhere, move down others, set this one onto top; default: // found somewhere, move down others, set this one onto
orders.remove(posColumn); // top;
orders.add(0, new Order(column)); orders.remove(posColumn);
break; orders.add(0, new Order(column));
break;
}
if (orders.size() > MAX_DEPTH) {
orders.remove(MAX_DEPTH);
} }
if(orders.size() > MAX_DEPTH) { orders.remove(MAX_DEPTH); }
isSorterReady = false; isSorterReady = false;
} }
@@ -96,14 +109,29 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
private final List<TableColumnInfo<T>> columns; private final List<TableColumnInfo<T>> columns;
private final SortOrders sortOrders = new SortOrders(); private final SortOrders sortOrders = new SortOrders();
public TableModel(final CardPanelBase cd, final List<TableColumnInfo<T>> columnsToShow, Class<T> cls) { /**
* Instantiates a new table model.
*
* @param cd
* the cd
* @param columnsToShow
* the columns to show
* @param cls
* the cls
*/
public TableModel(final CardPanelBase cd, final List<TableColumnInfo<T>> columnsToShow, final Class<T> cls) {
data = new ItemPool<T>(cls); data = new ItemPool<T>(cls);
cardDisplay = cd; cardDisplay = cd;
columns = columnsToShow; columns = columnsToShow;
columns.get(4).isMinMaxApplied = false; columns.get(4).isMinMaxApplied = false;
} }
/**
* Resize cols.
*
* @param table
* the table
*/
public void resizeCols(final JTable table) { public void resizeCols(final JTable table) {
TableColumn tableColumn = null; TableColumn tableColumn = null;
for (int i = 0; i < table.getColumnCount(); i++) { for (int i = 0; i < table.getColumnCount(); i++) {
@@ -118,13 +146,29 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
} }
} }
public void clear() { data.clear(); } /**
public ItemPoolView<T> getCards() { return data.getView(); } * Clear.
*/
public void clear() {
data.clear();
}
/** /**
* <p>removeCard.</p> * Gets the cards.
* *
* @param c a {@link forge.Card} object. * @return the cards
*/
public ItemPoolView<T> getCards() {
return data.getView();
}
/**
* <p>
* removeCard.
* </p>
*
* @param c
* a {@link forge.Card} object.
*/ */
public void removeCard(final T c) { public void removeCard(final T c) {
boolean wasThere = data.count(c) > 0; boolean wasThere = data.count(c) > 0;
@@ -134,36 +178,89 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
} }
} }
/**
* Adds the card.
*
* @param c
* the c
*/
public void addCard(final T c) { public void addCard(final T c) {
data.add(c); data.add(c);
fireTableDataChanged(); fireTableDataChanged();
} }
/**
* Adds the card.
*
* @param c
* the c
* @param count
* the count
*/
public void addCard(final T c, final int count) { public void addCard(final T c, final int count) {
data.add(c, count); data.add(c, count);
fireTableDataChanged(); fireTableDataChanged();
} }
/**
* Adds the card.
*
* @param e
* the e
*/
public void addCard(final Entry<T, Integer> e) { public void addCard(final Entry<T, Integer> e) {
data.add(e.getKey(), e.getValue()); data.add(e.getKey(), e.getValue());
fireTableDataChanged(); fireTableDataChanged();
} }
/**
* Adds the cards.
*
* @param c
* the c
*/
public void addCards(final Iterable<Entry<T, Integer>> c) { public void addCards(final Iterable<Entry<T, Integer>> c) {
data.addAll(c); data.addAll(c);
fireTableDataChanged(); fireTableDataChanged();
} }
/**
* Adds the all cards.
*
* @param c
* the c
*/
public void addAllCards(final Iterable<T> c) { public void addAllCards(final Iterable<T> c) {
data.addAllCards(c); data.addAllCards(c);
fireTableDataChanged(); fireTableDataChanged();
} }
/**
* Row to card.
*
* @param row
* the row
* @return the entry
*/
public Entry<T, Integer> rowToCard(final int row) { public Entry<T, Integer> rowToCard(final int row) {
List<Entry<T, Integer>> model = data.getOrderedList(); List<Entry<T, Integer>> model = data.getOrderedList();
return row >= 0 && row < model.size() ? model.get(row) : null; return row >= 0 && row < model.size() ? model.get(row) : null;
} }
/*
* (non-Javadoc)
*
* @see javax.swing.table.TableModel#getRowCount()
*/
public int getRowCount() { public int getRowCount() {
return data.countDistinct(); return data.countDistinct();
} }
/*
* (non-Javadoc)
*
* @see javax.swing.table.TableModel#getColumnCount()
*/
public int getColumnCount() { public int getColumnCount() {
return columns.size(); return columns.size();
} }
@@ -179,34 +276,67 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
return columns.get(column).fnDisplay.apply(rowToCard(row)); return columns.get(column).fnDisplay.apply(rowToCard(row));
} }
/**
* The listener interface for receiving column events. The class that is
* interested in processing a column event implements this interface, and
* the object created with that class is registered with a component using
* the component's <code>addColumnListener<code> method. When
* the column event occurs, that object's appropriate
* method is invoked.
*
* @see ColumnEvent
*/
class ColumnListener extends MouseAdapter { class ColumnListener extends MouseAdapter {
/** The table. */
protected JTable table; protected JTable table;
public ColumnListener(final JTable t) { table = t; } /**
* Instantiates a new column listener.
public void mouseClicked(final MouseEvent e) { *
TableColumnModel colModel = table.getColumnModel(); * @param t
int columnModelIndex = colModel.getColumnIndexAtX(e.getX()); * the t
int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex(); */
public ColumnListener(final JTable t) {
if (modelIndex < 0) { return; } table = t;
// This will invert if needed
sortOrders.add(modelIndex);
for (int i = 0; i < columns.size(); i++) {
TableColumn column = colModel.getColumn(i);
column.setHeaderValue(getColumnName(column.getModelIndex()));
}
table.getTableHeader().repaint();
resort();
table.tableChanged(new TableModelEvent(TableModel.this));
table.repaint();
} }
}
/*
* (non-Javadoc)
*
* @see
* java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
*/
public void mouseClicked(final MouseEvent e) {
TableColumnModel colModel = table.getColumnModel();
int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
if (modelIndex < 0) {
return;
}
// This will invert if needed
sortOrders.add(modelIndex);
for (int i = 0; i < columns.size(); i++) {
TableColumn column = colModel.getColumn(i);
column.setHeaderValue(getColumnName(column.getModelIndex()));
}
table.getTableHeader().repaint();
resort();
table.tableChanged(new TableModelEvent(TableModel.this));
table.repaint();
}
}
/**
* Show selected card.
*
* @param table
* the table
*/
public void showSelectedCard(final JTable table) { public void showSelectedCard(final JTable table) {
int row = table.getSelectedRow(); int row = table.getSelectedRow();
if (row != -1) { if (row != -1) {
@@ -216,12 +346,15 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
} }
/** /**
* <p>addListeners.</p> * <p>
* * addListeners.
* @param table a {@link javax.swing.JTable} object. * </p>
*
* @param table
* a {@link javax.swing.JTable} object.
*/ */
public void addListeners(final JTable table) { public void addListeners(final JTable table) {
//updates card detail, listens to any key strokes // updates card detail, listens to any key strokes
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override @Override
@@ -231,24 +364,38 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
}); });
table.addFocusListener(new FocusListener() { table.addFocusListener(new FocusListener() {
@Override public void focusLost(final FocusEvent e) {} @Override
@Override public void focusGained(final FocusEvent e) { public void focusLost(final FocusEvent e) {
}
@Override
public void focusGained(final FocusEvent e) {
showSelectedCard(table); showSelectedCard(table);
} }
}); });
table.getTableHeader().addMouseListener(new ColumnListener(table)); table.getTableHeader().addMouseListener(new ColumnListener(table));
}//addCardListener() }// addCardListener()
/**
* Resort.
*/
public void resort() { public void resort() {
Collections.sort(data.getOrderedList(), sortOrders.getSorter()); Collections.sort(data.getOrderedList(), sortOrders.getSorter());
} }
public void sort( int iCol, boolean isAsc ) { /**
* Sort.
*
* @param iCol
* the i col
* @param isAsc
* the is asc
*/
public void sort(final int iCol, final boolean isAsc) {
sortOrders.add(iCol, isAsc); sortOrders.add(iCol, isAsc);
resort(); resort();
} }
}//CardTableModel }// CardTableModel

View File

@@ -1,50 +1,66 @@
package forge.gui.deckeditor; package forge.gui.deckeditor;
import forge.item.CardPrinted;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map.Entry; import java.util.Map.Entry;
import net.slightlymagic.braids.util.lambda.Lambda1; import net.slightlymagic.braids.util.lambda.Lambda1;
import forge.item.CardPrinted;
/** /**
* <p>TableSorter class.</p> * <p>
* * TableSorter class.
* </p>
*
* @param <T>
* the generic type
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
@SuppressWarnings("unchecked") // Comparable needs <type> @SuppressWarnings("unchecked")
// Comparable needs <type>
public class TableSorter<T> implements Comparator<Entry<T, Integer>> { public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
private boolean ascending; private boolean ascending;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private Lambda1<Comparable, Entry<T, Integer>> field; private Lambda1<Comparable, Entry<T, Integer>> field;
/** /**
* <p>Constructor for TableSorter.</p> * <p>
* * Constructor for TableSorter.
* @param in_all a {@link forge.CardList} object. * </p>
* @param in_column a int. *
* @param in_ascending a boolean. * @param field
* the field
* @param in_ascending
* a boolean.
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public TableSorter(Lambda1<Comparable, Entry<T, Integer>> field, boolean in_ascending) { public TableSorter(final Lambda1<Comparable, Entry<T, Integer>> field, final boolean in_ascending) {
this.field = field; this.field = field;
ascending = in_ascending; ascending = in_ascending;
} }
/** The Constant byNameThenSet. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static final TableSorter<CardPrinted> byNameThenSet = new TableSorter<CardPrinted>( public static final TableSorter<CardPrinted> byNameThenSet = new TableSorter<CardPrinted>(
new Lambda1<Comparable, Entry<CardPrinted, Integer>>() { new Lambda1<Comparable, Entry<CardPrinted, Integer>>() {
@Override public Comparable apply(final Entry<CardPrinted, Integer> from) { return from.getKey(); } @Override
}, true); public Comparable apply(final Entry<CardPrinted, Integer> from) {
return from.getKey();
}
}, true);
/*
* (non-Javadoc)
*
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public int compare(Entry<T, Integer> arg0, Entry<T, Integer> arg1) { public final int compare(final Entry<T, Integer> arg0, final Entry<T, Integer> arg1) {
Comparable obj1 = field.apply(arg0); Comparable obj1 = field.apply(arg0);
Comparable obj2 = field.apply(arg1); Comparable obj2 = field.apply(arg1);
//System.out.println(String.format("%s vs %s _______ %s vs %s", arg0, arg1, obj1, obj2)); // System.out.println(String.format("%s vs %s _______ %s vs %s", arg0,
// arg1, obj1, obj2));
return ascending ? obj1.compareTo(obj2) : obj2.compareTo(obj1); return ascending ? obj1.compareTo(obj2) : obj2.compareTo(obj1);
} }
} }

View File

@@ -1,18 +1,20 @@
package forge.gui.deckeditor; package forge.gui.deckeditor;
import forge.item.InventoryItem;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import forge.item.InventoryItem;
/** /**
* <p>TableSorter class.</p> * <p>
* * TableSorter class.
* </p>
*
* @param <T>
* extends InventoryItem
* @author Forge * @author Forge
* @version $Id: TableSorter.java 10146 2011-09-01 18:11:00Z Max mtg $ * @version $Id: TableSorter.java 10146 2011-09-01 18:11:00Z Max mtg $
*
* @param <T> extends InventoryItem
*/ */
public class TableSorterCascade<T extends InventoryItem> implements Comparator<Entry<T, Integer>> { public class TableSorterCascade<T extends InventoryItem> implements Comparator<Entry<T, Integer>> {
private List<TableSorter<T>> sorters; private List<TableSorter<T>> sorters;
@@ -21,20 +23,29 @@ public class TableSorterCascade<T extends InventoryItem> implements Comparator<E
/** /**
* *
* TableSorterCascade Constructor. * TableSorterCascade Constructor.
* @param sortersCascade a List<TableSorter<T>> *
* @param sortersCascade
* a List<TableSorter<T>>
*/ */
public TableSorterCascade(final List<TableSorter<T>> sortersCascade) { public TableSorterCascade(final List<TableSorter<T>> sortersCascade) {
this.sorters = sortersCascade; this.sorters = sortersCascade;
cntFields = sortersCascade.size(); cntFields = sortersCascade.size();
} }
/*
* (non-Javadoc)
*
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
@Override @Override
public final int compare(final Entry<T, Integer> arg0, final Entry<T, Integer> arg1) { public final int compare(final Entry<T, Integer> arg0, final Entry<T, Integer> arg1) {
int lastCompare = 0; int lastCompare = 0;
int iField = -1; int iField = -1;
while (++iField < cntFields && lastCompare == 0) { // reverse iteration while (++iField < cntFields && lastCompare == 0) { // reverse iteration
TableSorter<T> sorter = sorters.get(iField); TableSorter<T> sorter = sorters.get(iField);
if (sorter == null) { break; } if (sorter == null) {
break;
}
lastCompare = sorter.compare(arg0, arg1); lastCompare = sorter.compare(arg0, arg1);
} }
return lastCompare; return lastCompare;

View File

@@ -14,7 +14,6 @@ import javax.swing.event.TableModelListener;
import javax.swing.table.TableCellRenderer; import javax.swing.table.TableCellRenderer;
import net.slightlymagic.maxmtg.Predicate; import net.slightlymagic.maxmtg.Predicate;
import forge.Constant; import forge.Constant;
import forge.Singletons; import forge.Singletons;
import forge.card.CardRules; import forge.card.CardRules;
@@ -22,48 +21,75 @@ import forge.item.InventoryItem;
import forge.item.ItemPool; import forge.item.ItemPool;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
/** /**
* TableWithCards. * TableWithCards.
* *
*/ */
public final class TableWithCards { public final class TableWithCards {
/** The pool. */
protected ItemPool<InventoryItem> pool; protected ItemPool<InventoryItem> pool;
/** The model. */
protected TableModel<InventoryItem> model; protected TableModel<InventoryItem> model;
/** The table. */
protected JTable table = new JTable(); protected JTable table = new JTable();
/** The j scroll pane. */
protected JScrollPane jScrollPane = new JScrollPane(); protected JScrollPane jScrollPane = new JScrollPane();
/** The stats label. */
protected JLabel statsLabel = new JLabel(); protected JLabel statsLabel = new JLabel();
/** The filter. */
protected Predicate<InventoryItem> filter = null; protected Predicate<InventoryItem> filter = null;
/** The is tracking stats. */
protected boolean isTrackingStats = false; protected boolean isTrackingStats = false;
/** The want unique. */
protected boolean wantUnique = false; protected boolean wantUnique = false;
// need this to allow users place its contents // need this to allow users place its contents
/** /**
* *
* getTableDecorated. * getTableDecorated.
*
* @return JComponent * @return JComponent
*/ */
public JComponent getTableDecorated() { return jScrollPane; } public JComponent getTableDecorated() {
return jScrollPane;
}
/** /**
* *
* getTable. * getTable.
*
* @return JTable * @return JTable
*/ */
public JTable getTable() { return table; } public JTable getTable() {
return table;
}
/** /**
* *
* getLabel. * getLabel.
*
* @return JComponent * @return JComponent
*/ */
public JComponent getLabel() { return statsLabel; } public JComponent getLabel() {
return statsLabel;
}
/** /**
* *
* TableWithCards. * TableWithCards.
* @param title a String *
* @param showStats a boolean * @param title
* a String
* @param showStats
* a boolean
*/ */
public TableWithCards(final String title, final boolean showStats) { public TableWithCards(final String title, final boolean showStats) {
this(title, showStats, false); this(title, showStats, false);
@@ -72,9 +98,13 @@ public final class TableWithCards {
/** /**
* *
* TableWithCards Constructor. * TableWithCards Constructor.
* @param title a String *
* @param showStats a boolean * @param title
* @param forceUnique a boolean * a String
* @param showStats
* a boolean
* @param forceUnique
* a boolean
*/ */
public TableWithCards(final String title, final boolean showStats, final boolean forceUnique) { public TableWithCards(final String title, final boolean showStats, final boolean forceUnique) {
// components // components
@@ -99,11 +129,13 @@ public final class TableWithCards {
/** /**
* *
* setup. * setup.
* @param columns a List<TableColumnInfo<InventoryItem>> *
* @param cardView a CardPanelBase * @param columns
* a List<TableColumnInfo<InventoryItem>>
* @param cardView
* a CardPanelBase
*/ */
public void setup(final List<TableColumnInfo<InventoryItem>> columns, final CardPanelBase cardView) public void setup(final List<TableColumnInfo<InventoryItem>> columns, final CardPanelBase cardView) {
{
model = new TableModel<InventoryItem>(cardView, columns, InventoryItem.class); model = new TableModel<InventoryItem>(cardView, columns, InventoryItem.class);
model.addListeners(table); model.addListeners(table);
table.setModel(model); table.setModel(model);
@@ -131,7 +163,9 @@ public final class TableWithCards {
/** /**
* *
* getStats. * getStats.
* @param deck an ItemPoolView<InventoryITem> *
* @param deck
* an ItemPoolView<InventoryITem>
* @return String * @return String
*/ */
public static String getStats(final ItemPoolView<InventoryItem> deck) { public static String getStats(final ItemPoolView<InventoryItem> deck) {
@@ -140,8 +174,8 @@ public final class TableWithCards {
int land = CardRules.Predicates.Presets.isLand.aggregate(deck, deck.fnToCard, deck.fnToCount); int land = CardRules.Predicates.Presets.isLand.aggregate(deck, deck.fnToCard, deck.fnToCount);
StringBuffer show = new StringBuffer(); StringBuffer show = new StringBuffer();
show.append("Total - ").append(total).append(", Creatures - ") show.append("Total - ").append(total).append(", Creatures - ").append(creature).append(", Land - ")
.append(creature).append(", Land - ").append(land); .append(land);
String[] color = Constant.Color.onlyColors; String[] color = Constant.Color.onlyColors;
List<Predicate<CardRules>> predicates = CardRules.Predicates.Presets.colors; List<Predicate<CardRules>> predicates = CardRules.Predicates.Presets.colors;
for (int i = 0; i < color.length; ++i) { for (int i = 0; i < color.length; ++i) {
@@ -154,16 +188,23 @@ public final class TableWithCards {
/** /**
* *
* sort. * sort.
* @param iCol an int *
* @param iCol
* an int
* @return TableWithCards * @return TableWithCards
*/ */
public TableWithCards sort(final int iCol) { return sort(iCol, true); } public TableWithCards sort(final int iCol) {
return sort(iCol, true);
}
/** /**
* *
* sort. * sort.
* @param iCol an int *
* @param isAsc a boolean * @param iCol
* an int
* @param isAsc
* a boolean
* @return TableWithCards * @return TableWithCards
*/ */
public TableWithCards sort(final int iCol, final boolean isAsc) { public TableWithCards sort(final int iCol, final boolean isAsc) {
@@ -174,14 +215,18 @@ public final class TableWithCards {
/** /**
* *
* fixSelection. Call this after deleting an item from table. * fixSelection. Call this after deleting an item from table.
* @param rowLastSelected an int *
* @param rowLastSelected
* an int
*/ */
public void fixSelection(final int rowLastSelected) { public void fixSelection(final int rowLastSelected) {
// 3 cases: 0 cards left, select the same row, select prev row // 3 cases: 0 cards left, select the same row, select prev row
int newRow = rowLastSelected; int newRow = rowLastSelected;
int cntRowsAbove = model.getRowCount(); int cntRowsAbove = model.getRowCount();
if (cntRowsAbove != 0) { if (cntRowsAbove != 0) {
if (cntRowsAbove == newRow) { newRow--; } // move selection away from the last, already missing, option if (cntRowsAbove == newRow) {
newRow--;
} // move selection away from the last, already missing, option
table.setRowSelectionInterval(newRow, newRow); table.setRowSelectionInterval(newRow, newRow);
} }
} }
@@ -189,17 +234,21 @@ public final class TableWithCards {
/** /**
* *
* setDeck. * setDeck.
* @param cards an Iterable<InventoryITem> *
* @param cards
* an Iterable<InventoryITem>
*/ */
public void setDeck(final Iterable<InventoryItem> cards) { public void setDeck(final Iterable<InventoryItem> cards) {
setDeckImpl(ItemPool.createFrom(cards, InventoryItem.class)); setDeckImpl(ItemPool.createFrom(cards, InventoryItem.class));
} }
/** /**
*
* setDeck. * setDeck.
* @param poolView an ItemPoolView *
* @param <T> an Object * @param <T>
* an Object
* @param poolView
* an ItemPoolView
*/ */
public <T extends InventoryItem> void setDeck(final ItemPoolView<T> poolView) { public <T extends InventoryItem> void setDeck(final ItemPoolView<T> poolView) {
setDeckImpl(ItemPool.createFrom(poolView, InventoryItem.class)); setDeckImpl(ItemPool.createFrom(poolView, InventoryItem.class));
@@ -208,7 +257,9 @@ public final class TableWithCards {
/** /**
* *
* setDeckImpl. * setDeckImpl.
* @param thePool an ItemPool *
* @param thePool
* an ItemPool
*/ */
protected void setDeckImpl(final ItemPool<InventoryItem> thePool) { protected void setDeckImpl(final ItemPool<InventoryItem> thePool) {
model.clear(); model.clear();
@@ -220,6 +271,7 @@ public final class TableWithCards {
/** /**
* *
* getSelectedCard. * getSelectedCard.
*
* @return InventoryItem * @return InventoryItem
*/ */
public InventoryItem getSelectedCard() { public InventoryItem getSelectedCard() {
@@ -227,12 +279,16 @@ public final class TableWithCards {
return iRow >= 0 ? model.rowToCard(iRow).getKey() : null; return iRow >= 0 ? model.rowToCard(iRow).getKey() : null;
} }
private boolean isUnfiltered() { return filter == null || filter.is1(); } private boolean isUnfiltered() {
return filter == null || filter.is1();
}
/** /**
* *
* setFilter. * setFilter.
* @param filterToSet a Predicate *
* @param filterToSet
* a Predicate
*/ */
public void setFilter(final Predicate<InventoryItem> filterToSet) { public void setFilter(final Predicate<InventoryItem> filterToSet) {
filter = filterToSet; filter = filterToSet;
@@ -242,24 +298,32 @@ public final class TableWithCards {
/** /**
* *
* addCard. * addCard.
* @param card an InventoryItem *
* @param card
* an InventoryItem
*/ */
public void addCard(final InventoryItem card) { public void addCard(final InventoryItem card) {
//int n = table.getSelectedRow(); // int n = table.getSelectedRow();
pool.add(card); pool.add(card);
if (isUnfiltered()) { model.addCard(card); } if (isUnfiltered()) {
model.addCard(card);
}
updateView(false); updateView(false);
} }
/** /**
* *
* removeCard. * removeCard.
* @param card an InventoryItem *
* @param card
* an InventoryItem
*/ */
public void removeCard(final InventoryItem card) { public void removeCard(final InventoryItem card) {
int n = table.getSelectedRow(); int n = table.getSelectedRow();
pool.remove(card); pool.remove(card);
if (isUnfiltered()) { model.removeCard(card); } if (isUnfiltered()) {
model.removeCard(card);
}
updateView(false); updateView(false);
fixSelection(n); fixSelection(n);
} }
@@ -267,7 +331,9 @@ public final class TableWithCards {
/** /**
* *
* updateView. * updateView.
* @param bForceFilter a boolean *
* @param bForceFilter
* a boolean
*/ */
public void updateView(final boolean bForceFilter) { public void updateView(final boolean bForceFilter) {
boolean useFilter = (bForceFilter && filter != null) || !isUnfiltered(); boolean useFilter = (bForceFilter && filter != null) || !isUnfiltered();
@@ -281,9 +347,8 @@ public final class TableWithCards {
} else if (useFilter) { } else if (useFilter) {
model.addCards(filter.select(pool, pool.fnToPrinted)); model.addCards(filter.select(pool, pool.fnToPrinted));
} else if (wantUnique) { } else if (wantUnique) {
model.addCards( model.addCards(CardRules.Predicates.Presets.constantTrue.uniqueByLast(pool, pool.fnToCardName,
CardRules.Predicates.Presets.constantTrue.uniqueByLast( pool.fnToCard));
pool, pool.fnToCardName, pool.fnToCard));
} }
model.resort(); model.resort();
@@ -292,6 +357,7 @@ public final class TableWithCards {
/** /**
* *
* getCards. * getCards.
*
* @return ItemPoolView * @return ItemPoolView
*/ */
public ItemPoolView<InventoryItem> getCards() { public ItemPoolView<InventoryItem> getCards() {

View File

@@ -1,2 +1,3 @@
/** Forge Card Game */ /** Forge Card Game. */
package forge.gui.deckeditor; package forge.gui.deckeditor;