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.
*
*
*/
public abstract class CardPanelBase extends JPanel {
private static final long serialVersionUID = -2230733670423143126L;
@@ -14,7 +14,9 @@ public abstract class CardPanelBase extends JPanel {
/**
*
* showCard.
* @param card an InventoryItem
*
* @param card
* an InventoryItem
*/
public abstract void showCard(InventoryItem card);

View File

@@ -10,10 +10,8 @@ import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import net.miginfocom.swing.MigLayout;
import arcane.ui.CardPanel;
import arcane.ui.ViewPanel;
import forge.Card;
import forge.GuiDisplayUtil;
import forge.ImagePreviewPanel;
@@ -24,105 +22,121 @@ import forge.item.InventoryItem;
import forge.properties.ForgeProps;
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 {
private static final long serialVersionUID = -7134546689397508597L;
private JButton changeStateButton = new JButton();
/*
* Removed Oct 25 2011 - Hellfish
private JButton changePictureButton = new JButton();
private JButton removePictureButton = new JButton();
* Removed Oct 25 2011 - Hellfish private JButton changePictureButton = 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);
/** The picture. */
protected CardPanel picture = new CardPanel(null);
/** The picture view panel. */
protected ViewPanel pictureViewPanel = new ViewPanel();
// fake card to allow picture changes
// fake card to allow picture changes
/** The c card hq. */
public Card cCardHQ;
/** Constant <code>previousDirectory</code> */
/** Constant <code>previousDirectory</code>. */
protected static File previousDirectory = null;
/**
* Instantiates a new card panel heavy.
*/
public CardPanelHeavy() {
changeStateButton.setVisible(false);
changeStateButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
public void actionPerformed(final ActionEvent e) {
changeStateButton_actionPerformed(e);
}
});
if (!Singletons.getModel().getPreferences().lafFonts)
if (!Singletons.getModel().getPreferences().lafFonts) {
changeStateButton.setFont(new java.awt.Font("Dialog", 0, 10));
}
/*
* Removed Oct 25 2011 - Hellfish
changePictureButton.setText("Change picture...");
changePictureButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
changePictureButton_actionPerformed(e);
}
});
if (!Singletons.getModel().getPreferences().lafFonts)
changePictureButton.setFont(new java.awt.Font("Dialog", 0, 10));
removePictureButton.setText("Remove picture...");
removePictureButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
removePictureButton_actionPerformed(e);
}
});
if (!Singletons.getModel().getPreferences().lafFonts)
removePictureButton.setFont(new java.awt.Font("Dialog", 0, 10));
* changePictureButton.setText("Change picture...");
* changePictureButton.addActionListener(new
* java.awt.event.ActionListener() { public void
* actionPerformed(ActionEvent e) {
* changePictureButton_actionPerformed(e); } }); if
* (!Singletons.getModel().getPreferences().lafFonts)
* changePictureButton.setFont(new java.awt.Font("Dialog", 0, 10));
*
* removePictureButton.setText("Remove picture...");
* removePictureButton.addActionListener(new
* java.awt.event.ActionListener() { public void
* actionPerformed(ActionEvent e) {
* removePictureButton_actionPerformed(e); } }); if
* (!Singletons.getModel().getPreferences().lafFonts)
* removePictureButton.setFont(new java.awt.Font("Dialog", 0, 10));
*/
pictureViewPanel.setCardPanel(picture);
this.setLayout(new MigLayout("fill, ins 0"));
this.add(detail, "w 239, h 323, grow, flowy, wrap");
/*
* Removed Oct 25 2011 - Hellfish
this.add(changeStateButton, "align 50% 0%, split 3, flowx");
this.add(changePictureButton, "align 50% 0%");
this.add(removePictureButton, "align 50% 0%, wrap");
* Removed Oct 25 2011 - Hellfish this.add(changeStateButton,
* "align 50% 0%, split 3, flowx"); this.add(changePictureButton,
* "align 50% 0%"); this.add(removePictureButton, "align 50% 0%, wrap");
*/
this.add(changeStateButton, "align 50% 0%, flowx, wrap");
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;
detail.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.setCard(c);
if(c.hasAlternateState()) {
if (c.hasAlternateState()) {
changeStateButton.setVisible(true);
if(c.isFlip()) {
if (c.isFlip()) {
changeStateButton.setText("Flip");
}
else {
} else {
changeStateButton.setText("Transform");
}
}
else {
} else {
changeStateButton.setVisible(false);
}
}
/**
* <p>
* changeStateButton_actionPerformed.
@@ -131,7 +145,7 @@ public class CardPanelHeavy extends CardPanelBase {
* @param e
* a {@link java.awt.event.ActionEvent} object.
*/
void changeStateButton_actionPerformed(ActionEvent e) {
final void changeStateButton_actionPerformed(final ActionEvent e) {
Card cur = picture.getCard();
cur.changeState();
@@ -147,7 +161,7 @@ public class CardPanelHeavy extends CardPanelBase {
* @param e
* a {@link java.awt.event.ActionEvent} object.
*/
void changePictureButton_actionPerformed(ActionEvent e) {
final void changePictureButton_actionPerformed(final ActionEvent e) {
if (cCardHQ != null) {
File file = getImportFilename();
if (file != null) {
@@ -159,7 +173,8 @@ public class CardPanelHeavy extends CardPanelBase {
try {
org.apache.commons.io.FileUtils.copyFile(file, f);
} 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();
}
setCard(cCardHQ);
@@ -192,10 +207,11 @@ public class CardPanelHeavy extends CardPanelBase {
}
/** The dck filter. */
protected FileFilter dckFilter = new FileFilter() {
@Override
public boolean accept(File f) {
public boolean accept(final File f) {
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
* the e
*/
void removePictureButton_actionPerformed(ActionEvent e) {
final void removePictureButton_actionPerformed(final ActionEvent e) {
if (cCardHQ != null) {
String options[] = { "Yes", "No" };
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 net.miginfocom.swing.MigLayout;
import forge.Card;
import forge.Singletons;
import forge.gui.game.CardDetailPanel;
@@ -23,6 +22,7 @@ public class CardPanelLite extends CardPanelBase {
private static final long serialVersionUID = -7134546689397508597L;
// Controls to show card details
/** The detail. */
protected CardDetailPanel detail = new CardDetailPanel(null);
private CardPicturePanel picture = new CardPicturePanel(null);
private JButton bChangeState = new JButton();
@@ -34,13 +34,14 @@ public class CardPanelLite extends CardPanelBase {
public CardPanelLite() {
bChangeState.setVisible(false);
bChangeState.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
public void actionPerformed(final ActionEvent e) {
bChangeState_actionPerformed(e);
}
});
if (!Singletons.getModel().getPreferences().lafFonts)
if (!Singletons.getModel().getPreferences().lafFonts) {
bChangeState.setFont(new java.awt.Font("Dialog", 0, 10));
}
this.setLayout(new MigLayout("fill, ins 0"));
this.add(detail, "w 239, h 303, grow, flowy, wrap");
this.add(bChangeState, "align 50% 0%, wrap");
@@ -58,32 +59,36 @@ public class CardPanelLite extends CardPanelBase {
picture.setCard(card);
boolean isCard = card != null && card instanceof CardPrinted;
detail.setVisible(isCard);
if (isCard) {
if (isCard) {
Card toSet = ((CardPrinted) card).toForgeCard();
detail.setCard(toSet);
if(toSet.hasAlternateState()) {
if (toSet.hasAlternateState()) {
bChangeState.setVisible(true);
if(toSet.isFlip()) {
if (toSet.isFlip()) {
bChangeState.setText("Flip");
}
else {
} else {
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);
if(c != null) {
if (c != null) {
detail.setCard(c);
if(c.hasAlternateState()) {
if (c.hasAlternateState()) {
bChangeState.setVisible(true);
if(c.isFlip()) {
if (c.isFlip()) {
bChangeState.setText("Flip");
}
else {
} else {
bChangeState.setText("Transform");
}
}
@@ -99,12 +104,12 @@ public class CardPanelLite extends CardPanelBase {
public final Card getCard() {
return detail.getCard();
}
private void bChangeState_actionPerformed(ActionEvent e) {
private void bChangeState_actionPerformed(final ActionEvent e) {
Card cur = detail.getCard();
if(cur != null) {
if (cur != null) {
cur.changeState();
setCard(cur);
}
}

View File

@@ -7,8 +7,7 @@ import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
/**
* Custom check box class for filter icon
*
* Custom check box class for filter icon.
*/
public class CheckBoxWithIcon extends JCheckBox {
/* CHOPPIC */
@@ -20,7 +19,15 @@ public class CheckBoxWithIcon extends JCheckBox {
private String iconNo;
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);
cb = this;
iconYes = imagePath + "filter_" + filterName + "_y.png";
@@ -28,7 +35,7 @@ public class CheckBoxWithIcon extends JCheckBox {
this.setIcon(new ImageIcon(iconYes));
this.setToolTipText(toolTip);
this.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
public void actionPerformed(final ActionEvent actionEvent) {
if (cb.isSelected()) {
cb.setIcon(new ImageIcon(iconYes));
} else {

View File

@@ -28,6 +28,7 @@ import javax.swing.border.BevelBorder;
import javax.swing.event.MouseInputAdapter;
import javax.swing.table.DefaultTableModel;
import net.miginfocom.swing.MigLayout;
import forge.CardList;
import forge.MyRandom;
import forge.card.CardRules;
@@ -35,8 +36,6 @@ import forge.card.CardType;
import forge.item.CardPrinted;
import forge.item.ItemPoolView;
import net.miginfocom.swing.MigLayout;
/**
* 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
@@ -99,7 +98,10 @@ public class DeckAnalysis extends javax.swing.JDialog {
private JFrame jF;
// private ButtonGroup buttonGroup1;
/** The filter card list. */
public CardList filterCardList;
/** The deck. */
public ItemPoolView<CardPrinted> deck;
/**
@@ -109,10 +111,10 @@ public class DeckAnalysis extends javax.swing.JDialog {
*
* @param g
* a {@link javax.swing.JFrame} object.
* @param tb
* a {@link forge.gui.deckeditor.TableModel} object.
* @param deckView
* the deck view
*/
public DeckAnalysis(JFrame g, ItemPoolView<CardPrinted> deckView) {
public DeckAnalysis(final JFrame g, final ItemPoolView<CardPrinted> deckView) {
super(g);
deck = deckView;
@@ -145,12 +147,12 @@ public class DeckAnalysis extends javax.swing.JDialog {
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent arg0) {
public void windowClosing(final WindowEvent arg0) {
jF.setEnabled(true);
}
@Override
public void windowOpened(WindowEvent arg0) {
public void windowOpened(final WindowEvent arg0) {
int cBlack, cBlue, cGreen, cRed, cWhite, cMulticolor, cColorless, cLand;
int cArtifact, cCreature, cEnchant, cInstant, cLandType, cPlaneswalker, cSorcery;
@@ -188,36 +190,69 @@ public class DeckAnalysis extends javax.swing.JDialog {
if (c.getColor().isMulticolor()) {
cMulticolor = cMulticolor + cnt;
} else {
if (c.getColor().isBlack()) { cBlack = cBlack + cnt; }
if (c.getColor().isBlue()) { 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().isBlack()) {
cBlack = cBlack + cnt;
}
if (c.getColor().isBlue()) {
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.getType().isLand()) { cLand = cLand + cnt; }
else { cColorless = cColorless + cnt; }
if (c.getType().isLand()) {
cLand = cLand + cnt;
} else {
cColorless = cColorless + cnt;
}
}
}
// count card types
CardType cType = c.getType();
if (cType.isArtifact()) { cArtifact = cArtifact + cnt; }
if (cType.isCreature()) { cCreature = cCreature + 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; }
if (cType.isArtifact()) {
cArtifact = cArtifact + cnt;
}
if (cType.isCreature()) {
cCreature = cCreature + 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();
if (cmc == 0) { mZero = mZero + cnt;
} else if (cmc == 1) { mOne = mOne + cnt;
} else if (cmc == 2) { mTwo = mTwo + cnt;
} 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;
if (cmc == 0) {
mZero = mZero + cnt;
} else if (cmc == 1) {
mOne = mOne + cnt;
} else if (cmc == 2) {
mTwo = mTwo + cnt;
} 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;
@@ -230,51 +265,95 @@ public class DeckAnalysis extends javax.swing.JDialog {
jLabelManaCost.setText("Mana cost (ACC:" + aManaCost + ")");
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));
if (cBlue == 0) { jLabelBlue.setForeground(cr); }
if (cBlue == 0) {
jLabelBlue.setForeground(cr);
}
jLabelBlue.setText(formatStat("Blue", cBlue, total));
if (cGreen == 0) { jLabelGreen.setForeground(cr); }
if (cGreen == 0) {
jLabelGreen.setForeground(cr);
}
jLabelGreen.setText(formatStat("Green", cGreen, total));
if (cRed == 0) { jLabelRed.setForeground(cr); }
if (cRed == 0) {
jLabelRed.setForeground(cr);
}
jLabelRed.setText(formatStat("Red", cRed, total));
if (cWhite == 0) { jLabelWhite.setForeground(cr); }
if (cWhite == 0) {
jLabelWhite.setForeground(cr);
}
jLabelWhite.setText(formatStat("White", cWhite, total));
if (cMulticolor == 0) { jLabelMultiColor.setForeground(cr); }
if (cMulticolor == 0) {
jLabelMultiColor.setForeground(cr);
}
jLabelMultiColor.setText(formatStat("Multicolor", cMulticolor, total));
if (cColorless == 0) { jLabelColorless.setForeground(cr); }
if (cColorless == 0) {
jLabelColorless.setForeground(cr);
}
jLabelColorless.setText(formatStat("Colorless", cColorless, total));
if (cLand == 0) { jLabelLand.setForeground(cr); }
if (cLand == 0) {
jLabelLand.setForeground(cr);
}
jLabelLand.setText(formatStat("Land", cLand, total));
if (cArtifact == 0) { jLabelArtifact.setForeground(cr); }
if (cArtifact == 0) {
jLabelArtifact.setForeground(cr);
}
jLabelArtifact.setText(formatStat("Artifact", cArtifact, total));
if (cCreature == 0) { jLabelCreature.setForeground(cr); }
if (cCreature == 0) {
jLabelCreature.setForeground(cr);
}
jLabelCreature.setText(formatStat("Creature", cCreature, total));
if (cEnchant == 0) { jLabelEnchant.setForeground(cr); }
if (cEnchant == 0) {
jLabelEnchant.setForeground(cr);
}
jLabelEnchant.setText(formatStat("Enchant", cEnchant, total));
if (cInstant == 0) { jLabelInstant.setForeground(cr); }
if (cInstant == 0) {
jLabelInstant.setForeground(cr);
}
jLabelInstant.setText(formatStat("Instant", cInstant, total));
if (cLandType == 0) { jLabelLandType.setForeground(cr); }
if (cLandType == 0) {
jLabelLandType.setForeground(cr);
}
jLabelLandType.setText(formatStat("Land", cLandType, total));
if (cPlaneswalker == 0) { jLabelPlaneswalker.setForeground(cr); }
if (cPlaneswalker == 0) {
jLabelPlaneswalker.setForeground(cr);
}
jLabelPlaneswalker.setText(formatStat("Planeswalker", cPlaneswalker, total));
if (cSorcery == 0) { jLabelSorcery.setForeground(cr); }
if (cSorcery == 0) {
jLabelSorcery.setForeground(cr);
}
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));
if (mOne == 0) { jLabelOneMana.setForeground(cr); }
if (mOne == 0) {
jLabelOneMana.setForeground(cr);
}
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));
if (mThree == 0) { jLabelThreeMana.setForeground(cr); }
if (mThree == 0) {
jLabelThreeMana.setForeground(cr);
}
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));
if (mFive == 0) { jLabelFiveMana.setForeground(cr); }
if (mFive == 0) {
jLabelFiveMana.setForeground(cr);
}
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));
}
});
@@ -293,9 +372,8 @@ public class DeckAnalysis extends javax.swing.JDialog {
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);
}
@@ -380,7 +458,7 @@ public class DeckAnalysis extends javax.swing.JDialog {
jButtonOk.setBounds(206, 536, 168, 31);
jButtonOk.addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
public void mouseClicked(final MouseEvent e) {
jF.setEnabled(true);
dispose();
}
@@ -929,12 +1007,12 @@ public class DeckAnalysis extends javax.swing.JDialog {
if (jListFirstHand == null) {
jListFirstHand = new JList();
}
if (rList.size() >= 40) {
jList1Model = new DefaultComboBoxModel(new String[] { rList.get(0).getName(),
rList.get(1).getName(), rList.get(2).getName(), rList.get(3).getName(),
rList.get(4).getName(), rList.get(5).getName(), rList.get(6).getName() });
jList1Model = new DefaultComboBoxModel(new String[] { rList.get(0).getName(), rList.get(1).getName(),
rList.get(2).getName(), rList.get(3).getName(), rList.get(4).getName(), rList.get(5).getName(),
rList.get(6).getName() });
} else {
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.setBounds(2, 189, 133, 13);
jButtonRegenerate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
public void actionPerformed(final ActionEvent e) {
jButtonRegenerate_actionPerformed(e);
}
});
@@ -1059,7 +1137,7 @@ public class DeckAnalysis extends javax.swing.JDialog {
* @param e
* a {@link java.awt.event.ActionEvent} object.
*/
void jButtonRegenerate_actionPerformed(ActionEvent e) {
final void jButtonRegenerate_actionPerformed(final ActionEvent e) {
getContentPane().removeAll();
getContentPane().add(getJPanel5());
getContentPane().add(getJLabel1xx());

View File

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

View File

@@ -10,7 +10,6 @@ import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import net.slightlymagic.maxmtg.Predicate;
import forge.deck.Deck;
import forge.game.GameType;
import forge.item.CardPrinted;
@@ -18,39 +17,90 @@ import forge.item.InventoryItem;
import forge.item.ItemPool;
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;
/** The filter boxes. */
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;
/** The card view. */
protected CardPanelBase cardView;
// CardPools and Table data for top and bottom lists
/** The top. */
protected TableWithCards top;
/** The bottom. */
protected TableWithCards bottom;
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
// if constructed, top shows all cards
// if sealed, top shows N booster packs
// 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
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
// 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();
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()) {
JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck",
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;
}
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;
top.setDeck(topParam);
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;
top.setDeck(topParam);
bottom.setDeck(bottomParam);
}
public void updateDisplay() {
/**
* Update display.
*/
public final void updateDisplay() {
top.setFilter(buildFilter());
}
/** The item listener updates display. */
protected ItemListener itemListenerUpdatesDisplay = new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (isFiltersChangeFiringUpdate) { updateDisplay(); }
public void itemStateChanged(final ItemEvent e) {
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 {
private void onChange() { if (isFiltersChangeFiringUpdate) { updateDisplay(); } }
@Override public void insertUpdate(DocumentEvent e) { onChange(); }
@Override public void removeUpdate(DocumentEvent e) { onChange(); }
@Override public void changedUpdate(DocumentEvent e) { } // Happend only on ENTER pressed
private void onChange() {
if (isFiltersChangeFiringUpdate) {
updateDisplay();
}
}
/*
* (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.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) {
deck.addSideboard(ItemPool.createFrom(getTop(), CardPrinted.class));
}
return deck;
}//getDeck()
}// getDeck()
}

View File

@@ -1,9 +1,9 @@
package forge.gui.deckeditor;
import java.awt.Container;
import java.awt.Dialog.ModalityType;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Dialog.ModalityType;
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
@@ -17,6 +17,7 @@ import java.util.List;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import net.miginfocom.swing.MigLayout;
import net.slightlymagic.maxmtg.Predicate;
import forge.AllZone;
@@ -42,18 +43,25 @@ public final class DeckEditorCommon extends DeckEditorBase {
/** Constant <code>serialVersionUID=130339644136746796L</code> */
private static final long serialVersionUID = 130339644136746796L;
/** The custom menu. */
public DeckEditorCommonMenu customMenu;
private JButton removeButton = new JButton();
private JButton addButton = new JButton();
private JButton importButton = new JButton();
private JButton analysisButton = new JButton();
private JButton clearFilterButton = new JButton();
private JLabel jLabelAnalysisGap = new JLabel("");
private JLabel jLabelAnalysisGap = new JLabel("");
private FilterNameTypeSetPanel filterNameTypeSet;
/**
* Show.
*
* @param exitCommand
* the exit command
*/
public void show(final Command exitCommand) {
final Command exit = new Command() {
private static final long serialVersionUID = 5210924838133689758L;
@@ -77,8 +85,6 @@ public final class DeckEditorCommon extends DeckEditorBase {
setup();
// show cards, makes this user friendly
if (!getGameType().isLimited()) {
customMenu.newConstructed(false);
@@ -89,23 +95,28 @@ public final class DeckEditorCommon extends DeckEditorBase {
} // show(Command)
private void setup() {
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
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>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet));
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare, 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>("Color", 50, PresetColumns.fnColorCompare,
PresetColumns.fnColorGet));
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare,
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>("AI", 30, PresetColumns.fnAiStatusCompare, PresetColumns.fnAiStatusGet));
columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.fnAiStatusCompare,
PresetColumns.fnAiStatusGet));
columns.get(2).setCellRenderer(new ManaCostRenderer());
top.setup(columns, cardView);
bottom.setup(columns, cardView);
filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), itemListenerUpdatesDisplay);
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);
try {
filterBoxes = new FilterCheckBoxes(true);
@@ -122,14 +138,13 @@ public final class DeckEditorCommon extends DeckEditorBase {
bottom = new TableWithCards("Deck", true);
cardView = new CardPanelHeavy();
filterNameTypeSet = new FilterNameTypeSetPanel();
jbInit();
} catch (Exception ex) {
ErrorViewer.showError(ex);
}
}
private void jbInit() {
if (!Singletons.getModel().getPreferences().lafFonts) {
@@ -140,28 +155,45 @@ public final class DeckEditorCommon extends DeckEditorBase {
clearFilterButton.setFont(fButtons);
analysisButton.setFont(fButtons);
}
addButton.setText("Add to Deck");
addButton.setText("Add to Deck");
removeButton.setText("Remove from Deck");
importButton.setText("Import a Deck");
clearFilterButton.setText("Clear Filter");
analysisButton.setText("Deck Analysis");
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() {
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() {
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() {
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() {
public void actionPerformed(final ActionEvent e) { analysisButton_actionPerformed(e); } });
public void actionPerformed(final ActionEvent e) {
analysisButton_actionPerformed(e);
}
});
// Type filtering
Font f = new Font("Tahoma", Font.PLAIN, 10);
for (JCheckBox box : filterBoxes.allTypes) {
if (!Singletons.getModel().getPreferences().lafFonts) { box.setFont(f); }
if (!Singletons.getModel().getPreferences().lafFonts) {
box.setFont(f);
}
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(removeButton, "w 100, h 49, sg button");
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(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");
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() {
@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();
//rootPane.setDefaultButton(filterButton);
// javax.swing.JRootPane rootPane = this.getRootPane();
// rootPane.setDefaultButton(filterButton);
}
/*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckEditorBase#buildFilter()
*/
@Override
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);
}
/*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckEditorBase#setDeck(forge.item.ItemPoolView,
* forge.item.ItemPoolView, forge.game.GameType)
*/
@Override
public void setDeck(ItemPoolView<CardPrinted> topParam, ItemPoolView<CardPrinted> bottomParam, GameType gt)
{
boolean keepRecievedCards = gt.isLimited() || topParam != null;
public void setDeck(final ItemPoolView<CardPrinted> topParam, final ItemPoolView<CardPrinted> bottomParam,
final GameType gt) {
boolean keepRecievedCards = gt.isLimited() || topParam != null;
// 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());
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
isFiltersChangeFiringUpdate = false;
for (JCheckBox box : filterBoxes.allTypes) { if (!box.isSelected()) { box.doClick(); } }
for (JCheckBox box : filterBoxes.allColors) { if (!box.isSelected()) { box.doClick(); } }
for (JCheckBox box : filterBoxes.allTypes) {
if (!box.isSelected()) {
box.doClick();
}
}
for (JCheckBox box : filterBoxes.allColors) {
if (!box.isSelected()) {
box.doClick();
}
}
filterNameTypeSet.clearFilters();
@@ -251,13 +324,24 @@ public final class DeckEditorCommon extends DeckEditorBase {
top.setFilter(null);
}
void addButton_actionPerformed(ActionEvent e) {
/**
* Adds the button_action performed.
*
* @param e
* the e
*/
void addButton_actionPerformed(final ActionEvent e) {
addCardToDeck();
}
/**
* Adds the card to deck.
*/
void addCardToDeck() {
InventoryItem item = top.getSelectedCard();
if (item == null || !( item instanceof CardPrinted )) { return; }
if (item == null || !(item instanceof CardPrinted)) {
return;
}
CardPrinted card = (CardPrinted) item;
setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved");
@@ -266,13 +350,21 @@ public final class DeckEditorCommon extends DeckEditorBase {
if (getGameType().isLimited()) {
top.removeCard(card);
}
customMenu.notifyDeckChange();
}
void removeButtonClicked(ActionEvent e) {
/**
* Removes the button clicked.
*
* @param e
* the e
*/
void removeButtonClicked(final ActionEvent e) {
InventoryItem item = bottom.getSelectedCard();
if (item == null || !( item instanceof CardPrinted )) { return; }
if (item == null || !(item instanceof CardPrinted)) {
return;
}
CardPrinted card = (CardPrinted) item;
@@ -282,11 +374,17 @@ public final class DeckEditorCommon extends DeckEditorBase {
if (getGameType().isLimited()) {
top.addCard(card);
}
customMenu.notifyDeckChange();
}
void importButton_actionPerformed(ActionEvent e) {
/**
* Import button_action performed.
*
* @param e
* the e
*/
void importButton_actionPerformed(final ActionEvent e) {
DeckEditorBase g = this;
DeckImport dImport = new DeckImport(g);
dImport.setModalityType(ModalityType.APPLICATION_MODAL);

View File

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

View File

@@ -1,25 +1,5 @@
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.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -38,10 +18,30 @@ import javax.swing.JButton;
import javax.swing.JOptionPane;
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
* @version $Id$
*/
@@ -57,18 +57,23 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
private CardPanelLite cardView = new CardPanelLite();
private MouseListener pickWithMouse = new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
// Pick on left-button double click
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0 && e.getClickCount() == 2) {
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();
int rowNumber = table.rowAtPoint(e.getPoint());
// after hittest - if it was outside of rows - discard this click
if (rowNumber == -1) { return; }
// after hittest - if it was outside of rows - discard this
// click
if (rowNumber == -1) {
return;
}
// if row was not selected, select it. If it was, pick a card
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;
setup();
showChoices(boosterDraft.nextChoice());
bottom.setDeck((Iterable<InventoryItem>)null);
bottom.setDeck((Iterable<InventoryItem>) null);
top.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() {
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent ev) {
public void windowClosing(final WindowEvent ev) {
int n = JOptionPane.showConfirmDialog(null, ForgeProps.getLocalized(CLOSE_MESSAGE), "",
JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
dispose();
if (System.getenv("NG2") != null) {
if (System.getenv("NG2").equalsIgnoreCase("true")) {
String argz[] = {};
String[] argz = {};
Gui_HomeScreen.main(argz);
} else {
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() {
addListeners();
// setupMenu();
// setupMenu();
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
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>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet));
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare, 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>("Color", 50, PresetColumns.fnColorCompare,
PresetColumns.fnColorGet));
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare,
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>("AI", 30, PresetColumns.fnAiStatusCompare, PresetColumns.fnAiStatusGet));
columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.fnAiStatusCompare,
PresetColumns.fnAiStatusGet));
columns.get(2).setCellRenderer(new ManaCostRenderer());
top.setup(columns, cardView);
@@ -149,11 +170,19 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
top.getTable().addMouseListener(pickWithMouse);
top.getTable().addKeyListener(new KeyAdapter() {
@Override public void keyPressed(final KeyEvent e) {
if (e.getKeyChar() == ' ') { jButtonPickClicked(null); } } });
@Override
public void keyPressed(final KeyEvent e) {
if (e.getKeyChar() == ' ') {
jButtonPickClicked(null);
}
}
});
}
/**
* Instantiates a new deck editor draft.
*/
public DeckEditorDraft() {
super(GameType.Draft);
try {
@@ -167,11 +196,13 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
}
}
/**
* <p>jbInit.</p>
*
* @throws java.lang.Exception if any.
* <p>
* jbInit.
* </p>
*
* @throws java.lang.Exception
* if any.
*/
private void jbInit() throws Exception {
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));
bottom.getTableDecorated().setBounds(new Rectangle(19, 478, 680, 184));
bottom.getLabel().setBounds(new Rectangle(19, 680, 665, 31));
cardView.setBounds(new Rectangle(715, 23, 240, 666));
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
this.setTitle("Booster Draft");
jButtonPick.setBounds(new Rectangle(238, 418, 147, 44));
jButtonPick.setFont(new java.awt.Font("Dialog", 0, 16));
jButtonPick.setText("Choose Card");
jButtonPick.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
public void actionPerformed(final ActionEvent e) {
jButtonPickClicked(e);
}
});
this.getContentPane().add(cardView, null);
this.getContentPane().add(top.getTableDecorated(), null);
this.getContentPane().add(bottom.getLabel(), null);
@@ -202,55 +233,65 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
}
/**
* <p>jButton1_actionPerformed.</p>
*
* @param e a {@link java.awt.event.ActionEvent} object.
* <p>
* jButton1_actionPerformed.
* </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();
if (item == null || !( item instanceof CardPrinted )) { return; }
if (item == null || !(item instanceof CardPrinted)) {
return;
}
CardPrinted card = (CardPrinted) item;
bottom.addCard(card);
//get next booster pack
// get next booster pack
boosterDraft.setChoice(card);
if (boosterDraft.hasNextChoice()) {
showChoices(boosterDraft.nextChoice());
} else {
boosterDraft.finishedDrafting();
//quit
// quit
saveDraft();
dispose();
}
}/*OK Button*/
}/* OK Button */
/**
* <p>showChoices.</p>
*
* @param list a {@link forge.CardList} object.
* <p>
* showChoices.
* </p>
*
* @param list
* a {@link forge.CardList} object.
*/
private void showChoices(ItemPoolView<CardPrinted> list) {
private void showChoices(final ItemPoolView<CardPrinted> list) {
top.setDeck(list);
cardView.showCard(null);
top.fixSelection(0);
}//showChoices()
}// showChoices()
/**
* <p>getPlayersDeck.</p>
*
* <p>
* getPlayersDeck.
* </p>
*
* @return a {@link forge.deck.Deck} object.
*/
private Deck getPlayersDeck() {
Deck deck = new Deck(GameType.Draft);
Constant.Runtime.HumanDeck[0] = deck;
//add sideboard to deck
// add sideboard to deck
ItemPoolView<CardPrinted> list = ItemPool.createFrom(bottom.getCards(), CardPrinted.class);
deck.addSideboard(list);
String landSet = BoosterDraft.LandSetCode[0];
final int LANDS_COUNT = 20;
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);
return deck;
}//getPlayersDeck()
}// getPlayersDeck()
/**
* <p>saveDraft.</p>
* <p>
* saveDraft.
* </p>
*/
private void saveDraft() {
String s = "";
@@ -271,35 +314,36 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
s = JOptionPane.showInputDialog(null, ForgeProps.getLocalized(SAVE_DRAFT_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
//save draft
// construct computer's decks
// save draft
Deck[] computer = boosterDraft.getDecks();
Deck human = getPlayersDeck();
human.setName(s);
Deck[] all = {
human, computer[0], computer[1], computer[2], computer[3], computer[4], computer[5], computer[6]};
Deck[] all = { 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));
}
//DeckManager deckManager = new DeckManager(ForgeProps.getFile(NEW_DECKS));
// DeckManager deckManager = new
// DeckManager(ForgeProps.getFile(NEW_DECKS));
DeckManager deckManager = AllZone.getDeckManager();
deckManager.addDraftDeck(all);
//write file
// write file
DeckManager.writeDraftDecks(all);
//close and open next screen
// close and open next screen
dispose();
if (System.getenv("NG2") != null) {
if (System.getenv("NG2").equalsIgnoreCase("true")) {
String argz[] = {};
String[] argz = {};
Gui_HomeScreen.main(argz);
} else {
new OldGuiNewGame();
@@ -308,11 +352,15 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
new OldGuiNewGame();
}
}/*saveDraft()*/
}/* saveDraft() */
/*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckEditorBase#buildFilter()
*/
@Override
protected Predicate<InventoryItem> buildFilter() {
protected final Predicate<InventoryItem> buildFilter() {
return Predicate.getTrue(InventoryItem.class);
}
}

View File

@@ -1,5 +1,20 @@
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.Constant;
import forge.Singletons;
@@ -14,22 +29,6 @@ import forge.item.ItemPoolView;
import forge.properties.NewConstants;
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;
/**
@@ -44,22 +43,27 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
/** Constant <code>serialVersionUID=152061168634545L</code> */
private static final long serialVersionUID = 152061168634545L;
/** The custom menu. */
DeckEditorQuestMenu customMenu;
// private ImageIcon upIcon = Constant.IO.upIcon;
// private ImageIcon downIcon = Constant.IO.downIcon;
//private JLabel labelSortHint = new JLabel();
// private JLabel labelSortHint = new JLabel();
private JButton addButton = new JButton();
private JButton removeButton = new JButton();
private JButton analysisButton = new JButton();
private FilterNameTypeSetPanel filterNameTypeSet;
private QuestData questData;
/**
* Show.
*
* @param exitCommand
* the exit command
*/
public void show(final Command exitCommand) {
final Command exit = new Command() {
private static final long serialVersionUID = -7428793574300520612L;
@@ -114,7 +118,6 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
bottom.sort(1, true);
} // show(Command)
/**
* <p>
* setup.
@@ -122,23 +125,29 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
*/
public void setup() {
this.setLayout(null);
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
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>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet));
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare, 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>("Color", 50, PresetColumns.fnColorCompare,
PresetColumns.fnColorGet));
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare,
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>("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());
top.setup(columns, cardView);
bottom.setup(columns, cardView);
filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), itemListenerUpdatesDisplay);
this.setSize(1024, 768);
@@ -151,7 +160,13 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
// setExtendedState(Frame.MAXIMIZED_BOTH);
} // setupAndDisplay()
public DeckEditorQuest(QuestData questData2) {
/**
* Instantiates a new deck editor quest.
*
* @param questData2
* the quest data2
*/
public DeckEditorQuest(final QuestData questData2) {
super(GameType.Quest);
questData = questData2;
try {
@@ -166,22 +181,21 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
//labelSortHint.setText("Click on the column name (like name or color) to sort the cards");
//labelSortHint.setBounds(new Rectangle(20, 27, 400, 19));
// labelSortHint.setText("Click on the column name (like name or color) to sort the cards");
// labelSortHint.setBounds(new Rectangle(20, 27, 400, 19));
filterNameTypeSet.setBounds(new Rectangle(19, 10, 726, 25));
top.getTableDecorated().setBounds(new Rectangle(19, 40, 726, 316));
bottom.getTableDecorated().setBounds(new Rectangle(19, 458, 726, 218));
removeButton.setBounds(new Rectangle(180, 403, 146, 49));
// removeButton.setIcon(upIcon);
if (!Singletons.getModel().getPreferences().lafFonts)
if (!Singletons.getModel().getPreferences().lafFonts) {
removeButton.setFont(new java.awt.Font("Dialog", 0, 13));
}
removeButton.setText("Remove Card");
removeButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
@@ -195,8 +209,9 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
}
});
// addButton.setIcon(downIcon);
if (!Singletons.getModel().getPreferences().lafFonts)
if (!Singletons.getModel().getPreferences().lafFonts) {
addButton.setFont(new java.awt.Font("Dialog", 0, 13));
}
addButton.setBounds(new Rectangle(23, 403, 146, 49));
analysisButton.setText("Deck Analysis");
@@ -205,8 +220,9 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
analysisButton_actionPerformed(e);
}
});
if (!Singletons.getModel().getPreferences().lafFonts)
if (!Singletons.getModel().getPreferences().lafFonts) {
analysisButton.setFont(new java.awt.Font("Dialog", 0, 13));
}
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.artifact.setBounds(638, 400, 58, 20);
filterBoxes.enchantment.setBounds(692, 400, 80, 20);
Font f = new Font("Tahoma", Font.PLAIN, 10);
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.addItemListener(itemListenerUpdatesDisplay);
}
@@ -252,7 +270,6 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
// x 768 screen size
this.setTitle("Deck Editor");
this.getContentPane().add(filterNameTypeSet, null);
this.getContentPane().add(top.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(bottom.getLabel(), null);
this.getContentPane().add(top.getLabel(), null);
//this.getContentPane().add(labelSortHint, null);
// this.getContentPane().add(labelSortHint, null);
this.getContentPane().add(cardView, null);
for (JCheckBox box : filterBoxes.allTypes) {
@@ -275,21 +292,29 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
top.getTable().addKeyListener(new KeyAdapter() {
@Override
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
protected Predicate<InventoryItem> buildFilter() {
Predicate<CardPrinted> cardFilter = Predicate.and(filterBoxes.buildFilter(), filterNameTypeSet.buildFilter());
return Predicate.instanceOf(cardFilter, CardPrinted.class);
}
private void addButtonActionPerformed(final ActionEvent e) {
return Predicate.instanceOf(cardFilter, CardPrinted.class);
}
private void addButtonActionPerformed(final ActionEvent e) {
InventoryItem item = top.getSelectedCard();
if (item == null || !( item instanceof CardPrinted )) { return; }
if (item == null || !(item instanceof CardPrinted)) {
return;
}
CardPrinted card = (CardPrinted) item;
@@ -299,10 +324,11 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
bottom.addCard(card);
}
private void removeButtonActionPerformed(final ActionEvent e) {
InventoryItem item = bottom.getSelectedCard();
if (item == null || !( item instanceof CardPrinted )) { return; }
if (item == null || !(item instanceof CardPrinted)) {
return;
}
CardPrinted card = (CardPrinted) item;
@@ -312,7 +338,12 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
bottom.removeCard(card);
}
/**
* Adds the cheat card.
*
* @param card
* the card
*/
public void addCheatCard(final CardPrinted card) {
top.addCard(card);
questData.getCards().getCardpool().add(card);

View File

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

View File

@@ -18,7 +18,6 @@ import javax.swing.JOptionPane;
import net.slightlymagic.braids.util.lambda.Lambda1;
import net.slightlymagic.maxmtg.Predicate;
import forge.Command;
import forge.Singletons;
import forge.deck.Deck;
@@ -56,15 +55,19 @@ public final class DeckEditorShop extends DeckEditorBase {
private double multiplier;
private QuestData questData;
//private CardPoolView newCardsList;
// private CardPoolView newCardsList;
// get pricelist:
private ReadPriceList r = new ReadPriceList();
private Map<String, Integer> mapPrices = r.getPriceList();
private Map<CardPrinted, Integer> decksUsingMyCards;
/**
* Show.
*
* @param exitCommand
* the exit command
*/
public void show(final Command exitCommand) {
final Command exit = new Command() {
private static final long serialVersionUID = -7428793574300520612L;
@@ -74,11 +77,11 @@ public final class DeckEditorShop extends DeckEditorBase {
exitCommand.execute();
}
};
// do not change this!!!!
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent ev) {
public void windowClosing(final WindowEvent ev) {
exit.execute();
}
});
@@ -95,7 +98,7 @@ public final class DeckEditorShop extends DeckEditorBase {
forSale = questData.getCards().getShopList();
}
ItemPoolView<InventoryItem> owned = questData.getCards().getCardpool().getView();
//newCardsList = questData.getCards().getNewCards();
// newCardsList = questData.getCards().getNewCards();
setItems(forSale, owned, GameType.Quest);
@@ -104,8 +107,11 @@ public final class DeckEditorShop extends DeckEditorBase {
String maxSellingPrice = "";
int maxSellPrice = questData.getCards().getSellPriceLimit();
if (maxSellPrice < Integer.MAX_VALUE) { 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>");
if (maxSellPrice < Integer.MAX_VALUE) {
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);
bottom.sort(1, true);
@@ -125,7 +131,7 @@ public final class DeckEditorShop extends DeckEditorBase {
}
return result;
}
/**
* <p>
* setup.
@@ -134,21 +140,27 @@ public final class DeckEditorShop extends DeckEditorBase {
private void setup() {
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
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>("Color", 50, PresetColumns.fnColorCompare, PresetColumns.fnColorGet));
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare, 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>("Color", 50, PresetColumns.fnColorCompare,
PresetColumns.fnColorGet));
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.fnTypeCompare,
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.get(2).setCellRenderer(new ManaCostRenderer());
List<TableColumnInfo<InventoryItem>> columnsBelow = new ArrayList<TableColumnInfo<InventoryItem>>(columns);
columns.add(new TableColumnInfo<InventoryItem>("Price", 36, fnPriceCompare, fnPriceGet));
top.setup(columns, cardView);
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));
bottom.setup(columnsBelow, cardView);
@@ -179,7 +191,6 @@ public final class DeckEditorShop extends DeckEditorBase {
}
}
/**
* <p>
* jbInit.
@@ -196,23 +207,25 @@ public final class DeckEditorShop extends DeckEditorBase {
sellButton.setBounds(new Rectangle(180, 403, 146, 49));
// removeButton.setIcon(upIcon);
if (!Singletons.getModel().getPreferences().lafFonts)
if (!Singletons.getModel().getPreferences().lafFonts) {
sellButton.setFont(new java.awt.Font("Dialog", 0, 13));
}
sellButton.setText("Sell Card");
sellButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
public void actionPerformed(final ActionEvent e) {
sellButton_actionPerformed(e);
}
});
buyButton.setText("Buy Card");
buyButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
public void actionPerformed(final ActionEvent e) {
buyButton_actionPerformed(e);
}
});
if (!Singletons.getModel().getPreferences().lafFonts)
if (!Singletons.getModel().getPreferences().lafFonts) {
buyButton.setFont(new java.awt.Font("Dialog", 0, 13));
}
buyButton.setBounds(new Rectangle(23, 403, 146, 49));
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.setText("Total credits: " + questData.getCredits());
if (!Singletons.getModel().getPreferences().lafFonts)
if (!Singletons.getModel().getPreferences().lafFonts) {
creditsLabel.setFont(new java.awt.Font("Dialog", 0, 14));
}
sellPercentageLabel.setBounds(new Rectangle(350, 403, 450, 31));
sellPercentageLabel.setText("(Sell percentage: " + multiplier + ")");
if (!Singletons.getModel().getPreferences().lafFonts)
if (!Singletons.getModel().getPreferences().lafFonts) {
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.setBounds(new Rectangle(20, 1, 400, 19));
this.getContentPane().add(cardView, null);
this.getContentPane().add(top.getTableDecorated(), null);
this.getContentPane().add(bottom.getTableDecorated(), null);
@@ -245,14 +260,20 @@ public final class DeckEditorShop extends DeckEditorBase {
private Integer getCardValue(final InventoryItem card) {
if (mapPrices.containsKey(card.getName())) {
return mapPrices.get(card.getName());
} else if (card instanceof CardPrinted) {
} else if (card instanceof CardPrinted) {
switch (((CardPrinted) card).getRarity()) {
case BasicLand: return Integer.valueOf(4);
case Common: return Integer.valueOf(6);
case Uncommon: return Integer.valueOf(40);
case Rare: return Integer.valueOf(120);
case MythicRare: return Integer.valueOf(600);
default: return Integer.valueOf(15);
case BasicLand:
return Integer.valueOf(4);
case Common:
return Integer.valueOf(6);
case Uncommon:
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) {
return 395;
@@ -260,9 +281,11 @@ public final class DeckEditorShop extends DeckEditorBase {
return 1337;
}
private void buyButton_actionPerformed(ActionEvent e) {
private void buyButton_actionPerformed(final ActionEvent e) {
InventoryItem item = top.getSelectedCard();
if (item == null ) { return; }
if (item == null) {
return;
}
int value = getCardValue(item);
@@ -278,8 +301,11 @@ public final class DeckEditorShop extends DeckEditorBase {
BoosterPack booster = (BoosterPack) ((BoosterPack) item).clone();
questData.getCards().buyBooster(booster, value);
List<CardPrinted> newCards = booster.getCards();
for (CardPrinted card : newCards) { bottom.addCard(card); }
CardListViewer c = new CardListViewer(booster.getName(), "You have found the following cards inside:", newCards);
for (CardPrinted card : newCards) {
bottom.addCard(card);
}
CardListViewer c = new CardListViewer(booster.getName(), "You have found the following cards inside:",
newCards);
c.show();
}
@@ -289,14 +315,21 @@ public final class DeckEditorShop extends DeckEditorBase {
}
}
/*
* (non-Javadoc)
*
* @see forge.gui.deckeditor.DeckEditorBase#buildFilter()
*/
@Override
protected Predicate<InventoryItem> buildFilter() {
return Predicate.getTrue(InventoryItem.class);
}
private void sellButton_actionPerformed(ActionEvent e) {
private void sellButton_actionPerformed(final ActionEvent e) {
InventoryItem item = bottom.getSelectedCard();
if (item == null || !( item instanceof CardPrinted )) { return; }
if (item == null || !(item instanceof CardPrinted)) {
return;
}
CardPrinted card = (CardPrinted) item;
bottom.removeCard(card);
@@ -309,29 +342,39 @@ public final class DeckEditorShop extends DeckEditorBase {
}
@SuppressWarnings("rawtypes")
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnPriceCompare =
new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { return getCardValue(from.getKey()); } };
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceGet =
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 =
new Lambda1<Object, Entry<InventoryItem, Integer>>() { @Override
public Object apply(final Entry<InventoryItem, Integer> from) { return (int) (multiplier * getCardValue(from.getKey())); } };
@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();
} };
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnPriceCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
@Override
public Comparable apply(final Entry<InventoryItem, Integer> from) {
return getCardValue(from.getKey());
}
};
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceGet = 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 = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override
public Object apply(final Entry<InventoryItem, Integer> from) {
return (int) (multiplier * getCardValue(from.getKey()));
}
};
@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 net.miginfocom.swing.MigLayout;
import forge.Singletons;
import forge.deck.Deck;
import forge.deck.DeckRecognizer;
@@ -32,33 +31,32 @@ import forge.game.GameType;
import forge.gui.GuiUtils;
import forge.item.CardPrinted;
/**
* Dialog for quick import of decks
*
/**
* Dialog for quick import of decks.
*/
public class DeckImport extends JDialog {
private static final long serialVersionUID = -5837776824284093004L;
private JTextArea txtInput = new JTextArea();
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;} " +
//"h1 {border-bottom: solid 1px black; color: blue; font-size: 12px; margin: 3px 0 9px 0; } " +
".comment {color: #666666;} " +
".knowncard {color: #009900;} " +
".unknowncard {color: #990000;} " +
".section {padding: 3px 10px; margin: 3px 0; font-weight: 700; background-color: #DDDDDD; } " +
"</style>";
private static final String htmlWelcomeText = "<html>"+stylesheet+"<h3>You'll see recognized cards here</h3>" +
"<div class='section'>Legend</div>" +
"<ul>" +
"<li class='knowncard'>Recognized cards will be shown in green. These cards will be auto-imported into a new deck<BR></li>" +
"<li class='unknowncard'>Lines which seem to be cards but are either misspelled or unsupported by Forge, are shown in dark-red<BR></li>" +
"<li class='comment'>Lines that appear unsignificant will be shown in gray<BR><BR></li>" +
"</ul>" +
"<div class='comment'>Submit feedback to Max mtg on slightlymagic.net forum</div>" +
"<div class='comment'>Post bug-reports to http://cardforge.org/bugz/</div>" +
"</html>";
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;} "
+
// "h1 {border-bottom: solid 1px black; color: blue; font-size: 12px; margin: 3px 0 9px 0; } "
// +
".comment {color: #666666;} " + ".knowncard {color: #009900;} " + ".unknowncard {color: #990000;} "
+ ".section {padding: 3px 10px; margin: 3px 0; font-weight: 700; background-color: #DDDDDD; } "
+ "</style>";
private static final String htmlWelcomeText = "<html>"
+ stylesheet
+ "<h3>You'll see recognized cards here</h3>"
+ "<div class='section'>Legend</div>"
+ "<ul>"
+ "<li class='knowncard'>Recognized cards will be shown in green. These cards will be auto-imported into a new deck<BR></li>"
+ "<li class='unknowncard'>Lines which seem to be cards but are either misspelled or unsupported by Forge, are shown in dark-red<BR></li>"
+ "<li class='comment'>Lines that appear unsignificant will be shown in gray<BR><BR></li>" + "</ul>"
+ "<div class='comment'>Submit feedback to Max mtg on slightlymagic.net forum</div>"
+ "<div class='comment'>Post bug-reports to http://cardforge.org/bugz/</div>" + "</html>";
private JEditorPane htmlOutput = new JEditorPane("text/html", htmlWelcomeText);
private JScrollPane scrollInput = new JScrollPane(txtInput);
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 JButton cmdAccept = new JButton("Import Deck");
private JButton cmdCancel = new JButton("Cancel");
/** The tokens. */
List<DeckRecognizer.Token> tokens = new ArrayList<DeckRecognizer.Token>();
private final DeckEditorBase host;
public DeckImport(DeckEditorBase g) {
/**
* Instantiates a new deck import.
*
* @param g
* the g
*/
public DeckImport(final DeckEditorBase g) {
host = g;
int wWidth = 600;
int wHeight = 600;
setPreferredSize(new java.awt.Dimension(wWidth, wHeight));
setSize(wWidth, wHeight);
GuiUtils.centerFrame(this);
setResizable(false);
setTitle("Deck Import (wip)");
if (!Singletons.getModel().getPreferences().lafFonts) {
Font fButtons = new java.awt.Font("Dialog", 0, 13);
cmdAccept.setFont(fButtons);
cmdCancel.setFont(fButtons);
txtInput.setFont(fButtons);
//htmlOutput.setFont(fButtons);
// htmlOutput.setFont(fButtons);
}
htmlOutput.setEditable(false);
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());
scrollOutput.setViewportBorder(BorderFactory.createLoweredBevelBorder());
getContentPane().setLayout(new MigLayout("fill"));
getContentPane().add(scrollInput, "cell 0 0, w 50%, sy 4, 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(cmdCancel, "w 100");
cmdCancel.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING)); } });
cmdCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING));
}
});
cmdAccept.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
cmdAccept.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
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);
if (JOptionPane.NO_OPTION == answer) { return; }
int answer = JOptionPane.showConfirmDialog(DeckImport.this, warning, "Replacing old deck",
JOptionPane.YES_NO_OPTION);
if (JOptionPane.NO_OPTION == answer) {
return;
}
Deck toSet = buildDeck();
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());
cmdAccept.setEnabled(false);
}
private void readInput()
{
private void readInput() {
tokens.clear();
ElementIterator it = new ElementIterator(txtInput.getDocument().getDefaultRootElement());
Element e;
while ((e=it.next()) != null) {
if (!e.isLeaf()) { continue; }
while ((e = it.next()) != null) {
if (!e.isLeaf()) {
continue;
}
int rangeStart = e.getStartOffset();
int rangeEnd = e.getEndOffset();
try {
String line = txtInput.getText(rangeStart, rangeEnd-rangeStart);
String line = txtInput.getText(rangeStart, rangeEnd - rangeStart);
tokens.add(DeckRecognizer.recognizeLine(line));
} catch (BadLocationException ex) {
}
}
}
private void displayTokens() {
StringBuilder sbOut = new StringBuilder("<html>");
sbOut.append(stylesheet);
@@ -155,30 +168,41 @@ public class DeckImport extends JDialog {
sbOut.append("</html>");
htmlOutput.setText(sbOut.toString());
}
private void updateSummaries() {
int[] cardsOk = new int[2];
int[] cardsUnknown = new int[2];
int idx = 0;
for (DeckRecognizer.Token t : tokens) {
if (t.getType() == TokenType.KnownCard) { cardsOk[idx] += t.getNumber(); }
if (t.getType() == TokenType.UnknownCard) { cardsUnknown[idx] += t.getNumber(); }
if (t.getType() == TokenType.SectionName && t.getText().toLowerCase().contains("side") ) { idx = 1; }
if (t.getType() == TokenType.KnownCard) {
cardsOk[idx] += t.getNumber();
}
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]));
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);
}
private Deck buildDeck(){
private Deck buildDeck() {
Deck result = new Deck(GameType.Constructed);
boolean isMain = true;
for (DeckRecognizer.Token t : tokens) {
DeckRecognizer.TokenType type = t.getType();
if (type == DeckRecognizer.TokenType.SectionName && t.getText().toLowerCase().contains("side") ) { isMain = false; }
if (type != DeckRecognizer.TokenType.KnownCard) { continue; }
if (type == DeckRecognizer.TokenType.SectionName && t.getText().toLowerCase().contains("side")) {
isMain = false;
}
if (type != DeckRecognizer.TokenType.KnownCard) {
continue;
}
CardPrinted crd = t.getCard();
if(crd.isAlternate()) {
if (crd.isAlternate()) {
continue;
}
if (isMain) {
@@ -190,27 +214,68 @@ public class DeckImport extends JDialog {
return result;
}
/**
* The Class OnChangeTextUpdate.
*/
protected class OnChangeTextUpdate implements DocumentListener {
private void onChange() { readInput(); displayTokens(); updateSummaries(); }
@Override public void insertUpdate(DocumentEvent e) { onChange(); }
@Override public void removeUpdate(DocumentEvent e) { onChange(); }
@Override public void changedUpdate(DocumentEvent e) { } // Happend only on ENTER pressed
}
private void onChange() {
readInput();
displayTokens();
updateSummaries();
}
private String makeHtmlViewOfToken(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:
/*
* (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
}
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());
case SectionName:
return String.format("<div class='section'>%s</div>", token.getText());
case UnknownText:
case Comment:
return String.format("<div class='comment'>%s</div>", token.getText());
default:
break;
}
return "";
}
}

View File

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

View File

@@ -22,27 +22,41 @@ import forge.card.CardSet;
import forge.game.GameFormat;
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;
/** The label filter name. */
public final JLabel labelFilterName = new JLabel();
/** The label filter type. */
public final JLabel labelFilterType = new JLabel();
/** The label filter rules. */
public final JLabel labelFilterRules = new JLabel();
/** The txt card name. */
public final JTextField txtCardName = new JTextField();
/** The txt card type. */
public final JTextField txtCardType = new JTextField();
/** The txt card rules. */
public final JTextField txtCardRules = new JTextField();
/** The search set combo. */
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"));
labelFilterName.setText("Name:");
labelFilterName.setToolTipText("Card names must include the text in this field");
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");
this.add(labelFilterType, "");
this.add(txtCardType, "wmin 100, grow");
labelFilterRules.setText("Text:");
labelFilterRules.setToolTipText("Card descriptions must include the text in this field");
this.add(labelFilterRules, "");
this.add(txtCardRules, "wmin 200, grow");
searchSetCombo.removeAllItems();
searchSetCombo.addItem("(all sets and formats)");
for (GameFormat s : SetUtils.getFormats()) {
searchSetCombo.addItem(s);
}
}
for (CardSet s : SetUtils.getAllSets()) {
searchSetCombo.addItem(s);
}
@@ -71,28 +84,42 @@ public class FilterNameTypeSetPanel extends JComponent{
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);
txtCardRules.getDocument().addDocumentListener(onTextChange);
txtCardName.getDocument().addDocumentListener(onTextChange);
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);
if (StringUtils.isNotBlank(txtCardName.getText())) {
rules.add(CardPrinted.Predicates.name(StringOp.CONTAINS, txtCardName.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())) {
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) {
Object selected = searchSetCombo.getSelectedItem();
if (selected instanceof CardSet) {
@@ -102,18 +129,22 @@ public class FilterNameTypeSetPanel extends JComponent{
}
}
switch (rules.size()){
case 0: return Predicate.getTrue(CardPrinted.class);
case 1: return rules.get(0);
case 2: return Predicate.and(rules.get(0), rules.get(1));
default: return Predicate.and(rules);
switch (rules.size()) {
case 0:
return Predicate.getTrue(CardPrinted.class);
case 1:
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.
*/
public void clearFilters() {
public final void clearFilters() {
txtCardName.setText("");
txtCardType.setText("");
txtCardRules.setText("");

View File

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

View File

@@ -12,90 +12,195 @@ import forge.item.CardPrinted;
import forge.item.InventoryItem;
import forge.item.InventoryItemFromSet;
/**
/**
* TODO: Write javadoc for this type.
*
*
*/
public abstract class PresetColumns {
private static CardManaCost toManaCost(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getManaCost() : CardManaCost.empty; }
private static CardColor toColor(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getColor() : CardColor.nullColor; }
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(); } };
private static CardManaCost toManaCost(final InventoryItem i) {
return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getManaCost() : CardManaCost.empty;
}
@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(); } };
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(); } };
private static CardColor toColor(final InventoryItem i) {
return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getColor() : CardColor.nullColor;
}
@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()); } };
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()); } };
private static String toPTL(final InventoryItem i) {
return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getPTorLoyalty() : "";
}
@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()); } };
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()); } };
private static CardRarity toRarity(final InventoryItem i) {
return i instanceof CardPrinted ? ((CardPrinted) i).getRarity() : CardRarity.Unknown;
}
@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(); } };
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(); } };
private static CardSet toSetCmp(final InventoryItem i) {
return i instanceof InventoryItemFromSet ? SetUtils.getSetByCode(((InventoryItemFromSet) i).getSet())
: CardSet.unknown;
}
@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()); } };
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()); } };
private static String toSetStr(final InventoryItem i) {
return i instanceof InventoryItemFromSet ? ((InventoryItemFromSet) i).getSet() : "n/a";
}
@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()); } };
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()); } };
private static Integer toAiCmp(final InventoryItem i) {
return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatusComparable() : Integer.valueOf(-1);
}
@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()); } };
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()); } };
private static String toAiStr(final InventoryItem i) {
return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatus() : "n/a";
}
/** The Constant fnQtyCompare. */
@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()); } };
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()); } };
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();
}
};
/** 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;
/**
* Holds single column set up for TableModel.
* Contains name, width + functions to retrieve column's value for compare and for display
* (they are different, in case of sets for instance)
/**
* Holds single column set up for TableModel. Contains name, width + functions
* to retrieve column's value for compare and for display (they are different,
* in case of sets for instance)
*
* @param <T>
* the generic type
*/
@SuppressWarnings("rawtypes")
public class TableColumnInfo<T> {
private final String name;
@SuppressWarnings("rawtypes")
public class TableColumnInfo<T> {
private final String name;
public int minWidth;
public int maxWidth;
public int nominalWidth;
/** The min width. */
public int minWidth;
public boolean isMinMaxApplied = true;
/** The max width. */
public int maxWidth;
public final Lambda1<Comparable, Entry<T, Integer>> fnSort; // this will be used for sorting
public final Lambda1<Object, Entry<T, Integer>> fnDisplay; // this is used to display
/** The nominal width. */
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,
final Lambda1<Comparable, Entry<T, Integer>> fieldSort,
final Lambda1<Object, Entry<T, Integer>> fieldDisplay) {
fnSort = fieldSort;
fnDisplay = fieldDisplay;
this.name = colName;
}
/** The fn display. */
public final Lambda1<Object, Entry<T, Integer>> fnDisplay; // this is used
// to 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;
}
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;
}
private TableCellRenderer cellRenderer = null;
public void setCellRenderer(final TableCellRenderer renderer) {
cellRenderer = renderer;
}
public final TableCellRenderer getCellRenderer() {
return cellRenderer;
}
/**
* Gets the name.
*
* @return the name
*/
public final String getName() {
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;
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.ListSelectionListener;
import javax.swing.event.TableModelEvent;
@@ -13,16 +21,13 @@ import forge.item.InventoryItem;
import forge.item.ItemPool;
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
* @version $Id$
*/
@@ -36,13 +41,17 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
private class Order {
public final int sortColumn;
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 List<Order> orders = new ArrayList<Order>(3);
private TableSorterCascade<T> sorter = null;
private boolean isSorterReady = false;
private int indexOfColumn(final int column) {
int posColumn = orders.size() - 1;
for (; posColumn >= 0; posColumn--) {
@@ -60,22 +69,26 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
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) {
int posColumn = indexOfColumn(column);
switch (posColumn) {
case -1: // no such column here - let's add then
orders.add(0, new Order(column));
break;
case 0: // found at top-level, should invert
orders.get(0).isSortAsc ^= true; // invert
break;
default: // found somewhere, move down others, set this one onto top;
orders.remove(posColumn);
orders.add(0, new Order(column));
break;
case -1: // no such column here - let's add then
orders.add(0, new Order(column));
break;
case 0: // found at top-level, should invert
orders.get(0).isSortAsc ^= true; // invert
break;
default: // found somewhere, move down others, set this one onto
// top;
orders.remove(posColumn);
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;
}
@@ -96,14 +109,29 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
private final List<TableColumnInfo<T>> columns;
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);
cardDisplay = cd;
columns = columnsToShow;
columns.get(4).isMinMaxApplied = false;
}
/**
* Resize cols.
*
* @param table
* the table
*/
public void resizeCols(final JTable table) {
TableColumn tableColumn = null;
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>
*
* @param c a {@link forge.Card} object.
* Gets the cards.
*
* @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) {
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) {
data.add(c);
fireTableDataChanged();
}
/**
* Adds the card.
*
* @param c
* the c
* @param count
* the count
*/
public void addCard(final T c, final int count) {
data.add(c, count);
fireTableDataChanged();
}
/**
* Adds the card.
*
* @param e
* the e
*/
public void addCard(final Entry<T, Integer> e) {
data.add(e.getKey(), e.getValue());
fireTableDataChanged();
}
/**
* Adds the cards.
*
* @param c
* the c
*/
public void addCards(final Iterable<Entry<T, Integer>> c) {
data.addAll(c);
fireTableDataChanged();
}
/**
* Adds the all cards.
*
* @param c
* the c
*/
public void addAllCards(final Iterable<T> c) {
data.addAllCards(c);
fireTableDataChanged();
}
/**
* Row to card.
*
* @param row
* the row
* @return the entry
*/
public Entry<T, Integer> rowToCard(final int row) {
List<Entry<T, Integer>> model = data.getOrderedList();
return row >= 0 && row < model.size() ? model.get(row) : null;
}
/*
* (non-Javadoc)
*
* @see javax.swing.table.TableModel#getRowCount()
*/
public int getRowCount() {
return data.countDistinct();
}
/*
* (non-Javadoc)
*
* @see javax.swing.table.TableModel#getColumnCount()
*/
public int getColumnCount() {
return columns.size();
}
@@ -179,34 +276,67 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
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 {
/** The table. */
protected JTable table;
public ColumnListener(final JTable t) { table = t; }
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();
/**
* Instantiates a new column listener.
*
* @param t
* the t
*/
public ColumnListener(final JTable t) {
table = t;
}
}
/*
* (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) {
int row = table.getSelectedRow();
if (row != -1) {
@@ -216,12 +346,15 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
}
/**
* <p>addListeners.</p>
*
* @param table a {@link javax.swing.JTable} object.
* <p>
* addListeners.
* </p>
*
* @param table
* a {@link javax.swing.JTable} object.
*/
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() {
@Override
@@ -231,24 +364,38 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
});
table.addFocusListener(new FocusListener() {
@Override public void focusLost(final FocusEvent e) {}
@Override public void focusGained(final FocusEvent e) {
@Override
public void focusLost(final FocusEvent e) {
}
@Override
public void focusGained(final FocusEvent e) {
showSelectedCard(table);
}
});
table.getTableHeader().addMouseListener(new ColumnListener(table));
}//addCardListener()
}// addCardListener()
/**
* Resort.
*/
public void resort() {
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);
resort();
}
}//CardTableModel
}// CardTableModel

View File

@@ -1,50 +1,66 @@
package forge.gui.deckeditor;
import forge.item.CardPrinted;
import java.util.Comparator;
import java.util.Map.Entry;
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
* @version $Id$
*/
@SuppressWarnings("unchecked") // Comparable needs <type>
@SuppressWarnings("unchecked")
// Comparable needs <type>
public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
private boolean ascending;
@SuppressWarnings("rawtypes")
private Lambda1<Comparable, Entry<T, Integer>> field;
/**
* <p>Constructor for TableSorter.</p>
*
* @param in_all a {@link forge.CardList} object.
* @param in_column a int.
* @param in_ascending a boolean.
* <p>
* Constructor for TableSorter.
* </p>
*
* @param field
* the field
* @param in_ascending
* a boolean.
*/
@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;
ascending = in_ascending;
}
/** The Constant byNameThenSet. */
@SuppressWarnings("rawtypes")
public static final TableSorter<CardPrinted> byNameThenSet = new TableSorter<CardPrinted>(
new Lambda1<Comparable, Entry<CardPrinted, Integer>>() {
@Override public Comparable apply(final Entry<CardPrinted, Integer> from) { return from.getKey(); }
}, true);
new Lambda1<Comparable, Entry<CardPrinted, Integer>>() {
@Override
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")
@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 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);
}
}

View File

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

View File

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

View File

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