checkstyle and refactor. Turn off magic number check for time being

This commit is contained in:
jendave
2011-11-01 15:12:59 +00:00
parent 74596b2a60
commit 1fac42e697
23 changed files with 2081 additions and 1671 deletions

View File

@@ -188,7 +188,7 @@
<!-- <module name="HiddenField"/> --> <!-- <module name="HiddenField"/> -->
<module name="IllegalInstantiation"/> <module name="IllegalInstantiation"/>
<module name="InnerAssignment"/> <module name="InnerAssignment"/>
<module name="MagicNumber"/> <!-- <module name="MagicNumber"/> -->
<module name="MissingSwitchDefault"/> <module name="MissingSwitchDefault"/>
<module name="RedundantThrows"/> <module name="RedundantThrows"/>
<module name="SimplifyBooleanExpression"/> <module name="SimplifyBooleanExpression"/>

View File

@@ -698,7 +698,7 @@ public class DeckManager {
private static void writeCardPool(final ItemPoolView<CardPrinted> pool, final BufferedWriter out) private static void writeCardPool(final ItemPoolView<CardPrinted> pool, final BufferedWriter out)
throws IOException { throws IOException {
final List<Entry<CardPrinted, Integer>> main2sort = pool.getOrderedList(); final List<Entry<CardPrinted, Integer>> main2sort = pool.getOrderedList();
Collections.sort(main2sort, TableSorter.byNameThenSet); Collections.sort(main2sort, TableSorter.BY_NAME_THEN_SET);
for (final Entry<CardPrinted, Integer> e : main2sort) { for (final Entry<CardPrinted, Integer> e : main2sort) {
final CardPrinted card = e.getKey(); final CardPrinted card = e.getKey();
final boolean hasBadSetInfo = "???".equals(card.getSet()) || StringUtils.isBlank(card.getSet()); final boolean hasBadSetInfo = "???".equals(card.getSet()) || StringUtils.isBlank(card.getSet());

View File

@@ -29,7 +29,7 @@ public class CardPanelHeavy extends CardPanelBase {
private static final long serialVersionUID = -7134546689397508597L; private static final long serialVersionUID = -7134546689397508597L;
private JButton changeStateButton = new JButton(); private final JButton changeStateButton = new JButton();
/* /*
* Removed Oct 25 2011 - Hellfish private JButton changePictureButton = new * Removed Oct 25 2011 - Hellfish private JButton changePictureButton = new
@@ -38,33 +38,34 @@ public class CardPanelHeavy extends CardPanelBase {
// Controls to show card details // Controls to show card details
/** The detail. */ /** The detail. */
protected CardDetailPanel detail = new CardDetailPanel(null); private CardDetailPanel detail = new CardDetailPanel(null);
/** The picture. */ /** The picture. */
protected CardPanel picture = new CardPanel(null); private CardPanel picture = new CardPanel(null);
/** The picture view panel. */ /** The picture view panel. */
protected ViewPanel pictureViewPanel = new ViewPanel(); private ViewPanel pictureViewPanel = new ViewPanel();
// fake card to allow picture changes // fake card to allow picture changes
/** The c card hq. */ /** The c card hq. */
public Card cCardHQ; private Card cCardHQ;
/** Constant <code>previousDirectory</code>. */ /** Constant <code>previousDirectory</code>. */
protected static File previousDirectory = null; private static File previousDirectory = null;
/** /**
* Instantiates a new card panel heavy. * Instantiates a new card panel heavy.
*/ */
public CardPanelHeavy() { public CardPanelHeavy() {
changeStateButton.setVisible(false); this.changeStateButton.setVisible(false);
changeStateButton.addActionListener(new java.awt.event.ActionListener() { this.changeStateButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
changeStateButton_actionPerformed(e); CardPanelHeavy.this.changeStateButtonActionPerformed(e);
} }
}); });
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
changeStateButton.setFont(new java.awt.Font("Dialog", 0, 10)); this.changeStateButton.setFont(new java.awt.Font("Dialog", 0, 10));
} }
/* /*
@@ -86,17 +87,17 @@ public class CardPanelHeavy extends CardPanelBase {
* removePictureButton.setFont(new java.awt.Font("Dialog", 0, 10)); * removePictureButton.setFont(new java.awt.Font("Dialog", 0, 10));
*/ */
pictureViewPanel.setCardPanel(picture); this.pictureViewPanel.setCardPanel(this.picture);
this.setLayout(new MigLayout("fill, ins 0")); this.setLayout(new MigLayout("fill, ins 0"));
this.add(detail, "w 239, h 323, grow, flowy, wrap"); this.add(this.detail, "w 239, h 323, grow, flowy, wrap");
/* /*
* Removed Oct 25 2011 - Hellfish this.add(changeStateButton, * Removed Oct 25 2011 - Hellfish this.add(changeStateButton,
* "align 50% 0%, split 3, flowx"); this.add(changePictureButton, * "align 50% 0%, split 3, flowx"); this.add(changePictureButton,
* "align 50% 0%"); this.add(removePictureButton, "align 50% 0%, wrap"); * "align 50% 0%"); this.add(removePictureButton, "align 50% 0%, wrap");
*/ */
this.add(changeStateButton, "align 50% 0%, flowx, wrap"); this.add(this.changeStateButton, "align 50% 0%, flowx, wrap");
this.add(pictureViewPanel, "wmin 239, hmin 323, grow"); this.add(this.pictureViewPanel, "wmin 239, hmin 323, grow");
} }
/* /*
@@ -105,10 +106,11 @@ public class CardPanelHeavy extends CardPanelBase {
* @see * @see
* forge.gui.deckeditor.CardPanelBase#showCard(forge.item.InventoryItem) * forge.gui.deckeditor.CardPanelBase#showCard(forge.item.InventoryItem)
*/ */
@Override
public final void showCard(final InventoryItem card) { public final void showCard(final InventoryItem card) {
Card card2 = card instanceof CardPrinted ? ((CardPrinted) card).toForgeCard() : null; final Card card2 = card instanceof CardPrinted ? ((CardPrinted) card).toForgeCard() : null;
detail.setCard(card2); this.detail.setCard(card2);
setCard(card2); this.setCard(card2);
} }
/** /**
@@ -118,22 +120,22 @@ public class CardPanelHeavy extends CardPanelBase {
* the new card * the new card
*/ */
public final void setCard(final Card c) { public final void setCard(final Card c) {
if (picture.getCard() != null) { if (this.picture.getCard() != null) {
if (picture.getCard().isInAlternateState()) { if (this.picture.getCard().isInAlternateState()) {
picture.getCard().changeState(); this.picture.getCard().changeState();
} }
} }
picture.setCard(c); this.picture.setCard(c);
if (c.hasAlternateState()) { if (c.hasAlternateState()) {
changeStateButton.setVisible(true); this.changeStateButton.setVisible(true);
if (c.isFlip()) { if (c.isFlip()) {
changeStateButton.setText("Flip"); this.changeStateButton.setText("Flip");
} else { } else {
changeStateButton.setText("Transform"); this.changeStateButton.setText("Transform");
} }
} else { } else {
changeStateButton.setVisible(false); this.changeStateButton.setVisible(false);
} }
} }
@@ -145,12 +147,12 @@ public class CardPanelHeavy extends CardPanelBase {
* @param e * @param e
* a {@link java.awt.event.ActionEvent} object. * a {@link java.awt.event.ActionEvent} object.
*/ */
final void changeStateButton_actionPerformed(final ActionEvent e) { final void changeStateButtonActionPerformed(final ActionEvent e) {
Card cur = picture.getCard(); final Card cur = this.picture.getCard();
cur.changeState(); cur.changeState();
picture.setCard(cur); this.picture.setCard(cur);
detail.setCard(cur); this.detail.setCard(cur);
} }
/** /**
@@ -161,23 +163,23 @@ public class CardPanelHeavy extends CardPanelBase {
* @param e * @param e
* a {@link java.awt.event.ActionEvent} object. * a {@link java.awt.event.ActionEvent} object.
*/ */
final void changePictureButton_actionPerformed(final ActionEvent e) { private void changePictureButtonActionPerformed(final ActionEvent e) {
if (cCardHQ != null) { if (this.cCardHQ != null) {
File file = getImportFilename(); final File file = this.getImportFilename();
if (file != null) { if (file != null) {
String fileName = GuiDisplayUtil.cleanString(cCardHQ.getName()) + ".jpg"; final String fileName = GuiDisplayUtil.cleanString(this.cCardHQ.getName()) + ".jpg";
File base = ForgeProps.getFile(NewConstants.IMAGE_BASE); final File base = ForgeProps.getFile(NewConstants.IMAGE_BASE);
File f = new File(base, fileName); final File f = new File(base, fileName);
f.delete(); f.delete();
try { try {
org.apache.commons.io.FileUtils.copyFile(file, f); org.apache.commons.io.FileUtils.copyFile(file, f);
} catch (IOException e1) { } catch (final IOException e1) {
// TODO Auto-generated catch block ignores the exception, // TODO Auto-generated catch block ignores the exception,
// but sends it to System.err and probably forge.log. // but sends it to System.err and probably forge.log.
e1.printStackTrace(); e1.printStackTrace();
} }
setCard(cCardHQ); this.setCard(this.cCardHQ);
} }
} }
} }
@@ -190,16 +192,16 @@ public class CardPanelHeavy extends CardPanelBase {
* @return a {@link java.io.File} object. * @return a {@link java.io.File} object.
*/ */
private File getImportFilename() { private File getImportFilename() {
JFileChooser chooser = new JFileChooser(previousDirectory); final JFileChooser chooser = new JFileChooser(CardPanelHeavy.previousDirectory);
ImagePreviewPanel preview = new ImagePreviewPanel(); final ImagePreviewPanel preview = new ImagePreviewPanel();
chooser.setAccessory(preview); chooser.setAccessory(preview);
chooser.addPropertyChangeListener(preview); chooser.addPropertyChangeListener(preview);
chooser.addChoosableFileFilter(dckFilter); chooser.addChoosableFileFilter(this.dckFilter);
int returnVal = chooser.showOpenDialog(null); final int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile(); final File file = chooser.getSelectedFile();
previousDirectory = file.getParentFile(); CardPanelHeavy.previousDirectory = file.getParentFile();
return file; return file;
} }
@@ -208,7 +210,7 @@ public class CardPanelHeavy extends CardPanelBase {
} }
/** The dck filter. */ /** The dck filter. */
protected FileFilter dckFilter = new FileFilter() { private FileFilter dckFilter = new FileFilter() {
@Override @Override
public boolean accept(final File f) { public boolean accept(final File f) {
@@ -231,20 +233,20 @@ public class CardPanelHeavy extends CardPanelBase {
* @param e * @param e
* the e * the e
*/ */
final void removePictureButton_actionPerformed(final ActionEvent e) { final void removePictureButtonActionPerformed(final ActionEvent e) {
if (cCardHQ != null) { if (this.cCardHQ != null) {
String options[] = { "Yes", "No" }; final String[] options = { "Yes", "No" };
int value = JOptionPane.showOptionDialog(null, "Do you want delete " + cCardHQ.getName() + " picture?", final int value = JOptionPane.showOptionDialog(null, "Do you want delete " + this.cCardHQ.getName()
"Delete picture", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, + " picture?", "Delete picture", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
options[1]); options, options[1]);
if (value == 0) { if (value == 0) {
String fileName = GuiDisplayUtil.cleanString(cCardHQ.getName()) + ".jpg"; final String fileName = GuiDisplayUtil.cleanString(this.cCardHQ.getName()) + ".jpg";
File base = ForgeProps.getFile(NewConstants.IMAGE_BASE); final File base = ForgeProps.getFile(NewConstants.IMAGE_BASE);
File f = new File(base, fileName); final File f = new File(base, fileName);
f.delete(); f.delete();
JOptionPane.showMessageDialog(null, "Picture " + cCardHQ.getName() + " deleted.", "Delete picture", JOptionPane.showMessageDialog(null, "Picture " + this.cCardHQ.getName() + " deleted.",
JOptionPane.INFORMATION_MESSAGE); "Delete picture", JOptionPane.INFORMATION_MESSAGE);
setCard(cCardHQ); this.setCard(this.cCardHQ);
} }
} }
} }
@@ -255,7 +257,7 @@ public class CardPanelHeavy extends CardPanelBase {
* @return the card * @return the card
*/ */
public final Card getCard() { public final Card getCard() {
return detail.getCard(); return this.detail.getCard();
} }
} }

View File

@@ -23,29 +23,30 @@ public class CardPanelLite extends CardPanelBase {
// Controls to show card details // Controls to show card details
/** The detail. */ /** The detail. */
protected CardDetailPanel detail = new CardDetailPanel(null); private CardDetailPanel detail = new CardDetailPanel(null);
private CardPicturePanel picture = new CardPicturePanel(null); private final CardPicturePanel picture = new CardPicturePanel(null);
private JButton bChangeState = new JButton(); private final JButton bChangeState = new JButton();
/** /**
* *
* Constructor. * Constructor.
*/ */
public CardPanelLite() { public CardPanelLite() {
bChangeState.setVisible(false); this.bChangeState.setVisible(false);
bChangeState.addActionListener(new ActionListener() { this.bChangeState.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
bChangeState_actionPerformed(e); CardPanelLite.this.bChangeStateActionPerformed(e);
} }
}); });
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
bChangeState.setFont(new java.awt.Font("Dialog", 0, 10)); this.bChangeState.setFont(new java.awt.Font("Dialog", 0, 10));
} }
this.setLayout(new MigLayout("fill, ins 0")); this.setLayout(new MigLayout("fill, ins 0"));
this.add(detail, "w 239, h 303, grow, flowy, wrap"); this.add(this.detail, "w 239, h 303, grow, flowy, wrap");
this.add(bChangeState, "align 50% 0%, wrap"); this.add(this.bChangeState, "align 50% 0%, wrap");
this.add(picture, "wmin 239, hmin 323, grow"); this.add(this.picture, "wmin 239, hmin 323, grow");
} }
/** /**
@@ -55,20 +56,21 @@ public class CardPanelLite extends CardPanelBase {
* @param card * @param card
* an InventoryItem * an InventoryItem
*/ */
@Override
public final void showCard(final InventoryItem card) { public final void showCard(final InventoryItem card) {
picture.setCard(card); this.picture.setCard(card);
boolean isCard = card != null && card instanceof CardPrinted; final boolean isCard = (card != null) && (card instanceof CardPrinted);
detail.setVisible(isCard); this.detail.setVisible(isCard);
if (isCard) { if (isCard) {
Card toSet = ((CardPrinted) card).toForgeCard(); final Card toSet = ((CardPrinted) card).toForgeCard();
detail.setCard(toSet); this.detail.setCard(toSet);
if (toSet.hasAlternateState()) { if (toSet.hasAlternateState()) {
bChangeState.setVisible(true); this.bChangeState.setVisible(true);
if (toSet.isFlip()) { if (toSet.isFlip()) {
bChangeState.setText("Flip"); this.bChangeState.setText("Flip");
} else { } else {
bChangeState.setText("Transform"); this.bChangeState.setText("Transform");
} }
} }
} }
@@ -81,15 +83,15 @@ public class CardPanelLite extends CardPanelBase {
* the new card * the new card
*/ */
public final void setCard(final Card c) { public final void setCard(final Card c) {
picture.setCard(c); this.picture.setCard(c);
if (c != null) { if (c != null) {
detail.setCard(c); this.detail.setCard(c);
if (c.hasAlternateState()) { if (c.hasAlternateState()) {
bChangeState.setVisible(true); this.bChangeState.setVisible(true);
if (c.isFlip()) { if (c.isFlip()) {
bChangeState.setText("Flip"); this.bChangeState.setText("Flip");
} else { } else {
bChangeState.setText("Transform"); this.bChangeState.setText("Transform");
} }
} }
} }
@@ -102,15 +104,15 @@ public class CardPanelLite extends CardPanelBase {
* @return Card * @return Card
*/ */
public final Card getCard() { public final Card getCard() {
return detail.getCard(); return this.detail.getCard();
} }
private void bChangeState_actionPerformed(final ActionEvent e) { private void bChangeStateActionPerformed(final ActionEvent e) {
Card cur = detail.getCard(); final Card cur = this.detail.getCard();
if (cur != null) { if (cur != null) {
cur.changeState(); cur.changeState();
setCard(cur); this.setCard(cur);
} }
} }

View File

@@ -14,10 +14,10 @@ public class CheckBoxWithIcon extends JCheckBox {
/* Custom check box class for filter icons */ /* Custom check box class for filter icons */
private static final long serialVersionUID = -8099263807219520120L; private static final long serialVersionUID = -8099263807219520120L;
private String imagePath = "res/images/deckeditor/"; private final String imagePath = "res/images/deckeditor/";
private String iconYes; private final String iconYes;
private String iconNo; private final String iconNo;
private CheckBoxWithIcon cb; private final CheckBoxWithIcon cb;
/** /**
* Instantiates a new check box with icon. * Instantiates a new check box with icon.
@@ -29,17 +29,18 @@ public class CheckBoxWithIcon extends JCheckBox {
*/ */
CheckBoxWithIcon(final String filterName, final String toolTip) { CheckBoxWithIcon(final String filterName, final String toolTip) {
super("", true); super("", true);
cb = this; this.cb = this;
iconYes = imagePath + "filter_" + filterName + "_y.png"; this.iconYes = this.imagePath + "filter_" + filterName + "_y.png";
iconNo = imagePath + "filter_" + filterName + "_n.png"; this.iconNo = this.imagePath + "filter_" + filterName + "_n.png";
this.setIcon(new ImageIcon(iconYes)); this.setIcon(new ImageIcon(this.iconYes));
this.setToolTipText(toolTip); this.setToolTipText(toolTip);
this.addActionListener(new ActionListener() { this.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent actionEvent) { public void actionPerformed(final ActionEvent actionEvent) {
if (cb.isSelected()) { if (CheckBoxWithIcon.this.cb.isSelected()) {
cb.setIcon(new ImageIcon(iconYes)); CheckBoxWithIcon.this.cb.setIcon(new ImageIcon(CheckBoxWithIcon.this.iconYes));
} else { } else {
cb.setIcon(new ImageIcon(iconNo)); CheckBoxWithIcon.this.cb.setIcon(new ImageIcon(CheckBoxWithIcon.this.iconNo));
} }
} }
}); });

File diff suppressed because it is too large Load Diff

View File

@@ -24,21 +24,21 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
private static final long serialVersionUID = -401223933343539977L; private static final long serialVersionUID = -401223933343539977L;
/** The filter boxes. */ /** The filter boxes. */
protected FilterCheckBoxes filterBoxes; private FilterCheckBoxes filterBoxes;
// set this to false when resetting filter from code (like // set this to false when resetting filter from code (like
// "clearFiltersPressed"), reset when done. // "clearFiltersPressed"), reset when done.
/** The is filters change firing update. */ /** The is filters change firing update. */
protected boolean isFiltersChangeFiringUpdate = true; private boolean isFiltersChangeFiringUpdate = true;
/** The card view. */ /** The card view. */
protected CardPanelBase cardView; private CardPanelBase cardView;
// CardPools and Table data for top and bottom lists // CardPools and Table data for top and bottom lists
/** The top. */ /** The top. */
protected TableWithCards top; private TableWithCards topTableWithCards;
/** The bottom. */ /** The bottom. */
protected TableWithCards bottom; private TableWithCards bottomTableWithCards;
private GameType gameType; private GameType gameType;
@@ -47,8 +47,9 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
* *
* @see forge.gui.deckeditor.DeckDisplay#getGameType() * @see forge.gui.deckeditor.DeckDisplay#getGameType()
*/ */
@Override
public final GameType getGameType() { public final GameType getGameType() {
return gameType; return this.gameType;
} }
// top shows available card pool // top shows available card pool
@@ -61,7 +62,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
* @return the top table model * @return the top table model
*/ */
public final TableWithCards getTopTableModel() { public final TableWithCards getTopTableModel() {
return top; return this.getTopTableWithCards();
} }
/* /*
@@ -69,8 +70,9 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
* *
* @see forge.gui.deckeditor.DeckDisplay#getTop() * @see forge.gui.deckeditor.DeckDisplay#getTop()
*/ */
@Override
public final ItemPoolView<InventoryItem> getTop() { public final ItemPoolView<InventoryItem> getTop() {
return top.getCards(); return this.getTopTableWithCards().getCards();
} }
// bottom shows player's choice - be it deck or draft // bottom shows player's choice - be it deck or draft
@@ -79,8 +81,9 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
* *
* @see forge.gui.deckeditor.DeckDisplay#getBottom() * @see forge.gui.deckeditor.DeckDisplay#getBottom()
*/ */
@Override
public final ItemPoolView<InventoryItem> getBottom() { public final ItemPoolView<InventoryItem> getBottom() {
return bottom.getCards(); return this.getBottomTableWithCards().getCards();
} }
// THIS IS HERE FOR OVERLOADING!!!1 // THIS IS HERE FOR OVERLOADING!!!1
@@ -99,14 +102,15 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
* @param e * @param e
* the e * the e
*/ */
final void analysisButton_actionPerformed(final ActionEvent e) { final void analysisButtonActionPerformed(final ActionEvent e) {
ItemPoolView<CardPrinted> deck = ItemPool.createFrom(bottom.getCards(), CardPrinted.class); final ItemPoolView<CardPrinted> deck = ItemPool.createFrom(this.getBottomTableWithCards().getCards(),
CardPrinted.class);
if (deck.isEmpty()) { if (deck.isEmpty()) {
JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck", JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck",
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
} else { } else {
DeckEditorBase g = DeckEditorBase.this; final DeckEditorBase g = DeckEditorBase.this;
DeckAnalysis dAnalysis = new DeckAnalysis(g, deck); final DeckAnalysis dAnalysis = new DeckAnalysis(g, deck);
dAnalysis.setVisible(true); dAnalysis.setVisible(true);
g.setEnabled(false); g.setEnabled(false);
} }
@@ -119,7 +123,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
* the gametype * the gametype
*/ */
public DeckEditorBase(final GameType gametype) { public DeckEditorBase(final GameType gametype) {
gameType = gametype; this.gameType = gametype;
} }
/* /*
@@ -128,11 +132,12 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
* @see forge.gui.deckeditor.DeckDisplay#setDeck(forge.item.ItemPoolView, * @see forge.gui.deckeditor.DeckDisplay#setDeck(forge.item.ItemPoolView,
* forge.item.ItemPoolView, forge.game.GameType) * forge.item.ItemPoolView, forge.game.GameType)
*/ */
@Override
public void setDeck(final ItemPoolView<CardPrinted> topParam, final ItemPoolView<CardPrinted> bottomParam, public void setDeck(final ItemPoolView<CardPrinted> topParam, final ItemPoolView<CardPrinted> bottomParam,
final GameType gt) { final GameType gt) {
gameType = gt; this.gameType = gt;
top.setDeck(topParam); this.getTopTableWithCards().setDeck(topParam);
bottom.setDeck(bottomParam); this.getBottomTableWithCards().setDeck(bottomParam);
} }
/* /*
@@ -141,25 +146,27 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
* @see forge.gui.deckeditor.DeckDisplay#setItems(forge.item.ItemPoolView, * @see forge.gui.deckeditor.DeckDisplay#setItems(forge.item.ItemPoolView,
* forge.item.ItemPoolView, forge.game.GameType) * forge.item.ItemPoolView, forge.game.GameType)
*/ */
@Override
public final <T extends InventoryItem> void setItems(final ItemPoolView<T> topParam, public final <T extends InventoryItem> void setItems(final ItemPoolView<T> topParam,
final ItemPoolView<T> bottomParam, final GameType gt) { final ItemPoolView<T> bottomParam, final GameType gt) {
gameType = gt; this.gameType = gt;
top.setDeck(topParam); this.getTopTableWithCards().setDeck(topParam);
bottom.setDeck(bottomParam); this.getBottomTableWithCards().setDeck(bottomParam);
} }
/** /**
* Update display. * Update display.
*/ */
public final void updateDisplay() { public final void updateDisplay() {
top.setFilter(buildFilter()); this.getTopTableWithCards().setFilter(this.buildFilter());
} }
/** The item listener updates display. */ /** The item listener updates display. */
protected ItemListener itemListenerUpdatesDisplay = new ItemListener() { private ItemListener itemListenerUpdatesDisplay = new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) { public void itemStateChanged(final ItemEvent e) {
if (isFiltersChangeFiringUpdate) { if (DeckEditorBase.this.isFiltersChangeFiringUpdate()) {
updateDisplay(); DeckEditorBase.this.updateDisplay();
} }
} }
}; };
@@ -170,8 +177,8 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
*/ */
protected class OnChangeTextUpdateDisplay implements DocumentListener { protected class OnChangeTextUpdateDisplay implements DocumentListener {
private void onChange() { private void onChange() {
if (isFiltersChangeFiringUpdate) { if (DeckEditorBase.this.isFiltersChangeFiringUpdate()) {
updateDisplay(); DeckEditorBase.this.updateDisplay();
} }
} }
@@ -184,7 +191,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
*/ */
@Override @Override
public final void insertUpdate(final DocumentEvent e) { public final void insertUpdate(final DocumentEvent e) {
onChange(); this.onChange();
} }
/* /*
@@ -196,7 +203,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
*/ */
@Override @Override
public final void removeUpdate(final DocumentEvent e) { public final void removeUpdate(final DocumentEvent e) {
onChange(); this.onChange();
} }
/* /*
@@ -216,15 +223,116 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
* *
* @see forge.gui.deckeditor.DeckDisplay#getDeck() * @see forge.gui.deckeditor.DeckDisplay#getDeck()
*/ */
@Override
public final Deck getDeck() { public final Deck getDeck() {
Deck deck = new Deck(gameType); final Deck deck = new Deck(this.gameType);
deck.addMain(ItemPool.createFrom(getBottom(), CardPrinted.class)); deck.addMain(ItemPool.createFrom(this.getBottom(), CardPrinted.class));
// if sealed or draft, move "top" to sideboard // if sealed or draft, move "top" to sideboard
if (gameType.isLimited() && gameType != GameType.Quest) { if (this.gameType.isLimited() && (this.gameType != GameType.Quest)) {
deck.addSideboard(ItemPool.createFrom(getTop(), CardPrinted.class)); deck.addSideboard(ItemPool.createFrom(this.getTop(), CardPrinted.class));
} }
return deck; return deck;
}// getDeck() } // getDeck()
/**
* @return the itemListenerUpdatesDisplay
*/
public ItemListener getItemListenerUpdatesDisplay() {
return itemListenerUpdatesDisplay;
}
/**
* @param itemListenerUpdatesDisplay
* the itemListenerUpdatesDisplay to set
*/
public void setItemListenerUpdatesDisplay(ItemListener itemListenerUpdatesDisplay) {
this.itemListenerUpdatesDisplay = itemListenerUpdatesDisplay; // TODO:
// Add 0
// to
// parameter's
// name.
}
/**
* @return the isFiltersChangeFiringUpdate
*/
public boolean isFiltersChangeFiringUpdate() {
return isFiltersChangeFiringUpdate;
}
/**
* @param isFiltersChangeFiringUpdate
* the isFiltersChangeFiringUpdate to set
*/
public void setFiltersChangeFiringUpdate(boolean isFiltersChangeFiringUpdate) {
this.isFiltersChangeFiringUpdate = isFiltersChangeFiringUpdate; // TODO:
// Add 0
// to
// parameter's
// name.
}
/**
* @return the cardView
*/
public CardPanelBase getCardView() {
return cardView;
}
/**
* @param cardView
* the cardView to set
*/
public void setCardView(CardPanelBase cardView) {
this.cardView = cardView; // TODO: Add 0 to parameter's name.
}
/**
* @return the filterBoxes
*/
public FilterCheckBoxes getFilterBoxes() {
return filterBoxes;
}
/**
* @param filterBoxes
* the filterBoxes to set
*/
public void setFilterBoxes(FilterCheckBoxes filterBoxes) {
this.filterBoxes = filterBoxes; // TODO: Add 0 to parameter's name.
}
/**
* @return the bottomTableWithCards
*/
public TableWithCards getBottomTableWithCards() {
return bottomTableWithCards;
}
/**
* @param bottomTableWithCards
* the bottomTableWithCards to set
*/
public void setBottomTableWithCards(TableWithCards bottomTableWithCards) {
this.bottomTableWithCards = bottomTableWithCards; // TODO: Add 0 to
// parameter's name.
}
/**
* @return the topTableWithCards
*/
public TableWithCards getTopTableWithCards() {
return topTableWithCards;
}
/**
* @param topTableWithCards
* the topTableWithCards to set
*/
public void setTopTableWithCards(TableWithCards topTableWithCards) {
this.topTableWithCards = topTableWithCards; // TODO: Add 0 to
// parameter's name.
}
} }

View File

@@ -40,20 +40,20 @@ import forge.item.ItemPoolView;
* @version $Id$ * @version $Id$
*/ */
public final class DeckEditorCommon extends DeckEditorBase { public final class DeckEditorCommon extends DeckEditorBase {
/** Constant <code>serialVersionUID=130339644136746796L</code> */ /** Constant <code>serialVersionUID=130339644136746796L</code>. */
private static final long serialVersionUID = 130339644136746796L; private static final long serialVersionUID = 130339644136746796L;
/** The custom menu. */ /** The custom menu. */
public DeckEditorCommonMenu customMenu; private DeckEditorCommonMenu customMenu;
private JButton removeButton = new JButton(); private final JButton removeButton = new JButton();
private JButton addButton = new JButton(); private final JButton addButton = new JButton();
private JButton importButton = new JButton(); private final JButton importButton = new JButton();
private JButton analysisButton = new JButton(); private final JButton analysisButton = new JButton();
private JButton clearFilterButton = new JButton(); private final JButton clearFilterButton = new JButton();
private JLabel jLabelAnalysisGap = new JLabel(""); private final JLabel jLabelAnalysisGap = new JLabel("");
private FilterNameTypeSetPanel filterNameTypeSet; private FilterNameTypeSetPanel filterNameTypeSet;
/** /**
@@ -66,41 +66,44 @@ public final class DeckEditorCommon extends DeckEditorBase {
final Command exit = new Command() { final Command exit = new Command() {
private static final long serialVersionUID = 5210924838133689758L; private static final long serialVersionUID = 5210924838133689758L;
@Override
public void execute() { public void execute() {
DeckEditorCommon.this.dispose(); DeckEditorCommon.this.dispose();
exitCommand.execute(); exitCommand.execute();
} }
}; };
customMenu = new DeckEditorCommonMenu(this, AllZone.getDeckManager(), exit); this.setCustomMenu(new DeckEditorCommonMenu(this, AllZone.getDeckManager(), exit));
this.setJMenuBar(customMenu); this.setJMenuBar(this.getCustomMenu());
// do not change this!!!! // do not change this!!!!
this.addWindowListener(new WindowAdapter() { this.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing(final WindowEvent ev) { public void windowClosing(final WindowEvent ev) {
customMenu.close(); DeckEditorCommon.this.getCustomMenu().close();
} }
}); });
setup(); this.setup();
// show cards, makes this user friendly // show cards, makes this user friendly
if (!getGameType().isLimited()) { if (!this.getGameType().isLimited()) {
customMenu.newConstructed(false); this.getCustomMenu().newConstructed(false);
} }
top.sort(1, true); this.getTopTableWithCards().sort(1, true);
bottom.sort(1, true); this.getBottomTableWithCards().sort(1, true);
} // show(Command) } // show(Command)
private void setup() { private void setup() {
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>(); final List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE, PresetColumns.FN_QTY_GET)); columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE,
PresetColumns.FN_QTY_GET));
columns.add(new TableColumnInfo<InventoryItem>("Name", 175, PresetColumns.FN_NAME_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("Name", 175, PresetColumns.FN_NAME_COMPARE,
PresetColumns.FN_NAME_GET)); PresetColumns.FN_NAME_GET));
columns.add(new TableColumnInfo<InventoryItem>("Cost", 75, PresetColumns.FN_COST_COMPARE, PresetColumns.FN_COST_GET)); columns.add(new TableColumnInfo<InventoryItem>("Cost", 75, PresetColumns.FN_COST_COMPARE,
PresetColumns.FN_COST_GET));
columns.add(new TableColumnInfo<InventoryItem>("Color", 60, PresetColumns.FN_COLOR_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("Color", 60, PresetColumns.FN_COLOR_COMPARE,
PresetColumns.FN_COLOR_GET)); PresetColumns.FN_COLOR_GET));
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE,
@@ -109,18 +112,19 @@ public final class DeckEditorCommon extends DeckEditorBase {
PresetColumns.FN_STATS_GET)); PresetColumns.FN_STATS_GET));
columns.add(new TableColumnInfo<InventoryItem>("R", 25, PresetColumns.FN_RARITY_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("R", 25, PresetColumns.FN_RARITY_COMPARE,
PresetColumns.FN_RARITY_GET)); PresetColumns.FN_RARITY_GET));
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE, PresetColumns.FN_SET_GET)); columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE,
PresetColumns.FN_SET_GET));
columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.FN_AI_STATUS_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.FN_AI_STATUS_COMPARE,
PresetColumns.FN_AI_STATUS_GET)); PresetColumns.FN_AI_STATUS_GET));
columns.get(2).setCellRenderer(new ManaCostRenderer()); columns.get(2).setCellRenderer(new ManaCostRenderer());
top.setup(columns, cardView); this.getTopTableWithCards().setup(columns, this.getCardView());
bottom.setup(columns, cardView); this.getBottomTableWithCards().setup(columns, this.getCardView());
filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), itemListenerUpdatesDisplay); this.filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), this.getItemListenerUpdatesDisplay());
setSize(1024, 740); this.setSize(1024, 740);
setExtendedState(Frame.MAXIMIZED_BOTH); this.setExtendedState(Frame.MAXIMIZED_BOTH);
} }
@@ -133,14 +137,14 @@ public final class DeckEditorCommon extends DeckEditorBase {
public DeckEditorCommon(final GameType gameType) { public DeckEditorCommon(final GameType gameType) {
super(gameType); super(gameType);
try { try {
filterBoxes = new FilterCheckBoxes(true); this.setFilterBoxes(new FilterCheckBoxes(true));
top = new TableWithCards("Avaliable Cards", true, true); this.setTopTableWithCards(new TableWithCards("Avaliable Cards", true, true));
bottom = new TableWithCards("Deck", true); this.setBottomTableWithCards(new TableWithCards("Deck", true));
cardView = new CardPanelHeavy(); this.setCardView(new CardPanelHeavy());
filterNameTypeSet = new FilterNameTypeSetPanel(); this.filterNameTypeSet = new FilterNameTypeSetPanel();
jbInit(); this.jbInit();
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
} }
} }
@@ -148,49 +152,54 @@ public final class DeckEditorCommon extends DeckEditorBase {
private void jbInit() { private void jbInit() {
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
Font fButtons = new java.awt.Font("Dialog", 0, 13); final Font fButtons = new java.awt.Font("Dialog", 0, 13);
removeButton.setFont(fButtons); this.removeButton.setFont(fButtons);
addButton.setFont(fButtons); this.addButton.setFont(fButtons);
importButton.setFont(fButtons); this.importButton.setFont(fButtons);
clearFilterButton.setFont(fButtons); this.clearFilterButton.setFont(fButtons);
analysisButton.setFont(fButtons); this.analysisButton.setFont(fButtons);
} }
addButton.setText("Add to Deck"); this.addButton.setText("Add to Deck");
removeButton.setText("Remove from Deck"); this.removeButton.setText("Remove from Deck");
importButton.setText("Import a Deck"); this.importButton.setText("Import a Deck");
clearFilterButton.setText("Clear Filter"); this.clearFilterButton.setText("Clear Filter");
analysisButton.setText("Deck Analysis"); this.analysisButton.setText("Deck Analysis");
removeButton.addActionListener(new java.awt.event.ActionListener() { this.removeButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
removeButtonClicked(e); DeckEditorCommon.this.removeButtonClicked(e);
} }
}); });
addButton.addActionListener(new java.awt.event.ActionListener() { this.addButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
addButton_actionPerformed(e); DeckEditorCommon.this.addButtonActionPerformed(e);
} }
}); });
importButton.addActionListener(new java.awt.event.ActionListener() { this.importButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
importButton_actionPerformed(e); DeckEditorCommon.this.importButtonActionPerformed(e);
} }
}); });
clearFilterButton.addActionListener(new java.awt.event.ActionListener() { this.clearFilterButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
clearFilterButton_actionPerformed(e); DeckEditorCommon.this.clearFilterButtonActionPerformed(e);
} }
}); });
analysisButton.addActionListener(new java.awt.event.ActionListener() { this.analysisButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
analysisButton_actionPerformed(e); DeckEditorCommon.this.analysisButtonActionPerformed(e);
} }
}); });
// Type filtering // Type filtering
Font f = new Font("Tahoma", Font.PLAIN, 10); final Font f = new Font("Tahoma", Font.PLAIN, 10);
for (JCheckBox box : filterBoxes.allTypes) { for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
box.setFont(f); box.setFont(f);
} }
@@ -198,7 +207,7 @@ public final class DeckEditorCommon extends DeckEditorBase {
} }
// Color filtering // Color filtering
for (JCheckBox box : filterBoxes.allColors) { for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
box.setOpaque(false); box.setOpaque(false);
} }
@@ -206,58 +215,58 @@ public final class DeckEditorCommon extends DeckEditorBase {
// x 768 screen size // x 768 screen size
this.setTitle("Deck Editor"); this.setTitle("Deck Editor");
Container content = this.getContentPane(); final Container content = this.getContentPane();
MigLayout layout = new MigLayout("fill"); final MigLayout layout = new MigLayout("fill");
content.setLayout(layout); content.setLayout(layout);
boolean isFirst = true; boolean isFirst = true;
for (JCheckBox box : filterBoxes.allTypes) { for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
String growParameter = "grow"; String growParameter = "grow";
if (isFirst) { if (isFirst) {
growParameter = "cell 0 0, egx checkbox, grow, split 14"; growParameter = "cell 0 0, egx checkbox, grow, split 14";
isFirst = false; isFirst = false;
} }
content.add(box, growParameter); content.add(box, growParameter);
box.addItemListener(itemListenerUpdatesDisplay); box.addItemListener(this.getItemListenerUpdatesDisplay());
} }
for (JCheckBox box : filterBoxes.allColors) { for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
content.add(box, "grow"); content.add(box, "grow");
box.addItemListener(itemListenerUpdatesDisplay); box.addItemListener(this.getItemListenerUpdatesDisplay());
} }
content.add(clearFilterButton, "wmin 100, hmin 25, wmax 140, hmax 25, grow"); content.add(this.clearFilterButton, "wmin 100, hmin 25, wmax 140, hmax 25, grow");
content.add(filterNameTypeSet, "cell 0 1, grow"); content.add(this.filterNameTypeSet, "cell 0 1, grow");
content.add(top.getTableDecorated(), "cell 0 2 1 2, pushy, grow"); content.add(this.getTopTableWithCards().getTableDecorated(), "cell 0 2 1 2, pushy, grow");
content.add(top.getLabel(), "cell 0 4"); content.add(this.getTopTableWithCards().getLabel(), "cell 0 4");
content.add(addButton, "w 100, h 49, sg button, cell 0 5, split 5"); content.add(this.addButton, "w 100, h 49, sg button, cell 0 5, split 5");
content.add(removeButton, "w 100, h 49, sg button"); content.add(this.removeButton, "w 100, h 49, sg button");
content.add(importButton, "w 100, h 49, sg button, gapleft 40px"); content.add(this.importButton, "w 100, h 49, sg button, gapleft 40px");
// Label is used to push the analysis button to the right to separate // Label is used to push the analysis button to the right to separate
// analysis button from add/remove card ones // analysis button from add/remove card ones
content.add(jLabelAnalysisGap, "wmin 75, growx"); content.add(this.jLabelAnalysisGap, "wmin 75, growx");
content.add(analysisButton, "w 100, h 49, wrap"); content.add(this.analysisButton, "w 100, h 49, wrap");
content.add(bottom.getTableDecorated(), "cell 0 6, grow"); content.add(this.getBottomTableWithCards().getTableDecorated(), "cell 0 6, grow");
content.add(bottom.getLabel(), "cell 0 7"); content.add(this.getBottomTableWithCards().getLabel(), "cell 0 7");
content.add(cardView, "cell 1 0 1 8, flowy, grow"); content.add(this.getCardView(), "cell 1 0 1 8, flowy, grow");
top.getTable().addMouseListener(new MouseAdapter() { this.getTopTableWithCards().getTable().addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(final MouseEvent e) { public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) { if (e.getClickCount() == 2) {
addCardToDeck(); DeckEditorCommon.this.addCardToDeck();
} }
} }
}); });
top.getTable().addKeyListener(new KeyAdapter() { this.getTopTableWithCards().getTable().addKeyListener(new KeyAdapter() {
@Override @Override
public void keyPressed(final KeyEvent e) { public void keyPressed(final KeyEvent e) {
if (e.getKeyChar() == ' ') { if (e.getKeyChar() == ' ') {
addCardToDeck(); DeckEditorCommon.this.addCardToDeck();
} }
} }
}); });
@@ -273,8 +282,8 @@ public final class DeckEditorCommon extends DeckEditorBase {
*/ */
@Override @Override
protected Predicate<InventoryItem> buildFilter() { protected Predicate<InventoryItem> buildFilter() {
Predicate<CardPrinted> cardFilter = Predicate.and( final Predicate<CardPrinted> cardFilter = Predicate.and(
Predicate.and(filterBoxes.buildFilter(), filterNameTypeSet.buildFilter()), Predicate.and(this.getFilterBoxes().buildFilter(), this.filterNameTypeSet.buildFilter()),
CardPrinted.Predicates.Presets.nonAlternate); CardPrinted.Predicates.Presets.nonAlternate);
return Predicate.instanceOf(cardFilter, CardPrinted.class); return Predicate.instanceOf(cardFilter, CardPrinted.class);
} }
@@ -288,11 +297,11 @@ public final class DeckEditorCommon extends DeckEditorBase {
@Override @Override
public void setDeck(final ItemPoolView<CardPrinted> topParam, final ItemPoolView<CardPrinted> bottomParam, public void setDeck(final ItemPoolView<CardPrinted> topParam, final ItemPoolView<CardPrinted> bottomParam,
final GameType gt) { final GameType gt) {
boolean keepRecievedCards = gt.isLimited() || topParam != null; final boolean keepRecievedCards = gt.isLimited() || (topParam != null);
// if constructed, can add the all cards above // if constructed, can add the all cards above
ItemPoolView<CardPrinted> top = keepRecievedCards ? topParam : ItemPool.createFrom(CardDb.instance() final ItemPoolView<CardPrinted> top = keepRecievedCards ? topParam : ItemPool.createFrom(CardDb.instance()
.getAllCards(), CardPrinted.class); .getAllCards(), CardPrinted.class);
importButton.setVisible(!gt.isLimited()); this.importButton.setVisible(!gt.isLimited());
super.setDeck(top, bottomParam, gt); super.setDeck(top, bottomParam, gt);
} }
@@ -302,26 +311,26 @@ public final class DeckEditorCommon extends DeckEditorBase {
* @param e * @param e
* the e * the e
*/ */
void clearFilterButton_actionPerformed(final ActionEvent e) { void clearFilterButtonActionPerformed(final ActionEvent e) {
// disable automatic update triggered by listeners // disable automatic update triggered by listeners
isFiltersChangeFiringUpdate = false; this.setFiltersChangeFiringUpdate(false);
for (JCheckBox box : filterBoxes.allTypes) { for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
if (!box.isSelected()) { if (!box.isSelected()) {
box.doClick(); box.doClick();
} }
} }
for (JCheckBox box : filterBoxes.allColors) { for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
if (!box.isSelected()) { if (!box.isSelected()) {
box.doClick(); box.doClick();
} }
} }
filterNameTypeSet.clearFilters(); this.filterNameTypeSet.clearFilters();
isFiltersChangeFiringUpdate = true; this.setFiltersChangeFiringUpdate(true);
top.setFilter(null); this.getTopTableWithCards().setFilter(null);
} }
/** /**
@@ -330,28 +339,28 @@ public final class DeckEditorCommon extends DeckEditorBase {
* @param e * @param e
* the e * the e
*/ */
void addButton_actionPerformed(final ActionEvent e) { void addButtonActionPerformed(final ActionEvent e) {
addCardToDeck(); this.addCardToDeck();
} }
/** /**
* Adds the card to deck. * Adds the card to deck.
*/ */
void addCardToDeck() { void addCardToDeck() {
InventoryItem item = top.getSelectedCard(); final InventoryItem item = this.getTopTableWithCards().getSelectedCard();
if (item == null || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
CardPrinted card = (CardPrinted) item; final CardPrinted card = (CardPrinted) item;
setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved"); this.setTitle("Deck Editor : " + this.getCustomMenu().getDeckName() + " : unsaved");
bottom.addCard(card); this.getBottomTableWithCards().addCard(card);
if (getGameType().isLimited()) { if (this.getGameType().isLimited()) {
top.removeCard(card); this.getTopTableWithCards().removeCard(card);
} }
customMenu.notifyDeckChange(); this.getCustomMenu().notifyDeckChange();
} }
/** /**
@@ -361,21 +370,21 @@ public final class DeckEditorCommon extends DeckEditorBase {
* the e * the e
*/ */
void removeButtonClicked(final ActionEvent e) { void removeButtonClicked(final ActionEvent e) {
InventoryItem item = bottom.getSelectedCard(); final InventoryItem item = this.getBottomTableWithCards().getSelectedCard();
if (item == null || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
CardPrinted card = (CardPrinted) item; final CardPrinted card = (CardPrinted) item;
setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved"); this.setTitle("Deck Editor : " + this.getCustomMenu().getDeckName() + " : unsaved");
bottom.removeCard(card); this.getBottomTableWithCards().removeCard(card);
if (getGameType().isLimited()) { if (this.getGameType().isLimited()) {
top.addCard(card); this.getTopTableWithCards().addCard(card);
} }
customMenu.notifyDeckChange(); this.getCustomMenu().notifyDeckChange();
} }
/** /**
@@ -384,11 +393,26 @@ public final class DeckEditorCommon extends DeckEditorBase {
* @param e * @param e
* the e * the e
*/ */
void importButton_actionPerformed(final ActionEvent e) { void importButtonActionPerformed(final ActionEvent e) {
DeckEditorBase g = this; final DeckEditorBase g = this;
DeckImport dImport = new DeckImport(g); final DeckImport dImport = new DeckImport(g);
dImport.setModalityType(ModalityType.APPLICATION_MODAL); dImport.setModalityType(ModalityType.APPLICATION_MODAL);
dImport.setVisible(true); dImport.setVisible(true);
} }
/**
* @return the customMenu
*/
public DeckEditorCommonMenu getCustomMenu() {
return customMenu;
}
/**
* @param customMenu
* the customMenu to set
*/
public void setCustomMenu(DeckEditorCommonMenu customMenu) {
this.customMenu = customMenu; // TODO: Add 0 to parameter's name.
}
} }

View File

@@ -49,14 +49,14 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
/** Constant <code>previousDirectory</code>. */ /** Constant <code>previousDirectory</code>. */
private static File previousDirectory = null; private static File previousDirectory = null;
private DeckManager deckManager; private final DeckManager deckManager;
private boolean isDeckSaved = true; private boolean isDeckSaved = true;
private String currentDeckName; private String currentDeckName;
private DeckDisplay deckDisplay; private final DeckDisplay deckDisplay;
private Command exitCommand; private final Command exitCommand;
/** /**
* *
@@ -70,16 +70,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
* a Command * a Command
*/ */
public DeckEditorCommonMenu(final DeckDisplay inDisplay, final DeckManager dckManager, final Command exit) { public DeckEditorCommonMenu(final DeckDisplay inDisplay, final DeckManager dckManager, final Command exit) {
deckDisplay = inDisplay; this.deckDisplay = inDisplay;
exitCommand = exit; this.exitCommand = exit;
deckManager = dckManager; this.deckManager = dckManager;
// this is added just to make save() and saveAs() work ok // this is added just to make save() and saveAs() work ok
// when first started up, just a silly patch // when first started up, just a silly patch
setDeckData("", true); this.setDeckData("", true);
setupMenu(); this.setupMenu();
setupSortMenu(); this.setupSortMenu();
} }
/** /**
@@ -88,14 +88,14 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
* </p> * </p>
*/ */
private void setupSortMenu() { private void setupSortMenu() {
JMenuItem name = new JMenuItem("Card Name"); final JMenuItem name = new JMenuItem("Card Name");
JMenuItem cost = new JMenuItem("Cost"); final JMenuItem cost = new JMenuItem("Cost");
JMenuItem color = new JMenuItem("Color"); final JMenuItem color = new JMenuItem("Color");
JMenuItem type = new JMenuItem("Type"); final JMenuItem type = new JMenuItem("Type");
JMenuItem stats = new JMenuItem("Power/Toughness"); final JMenuItem stats = new JMenuItem("Power/Toughness");
JMenuItem rarity = new JMenuItem("Rarity"); final JMenuItem rarity = new JMenuItem("Rarity");
JMenu menu = new JMenu("Sort By"); final JMenu menu = new JMenu("Sort By");
menu.add(name); menu.add(name);
menu.add(cost); menu.add(cost);
menu.add(color); menu.add(color);
@@ -106,8 +106,9 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
this.add(menu); this.add(menu);
name.addActionListener(new ActionListener() { name.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
((DeckEditorCommon) deckDisplay).getTopTableModel().sort(1, true); ((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(1, true);
} }
}); });
@@ -115,33 +116,40 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
// private String column[] = {"Qty", "Name", "Cost", "Color", "Type", // private String column[] = {"Qty", "Name", "Cost", "Color", "Type",
// "Stats", "Rarity"}; // "Stats", "Rarity"};
cost.addActionListener(new ActionListener() { cost.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
((DeckEditorCommon) deckDisplay).getTopTableModel().sort(4).sort(3).sort(2); ((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(4).sort(3).sort(2);
} }
}); });
color.addActionListener(new ActionListener() { color.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
((DeckEditorCommon) deckDisplay).getTopTableModel().sort(4).sort(2).sort(3); ((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(4).sort(2).sort(3);
} }
}); });
type.addActionListener(new ActionListener() { type.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
((DeckEditorCommon) deckDisplay).getTopTableModel().sort(2).sort(3).sort(4); ((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(2).sort(3).sort(4);
} }
}); });
stats.addActionListener(new ActionListener() { stats.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
((DeckEditorCommon) deckDisplay).getTopTableModel().sort(4).sort(2).sort(3).sort(5); ((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(4).sort(2).sort(3)
.sort(5);
} }
}); });
rarity.addActionListener(new ActionListener() { rarity.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
// sort by cost, type, color, rarity // sort by cost, type, color, rarity
((DeckEditorCommon) deckDisplay).getTopTableModel().sort(2).sort(4).sort(3).sort(6); ((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(2).sort(4).sort(3)
.sort(6);
} }
}); });
} // setupSortMenu() } // setupSortMenu()
@@ -153,27 +161,28 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
* a boolean * a boolean
*/ */
public void newConstructed(final boolean careAboutOldDeck) { public void newConstructed(final boolean careAboutOldDeck) {
if (careAboutOldDeck && !canLeaveCurrentDeck()) { if (careAboutOldDeck && !this.canLeaveCurrentDeck()) {
return; return;
} }
setDeckData("", true); this.setDeckData("", true);
deckDisplay.setDeck(null, null, GameType.Constructed); this.deckDisplay.setDeck(null, null, GameType.Constructed);
} }
private void newRandomConstructed() { private void newRandomConstructed() {
if (!canLeaveCurrentDeck()) { if (!this.canLeaveCurrentDeck()) {
return; return;
} }
setDeckData("", false); this.setDeckData("", false);
// The only remaining reference to global variable! // The only remaining reference to global variable!
CardList random = new CardList(forge.AllZone.getCardFactory().getRandomCombinationWithoutRepetition(15 * 5)); final CardList random = new CardList(forge.AllZone.getCardFactory().getRandomCombinationWithoutRepetition(
15 * 5));
ItemPool<CardPrinted> cpRandom = new ItemPool<CardPrinted>(CardPrinted.class); final ItemPool<CardPrinted> cpRandom = new ItemPool<CardPrinted>(CardPrinted.class);
for (Card c : random) { for (final Card c : random) {
cpRandom.add(CardDb.instance().getCard(c)); cpRandom.add(CardDb.instance().getCard(c));
} }
cpRandom.add(CardDb.instance().getCard("Forest")); cpRandom.add(CardDb.instance().getCard("Forest"));
@@ -183,62 +192,62 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
cpRandom.add(CardDb.instance().getCard("Mountain")); cpRandom.add(CardDb.instance().getCard("Mountain"));
cpRandom.add(CardDb.instance().getCard("Terramorphic Expanse")); cpRandom.add(CardDb.instance().getCard("Terramorphic Expanse"));
deckDisplay.setDeck(cpRandom, null, GameType.Constructed); this.deckDisplay.setDeck(cpRandom, null, GameType.Constructed);
} }
private void newGenerateConstructed() { private void newGenerateConstructed() {
if (!canLeaveCurrentDeck()) { if (!this.canLeaveCurrentDeck()) {
return; return;
} }
setDeckData("", false); this.setDeckData("", false);
GenerateConstructedDeck gen = new GenerateConstructedDeck(); final GenerateConstructedDeck gen = new GenerateConstructedDeck();
ItemPool<CardPrinted> generated = new ItemPool<CardPrinted>(CardPrinted.class); final ItemPool<CardPrinted> generated = new ItemPool<CardPrinted>(CardPrinted.class);
for (Card c : gen.generateDeck()) { for (final Card c : gen.generateDeck()) {
generated.add(CardDb.instance().getCard(c)); generated.add(CardDb.instance().getCard(c));
} }
deckDisplay.setDeck(null, generated, GameType.Constructed); this.deckDisplay.setDeck(null, generated, GameType.Constructed);
} }
private File getImportFilename() { private File getImportFilename() {
JFileChooser chooser = new JFileChooser(previousDirectory); final JFileChooser chooser = new JFileChooser(DeckEditorCommonMenu.previousDirectory);
chooser.addChoosableFileFilter(DeckManager.DCK_FILTER); chooser.addChoosableFileFilter(DeckManager.DCK_FILTER);
int returnVal = chooser.showOpenDialog(null); final int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile(); final File file = chooser.getSelectedFile();
previousDirectory = file.getParentFile(); DeckEditorCommonMenu.previousDirectory = file.getParentFile();
return file; return file;
} }
return null; return null;
} // openFileDialog() } // openFileDialog()
private void importDeck() { private void importDeck() {
File file = getImportFilename(); final File file = this.getImportFilename();
if (file == null) { if (file == null) {
} else if (file.getName().endsWith(".dck")) { } else if (file.getName().endsWith(".dck")) {
try { try {
FileChannel srcChannel = new FileInputStream(file).getChannel(); final FileChannel srcChannel = new FileInputStream(file).getChannel();
File dst = new File(ForgeProps.getFile(NEW_DECKS).getAbsolutePath(), file.getName()); final File dst = new File(ForgeProps.getFile(NewConstants.NEW_DECKS).getAbsolutePath(), file.getName());
if (!dst.createNewFile()) { if (!dst.createNewFile()) {
JOptionPane.showMessageDialog(null, "Cannot import deck " + file.getName() JOptionPane.showMessageDialog(null, "Cannot import deck " + file.getName()
+ ", a deck currently has that name."); + ", a deck currently has that name.");
return; return;
} }
FileChannel dstChannel = new FileOutputStream(dst).getChannel(); final FileChannel dstChannel = new FileOutputStream(dst).getChannel();
dstChannel.transferFrom(srcChannel, 0, srcChannel.size()); dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
srcChannel.close(); srcChannel.close();
dstChannel.close(); dstChannel.close();
Deck newDeck = DeckManager.readDeck(file); final Deck newDeck = DeckManager.readDeck(file);
deckManager.addDeck(newDeck); this.deckManager.addDeck(newDeck);
showDeck(newDeck, newDeck.getDeckType()); this.showDeck(newDeck, newDeck.getDeckType());
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error, " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error, " + ex);
} }
@@ -252,31 +261,31 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
* </p> * </p>
*/ */
private void exportDeck() { private void exportDeck() {
File filename = getExportFilename(); final File filename = this.getExportFilename();
if (filename == null) { if (filename == null) {
return; return;
} }
Deck deck = getDeck(); final Deck deck = this.getDeck();
try { try {
DeckManager.writeDeck(deck, filename); DeckManager.writeDeck(deck, filename);
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error, " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error, " + ex);
} }
} }
private File getExportFilename() { private File getExportFilename() {
JFileChooser save = new JFileChooser(previousDirectory); final JFileChooser save = new JFileChooser(DeckEditorCommonMenu.previousDirectory);
save.setDialogTitle("Export Deck Filename"); save.setDialogTitle("Export Deck Filename");
save.setDialogType(JFileChooser.SAVE_DIALOG); save.setDialogType(JFileChooser.SAVE_DIALOG);
save.setFileFilter(DeckManager.DCK_FILTER); save.setFileFilter(DeckManager.DCK_FILTER);
if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
File file = save.getSelectedFile(); final File file = save.getSelectedFile();
String check = file.getAbsolutePath(); final String check = file.getAbsolutePath();
previousDirectory = file.getParentFile(); DeckEditorCommonMenu.previousDirectory = file.getParentFile();
return check.endsWith(".dck") ? file : new File(check + ".dck"); return check.endsWith(".dck") ? file : new File(check + ".dck");
} }
@@ -289,31 +298,31 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
* </p> * </p>
*/ */
private void generateProxies() { private void generateProxies() {
File filename = getProxiesFilename(); final File filename = this.getProxiesFilename();
if (filename == null) { if (filename == null) {
return; return;
} }
Deck deck = getDeck(); final Deck deck = this.getDeck();
try { try {
DeckManager.writeDeckHtml(deck, filename); DeckManager.writeDeckHtml(deck, filename);
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : printProxies() error, " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : printProxies() error, " + ex);
} }
} }
private File getProxiesFilename() { private File getProxiesFilename() {
JFileChooser save = new JFileChooser(previousDirectory); final JFileChooser save = new JFileChooser(DeckEditorCommonMenu.previousDirectory);
save.setDialogTitle("Proxy HTML Filename"); save.setDialogTitle("Proxy HTML Filename");
save.setDialogType(JFileChooser.SAVE_DIALOG); save.setDialogType(JFileChooser.SAVE_DIALOG);
save.setFileFilter(DeckManager.HTML_FILTER); save.setFileFilter(DeckManager.HTML_FILTER);
if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
File file = save.getSelectedFile(); final File file = save.getSelectedFile();
String check = file.getAbsolutePath(); final String check = file.getAbsolutePath();
previousDirectory = file.getParentFile(); DeckEditorCommonMenu.previousDirectory = file.getParentFile();
return check.endsWith(".html") ? file : new File(check + ".html"); return check.endsWith(".html") ? file : new File(check + ".html");
} }
@@ -321,18 +330,19 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
} }
private void openDeck(final GameType gameType) { private void openDeck(final GameType gameType) {
if (!canLeaveCurrentDeck()) { if (!this.canLeaveCurrentDeck()) {
return; return;
} }
String name = getUserInputOpenDeck(gameType); final String name = this.getUserInputOpenDeck(gameType);
if (StringUtils.isBlank(name)) { if (StringUtils.isBlank(name)) {
return; return;
} }
Deck deck = gameType == GameType.Draft ? deckManager.getDraftDeck(name)[0] : deckManager.getDeck(name); final Deck deck = gameType == GameType.Draft ? this.deckManager.getDraftDeck(name)[0] : this.deckManager
showDeck(deck, gameType); .getDeck(name);
this.showDeck(deck, gameType);
} }
/** /**
@@ -345,83 +355,83 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
* a GameType * a GameType
*/ */
public void showDeck(final Deck deck, final GameType gameType) { public void showDeck(final Deck deck, final GameType gameType) {
setDeckData(deck.getName(), true); this.setDeckData(deck.getName(), true);
if (gameType.isLimited()) { if (gameType.isLimited()) {
deckDisplay.setDeck(deck.getSideboard(), deck.getMain(), gameType); this.deckDisplay.setDeck(deck.getSideboard(), deck.getMain(), gameType);
} else { } else {
deckDisplay.setDeck(null, deck.getMain(), gameType); this.deckDisplay.setDeck(null, deck.getMain(), gameType);
} }
} }
private void save() { private void save() {
if (currentDeckName.equals("")) { if (this.currentDeckName.equals("")) {
saveAs(); this.saveAs();
return; return;
} }
Deck deck = getDeck(); final Deck deck = this.getDeck();
if (deckDisplay.getGameType().equals(GameType.Draft)) { if (this.deckDisplay.getGameType().equals(GameType.Draft)) {
setDeckData(currentDeckName, true); this.setDeckData(this.currentDeckName, true);
// write booster deck // write booster deck
Deck[] all = deckManager.getDraftDeck(currentDeckName); final Deck[] all = this.deckManager.getDraftDeck(this.currentDeckName);
all[0] = deck; all[0] = deck;
deckManager.addDraftDeck(all); this.deckManager.addDraftDeck(all);
DeckManager.writeDraftDecks(all); DeckManager.writeDraftDecks(all);
} else { // constructed or sealed } else { // constructed or sealed
setDeckData(currentDeckName, true); this.setDeckData(this.currentDeckName, true);
deckManager.addDeck(deck); this.deckManager.addDeck(deck);
DeckManager.writeDeck(deck, DeckManager.makeFileName(deck)); DeckManager.writeDeck(deck, DeckManager.makeFileName(deck));
} }
isDeckSaved = true; this.isDeckSaved = true;
} }
private void saveAs() { private void saveAs() {
String name = getDeckNameFromDialog(); final String name = this.getDeckNameFromDialog();
if (name.equals("")) { if (name.equals("")) {
return; return;
} }
setDeckData(name, true); this.setDeckData(name, true);
Deck deck = getDeck(); final Deck deck = this.getDeck();
if (deckDisplay.getGameType().equals(GameType.Draft)) { if (this.deckDisplay.getGameType().equals(GameType.Draft)) {
// MUST copy array // MUST copy array
Deck[] read = deckManager.getDraftDeck(currentDeckName); final Deck[] read = this.deckManager.getDraftDeck(this.currentDeckName);
Deck[] all = new Deck[read.length]; final Deck[] all = new Deck[read.length];
System.arraycopy(read, 0, all, 0, read.length); System.arraycopy(read, 0, all, 0, read.length);
all[0] = deck; all[0] = deck;
deckManager.addDraftDeck(all); this.deckManager.addDraftDeck(all);
DeckManager.writeDraftDecks(all); DeckManager.writeDraftDecks(all);
} else { // constructed and sealed } else { // constructed and sealed
deckManager.addDeck(deck); this.deckManager.addDeck(deck);
DeckManager.writeDeck(deck, DeckManager.makeFileName(deck)); DeckManager.writeDeck(deck, DeckManager.makeFileName(deck));
} }
isDeckSaved = true; this.isDeckSaved = true;
} }
private void delete() { private void delete() {
if (StringUtils.isBlank(currentDeckName)) { if (StringUtils.isBlank(this.currentDeckName)) {
return; return;
} }
int n = JOptionPane.showConfirmDialog(null, "Do you want to delete this deck " + currentDeckName + " ?", final int n = JOptionPane.showConfirmDialog(null, "Do you want to delete this deck " + this.currentDeckName
"Delete", JOptionPane.YES_NO_OPTION); + " ?", "Delete", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.NO_OPTION) { if (n == JOptionPane.NO_OPTION) {
return; return;
} }
if (deckDisplay.getGameType().equals(GameType.Draft)) { if (this.deckDisplay.getGameType().equals(GameType.Draft)) {
deckManager.deleteDraftDeck(currentDeckName); this.deckManager.deleteDraftDeck(this.currentDeckName);
} else { } else {
deckManager.deleteDeck(currentDeckName); this.deckManager.deleteDeck(this.currentDeckName);
} }
setDeckData("", true); this.setDeckData("", true);
deckDisplay.setDeck(null, null, deckDisplay.getGameType()); this.deckDisplay.setDeck(null, null, this.deckDisplay.getGameType());
} }
/** /**
@@ -429,20 +439,20 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
* close window. * close window.
*/ */
public void close() { public void close() {
if (!canLeaveCurrentDeck()) { if (!this.canLeaveCurrentDeck()) {
return; return;
} }
exitCommand.execute(); this.exitCommand.execute();
} }
private boolean canLeaveCurrentDeck() { private boolean canLeaveCurrentDeck() {
if (isSaved()) { if (this.isSaved()) {
return true; return true;
} }
String message = String.format("Do you wish to save changes you made to your current deck '%s'?", final String message = String.format("Do you wish to save changes you made to your current deck '%s'?",
currentDeckName); this.currentDeckName);
int choice = JOptionPane final int choice = JOptionPane
.showConfirmDialog((Component) deckDisplay, message, "You have unsaved changes in your deck", .showConfirmDialog((Component) this.deckDisplay, message, "You have unsaved changes in your deck",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (JOptionPane.CANCEL_OPTION == choice) { if (JOptionPane.CANCEL_OPTION == choice) {
return false; return false;
@@ -451,23 +461,23 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
return true; return true;
} }
Deck deck = getDeck(); final Deck deck = this.getDeck();
deck.setName(currentDeckName); deck.setName(this.currentDeckName);
DeckManager.writeDeck(deck, DeckManager.makeFileName(deck)); DeckManager.writeDeck(deck, DeckManager.makeFileName(deck));
return true; return true;
} }
private Deck getDeck() { private Deck getDeck() {
Deck deck = deckDisplay.getDeck(); final Deck deck = this.deckDisplay.getDeck();
deck.setName(currentDeckName); deck.setName(this.currentDeckName);
return deck; return deck;
} }
private void setDeckData(final String deckName, final boolean inDeckSaved) { private void setDeckData(final String deckName, final boolean inDeckSaved) {
currentDeckName = deckName; this.currentDeckName = deckName;
isDeckSaved = inDeckSaved; this.isDeckSaved = inDeckSaved;
deckDisplay.setTitle("Deck Editor : " + currentDeckName); this.deckDisplay.setTitle("Deck Editor : " + this.currentDeckName);
} }
/** /**
@@ -477,7 +487,7 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
* @return a String * @return a String
*/ */
public String getDeckName() { public String getDeckName() {
return currentDeckName; return this.currentDeckName;
} }
/** /**
@@ -487,7 +497,7 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
* @return a boolean * @return a boolean
*/ */
public boolean isSaved() { public boolean isSaved() {
return isDeckSaved; return this.isDeckSaved;
} }
/** /**
@@ -498,33 +508,34 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private String getDeckNameFromDialog() { private String getDeckNameFromDialog() {
Object o = JOptionPane.showInputDialog(null, "Save As", "Deck Name", JOptionPane.OK_CANCEL_OPTION); final Object o = JOptionPane.showInputDialog(null, "Save As", "Deck Name", JOptionPane.OK_CANCEL_OPTION);
if (o == null) { if (o == null) {
return ""; return "";
} }
String deckName = DeckManager.cleanDeckName(o.toString()); final String deckName = DeckManager.cleanDeckName(o.toString());
boolean isDraft = deckDisplay.getGameType() == GameType.Draft; final boolean isDraft = this.deckDisplay.getGameType() == GameType.Draft;
boolean isUniqueName = isDraft ? deckManager.isUniqueDraft(deckName) : deckManager.isUnique(deckName); final boolean isUniqueName = isDraft ? this.deckManager.isUniqueDraft(deckName) : this.deckManager
boolean isGoodName = isUniqueName && StringUtils.isNotBlank(deckName); .isUnique(deckName);
final boolean isGoodName = isUniqueName && StringUtils.isNotBlank(deckName);
if (isGoodName) { if (isGoodName) {
return deckName; return deckName;
} }
JOptionPane.showMessageDialog(null, "Please pick another deck name, another deck currently has that name."); JOptionPane.showMessageDialog(null, "Please pick another deck name, another deck currently has that name.");
return getDeckNameFromDialog(); return this.getDeckNameFromDialog();
} }
private String getUserInputOpenDeck(final GameType deckType) { private String getUserInputOpenDeck(final GameType deckType) {
ArrayList<String> choices = deckManager.getDeckNames(deckType); final ArrayList<String> choices = this.deckManager.getDeckNames(deckType);
if (choices.isEmpty()) { if (choices.isEmpty()) {
JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE); JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE);
return null; return null;
} }
Object o = GuiUtils.getChoiceOptional("Open Deck", choices.toArray()); final Object o = GuiUtils.getChoiceOptional("Open Deck", choices.toArray());
return o == null ? null : o.toString(); return o == null ? null : o.toString();
} }
@@ -535,35 +546,35 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
* Notify of a Deck Change. * Notify of a Deck Change.
*/ */
public void notifyDeckChange() { public void notifyDeckChange() {
isDeckSaved = false; this.isDeckSaved = false;
} }
private void setupMenu() { private void setupMenu() {
JMenuItem newConstructed = new JMenuItem("New Deck - Constructed"); final JMenuItem newConstructed = new JMenuItem("New Deck - Constructed");
// JMenuItem newSealed = new JMenuItem("New Deck - Sealed"); // JMenuItem newSealed = new JMenuItem("New Deck - Sealed");
// JMenuItem newDraft = new JMenuItem("New Deck - Draft"); // JMenuItem newDraft = new JMenuItem("New Deck - Draft");
JMenuItem newRandomConstructed = new JMenuItem("New Deck - Generate Random Constructed Cardpool"); final JMenuItem newRandomConstructed = new JMenuItem("New Deck - Generate Random Constructed Cardpool");
JMenuItem newGenerateConstructed = new JMenuItem("New Deck - Generate Constructed Deck"); final JMenuItem newGenerateConstructed = new JMenuItem("New Deck - Generate Constructed Deck");
JMenuItem importDeck = new JMenuItem("Import Deck..."); final JMenuItem importDeck = new JMenuItem("Import Deck...");
JMenuItem exportDeck = new JMenuItem("Export Deck..."); final JMenuItem exportDeck = new JMenuItem("Export Deck...");
// JMenuItem downloadDeck = new JMenuItem("Download Deck"); // JMenuItem downloadDeck = new JMenuItem("Download Deck");
JMenuItem openConstructed = new JMenuItem("Open Deck - Constructed..."); final JMenuItem openConstructed = new JMenuItem("Open Deck - Constructed...");
JMenuItem openSealed = new JMenuItem("Open Deck - Sealed"); final JMenuItem openSealed = new JMenuItem("Open Deck - Sealed");
JMenuItem openDraft = new JMenuItem("Open Deck - Draft"); final JMenuItem openDraft = new JMenuItem("Open Deck - Draft");
// newDraftItem = newDraft; // newDraftItem = newDraft;
// newDraftItem.setEnabled(false); // newDraftItem.setEnabled(false);
JMenuItem save = new JMenuItem("Save"); final JMenuItem save = new JMenuItem("Save");
JMenuItem saveAs = new JMenuItem("Save As..."); final JMenuItem saveAs = new JMenuItem("Save As...");
JMenuItem delete = new JMenuItem("Delete"); final JMenuItem delete = new JMenuItem("Delete");
JMenuItem close = new JMenuItem("Close"); final JMenuItem close = new JMenuItem("Close");
JMenu fileMenu = new JMenu("Deck Actions"); final JMenu fileMenu = new JMenu("Deck Actions");
fileMenu.add(newConstructed); fileMenu.add(newConstructed);
// fileMenu.add(newSealed); // fileMenu.add(newSealed);
@@ -578,18 +589,20 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
fileMenu.add(importDeck); fileMenu.add(importDeck);
fileMenu.add(exportDeck); fileMenu.add(exportDeck);
JMenuItem generateProxies = new JMenuItem("Generate Proxies..."); final JMenuItem generateProxies = new JMenuItem("Generate Proxies...");
fileMenu.add(generateProxies); fileMenu.add(generateProxies);
generateProxies.addActionListener(new ActionListener() { generateProxies.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
generateProxies(); DeckEditorCommonMenu.this.generateProxies();
} }
}); });
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : generateProxies() error - " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : generateProxies() error - " + ex);
} }
@@ -613,14 +626,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
// add listeners // add listeners
exportDeck.addActionListener(new ActionListener() { exportDeck.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
exportDeck(); DeckEditorCommonMenu.this.exportDeck();
} }
}); });
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error - " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error - " + ex);
} }
@@ -628,14 +643,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
}); });
importDeck.addActionListener(new ActionListener() { importDeck.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
importDeck(); DeckEditorCommonMenu.this.importDeck();
} }
}); });
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error - " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error - " + ex);
} }
@@ -652,14 +669,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
* ex); } } }); * ex); } } });
*/ */
newConstructed.addActionListener(new ActionListener() { newConstructed.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
newConstructed(true); DeckEditorCommonMenu.this.newConstructed(true);
} }
}); });
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : newConstructed() error - " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : newConstructed() error - " + ex);
} }
@@ -667,14 +686,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
}); });
newRandomConstructed.addActionListener(new ActionListener() { newRandomConstructed.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
newRandomConstructed(); DeckEditorCommonMenu.this.newRandomConstructed();
} }
}); });
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : newRandomConstructed() error - " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : newRandomConstructed() error - " + ex);
} }
@@ -682,14 +703,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
}); });
newGenerateConstructed.addActionListener(new ActionListener() { newGenerateConstructed.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
newGenerateConstructed(); DeckEditorCommonMenu.this.newGenerateConstructed();
} }
}); });
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : newRandomConstructed() error - " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : newRandomConstructed() error - " + ex);
} }
@@ -697,14 +720,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
}); });
openConstructed.addActionListener(new ActionListener() { openConstructed.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
openDeck(GameType.Constructed); DeckEditorCommonMenu.this.openDeck(GameType.Constructed);
} }
}); });
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : openConstructed() error - " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : openConstructed() error - " + ex);
} }
@@ -712,14 +737,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
}); });
openSealed.addActionListener(new ActionListener() { openSealed.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
openDeck(GameType.Sealed); DeckEditorCommonMenu.this.openDeck(GameType.Sealed);
} }
}); });
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : openSealed() error - " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : openSealed() error - " + ex);
} }
@@ -727,14 +754,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
}); });
openDraft.addActionListener(new ActionListener() { openDraft.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
openDeck(GameType.Draft); DeckEditorCommonMenu.this.openDeck(GameType.Draft);
} }
}); });
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : openDraft() error - " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : openDraft() error - " + ex);
} }
@@ -742,14 +771,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
}); });
save.addActionListener(new ActionListener() { save.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
save(); DeckEditorCommonMenu.this.save();
} }
}); });
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : save() error - " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : save() error - " + ex);
} }
@@ -757,14 +788,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
}); });
saveAs.addActionListener(new ActionListener() { saveAs.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
saveAs(); DeckEditorCommonMenu.this.saveAs();
} }
}); });
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : saveAs() error - " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : saveAs() error - " + ex);
} }
@@ -772,14 +805,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
}); });
delete.addActionListener(new ActionListener() { delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
delete(); DeckEditorCommonMenu.this.delete();
} }
}); });
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : delete() error - " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : delete() error - " + ex);
} }
@@ -787,14 +822,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
}); });
close.addActionListener(new ActionListener() { close.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev) { public void actionPerformed(final ActionEvent ev) {
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
close(); DeckEditorCommonMenu.this.close();
} }
}); });
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : close() error - " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : close() error - " + ex);
} }

View File

@@ -17,6 +17,7 @@ import java.util.List;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.WindowConstants;
import net.slightlymagic.maxmtg.Predicate; import net.slightlymagic.maxmtg.Predicate;
import forge.AllZone; import forge.AllZone;
@@ -34,6 +35,7 @@ import forge.item.ItemPool;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.properties.NewConstants.LANG.Gui_BoosterDraft;
import forge.view.swing.Gui_HomeScreen; import forge.view.swing.Gui_HomeScreen;
import forge.view.swing.OldGuiNewGame; import forge.view.swing.OldGuiNewGame;
@@ -47,28 +49,28 @@ import forge.view.swing.OldGuiNewGame;
*/ */
public class DeckEditorDraft extends DeckEditorBase implements NewConstants, NewConstants.LANG.Gui_BoosterDraft { public class DeckEditorDraft extends DeckEditorBase implements NewConstants, NewConstants.LANG.Gui_BoosterDraft {
/** /**
* Constant <code>serialVersionUID=-6055633915602448260L</code> * Constant <code>serialVersionUID=-6055633915602448260L</code>.
*/ */
private static final long serialVersionUID = -6055633915602448260L; private static final long serialVersionUID = -6055633915602448260L;
private BoosterDraft boosterDraft; private BoosterDraft boosterDraft;
private JButton jButtonPick = new JButton(); private final JButton jButtonPick = new JButton();
private CardPanelLite cardView = new CardPanelLite(); private CardPanelLite cardView = new CardPanelLite();
private MouseListener pickWithMouse = new MouseAdapter() { private final MouseListener pickWithMouse = new MouseAdapter() {
@Override @Override
public void mouseClicked(final MouseEvent e) { public void mouseClicked(final MouseEvent e) {
// Pick on left-button double click // Pick on left-button double click
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0 && e.getClickCount() == 2) { if (((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) && (e.getClickCount() == 2)) {
jButtonPickClicked(null); DeckEditorDraft.this.jButtonPickClicked(null);
} else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { // pick } else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { // pick
// on // on
// right // right
// click // click
JTable table = top.getTable(); final JTable table = DeckEditorDraft.this.getTopTableWithCards().getTable();
int rowNumber = table.rowAtPoint(e.getPoint()); final int rowNumber = table.rowAtPoint(e.getPoint());
// after hittest - if it was outside of rows - discard this // after hittest - if it was outside of rows - discard this
// click // click
if (rowNumber == -1) { if (rowNumber == -1) {
@@ -79,7 +81,7 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
if (rowNumber != table.getSelectedRow()) { if (rowNumber != table.getSelectedRow()) {
table.getSelectionModel().setSelectionInterval(rowNumber, rowNumber); table.getSelectionModel().setSelectionInterval(rowNumber, rowNumber);
} else { } else {
jButtonPickClicked(null); DeckEditorDraft.this.jButtonPickClicked(null);
} }
} }
} }
@@ -88,20 +90,20 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
/** /**
* Show gui. * Show gui.
* *
* @param in_boosterDraft * @param inBoosterDraft
* the in_booster draft * the in_booster draft
*/ */
public final void showGui(final BoosterDraft in_boosterDraft) { public final void showGui(final BoosterDraft inBoosterDraft) {
boosterDraft = in_boosterDraft; this.boosterDraft = inBoosterDraft;
setup(); this.setup();
showChoices(boosterDraft.nextChoice()); this.showChoices(this.boosterDraft.nextChoice());
bottom.setDeck((Iterable<InventoryItem>) null); this.getBottomTableWithCards().setDeck((Iterable<InventoryItem>) null);
top.sort(1, true); this.getTopTableWithCards().sort(1, true);
bottom.sort(1, true); this.getBottomTableWithCards().sort(1, true);
setVisible(true); this.setVisible(true);
} }
/** /**
@@ -113,14 +115,14 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
this.addWindowListener(new WindowAdapter() { this.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing(final WindowEvent ev) { public void windowClosing(final WindowEvent ev) {
int n = JOptionPane.showConfirmDialog(null, ForgeProps.getLocalized(CLOSE_MESSAGE), "", final int n = JOptionPane.showConfirmDialog(null,
JOptionPane.YES_NO_OPTION); ForgeProps.getLocalized(Gui_BoosterDraft.CLOSE_MESSAGE), "", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) { if (n == JOptionPane.YES_OPTION) {
dispose(); DeckEditorDraft.this.dispose();
if (System.getenv("NG2") != null) { if (System.getenv("NG2") != null) {
if (System.getenv("NG2").equalsIgnoreCase("true")) { if (System.getenv("NG2").equalsIgnoreCase("true")) {
String[] argz = {}; final String[] argz = {};
Gui_HomeScreen.main(argz); Gui_HomeScreen.main(argz);
} else { } else {
new OldGuiNewGame(); new OldGuiNewGame();
@@ -130,9 +132,9 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
} }
} }
}// windowClosing() } // windowClosing()
}); });
}// addListeners() } // addListeners()
/** /**
* <p> * <p>
@@ -140,14 +142,16 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
* </p> * </p>
*/ */
private void setup() { private void setup() {
addListeners(); this.addListeners();
// setupMenu(); // setupMenu();
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>(); final List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE, PresetColumns.FN_QTY_GET)); columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE,
PresetColumns.FN_QTY_GET));
columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.FN_NAME_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.FN_NAME_COMPARE,
PresetColumns.FN_NAME_GET)); PresetColumns.FN_NAME_GET));
columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.FN_COST_COMPARE, PresetColumns.FN_COST_GET)); columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.FN_COST_COMPARE,
PresetColumns.FN_COST_GET));
columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.FN_COLOR_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.FN_COLOR_COMPARE,
PresetColumns.FN_COLOR_GET)); PresetColumns.FN_COLOR_GET));
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE,
@@ -156,24 +160,25 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
PresetColumns.FN_STATS_GET)); PresetColumns.FN_STATS_GET));
columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.FN_RARITY_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.FN_RARITY_COMPARE,
PresetColumns.FN_RARITY_GET)); PresetColumns.FN_RARITY_GET));
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE, PresetColumns.FN_SET_GET)); columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE,
PresetColumns.FN_SET_GET));
columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.FN_AI_STATUS_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.FN_AI_STATUS_COMPARE,
PresetColumns.FN_AI_STATUS_GET)); PresetColumns.FN_AI_STATUS_GET));
columns.get(2).setCellRenderer(new ManaCostRenderer()); columns.get(2).setCellRenderer(new ManaCostRenderer());
top.setup(columns, cardView); this.getTopTableWithCards().setup(columns, this.cardView);
bottom.setup(columns, cardView); this.getBottomTableWithCards().setup(columns, this.cardView);
this.setSize(980, 740); this.setSize(980, 740);
GuiUtils.centerFrame(this); GuiUtils.centerFrame(this);
this.setResizable(false); this.setResizable(false);
top.getTable().addMouseListener(pickWithMouse); this.getTopTableWithCards().getTable().addMouseListener(this.pickWithMouse);
top.getTable().addKeyListener(new KeyAdapter() { this.getTopTableWithCards().getTable().addKeyListener(new KeyAdapter() {
@Override @Override
public void keyPressed(final KeyEvent e) { public void keyPressed(final KeyEvent e) {
if (e.getKeyChar() == ' ') { if (e.getKeyChar() == ' ') {
jButtonPickClicked(null); DeckEditorDraft.this.jButtonPickClicked(null);
} }
} }
}); });
@@ -186,12 +191,12 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
public DeckEditorDraft() { public DeckEditorDraft() {
super(GameType.Draft); super(GameType.Draft);
try { try {
top = new TableWithCards("Choose one card", false); this.setTopTableWithCards(new TableWithCards("Choose one card", false));
bottom = new TableWithCards("Previously picked cards", true); this.setBottomTableWithCards(new TableWithCards("Previously picked cards", true));
filterBoxes = null; this.setFilterBoxes(null);
cardView = new CardPanelLite(); this.cardView = new CardPanelLite();
jbInit(); this.jbInit();
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
} }
} }
@@ -207,29 +212,30 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
private void jbInit() throws Exception { private void jbInit() throws Exception {
this.getContentPane().setLayout(null); this.getContentPane().setLayout(null);
top.getTableDecorated().setBounds(new Rectangle(19, 28, 680, 344)); this.getTopTableWithCards().getTableDecorated().setBounds(new Rectangle(19, 28, 680, 344));
bottom.getTableDecorated().setBounds(new Rectangle(19, 478, 680, 184)); this.getBottomTableWithCards().getTableDecorated().setBounds(new Rectangle(19, 478, 680, 184));
bottom.getLabel().setBounds(new Rectangle(19, 680, 665, 31)); this.getBottomTableWithCards().getLabel().setBounds(new Rectangle(19, 680, 665, 31));
cardView.setBounds(new Rectangle(715, 23, 240, 666)); this.cardView.setBounds(new Rectangle(715, 23, 240, 666));
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
this.setTitle("Booster Draft"); this.setTitle("Booster Draft");
jButtonPick.setBounds(new Rectangle(238, 418, 147, 44)); this.jButtonPick.setBounds(new Rectangle(238, 418, 147, 44));
jButtonPick.setFont(new java.awt.Font("Dialog", 0, 16)); this.jButtonPick.setFont(new java.awt.Font("Dialog", 0, 16));
jButtonPick.setText("Choose Card"); this.jButtonPick.setText("Choose Card");
jButtonPick.addActionListener(new ActionListener() { this.jButtonPick.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
jButtonPickClicked(e); DeckEditorDraft.this.jButtonPickClicked(e);
} }
}); });
this.getContentPane().add(cardView, null); this.getContentPane().add(this.cardView, null);
this.getContentPane().add(top.getTableDecorated(), null); this.getContentPane().add(this.getTopTableWithCards().getTableDecorated(), null);
this.getContentPane().add(bottom.getLabel(), null); this.getContentPane().add(this.getBottomTableWithCards().getLabel(), null);
this.getContentPane().add(bottom.getTableDecorated(), null); this.getContentPane().add(this.getBottomTableWithCards().getTableDecorated(), null);
this.getContentPane().add(jButtonPick, null); this.getContentPane().add(this.jButtonPick, null);
} }
/** /**
@@ -241,27 +247,27 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
* a {@link java.awt.event.ActionEvent} object. * a {@link java.awt.event.ActionEvent} object.
*/ */
final void jButtonPickClicked(final ActionEvent e) { final void jButtonPickClicked(final ActionEvent e) {
InventoryItem item = top.getSelectedCard(); final InventoryItem item = this.getTopTableWithCards().getSelectedCard();
if (item == null || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
CardPrinted card = (CardPrinted) item; final CardPrinted card = (CardPrinted) item;
bottom.addCard(card); this.getBottomTableWithCards().addCard(card);
// get next booster pack // get next booster pack
boosterDraft.setChoice(card); this.boosterDraft.setChoice(card);
if (boosterDraft.hasNextChoice()) { if (this.boosterDraft.hasNextChoice()) {
showChoices(boosterDraft.nextChoice()); this.showChoices(this.boosterDraft.nextChoice());
} else { } else {
boosterDraft.finishedDrafting(); this.boosterDraft.finishedDrafting();
// quit // quit
saveDraft(); this.saveDraft();
dispose(); this.dispose();
} }
}/* OK Button */ } /* OK Button */
/** /**
* <p> * <p>
@@ -272,10 +278,10 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
* a {@link forge.CardList} object. * a {@link forge.CardList} object.
*/ */
private void showChoices(final ItemPoolView<CardPrinted> list) { private void showChoices(final ItemPoolView<CardPrinted> list) {
top.setDeck(list); this.getTopTableWithCards().setDeck(list);
cardView.showCard(null); this.cardView.showCard(null);
top.fixSelection(0); this.getTopTableWithCards().fixSelection(0);
}// showChoices() } // showChoices()
/** /**
* <p> * <p>
@@ -285,23 +291,23 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
* @return a {@link forge.deck.Deck} object. * @return a {@link forge.deck.Deck} object.
*/ */
private Deck getPlayersDeck() { private Deck getPlayersDeck() {
Deck deck = new Deck(GameType.Draft); final Deck deck = new Deck(GameType.Draft);
Constant.Runtime.HUMAN_DECK[0] = deck; Constant.Runtime.HUMAN_DECK[0] = deck;
// add sideboard to deck // add sideboard to deck
ItemPoolView<CardPrinted> list = ItemPool.createFrom(bottom.getCards(), CardPrinted.class); final ItemPoolView<CardPrinted> list = ItemPool.createFrom(this.getBottomTableWithCards().getCards(), CardPrinted.class);
deck.addSideboard(list); deck.addSideboard(list);
String landSet = BoosterDraft.LAND_SET_CODE[0]; final String landSet = BoosterDraft.LAND_SET_CODE[0];
final int LANDS_COUNT = 20; final int landsCount = 20;
deck.addSideboard(CardDb.instance().getCard("Forest", landSet), LANDS_COUNT); deck.addSideboard(CardDb.instance().getCard("Forest", landSet), landsCount);
deck.addSideboard(CardDb.instance().getCard("Mountain", landSet), LANDS_COUNT); deck.addSideboard(CardDb.instance().getCard("Mountain", landSet), landsCount);
deck.addSideboard(CardDb.instance().getCard("Swamp", landSet), LANDS_COUNT); deck.addSideboard(CardDb.instance().getCard("Swamp", landSet), landsCount);
deck.addSideboard(CardDb.instance().getCard("Island", landSet), LANDS_COUNT); deck.addSideboard(CardDb.instance().getCard("Island", landSet), landsCount);
deck.addSideboard(CardDb.instance().getCard("Plains", landSet), LANDS_COUNT); deck.addSideboard(CardDb.instance().getCard("Plains", landSet), landsCount);
return deck; return deck;
}// getPlayersDeck() } // getPlayersDeck()
/** /**
* <p> * <p>
@@ -310,21 +316,22 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
*/ */
private void saveDraft() { private void saveDraft() {
String s = ""; String s = "";
while (s == null || s.length() == 0) { while ((s == null) || (s.length() == 0)) {
s = JOptionPane.showInputDialog(null, ForgeProps.getLocalized(SAVE_DRAFT_MESSAGE), s = JOptionPane.showInputDialog(null, ForgeProps.getLocalized(Gui_BoosterDraft.SAVE_DRAFT_MESSAGE),
ForgeProps.getLocalized(SAVE_DRAFT_TITLE), JOptionPane.QUESTION_MESSAGE); ForgeProps.getLocalized(Gui_BoosterDraft.SAVE_DRAFT_TITLE), JOptionPane.QUESTION_MESSAGE);
} }
// TODO: check if overwriting the same name, and let the user delete old // TODO: check if overwriting the same name, and let the user delete old
// drafts // drafts
// construct computer's decks // construct computer's decks
// save draft // save draft
Deck[] computer = boosterDraft.getDecks(); final Deck[] computer = this.boosterDraft.getDecks();
Deck human = getPlayersDeck(); final Deck human = this.getPlayersDeck();
human.setName(s); human.setName(s);
Deck[] all = { human, computer[0], computer[1], computer[2], computer[3], computer[4], computer[5], computer[6] }; final 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)); all[i].setName(String.format("Draft %s - Computer %d", s, i));
@@ -332,18 +339,18 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
// DeckManager deckManager = new // DeckManager deckManager = new
// DeckManager(ForgeProps.getFile(NEW_DECKS)); // DeckManager(ForgeProps.getFile(NEW_DECKS));
DeckManager deckManager = AllZone.getDeckManager(); final DeckManager deckManager = AllZone.getDeckManager();
deckManager.addDraftDeck(all); deckManager.addDraftDeck(all);
// write file // write file
DeckManager.writeDraftDecks(all); DeckManager.writeDraftDecks(all);
// close and open next screen // close and open next screen
dispose(); this.dispose();
if (System.getenv("NG2") != null) { if (System.getenv("NG2") != null) {
if (System.getenv("NG2").equalsIgnoreCase("true")) { if (System.getenv("NG2").equalsIgnoreCase("true")) {
String[] argz = {}; final String[] argz = {};
Gui_HomeScreen.main(argz); Gui_HomeScreen.main(argz);
} else { } else {
new OldGuiNewGame(); new OldGuiNewGame();
@@ -352,7 +359,7 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
new OldGuiNewGame(); new OldGuiNewGame();
} }
}/* saveDraft() */ } /* saveDraft() */
/* /*
* (non-Javadoc) * (non-Javadoc)

View File

@@ -40,23 +40,23 @@ import forge.quest.data.QuestData;
* @version $Id$ * @version $Id$
*/ */
public final class DeckEditorQuest extends DeckEditorBase implements NewConstants { public final class DeckEditorQuest extends DeckEditorBase implements NewConstants {
/** Constant <code>serialVersionUID=152061168634545L</code> */ /** Constant <code>serialVersionUID=152061168634545L</code>. */
private static final long serialVersionUID = 152061168634545L; private static final long serialVersionUID = 152061168634545L;
/** The custom menu. */ /** The custom menu. */
DeckEditorQuestMenu customMenu; private DeckEditorQuestMenu customMenu;
// private ImageIcon upIcon = Constant.IO.upIcon; // private ImageIcon upIcon = Constant.IO.upIcon;
// private ImageIcon downIcon = Constant.IO.downIcon; // private ImageIcon downIcon = Constant.IO.downIcon;
// private JLabel labelSortHint = new JLabel(); // private JLabel labelSortHint = new JLabel();
private JButton addButton = new JButton(); private final JButton addButton = new JButton();
private JButton removeButton = new JButton(); private final JButton removeButton = new JButton();
private JButton analysisButton = new JButton(); private final JButton analysisButton = new JButton();
private FilterNameTypeSetPanel filterNameTypeSet; private FilterNameTypeSetPanel filterNameTypeSet;
private QuestData questData; private final QuestData questData;
/** /**
* Show. * Show.
@@ -68,6 +68,7 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
final Command exit = new Command() { final Command exit = new Command() {
private static final long serialVersionUID = -7428793574300520612L; private static final long serialVersionUID = -7428793574300520612L;
@Override
public void execute() { public void execute() {
DeckEditorQuest.this.dispose(); DeckEditorQuest.this.dispose();
exitCommand.execute(); exitCommand.execute();
@@ -78,44 +79,44 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
this.addWindowListener(new WindowAdapter() { this.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing(final WindowEvent ev) { public void windowClosing(final WindowEvent ev) {
customMenu.close(); DeckEditorQuest.this.customMenu.close();
} }
}); });
setup(); this.setup();
customMenu = new DeckEditorQuestMenu(questData, this, exit); this.customMenu = new DeckEditorQuestMenu(this.questData, this, exit);
this.setJMenuBar(customMenu); this.setJMenuBar(this.customMenu);
Deck deck = null; Deck deck = null;
// open deck that the player used if QuestData has it // open deck that the player used if QuestData has it
if (Constant.Runtime.HUMAN_DECK[0] != null if ((Constant.Runtime.HUMAN_DECK[0] != null)
&& questData.getDeckNames().contains(Constant.Runtime.HUMAN_DECK[0].getName())) { && this.questData.getDeckNames().contains(Constant.Runtime.HUMAN_DECK[0].getName())) {
deck = questData.getDeck(Constant.Runtime.HUMAN_DECK[0].getName()); deck = this.questData.getDeck(Constant.Runtime.HUMAN_DECK[0].getName());
} else { } else {
deck = new Deck(GameType.Sealed); deck = new Deck(GameType.Sealed);
deck.setName(""); deck.setName("");
} }
// tell Gui_Quest_DeckEditor the name of the deck // tell Gui_Quest_DeckEditor the name of the deck
customMenu.setPlayerDeckName(deck.getName()); this.customMenu.setPlayerDeckName(deck.getName());
ItemPoolView<CardPrinted> bottomPool = deck.getMain(); final ItemPoolView<CardPrinted> bottomPool = deck.getMain();
ItemPool<CardPrinted> cardpool = new ItemPool<CardPrinted>(CardPrinted.class); final ItemPool<CardPrinted> cardpool = new ItemPool<CardPrinted>(CardPrinted.class);
cardpool.addAll(questData.getCards().getCardpool()); cardpool.addAll(this.questData.getCards().getCardpool());
// remove bottom cards that are in the deck from the card pool // remove bottom cards that are in the deck from the card pool
cardpool.removeAll(bottomPool); cardpool.removeAll(bottomPool);
// show cards, makes this user friendly // show cards, makes this user friendly
setDeck(cardpool, bottomPool, GameType.Quest); this.setDeck(cardpool, bottomPool, GameType.Quest);
// this affects the card pool // this affects the card pool
top.sort(4, true); // sort by type this.getTopTableWithCards().sort(4, true); // sort by type
top.sort(3, true); // then sort by color this.getTopTableWithCards().sort(3, true); // then sort by color
bottom.sort(1, true); this.getBottomTableWithCards().sort(1, true);
} // show(Command) } // show(Command)
/** /**
@@ -126,11 +127,13 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
public void setup() { public void setup() {
this.setLayout(null); this.setLayout(null);
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>(); final List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE, PresetColumns.FN_QTY_GET)); columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE,
PresetColumns.FN_QTY_GET));
columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.FN_NAME_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.FN_NAME_COMPARE,
PresetColumns.FN_NAME_GET)); PresetColumns.FN_NAME_GET));
columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.FN_COST_COMPARE, PresetColumns.FN_COST_GET)); columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.FN_COST_COMPARE,
PresetColumns.FN_COST_GET));
columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.FN_COLOR_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.FN_COLOR_COMPARE,
PresetColumns.FN_COLOR_GET)); PresetColumns.FN_COLOR_GET));
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE,
@@ -139,16 +142,17 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
PresetColumns.FN_STATS_GET)); PresetColumns.FN_STATS_GET));
columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.FN_RARITY_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.FN_RARITY_COMPARE,
PresetColumns.FN_RARITY_GET)); PresetColumns.FN_RARITY_GET));
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE, PresetColumns.FN_SET_GET)); columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE,
columns.add(new TableColumnInfo<InventoryItem>("New", 30, questData.getCards().fnNewCompare, questData PresetColumns.FN_SET_GET));
.getCards().fnNewGet)); columns.add(new TableColumnInfo<InventoryItem>("New", 30, this.questData.getCards().fnNewCompare,
this.questData.getCards().fnNewGet));
columns.get(2).setCellRenderer(new ManaCostRenderer()); columns.get(2).setCellRenderer(new ManaCostRenderer());
top.setup(columns, cardView); this.getTopTableWithCards().setup(columns, this.getCardView());
bottom.setup(columns, cardView); this.getBottomTableWithCards().setup(columns, this.getCardView());
filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), itemListenerUpdatesDisplay); this.filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), this.getItemListenerUpdatesDisplay());
this.setSize(1024, 768); this.setSize(1024, 768);
GuiUtils.centerFrame(this); GuiUtils.centerFrame(this);
@@ -168,15 +172,15 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
*/ */
public DeckEditorQuest(final QuestData questData2) { public DeckEditorQuest(final QuestData questData2) {
super(GameType.Quest); super(GameType.Quest);
questData = questData2; this.questData = questData2;
try { try {
filterBoxes = new FilterCheckBoxes(false); this.setFilterBoxes(new FilterCheckBoxes(false));
top = new TableWithCards("All Cards", true); this.setTopTableWithCards(new TableWithCards("All Cards", true));
bottom = new TableWithCards("Your deck", true); this.setBottomTableWithCards(new TableWithCards("Your deck", true));
cardView = new CardPanelHeavy(); this.setCardView(new CardPanelHeavy());
filterNameTypeSet = new FilterNameTypeSetPanel(); this.filterNameTypeSet = new FilterNameTypeSetPanel();
jbInit(); this.jbInit();
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
} }
} }
@@ -187,113 +191,116 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
// labelSortHint.setText("Click on the column name (like name or color) to sort the cards"); // labelSortHint.setText("Click on the column name (like name or color) to sort the cards");
// labelSortHint.setBounds(new Rectangle(20, 27, 400, 19)); // labelSortHint.setBounds(new Rectangle(20, 27, 400, 19));
filterNameTypeSet.setBounds(new Rectangle(19, 10, 726, 25)); this.filterNameTypeSet.setBounds(new Rectangle(19, 10, 726, 25));
top.getTableDecorated().setBounds(new Rectangle(19, 40, 726, 316)); this.getTopTableWithCards().getTableDecorated().setBounds(new Rectangle(19, 40, 726, 316));
bottom.getTableDecorated().setBounds(new Rectangle(19, 458, 726, 218)); this.getBottomTableWithCards().getTableDecorated().setBounds(new Rectangle(19, 458, 726, 218));
removeButton.setBounds(new Rectangle(180, 403, 146, 49)); this.removeButton.setBounds(new Rectangle(180, 403, 146, 49));
// removeButton.setIcon(upIcon); // removeButton.setIcon(upIcon);
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
removeButton.setFont(new java.awt.Font("Dialog", 0, 13)); this.removeButton.setFont(new java.awt.Font("Dialog", 0, 13));
} }
removeButton.setText("Remove Card"); this.removeButton.setText("Remove Card");
removeButton.addActionListener(new ActionListener() { this.removeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
removeButtonActionPerformed(e); DeckEditorQuest.this.removeButtonActionPerformed(e);
} }
}); });
addButton.setText("Add Card"); this.addButton.setText("Add Card");
addButton.addActionListener(new ActionListener() { this.addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
addButtonActionPerformed(e); DeckEditorQuest.this.addButtonActionPerformed(e);
} }
}); });
// addButton.setIcon(downIcon); // addButton.setIcon(downIcon);
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
addButton.setFont(new java.awt.Font("Dialog", 0, 13)); this.addButton.setFont(new java.awt.Font("Dialog", 0, 13));
} }
addButton.setBounds(new Rectangle(23, 403, 146, 49)); this.addButton.setBounds(new Rectangle(23, 403, 146, 49));
analysisButton.setText("Deck Analysis"); this.analysisButton.setText("Deck Analysis");
analysisButton.addActionListener(new ActionListener() { this.analysisButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
analysisButton_actionPerformed(e); DeckEditorQuest.this.analysisButtonActionPerformed(e);
} }
}); });
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
analysisButton.setFont(new java.awt.Font("Dialog", 0, 13)); this.analysisButton.setFont(new java.awt.Font("Dialog", 0, 13));
} }
analysisButton.setBounds(new Rectangle(578, 426, 166, 25)); this.analysisButton.setBounds(new Rectangle(578, 426, 166, 25));
/** /**
* Type filtering * Type filtering
*/ */
filterBoxes.land.setBounds(340, 400, 48, 20); this.getFilterBoxes().getLand().setBounds(340, 400, 48, 20);
filterBoxes.creature.setBounds(385, 400, 65, 20); this.getFilterBoxes().getCreature().setBounds(385, 400, 65, 20);
filterBoxes.sorcery.setBounds(447, 400, 62, 20); this.getFilterBoxes().getSorcery().setBounds(447, 400, 62, 20);
filterBoxes.instant.setBounds(505, 400, 60, 20); this.getFilterBoxes().getInstant().setBounds(505, 400, 60, 20);
filterBoxes.planeswalker.setBounds(558, 400, 85, 20); this.getFilterBoxes().getPlaneswalker().setBounds(558, 400, 85, 20);
filterBoxes.artifact.setBounds(638, 400, 58, 20); this.getFilterBoxes().getArtifact().setBounds(638, 400, 58, 20);
filterBoxes.enchantment.setBounds(692, 400, 80, 20); this.getFilterBoxes().getEnchantment().setBounds(692, 400, 80, 20);
Font f = new Font("Tahoma", Font.PLAIN, 10); final Font f = new Font("Tahoma", Font.PLAIN, 10);
for (JCheckBox box : filterBoxes.allTypes) { for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
box.setFont(f); box.setFont(f);
} }
box.setOpaque(false); box.setOpaque(false);
box.addItemListener(itemListenerUpdatesDisplay); box.addItemListener(this.getItemListenerUpdatesDisplay());
} }
/** /**
* Color filtering * Color filtering
*/ */
filterBoxes.white.setBounds(340, 430, 40, 20); this.getFilterBoxes().getWhite().setBounds(340, 430, 40, 20);
filterBoxes.blue.setBounds(380, 430, 40, 20); this.getFilterBoxes().getBlue().setBounds(380, 430, 40, 20);
filterBoxes.black.setBounds(420, 430, 40, 20); this.getFilterBoxes().getBlack().setBounds(420, 430, 40, 20);
filterBoxes.red.setBounds(460, 430, 40, 20); this.getFilterBoxes().getRed().setBounds(460, 430, 40, 20);
filterBoxes.green.setBounds(500, 430, 40, 20); this.getFilterBoxes().getGreen().setBounds(500, 430, 40, 20);
filterBoxes.colorless.setBounds(540, 430, 40, 20); this.getFilterBoxes().getColorless().setBounds(540, 430, 40, 20);
for (JCheckBox box : filterBoxes.allColors) { for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
box.setOpaque(false); box.setOpaque(false);
box.addItemListener(itemListenerUpdatesDisplay); box.addItemListener(this.getItemListenerUpdatesDisplay());
} }
/** /**
* Other * Other
*/ */
cardView.setBounds(new Rectangle(765, 23, 239, 687)); this.getCardView().setBounds(new Rectangle(765, 23, 239, 687));
top.getLabel().setBounds(new Rectangle(19, 365, 720, 31)); this.getTopTableWithCards().getLabel().setBounds(new Rectangle(19, 365, 720, 31));
bottom.getLabel().setBounds(new Rectangle(19, 672, 720, 31)); this.getBottomTableWithCards().getLabel().setBounds(new Rectangle(19, 672, 720, 31));
// Do not lower statsLabel any lower, we want this to be visible at 1024 // Do not lower statsLabel any lower, we want this to be visible at 1024
// x 768 screen size // x 768 screen size
this.setTitle("Deck Editor"); this.setTitle("Deck Editor");
this.getContentPane().add(filterNameTypeSet, null); this.getContentPane().add(this.filterNameTypeSet, null);
this.getContentPane().add(top.getTableDecorated(), null); this.getContentPane().add(this.getTopTableWithCards().getTableDecorated(), null);
this.getContentPane().add(bottom.getTableDecorated(), null); this.getContentPane().add(this.getBottomTableWithCards().getTableDecorated(), null);
this.getContentPane().add(addButton, null); this.getContentPane().add(this.addButton, null);
this.getContentPane().add(removeButton, null); this.getContentPane().add(this.removeButton, null);
this.getContentPane().add(analysisButton, null); this.getContentPane().add(this.analysisButton, null);
this.getContentPane().add(bottom.getLabel(), null); this.getContentPane().add(this.getBottomTableWithCards().getLabel(), null);
this.getContentPane().add(top.getLabel(), null); this.getContentPane().add(this.getTopTableWithCards().getLabel(), null);
// this.getContentPane().add(labelSortHint, null); // this.getContentPane().add(labelSortHint, null);
this.getContentPane().add(cardView, null); this.getContentPane().add(this.getCardView(), null);
for (JCheckBox box : filterBoxes.allTypes) { for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
this.getContentPane().add(box, null); this.getContentPane().add(box, null);
} }
for (JCheckBox box : filterBoxes.allColors) { for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
this.getContentPane().add(box, null); this.getContentPane().add(box, null);
} }
top.getTable().addKeyListener(new KeyAdapter() { this.getTopTableWithCards().getTable().addKeyListener(new KeyAdapter() {
@Override @Override
public void keyPressed(final KeyEvent e) { public void keyPressed(final KeyEvent e) {
if (e.getKeyChar() == ' ') { if (e.getKeyChar() == ' ') {
addButtonActionPerformed(null); DeckEditorQuest.this.addButtonActionPerformed(null);
} }
} }
}); });
@@ -306,36 +313,37 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
*/ */
@Override @Override
protected Predicate<InventoryItem> buildFilter() { protected Predicate<InventoryItem> buildFilter() {
Predicate<CardPrinted> cardFilter = Predicate.and(filterBoxes.buildFilter(), filterNameTypeSet.buildFilter()); final Predicate<CardPrinted> cardFilter = Predicate.and(this.getFilterBoxes().buildFilter(),
this.filterNameTypeSet.buildFilter());
return Predicate.instanceOf(cardFilter, CardPrinted.class); return Predicate.instanceOf(cardFilter, CardPrinted.class);
} }
private void addButtonActionPerformed(final ActionEvent e) { private void addButtonActionPerformed(final ActionEvent e) {
InventoryItem item = top.getSelectedCard(); final InventoryItem item = this.getTopTableWithCards().getSelectedCard();
if (item == null || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
CardPrinted card = (CardPrinted) item; final CardPrinted card = (CardPrinted) item;
setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved"); this.setTitle("Deck Editor : " + this.customMenu.getDeckName() + " : unsaved");
top.removeCard(card); this.getTopTableWithCards().removeCard(card);
bottom.addCard(card); this.getBottomTableWithCards().addCard(card);
} }
private void removeButtonActionPerformed(final ActionEvent e) { private void removeButtonActionPerformed(final ActionEvent e) {
InventoryItem item = bottom.getSelectedCard(); final InventoryItem item = this.getBottomTableWithCards().getSelectedCard();
if (item == null || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
CardPrinted card = (CardPrinted) item; final CardPrinted card = (CardPrinted) item;
setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved"); this.setTitle("Deck Editor : " + this.customMenu.getDeckName() + " : unsaved");
top.addCard(card); this.getTopTableWithCards().addCard(card);
bottom.removeCard(card); this.getBottomTableWithCards().removeCard(card);
} }
/** /**
@@ -345,8 +353,8 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
* the card * the card
*/ */
public void addCheatCard(final CardPrinted card) { public void addCheatCard(final CardPrinted card) {
top.addCard(card); this.getTopTableWithCards().addCard(card);
questData.getCards().getCardpool().add(card); this.questData.getCards().getCardpool().add(card);
} }
} }

View File

@@ -51,18 +51,18 @@ public class DeckEditorQuestMenu extends JMenuBar {
private static final long serialVersionUID = -4052319220021158574L; private static final long serialVersionUID = -4052319220021158574L;
/** Constant <code>deckEditorName="Deck Editor"</code>. */ /** Constant <code>deckEditorName="Deck Editor"</code>. */
private static final String deckEditorName = "Deck Editor"; private static final String DECK_EDITOR_NAME = "Deck Editor";
// used for import and export, try to made the gui user friendly // used for import and export, try to made the gui user friendly
/** Constant <code>previousDirectory</code>. */ /** Constant <code>previousDirectory</code>. */
private static File previousDirectory = null; private static File previousDirectory = null;
private Command exitCommand; private final Command exitCommand;
private forge.quest.data.QuestData questData; private final forge.quest.data.QuestData questData;
private Deck currentDeck; private Deck currentDeck;
// the class DeckDisplay is in the file "Gui_DeckEditor_Menu.java" // the class DeckDisplay is in the file "Gui_DeckEditor_Menu.java"
private DeckDisplay deckDisplay; private final DeckDisplay deckDisplay;
/** /**
* <p> * <p>
@@ -78,14 +78,14 @@ public class DeckEditorQuestMenu extends JMenuBar {
*/ */
public DeckEditorQuestMenu(final QuestData q, final DeckDisplay d, final Command exit) { public DeckEditorQuestMenu(final QuestData q, final DeckDisplay d, final Command exit) {
deckDisplay = d; this.deckDisplay = d;
questData = q; this.questData = q;
d.setTitle(deckEditorName); d.setTitle(DeckEditorQuestMenu.DECK_EDITOR_NAME);
exitCommand = exit; this.exitCommand = exit;
setupMenu(); this.setupMenu();
} }
/** /**
@@ -99,18 +99,20 @@ public class DeckEditorQuestMenu extends JMenuBar {
* a boolean. * a boolean.
*/ */
private void addImportExport(final JMenu menu, final boolean isHumanMenu) { private void addImportExport(final JMenu menu, final boolean isHumanMenu) {
JMenuItem import2 = new JMenuItem("Import"); final JMenuItem import2 = new JMenuItem("Import");
JMenuItem export = new JMenuItem("Export"); final JMenuItem export = new JMenuItem("Export");
import2.addActionListener(new ActionListener() { import2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
importDeck(); // importDeck(isHumanMenu); DeckEditorQuestMenu.this.importDeck(); // importDeck(isHumanMenu);
} }
}); // import }); // import
export.addActionListener(new ActionListener() { export.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
exportDeck(); DeckEditorQuestMenu.this.exportDeck();
} }
}); // export }); // export
@@ -125,7 +127,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
* </p> * </p>
*/ */
private void exportDeck() { private void exportDeck() {
File filename = getExportFilename(); final File filename = this.getExportFilename();
if (filename == null) { if (filename == null) {
return; return;
@@ -133,21 +135,21 @@ public class DeckEditorQuestMenu extends JMenuBar {
// write is an Object variable because you might just // write is an Object variable because you might just
// write one Deck object // write one Deck object
Deck deck = cardPoolToDeck(deckDisplay.getBottom()); final Deck deck = this.cardPoolToDeck(this.deckDisplay.getBottom());
deck.setName(filename.getName()); deck.setName(filename.getName());
try { try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename)); final ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename));
out.writeObject(deck); out.writeObject(deck);
out.flush(); out.flush();
out.close(); out.close();
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeck() error, " + ex); throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeck() error, " + ex);
} }
exportDeckText(getExportDeckText(deck), filename.getAbsolutePath()); this.exportDeckText(this.getExportDeckText(deck), filename.getAbsolutePath());
} // exportDeck() } // exportDeck()
@@ -164,16 +166,16 @@ public class DeckEditorQuestMenu extends JMenuBar {
private void exportDeckText(final String deckText, String filename) { private void exportDeckText(final String deckText, String filename) {
// remove ".deck" extension // remove ".deck" extension
int cut = filename.indexOf("."); final int cut = filename.indexOf(".");
filename = filename.substring(0, cut); filename = filename.substring(0, cut);
try { try {
FileWriter writer = new FileWriter(filename + ".txt"); final FileWriter writer = new FileWriter(filename + ".txt");
writer.write(deckText); writer.write(deckText);
writer.flush(); writer.flush();
writer.close(); writer.close();
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeckText() error, " + ex.getMessage() + " : " throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeckText() error, " + ex.getMessage() + " : "
+ Arrays.toString(ex.getStackTrace())); + Arrays.toString(ex.getStackTrace()));
@@ -191,12 +193,12 @@ public class DeckEditorQuestMenu extends JMenuBar {
*/ */
private String getExportDeckText(final Deck aDeck) { private String getExportDeckText(final Deck aDeck) {
// convert Deck into CardList // convert Deck into CardList
ItemPoolView<CardPrinted> all = aDeck.getMain(); final ItemPoolView<CardPrinted> all = aDeck.getMain();
// sort by card name // sort by card name
Collections.sort(all.getOrderedList(), TableSorter.byNameThenSet); Collections.sort(all.getOrderedList(), TableSorter.BY_NAME_THEN_SET);
StringBuffer sb = new StringBuffer(); final StringBuffer sb = new StringBuffer();
String newLine = "\r\n"; final String newLine = "\r\n";
sb.append(String.format("%d Total Cards%n%n", all.countAll())); sb.append(String.format("%d Total Cards%n%n", all.countAll()));
@@ -204,21 +206,22 @@ public class DeckEditorQuestMenu extends JMenuBar {
sb.append(String.format("%d Creatures%n-------------%n", sb.append(String.format("%d Creatures%n-------------%n",
CardRules.Predicates.Presets.IS_CREATURE.aggregate(all, all.fnToCard, all.fnToCount))); CardRules.Predicates.Presets.IS_CREATURE.aggregate(all, all.fnToCard, all.fnToCount)));
for (Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.IS_CREATURE.select(all, all.fnToCard)) { for (final Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.IS_CREATURE.select(all, all.fnToCard)) {
sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName())); sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName()));
} }
// spells // spells
sb.append(String.format("%d Spells%n----------%n", sb.append(String.format("%d Spells%n----------%n",
CardRules.Predicates.Presets.IS_NON_CREATURE_SPELL.aggregate(all, all.fnToCard, all.fnToCount))); CardRules.Predicates.Presets.IS_NON_CREATURE_SPELL.aggregate(all, all.fnToCard, all.fnToCount)));
for (Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.IS_NON_CREATURE_SPELL.select(all, all.fnToCard)) { for (final Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.IS_NON_CREATURE_SPELL.select(all,
all.fnToCard)) {
sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName())); sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName()));
} }
// lands // lands
sb.append(String.format("%d Land%n--------%n", sb.append(String.format("%d Land%n--------%n",
CardRules.Predicates.Presets.IS_LAND.aggregate(all, all.fnToCard, all.fnToCount))); CardRules.Predicates.Presets.IS_LAND.aggregate(all, all.fnToCard, all.fnToCount)));
for (Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.IS_LAND.select(all, all.fnToCard)) { for (final Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.IS_LAND.select(all, all.fnToCard)) {
sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName())); sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName()));
} }
@@ -235,7 +238,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
* @return a {@link javax.swing.filechooser.FileFilter} object. * @return a {@link javax.swing.filechooser.FileFilter} object.
*/ */
private FileFilter getFileFilter() { private FileFilter getFileFilter() {
FileFilter filter = new FileFilter() { final FileFilter filter = new FileFilter() {
@Override @Override
public boolean accept(final File f) { public boolean accept(final File f) {
return f.getName().endsWith(".dck") || f.isDirectory(); return f.getName().endsWith(".dck") || f.isDirectory();
@@ -260,20 +263,20 @@ public class DeckEditorQuestMenu extends JMenuBar {
private File getExportFilename() { private File getExportFilename() {
// Object o = null; // unused // Object o = null; // unused
JFileChooser save = new JFileChooser(previousDirectory); final JFileChooser save = new JFileChooser(DeckEditorQuestMenu.previousDirectory);
save.setDialogTitle("Export Deck Filename"); save.setDialogTitle("Export Deck Filename");
save.setDialogType(JFileChooser.SAVE_DIALOG); save.setDialogType(JFileChooser.SAVE_DIALOG);
save.addChoosableFileFilter(getFileFilter()); save.addChoosableFileFilter(this.getFileFilter());
save.setSelectedFile(new File(currentDeck.getName() + ".deck")); save.setSelectedFile(new File(this.currentDeck.getName() + ".deck"));
int returnVal = save.showSaveDialog(null); final int returnVal = save.showSaveDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = save.getSelectedFile(); final File file = save.getSelectedFile();
String check = file.getAbsolutePath(); final String check = file.getAbsolutePath();
previousDirectory = file.getParentFile(); DeckEditorQuestMenu.previousDirectory = file.getParentFile();
if (check.endsWith(".deck")) { if (check.endsWith(".deck")) {
return file; return file;
@@ -291,26 +294,26 @@ public class DeckEditorQuestMenu extends JMenuBar {
* </p> * </p>
*/ */
private void importDeck() { private void importDeck() {
File file = getImportFilename(); final File file = this.getImportFilename();
if (file == null) { if (file == null) {
} else if (file.getName().endsWith(".dck")) { } else if (file.getName().endsWith(".dck")) {
try { try {
Deck newDeck = DeckManager.readDeck(file); final Deck newDeck = DeckManager.readDeck(file);
questData.addDeck(newDeck); this.questData.addDeck(newDeck);
ItemPool<CardPrinted> cardpool = ItemPool.createFrom(questData.getCards().getCardpool(), final ItemPool<CardPrinted> cardpool = ItemPool.createFrom(this.questData.getCards().getCardpool(),
CardPrinted.class); CardPrinted.class);
ItemPool<CardPrinted> decklist = new ItemPool<CardPrinted>(CardPrinted.class); final ItemPool<CardPrinted> decklist = new ItemPool<CardPrinted>(CardPrinted.class);
for (Entry<CardPrinted, Integer> s : newDeck.getMain()) { for (final Entry<CardPrinted, Integer> s : newDeck.getMain()) {
CardPrinted cp = s.getKey(); final CardPrinted cp = s.getKey();
decklist.add(cp, s.getValue()); decklist.add(cp, s.getValue());
cardpool.add(cp, s.getValue()); cardpool.add(cp, s.getValue());
questData.getCards().getCardpool().add(cp, s.getValue()); this.questData.getCards().getCardpool().add(cp, s.getValue());
} }
deckDisplay.setDeck(cardpool, decklist, GameType.Quest); this.deckDisplay.setDeck(cardpool, decklist, GameType.Quest);
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error, " + ex); throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error, " + ex);
} }
@@ -326,14 +329,14 @@ public class DeckEditorQuestMenu extends JMenuBar {
* @return a {@link java.io.File} object. * @return a {@link java.io.File} object.
*/ */
private File getImportFilename() { private File getImportFilename() {
JFileChooser chooser = new JFileChooser(previousDirectory); final JFileChooser chooser = new JFileChooser(DeckEditorQuestMenu.previousDirectory);
chooser.addChoosableFileFilter(getFileFilter()); chooser.addChoosableFileFilter(this.getFileFilter());
int returnVal = chooser.showOpenDialog(null); final int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile(); final File file = chooser.getSelectedFile();
previousDirectory = file.getParentFile(); DeckEditorQuestMenu.previousDirectory = file.getParentFile();
return file; return file;
} }
@@ -341,57 +344,64 @@ public class DeckEditorQuestMenu extends JMenuBar {
} // openFileDialog() } // openFileDialog()
private final ActionListener addCardActionListener = new ActionListener() { private final ActionListener addCardActionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
// Provide a model here: all unique cards to be displayed by only // Provide a model here: all unique cards to be displayed by only
// name (unlike default toString) // name (unlike default toString)
Iterable<CardPrinted> uniqueCards = CardDb.instance().getAllUniqueCards(); final Iterable<CardPrinted> uniqueCards = CardDb.instance().getAllUniqueCards();
List<String> cards = new ArrayList<String>(); final List<String> cards = new ArrayList<String>();
for (CardPrinted c : uniqueCards) { for (final CardPrinted c : uniqueCards) {
cards.add(c.getName()); cards.add(c.getName());
} }
Collections.sort(cards); Collections.sort(cards);
// use standard forge's list selection dialog // use standard forge's list selection dialog
ListChooser<String> c = new ListChooser<String>("Cheat - Add Card to Your Cardpool", 0, 1, cards); final ListChooser<String> c = new ListChooser<String>("Cheat - Add Card to Your Cardpool", 0, 1, cards);
if (c.show()) { if (c.show()) {
String cardName = c.getSelectedValue(); final String cardName = c.getSelectedValue();
DeckEditorQuest g = (DeckEditorQuest) deckDisplay; final DeckEditorQuest g = (DeckEditorQuest) DeckEditorQuestMenu.this.deckDisplay;
g.addCheatCard(CardDb.instance().getCard(cardName)); g.addCheatCard(CardDb.instance().getCard(cardName));
} }
} }
}; };
private final ActionListener openDeckActionListener = new ActionListener() { private final ActionListener openDeckActionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
String deckName = getUserInput_OpenDeck(questData.getDeckNames()); final String deckName = DeckEditorQuestMenu.this.getUserInputOpenDeck(DeckEditorQuestMenu.this.questData
.getDeckNames());
// check if user selected "cancel" // check if user selected "cancel"
if (StringUtils.isBlank(deckName)) { if (StringUtils.isBlank(deckName)) {
return; return;
} }
setPlayerDeckName(deckName); DeckEditorQuestMenu.this.setPlayerDeckName(deckName);
ItemPool<CardPrinted> cards = ItemPool.createFrom(questData.getCards().getCardpool().getView(), final ItemPool<CardPrinted> cards = ItemPool.createFrom(DeckEditorQuestMenu.this.questData.getCards()
CardPrinted.class); .getCardpool().getView(), CardPrinted.class);
ItemPoolView<CardPrinted> deck = questData.getDeck(deckName).getMain(); final ItemPoolView<CardPrinted> deck = DeckEditorQuestMenu.this.questData.getDeck(deckName).getMain();
// show in pool all cards except ones used in deck // show in pool all cards except ones used in deck
cards.removeAll(deck); cards.removeAll(deck);
deckDisplay.setDeck(cards, deck, GameType.Quest); DeckEditorQuestMenu.this.deckDisplay.setDeck(cards, deck, GameType.Quest);
} }
}; };
private final ActionListener newDeckActionListener = new ActionListener() { private final ActionListener newDeckActionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
deckDisplay.setItems(questData.getCards().getCardpool().getView(), null, GameType.Quest); DeckEditorQuestMenu.this.deckDisplay.setItems(DeckEditorQuestMenu.this.questData.getCards().getCardpool()
setPlayerDeckName(""); .getView(), null, GameType.Quest);
DeckEditorQuestMenu.this.setPlayerDeckName("");
} }
}; };
private final ActionListener renameDeckActionListener = new ActionListener() { private final ActionListener renameDeckActionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
String deckName = getUserInput_GetDeckName(questData.getDeckNames()); final String deckName = DeckEditorQuestMenu.this
.getUserInputGetDeckName(DeckEditorQuestMenu.this.questData.getDeckNames());
// check if user cancels // check if user cancels
if (StringUtils.isBlank(deckName)) { if (StringUtils.isBlank(deckName)) {
@@ -399,27 +409,30 @@ public class DeckEditorQuestMenu extends JMenuBar {
} }
// is the current deck already saved and in QuestData? // is the current deck already saved and in QuestData?
if (questData.getDeckNames().contains(currentDeck.getName())) { if (DeckEditorQuestMenu.this.questData.getDeckNames().contains(
questData.removeDeck(currentDeck.getName()); DeckEditorQuestMenu.this.currentDeck.getName())) {
DeckEditorQuestMenu.this.questData.removeDeck(DeckEditorQuestMenu.this.currentDeck.getName());
} }
currentDeck.setName(deckName); DeckEditorQuestMenu.this.currentDeck.setName(deckName);
Deck deck = cardPoolToDeck(deckDisplay.getBottom()); final Deck deck = DeckEditorQuestMenu.this.cardPoolToDeck(DeckEditorQuestMenu.this.deckDisplay.getBottom());
deck.setName(deckName); deck.setName(deckName);
questData.addDeck(deck); DeckEditorQuestMenu.this.questData.addDeck(deck);
setPlayerDeckName(deckName); DeckEditorQuestMenu.this.setPlayerDeckName(deckName);
} }
}; };
private final ActionListener saveDeckActionListener = new ActionListener() { private final ActionListener saveDeckActionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
String name = currentDeck.getName(); String name = DeckEditorQuestMenu.this.currentDeck.getName();
// check to see if name is set // check to see if name is set
if (name.equals("")) { if (name.equals("")) {
name = getUserInput_GetDeckName(questData.getDeckNames()); name = DeckEditorQuestMenu.this.getUserInputGetDeckName(DeckEditorQuestMenu.this.questData
.getDeckNames());
// check if user cancels // check if user cancels
if (name.equals("")) { if (name.equals("")) {
@@ -427,51 +440,55 @@ public class DeckEditorQuestMenu extends JMenuBar {
} }
} }
setPlayerDeckName(name); DeckEditorQuestMenu.this.setPlayerDeckName(name);
Deck deck = cardPoolToDeck(deckDisplay.getBottom()); final Deck deck = DeckEditorQuestMenu.this.cardPoolToDeck(DeckEditorQuestMenu.this.deckDisplay.getBottom());
deck.setName(name); deck.setName(name);
questData.addDeck(deck); DeckEditorQuestMenu.this.questData.addDeck(deck);
} }
}; };
private final ActionListener copyDeckActionListener = new ActionListener() { private final ActionListener copyDeckActionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
String name = getUserInput_GetDeckName(questData.getDeckNames()); final String name = DeckEditorQuestMenu.this.getUserInputGetDeckName(DeckEditorQuestMenu.this.questData
.getDeckNames());
// check if user cancels // check if user cancels
if (name.equals("")) { if (name.equals("")) {
return; return;
} }
setPlayerDeckName(name); DeckEditorQuestMenu.this.setPlayerDeckName(name);
Deck deck = cardPoolToDeck(deckDisplay.getBottom()); final Deck deck = DeckEditorQuestMenu.this.cardPoolToDeck(DeckEditorQuestMenu.this.deckDisplay.getBottom());
deck.setName(name); deck.setName(name);
questData.addDeck(deck); DeckEditorQuestMenu.this.questData.addDeck(deck);
} }
}; };
private final ActionListener deleteDeckActionListener = new ActionListener() { private final ActionListener deleteDeckActionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
if (currentDeck.getName().equals("")) { if (DeckEditorQuestMenu.this.currentDeck.getName().equals("")) {
return; return;
} }
int check = JOptionPane.showConfirmDialog(null, "Do you really want to delete this deck?", "Delete", final int check = JOptionPane.showConfirmDialog(null, "Do you really want to delete this deck?", "Delete",
JOptionPane.YES_NO_OPTION); JOptionPane.YES_NO_OPTION);
if (check == JOptionPane.NO_OPTION) { if (check == JOptionPane.NO_OPTION) {
return; // stop here return; // stop here
} }
questData.removeDeck(currentDeck.getName()); DeckEditorQuestMenu.this.questData.removeDeck(DeckEditorQuestMenu.this.currentDeck.getName());
// show card pool // show card pool
deckDisplay.setItems(questData.getCards().getCardpool().getView(), null, GameType.Quest); DeckEditorQuestMenu.this.deckDisplay.setItems(DeckEditorQuestMenu.this.questData.getCards().getCardpool()
.getView(), null, GameType.Quest);
setPlayerDeckName(""); DeckEditorQuestMenu.this.setPlayerDeckName("");
} }
}; };
@@ -482,32 +499,33 @@ public class DeckEditorQuestMenu extends JMenuBar {
* </p> * </p>
*/ */
private void setupMenu() { private void setupMenu() {
JMenuItem openDeck = new JMenuItem("Open"); final JMenuItem openDeck = new JMenuItem("Open");
JMenuItem newDeck = new JMenuItem("New"); final JMenuItem newDeck = new JMenuItem("New");
JMenuItem rename = new JMenuItem("Rename"); final JMenuItem rename = new JMenuItem("Rename");
JMenuItem save = new JMenuItem("Save"); final JMenuItem save = new JMenuItem("Save");
JMenuItem copy = new JMenuItem("Copy"); final JMenuItem copy = new JMenuItem("Copy");
JMenuItem delete = new JMenuItem("Delete"); final JMenuItem delete = new JMenuItem("Delete");
JMenuItem exit = new JMenuItem("Exit"); final JMenuItem exit = new JMenuItem("Exit");
JMenuItem addCard = new JMenuItem("Cheat - Add Card"); final JMenuItem addCard = new JMenuItem("Cheat - Add Card");
addCard.addActionListener(addCardActionListener); addCard.addActionListener(this.addCardActionListener);
openDeck.addActionListener(openDeckActionListener); openDeck.addActionListener(this.openDeckActionListener);
newDeck.addActionListener(newDeckActionListener); newDeck.addActionListener(this.newDeckActionListener);
rename.addActionListener(renameDeckActionListener); rename.addActionListener(this.renameDeckActionListener);
save.addActionListener(saveDeckActionListener); save.addActionListener(this.saveDeckActionListener);
copy.addActionListener(copyDeckActionListener); copy.addActionListener(this.copyDeckActionListener);
delete.addActionListener(deleteDeckActionListener); delete.addActionListener(this.deleteDeckActionListener);
// human // human
exit.addActionListener(new ActionListener() { exit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
DeckEditorQuestMenu.this.close(); DeckEditorQuestMenu.this.close();
} }
}); });
JMenu deckMenu = new JMenu("Deck"); final JMenu deckMenu = new JMenu("Deck");
deckMenu.add(openDeck); deckMenu.add(openDeck);
deckMenu.add(newDeck); deckMenu.add(newDeck);
deckMenu.add(rename); deckMenu.add(rename);
@@ -520,7 +538,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
} }
deckMenu.addSeparator(); deckMenu.addSeparator();
addImportExport(deckMenu, true); this.addImportExport(deckMenu, true);
deckMenu.addSeparator(); deckMenu.addSeparator();
deckMenu.add(delete); deckMenu.add(delete);
@@ -542,7 +560,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
*/ */
private Deck cardPoolToDeck(final ItemPoolView<InventoryItem> list) { private Deck cardPoolToDeck(final ItemPoolView<InventoryItem> list) {
// put CardPool into Deck main // put CardPool into Deck main
Deck deck = new Deck(GameType.Sealed); final Deck deck = new Deck(GameType.Sealed);
deck.addMain(ItemPool.createFrom(list, CardPrinted.class)); deck.addMain(ItemPool.createFrom(list, CardPrinted.class));
return deck; return deck;
} }
@@ -558,10 +576,10 @@ public class DeckEditorQuestMenu extends JMenuBar {
*/ */
public final void setPlayerDeckName(final String deckName) { public final void setPlayerDeckName(final String deckName) {
// the gui uses this, Gui_Quest_DeckEditor // the gui uses this, Gui_Quest_DeckEditor
currentDeck = new Deck(GameType.Sealed); this.currentDeck = new Deck(GameType.Sealed);
currentDeck.setName(deckName); this.currentDeck.setName(deckName);
deckDisplay.setTitle(deckEditorName + " - " + deckName); this.deckDisplay.setTitle(DeckEditorQuestMenu.DECK_EDITOR_NAME + " - " + 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
@@ -575,11 +593,11 @@ public class DeckEditorQuestMenu extends JMenuBar {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private String cleanString(final String in) { private String cleanString(final String in) {
StringBuffer out = new StringBuffer(); final StringBuffer out = new StringBuffer();
char[] c = in.toCharArray(); final char[] c = in.toCharArray();
for (int i = 0; i < c.length && i < 20; i++) { for (int i = 0; (i < c.length) && (i < 20); i++) {
if (Character.isLetterOrDigit(c[i]) || c[i] == '-' || c[i] == '_' || c[i] == ' ') { if (Character.isLetterOrDigit(c[i]) || (c[i] == '-') || (c[i] == '_') || (c[i] == ' ')) {
out.append(c[i]); out.append(c[i]);
} }
} }
@@ -597,18 +615,18 @@ public class DeckEditorQuestMenu extends JMenuBar {
* a {@link java.util.List} object. * a {@link java.util.List} object.
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private String getUserInput_GetDeckName(final List<String> nameList) { private String getUserInputGetDeckName(final List<String> nameList) {
Object o = JOptionPane.showInputDialog(null, "", "Deck Name", JOptionPane.OK_CANCEL_OPTION); final Object o = JOptionPane.showInputDialog(null, "", "Deck Name", JOptionPane.OK_CANCEL_OPTION);
if (o == null) { if (o == null) {
return ""; return "";
} }
String deckName = cleanString(o.toString()); final String deckName = this.cleanString(o.toString());
if (nameList.contains(deckName) || deckName.equals("")) { if (nameList.contains(deckName) || deckName.equals("")) {
JOptionPane.showMessageDialog(null, "Please pick another deck name, a deck currently has that name."); JOptionPane.showMessageDialog(null, "Please pick another deck name, a deck currently has that name.");
return getUserInput_GetDeckName(nameList); return this.getUserInputGetDeckName(nameList);
} }
return deckName; return deckName;
@@ -624,8 +642,8 @@ public class DeckEditorQuestMenu extends JMenuBar {
* a {@link java.util.List} object. * a {@link java.util.List} object.
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private String getUserInput_OpenDeck(final List<String> deckNameList) { private String getUserInputOpenDeck(final List<String> deckNameList) {
List<String> choices = deckNameList; final List<String> choices = deckNameList;
if (choices.size() == 0) { if (choices.size() == 0) {
JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE); JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE);
return ""; return "";
@@ -634,7 +652,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
// Object o = JOptionPane.showInputDialog(null, "Deck Name", // Object o = JOptionPane.showInputDialog(null, "Deck Name",
// "Open Deck", JOptionPane.OK_CANCEL_OPTION, null, // "Open Deck", JOptionPane.OK_CANCEL_OPTION, null,
// choices.toArray(), choices.toArray()[0]); // choices.toArray(), choices.toArray()[0]);
Object o = GuiUtils.getChoiceOptional("Select Deck", choices.toArray()); final Object o = GuiUtils.getChoiceOptional("Select Deck", choices.toArray());
if (o == null) { if (o == null) {
return ""; return "";
@@ -650,7 +668,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
* </p> * </p>
*/ */
public final void close() { public final void close() {
exitCommand.execute(); this.exitCommand.execute();
} }
// used by Gui_Quest_DeckEditor // used by Gui_Quest_DeckEditor
@@ -662,7 +680,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public final String getDeckName() { public final String getDeckName() {
return currentDeck.getName(); return this.currentDeck.getName();
} }
} }

View File

@@ -45,21 +45,21 @@ public final class DeckEditorShop extends DeckEditorBase {
/** Constant <code>serialVersionUID=3988857075791576483L</code>. */ /** Constant <code>serialVersionUID=3988857075791576483L</code>. */
private static final long serialVersionUID = 3988857075791576483L; private static final long serialVersionUID = 3988857075791576483L;
private JButton buyButton = new JButton(); private final JButton buyButton = new JButton();
private JButton sellButton = new JButton(); private final JButton sellButton = new JButton();
private JLabel creditsLabel = new JLabel(); private final JLabel creditsLabel = new JLabel();
private JLabel jLabel1 = new JLabel(); private final JLabel jLabel1 = new JLabel();
private JLabel sellPercentageLabel = new JLabel(); private final JLabel sellPercentageLabel = new JLabel();
private double multiplier; private double multiplier;
private QuestData questData; private final QuestData questData;
// private CardPoolView newCardsList; // private CardPoolView newCardsList;
// get pricelist: // get pricelist:
private ReadPriceList r = new ReadPriceList(); private final ReadPriceList r = new ReadPriceList();
private Map<String, Integer> mapPrices = r.getPriceList(); private final Map<String, Integer> mapPrices = this.r.getPriceList();
private Map<CardPrinted, Integer> decksUsingMyCards; private Map<CardPrinted, Integer> decksUsingMyCards;
/** /**
@@ -72,6 +72,7 @@ public final class DeckEditorShop extends DeckEditorBase {
final Command exit = new Command() { final Command exit = new Command() {
private static final long serialVersionUID = -7428793574300520612L; private static final long serialVersionUID = -7428793574300520612L;
@Override
public void execute() { public void execute() {
DeckEditorShop.this.dispose(); DeckEditorShop.this.dispose();
exitCommand.execute(); exitCommand.execute();
@@ -86,46 +87,46 @@ public final class DeckEditorShop extends DeckEditorBase {
} }
}); });
setup(); this.setup();
decksUsingMyCards = countDecksForEachCard(); this.decksUsingMyCards = this.countDecksForEachCard();
multiplier = questData.getCards().getSellMutliplier(); this.multiplier = this.questData.getCards().getSellMutliplier();
ItemPoolView<InventoryItem> forSale = questData.getCards().getShopList(); ItemPoolView<InventoryItem> forSale = this.questData.getCards().getShopList();
if (forSale.isEmpty()) { if (forSale.isEmpty()) {
questData.getCards().generateCardsInShop(); this.questData.getCards().generateCardsInShop();
forSale = questData.getCards().getShopList(); forSale = this.questData.getCards().getShopList();
} }
ItemPoolView<InventoryItem> owned = questData.getCards().getCardpool().getView(); final ItemPoolView<InventoryItem> owned = this.questData.getCards().getCardpool().getView();
// newCardsList = questData.getCards().getNewCards(); // newCardsList = questData.getCards().getNewCards();
setItems(forSale, owned, GameType.Quest); this.setItems(forSale, owned, GameType.Quest);
double multiPercent = multiplier * 100; final double multiPercent = this.multiplier * 100;
NumberFormat formatter = new DecimalFormat("#0.00"); final NumberFormat formatter = new DecimalFormat("#0.00");
String maxSellingPrice = ""; String maxSellingPrice = "";
int maxSellPrice = questData.getCards().getSellPriceLimit(); final int maxSellPrice = this.questData.getCards().getSellPriceLimit();
if (maxSellPrice < Integer.MAX_VALUE) { if (maxSellPrice < Integer.MAX_VALUE) {
maxSellingPrice = String.format("Max selling price: %d", maxSellPrice); maxSellingPrice = String.format("Max selling price: %d", maxSellPrice);
} }
sellPercentageLabel.setText("<html>(You can sell cards at " + formatter.format(multiPercent) this.sellPercentageLabel.setText("<html>(You can sell cards at " + formatter.format(multiPercent)
+ "% of their value)<br>" + maxSellingPrice + "</html>"); + "% of their value)<br>" + maxSellingPrice + "</html>");
top.sort(1, true); this.getTopTableWithCards().sort(1, true);
bottom.sort(1, true); this.getBottomTableWithCards().sort(1, true);
} // show(Command) } // show(Command)
// fills number of decks using each card // fills number of decks using each card
private Map<CardPrinted, Integer> countDecksForEachCard() { private Map<CardPrinted, Integer> countDecksForEachCard() {
Map<CardPrinted, Integer> result = new HashMap<CardPrinted, Integer>(); final Map<CardPrinted, Integer> result = new HashMap<CardPrinted, Integer>();
for (String deckName : questData.getDeckNames()) { for (final String deckName : this.questData.getDeckNames()) {
Deck deck = questData.getDeck(deckName); final Deck deck = this.questData.getDeck(deckName);
for (Entry<CardPrinted, Integer> e : deck.getMain()) { for (final Entry<CardPrinted, Integer> e : deck.getMain()) {
CardPrinted card = e.getKey(); final CardPrinted card = e.getKey();
Integer iValue = result.get(card); final Integer iValue = result.get(card);
int cntDecks = iValue == null ? 1 : 1 + iValue.intValue(); final int cntDecks = iValue == null ? 1 : 1 + iValue.intValue();
result.put(card, Integer.valueOf(cntDecks)); result.put(card, Integer.valueOf(cntDecks));
} }
} }
@@ -138,11 +139,13 @@ public final class DeckEditorShop extends DeckEditorBase {
* </p> * </p>
*/ */
private void setup() { private void setup() {
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>(); final List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE, PresetColumns.FN_QTY_GET)); columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE,
PresetColumns.FN_QTY_GET));
columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.FN_NAME_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.FN_NAME_COMPARE,
PresetColumns.FN_NAME_GET)); PresetColumns.FN_NAME_GET));
columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.FN_COST_COMPARE, PresetColumns.FN_COST_GET)); columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.FN_COST_COMPARE,
PresetColumns.FN_COST_GET));
columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.FN_COLOR_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.FN_COLOR_COMPARE,
PresetColumns.FN_COLOR_GET)); PresetColumns.FN_COLOR_GET));
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE,
@@ -151,18 +154,19 @@ public final class DeckEditorShop extends DeckEditorBase {
PresetColumns.FN_STATS_GET)); PresetColumns.FN_STATS_GET));
columns.add(new TableColumnInfo<InventoryItem>("R", 30, PresetColumns.FN_RARITY_COMPARE, columns.add(new TableColumnInfo<InventoryItem>("R", 30, PresetColumns.FN_RARITY_COMPARE,
PresetColumns.FN_RARITY_GET)); PresetColumns.FN_RARITY_GET));
columns.add(new TableColumnInfo<InventoryItem>("Set", 35, PresetColumns.FN_SET_COMPARE, PresetColumns.FN_SET_GET)); columns.add(new TableColumnInfo<InventoryItem>("Set", 35, PresetColumns.FN_SET_COMPARE,
PresetColumns.FN_SET_GET));
columns.get(2).setCellRenderer(new ManaCostRenderer()); columns.get(2).setCellRenderer(new ManaCostRenderer());
List<TableColumnInfo<InventoryItem>> columnsBelow = new ArrayList<TableColumnInfo<InventoryItem>>(columns); final List<TableColumnInfo<InventoryItem>> columnsBelow = new ArrayList<TableColumnInfo<InventoryItem>>(columns);
columns.add(new TableColumnInfo<InventoryItem>("Price", 36, fnPriceCompare, fnPriceGet)); columns.add(new TableColumnInfo<InventoryItem>("Price", 36, this.fnPriceCompare, this.fnPriceGet));
top.setup(columns, cardView); this.getTopTableWithCards().setup(columns, this.getCardView());
columnsBelow.add(new TableColumnInfo<InventoryItem>("Dks", 30, fnDeckCompare, fnDeckGet)); columnsBelow.add(new TableColumnInfo<InventoryItem>("Dks", 30, this.fnDeckCompare, this.fnDeckGet));
columnsBelow.add(new TableColumnInfo<InventoryItem>("New", 35, questData.getCards().fnNewCompare, questData columnsBelow.add(new TableColumnInfo<InventoryItem>("New", 35, this.questData.getCards().fnNewCompare,
.getCards().fnNewGet)); this.questData.getCards().fnNewGet));
columnsBelow.add(new TableColumnInfo<InventoryItem>("Price", 36, fnPriceCompare, fnPriceSellGet)); columnsBelow.add(new TableColumnInfo<InventoryItem>("Price", 36, this.fnPriceCompare, this.fnPriceSellGet));
bottom.setup(columnsBelow, cardView); this.getBottomTableWithCards().setup(columnsBelow, this.getCardView());
this.setSize(1024, 768); this.setSize(1024, 768);
GuiUtils.centerFrame(this); GuiUtils.centerFrame(this);
@@ -179,14 +183,14 @@ public final class DeckEditorShop extends DeckEditorBase {
*/ */
public DeckEditorShop(final QuestData qd) { public DeckEditorShop(final QuestData qd) {
super(GameType.Quest); super(GameType.Quest);
questData = qd; this.questData = qd;
try { try {
filterBoxes = null; this.setFilterBoxes(null);
top = new TableWithCards("Cards for sale", false); this.setTopTableWithCards(new TableWithCards("Cards for sale", false));
bottom = new TableWithCards("Owned Cards", false); this.setBottomTableWithCards(new TableWithCards("Owned Cards", false));
cardView = new CardPanelLite(); this.setCardView(new CardPanelLite());
jbInit(); this.jbInit();
} catch (Exception ex) { } catch (final Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
} }
} }
@@ -202,64 +206,66 @@ public final class DeckEditorShop extends DeckEditorBase {
private void jbInit() throws Exception { private void jbInit() throws Exception {
this.setLayout(null); this.setLayout(null);
top.getTableDecorated().setBounds(new Rectangle(19, 20, 726, 346)); this.getTopTableWithCards().getTableDecorated().setBounds(new Rectangle(19, 20, 726, 346));
bottom.getTableDecorated().setBounds(new Rectangle(19, 458, 726, 276)); this.getBottomTableWithCards().getTableDecorated().setBounds(new Rectangle(19, 458, 726, 276));
sellButton.setBounds(new Rectangle(180, 403, 146, 49)); this.sellButton.setBounds(new Rectangle(180, 403, 146, 49));
// removeButton.setIcon(upIcon); // removeButton.setIcon(upIcon);
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
sellButton.setFont(new java.awt.Font("Dialog", 0, 13)); this.sellButton.setFont(new java.awt.Font("Dialog", 0, 13));
} }
sellButton.setText("Sell Card"); this.sellButton.setText("Sell Card");
sellButton.addActionListener(new java.awt.event.ActionListener() { this.sellButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
sellButtonActionPerformed(e); DeckEditorShop.this.sellButtonActionPerformed(e);
} }
}); });
buyButton.setText("Buy Card"); this.buyButton.setText("Buy Card");
buyButton.addActionListener(new java.awt.event.ActionListener() { this.buyButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
buyButtonActionPerformed(e); DeckEditorShop.this.buyButtonActionPerformed(e);
} }
}); });
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
buyButton.setFont(new java.awt.Font("Dialog", 0, 13)); this.buyButton.setFont(new java.awt.Font("Dialog", 0, 13));
} }
buyButton.setBounds(new Rectangle(23, 403, 146, 49)); this.buyButton.setBounds(new Rectangle(23, 403, 146, 49));
cardView.setBounds(new Rectangle(765, 23, 239, 710)); this.getCardView().setBounds(new Rectangle(765, 23, 239, 710));
// Do not lower statsLabel any lower, we want this to be visible at 1024 // Do not lower statsLabel any lower, we want this to be visible at 1024
// x 768 screen size // x 768 screen size
this.setTitle("Card Shop"); this.setTitle("Card Shop");
creditsLabel.setBounds(new Rectangle(19, 365, 720, 31)); this.creditsLabel.setBounds(new Rectangle(19, 365, 720, 31));
creditsLabel.setText("Total credits: " + questData.getCredits()); this.creditsLabel.setText("Total credits: " + this.questData.getCredits());
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
creditsLabel.setFont(new java.awt.Font("Dialog", 0, 14)); this.creditsLabel.setFont(new java.awt.Font("Dialog", 0, 14));
} }
sellPercentageLabel.setBounds(new Rectangle(350, 403, 450, 31)); this.sellPercentageLabel.setBounds(new Rectangle(350, 403, 450, 31));
sellPercentageLabel.setText("(Sell percentage: " + multiplier + ")"); this.sellPercentageLabel.setText("(Sell percentage: " + this.multiplier + ")");
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
sellPercentageLabel.setFont(new java.awt.Font("Dialog", 0, 14)); this.sellPercentageLabel.setFont(new java.awt.Font("Dialog", 0, 14));
} }
jLabel1.setText("Click on the column name (like name or color) to sort the cards"); this.jLabel1.setText("Click on the column name (like name or color) to sort the cards");
jLabel1.setBounds(new Rectangle(20, 1, 400, 19)); this.jLabel1.setBounds(new Rectangle(20, 1, 400, 19));
this.getContentPane().add(cardView, null); this.getContentPane().add(this.getCardView(), null);
this.getContentPane().add(top.getTableDecorated(), null); this.getContentPane().add(this.getTopTableWithCards().getTableDecorated(), null);
this.getContentPane().add(bottom.getTableDecorated(), null); this.getContentPane().add(this.getBottomTableWithCards().getTableDecorated(), null);
this.getContentPane().add(creditsLabel, null); this.getContentPane().add(this.creditsLabel, null);
this.getContentPane().add(buyButton, null); this.getContentPane().add(this.buyButton, null);
this.getContentPane().add(sellButton, null); this.getContentPane().add(this.sellButton, null);
this.getContentPane().add(sellPercentageLabel, null); this.getContentPane().add(this.sellPercentageLabel, null);
this.getContentPane().add(jLabel1, null); this.getContentPane().add(this.jLabel1, null);
} }
// TODO: move to cardshop // TODO: move to cardshop
private Integer getCardValue(final InventoryItem card) { private Integer getCardValue(final InventoryItem card) {
if (mapPrices.containsKey(card.getName())) { if (this.mapPrices.containsKey(card.getName())) {
return mapPrices.get(card.getName()); return this.mapPrices.get(card.getName());
} else if (card instanceof CardPrinted) { } else if (card instanceof CardPrinted) {
switch (((CardPrinted) card).getRarity()) { switch (((CardPrinted) card).getRarity()) {
case BasicLand: case BasicLand:
@@ -282,34 +288,34 @@ public final class DeckEditorShop extends DeckEditorBase {
} }
private void buyButtonActionPerformed(final ActionEvent e) { private void buyButtonActionPerformed(final ActionEvent e) {
InventoryItem item = top.getSelectedCard(); final InventoryItem item = this.getTopTableWithCards().getSelectedCard();
if (item == null) { if (item == null) {
return; return;
} }
int value = getCardValue(item); final int value = this.getCardValue(item);
if (value <= questData.getCredits()) { if (value <= this.questData.getCredits()) {
if (item instanceof CardPrinted) { if (item instanceof CardPrinted) {
CardPrinted card = (CardPrinted) item; final CardPrinted card = (CardPrinted) item;
bottom.addCard(card); this.getBottomTableWithCards().addCard(card);
top.removeCard(card); this.getTopTableWithCards().removeCard(card);
questData.getCards().buyCard(card, value); this.questData.getCards().buyCard(card, value);
} else if (item instanceof BoosterPack) { } else if (item instanceof BoosterPack) {
top.removeCard(item); this.getTopTableWithCards().removeCard(item);
BoosterPack booster = (BoosterPack) ((BoosterPack) item).clone(); final BoosterPack booster = (BoosterPack) ((BoosterPack) item).clone();
questData.getCards().buyBooster(booster, value); this.questData.getCards().buyBooster(booster, value);
List<CardPrinted> newCards = booster.getCards(); final List<CardPrinted> newCards = booster.getCards();
for (CardPrinted card : newCards) { for (final CardPrinted card : newCards) {
bottom.addCard(card); this.getBottomTableWithCards().addCard(card);
} }
CardListViewer c = new CardListViewer(booster.getName(), "You have found the following cards inside:", final CardListViewer c = new CardListViewer(booster.getName(),
newCards); "You have found the following cards inside:", newCards);
c.show(); c.show();
} }
creditsLabel.setText("Total credits: " + questData.getCredits()); this.creditsLabel.setText("Total credits: " + this.questData.getCredits());
} else { } else {
JOptionPane.showMessageDialog(null, "Not enough credits!"); JOptionPane.showMessageDialog(null, "Not enough credits!");
} }
@@ -326,38 +332,39 @@ public final class DeckEditorShop extends DeckEditorBase {
} }
private void sellButtonActionPerformed(final ActionEvent e) { private void sellButtonActionPerformed(final ActionEvent e) {
InventoryItem item = bottom.getSelectedCard(); final InventoryItem item = this.getBottomTableWithCards().getSelectedCard();
if (item == null || !(item instanceof CardPrinted)) { if ((item == null) || !(item instanceof CardPrinted)) {
return; return;
} }
CardPrinted card = (CardPrinted) item; final CardPrinted card = (CardPrinted) item;
bottom.removeCard(card); this.getBottomTableWithCards().removeCard(card);
top.addCard(card); this.getTopTableWithCards().addCard(card);
int price = Math.min((int) (multiplier * getCardValue(card)), questData.getCards().getSellPriceLimit()); final int price = Math.min((int) (this.multiplier * this.getCardValue(card)), this.questData.getCards()
questData.getCards().sellCard(card, price); .getSellPriceLimit());
this.questData.getCards().sellCard(card, price);
creditsLabel.setText("Total credits: " + questData.getCredits()); this.creditsLabel.setText("Total credits: " + this.questData.getCredits());
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnPriceCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnPriceCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
return getCardValue(from.getKey()); return DeckEditorShop.this.getCardValue(from.getKey());
} }
}; };
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
return getCardValue(from.getKey()); return DeckEditorShop.this.getCardValue(from.getKey());
} }
}; };
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceSellGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceSellGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
return (int) (multiplier * getCardValue(from.getKey())); return (int) (DeckEditorShop.this.multiplier * DeckEditorShop.this.getCardValue(from.getKey()));
} }
}; };
@@ -365,14 +372,14 @@ public final class DeckEditorShop extends DeckEditorBase {
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnDeckCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnDeckCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
Integer iValue = decksUsingMyCards.get(from.getKey()); final Integer iValue = DeckEditorShop.this.decksUsingMyCards.get(from.getKey());
return iValue == null ? Integer.valueOf(0) : iValue; return iValue == null ? Integer.valueOf(0) : iValue;
} }
}; };
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnDeckGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private final Lambda1<Object, Entry<InventoryItem, Integer>> fnDeckGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
Integer iValue = decksUsingMyCards.get(from.getKey()); final Integer iValue = DeckEditorShop.this.decksUsingMyCards.get(from.getKey());
return iValue == null ? "" : iValue.toString(); return iValue == null ? "" : iValue.toString();
} }
}; };

View File

@@ -37,17 +37,18 @@ import forge.item.CardPrinted;
public class DeckImport extends JDialog { public class DeckImport extends JDialog {
private static final long serialVersionUID = -5837776824284093004L; private static final long serialVersionUID = -5837776824284093004L;
private JTextArea txtInput = new JTextArea(); private final JTextArea txtInput = new JTextArea();
private static final String stylesheet = "<style>" private static final String STYLESHEET = "<style>"
+ "body, h1, h2, h3, h4, h5, h6, table, tr, td, p {margin: 1px; padding: 0; font-weight: normal; font-style: normal; text-decoration: none; font-family: Arial; font-size: 10px;} " + "body, h1, h2, h3, h4, h5, h6, table, tr, td, p {margin: 1px; padding: 0; font-weight: "
+ "normal; font-style: normal; text-decoration: none; font-family: Arial; font-size: 10px;} "
+ +
// "h1 {border-bottom: solid 1px black; color: blue; font-size: 12px; margin: 3px 0 9px 0; } " // "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;} " ".comment {color: #666666;} " + ".knowncard {color: #009900;} " + ".unknowncard {color: #990000;} "
+ ".section {padding: 3px 10px; margin: 3px 0; font-weight: 700; background-color: #DDDDDD; } " + ".section {padding: 3px 10px; margin: 3px 0; font-weight: 700; background-color: #DDDDDD; } "
+ "</style>"; + "</style>";
private static final String htmlWelcomeText = "<html>" private static final String HTML_WELCOME_TEXT = "<html>"
+ stylesheet + DeckImport.STYLESHEET
+ "<h3>You'll see recognized cards here</h3>" + "<h3>You'll see recognized cards here</h3>"
+ "<div class='section'>Legend</div>" + "<div class='section'>Legend</div>"
+ "<ul>" + "<ul>"
@@ -57,16 +58,16 @@ public class DeckImport extends JDialog {
+ "<div class='comment'>Submit feedback to Max mtg on slightlymagic.net forum</div>" + "<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>"; + "<div class='comment'>Post bug-reports to http://cardforge.org/bugz/</div>" + "</html>";
private JEditorPane htmlOutput = new JEditorPane("text/html", htmlWelcomeText); private final JEditorPane htmlOutput = new JEditorPane("text/html", DeckImport.HTML_WELCOME_TEXT);
private JScrollPane scrollInput = new JScrollPane(txtInput); private final JScrollPane scrollInput = new JScrollPane(this.txtInput);
private JScrollPane scrollOutput = new JScrollPane(htmlOutput); private final JScrollPane scrollOutput = new JScrollPane(this.htmlOutput);
private JLabel summaryMain = new JLabel("Imported deck summary will appear here"); private final JLabel summaryMain = new JLabel("Imported deck summary will appear here");
private JLabel summarySide = new JLabel("This is second line"); private final JLabel summarySide = new JLabel("This is second line");
private JButton cmdAccept = new JButton("Import Deck"); private final JButton cmdAccept = new JButton("Import Deck");
private JButton cmdCancel = new JButton("Cancel"); private final JButton cmdCancel = new JButton("Cancel");
/** The tokens. */ /** The tokens. */
List<DeckRecognizer.Token> tokens = new ArrayList<DeckRecognizer.Token>(); private List<DeckRecognizer.Token> tokens = new ArrayList<DeckRecognizer.Token>();
private final DeckEditorBase host; private final DeckEditorBase host;
@@ -77,131 +78,132 @@ public class DeckImport extends JDialog {
* the g * the g
*/ */
public DeckImport(final DeckEditorBase g) { public DeckImport(final DeckEditorBase g) {
host = g; this.host = g;
int wWidth = 600; final int wWidth = 600;
int wHeight = 600; final int wHeight = 600;
setPreferredSize(new java.awt.Dimension(wWidth, wHeight)); this.setPreferredSize(new java.awt.Dimension(wWidth, wHeight));
setSize(wWidth, wHeight); this.setSize(wWidth, wHeight);
GuiUtils.centerFrame(this); GuiUtils.centerFrame(this);
setResizable(false); this.setResizable(false);
setTitle("Deck Import (wip)"); this.setTitle("Deck Import (wip)");
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
Font fButtons = new java.awt.Font("Dialog", 0, 13); final Font fButtons = new java.awt.Font("Dialog", 0, 13);
cmdAccept.setFont(fButtons); this.cmdAccept.setFont(fButtons);
cmdCancel.setFont(fButtons); this.cmdCancel.setFont(fButtons);
txtInput.setFont(fButtons); this.txtInput.setFont(fButtons);
// htmlOutput.setFont(fButtons); // htmlOutput.setFont(fButtons);
} }
htmlOutput.setEditable(false); this.htmlOutput.setEditable(false);
scrollInput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(), "Paste or type a decklist")); this.scrollInput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(), "Paste or type a decklist"));
scrollOutput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(), this.scrollOutput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(),
"Expect the recognized lines to appear")); "Expect the recognized lines to appear"));
scrollInput.setViewportBorder(BorderFactory.createLoweredBevelBorder()); this.scrollInput.setViewportBorder(BorderFactory.createLoweredBevelBorder());
scrollOutput.setViewportBorder(BorderFactory.createLoweredBevelBorder()); this.scrollOutput.setViewportBorder(BorderFactory.createLoweredBevelBorder());
getContentPane().setLayout(new MigLayout("fill")); this.getContentPane().setLayout(new MigLayout("fill"));
getContentPane().add(scrollInput, "cell 0 0, w 50%, sy 4, growy, pushy"); this.getContentPane().add(this.scrollInput, "cell 0 0, w 50%, sy 4, growy, pushy");
getContentPane().add(scrollOutput, "cell 1 0, w 50%, growy, pushy"); this.getContentPane().add(this.scrollOutput, "cell 1 0, w 50%, growy, pushy");
getContentPane().add(summaryMain, "cell 1 1, label"); this.getContentPane().add(this.summaryMain, "cell 1 1, label");
getContentPane().add(summarySide, "cell 1 2, label"); this.getContentPane().add(this.summarySide, "cell 1 2, label");
getContentPane().add(cmdAccept, "cell 1 3, split 2, w 100, align c"); this.getContentPane().add(this.cmdAccept, "cell 1 3, split 2, w 100, align c");
getContentPane().add(cmdCancel, "w 100"); this.getContentPane().add(this.cmdCancel, "w 100");
cmdCancel.addActionListener(new ActionListener() { this.cmdCancel.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING)); DeckImport.this.processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING));
} }
}); });
cmdAccept.addActionListener(new ActionListener() { this.cmdAccept.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
String warning = "This will replace contents of your currently open deck with whatever you are importing. Proceed?"; final 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", final int answer = JOptionPane.showConfirmDialog(DeckImport.this, warning, "Replacing old deck",
JOptionPane.YES_NO_OPTION); JOptionPane.YES_NO_OPTION);
if (JOptionPane.NO_OPTION == answer) { if (JOptionPane.NO_OPTION == answer) {
return; return;
} }
Deck toSet = buildDeck(); final Deck toSet = DeckImport.this.buildDeck();
host.setDeck(null, toSet.getMain(), toSet.getDeckType()); DeckImport.this.host.setDeck(null, toSet.getMain(), toSet.getDeckType());
processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING)); DeckImport.this.processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING));
} }
}); });
txtInput.getDocument().addDocumentListener(new OnChangeTextUpdate()); this.txtInput.getDocument().addDocumentListener(new OnChangeTextUpdate());
cmdAccept.setEnabled(false); this.cmdAccept.setEnabled(false);
} }
private void readInput() { private void readInput() {
tokens.clear(); this.tokens.clear();
ElementIterator it = new ElementIterator(txtInput.getDocument().getDefaultRootElement()); final ElementIterator it = new ElementIterator(this.txtInput.getDocument().getDefaultRootElement());
Element e; Element e;
while ((e = it.next()) != null) { while ((e = it.next()) != null) {
if (!e.isLeaf()) { if (!e.isLeaf()) {
continue; continue;
} }
int rangeStart = e.getStartOffset(); final int rangeStart = e.getStartOffset();
int rangeEnd = e.getEndOffset(); final int rangeEnd = e.getEndOffset();
try { try {
String line = txtInput.getText(rangeStart, rangeEnd - rangeStart); final String line = this.txtInput.getText(rangeStart, rangeEnd - rangeStart);
tokens.add(DeckRecognizer.recognizeLine(line)); this.tokens.add(DeckRecognizer.recognizeLine(line));
} catch (BadLocationException ex) { } catch (final BadLocationException ex) {
} }
} }
} }
private void displayTokens() { private void displayTokens() {
StringBuilder sbOut = new StringBuilder("<html>"); final StringBuilder sbOut = new StringBuilder("<html>");
sbOut.append(stylesheet); sbOut.append(DeckImport.STYLESHEET);
for (DeckRecognizer.Token t : tokens) { for (final DeckRecognizer.Token t : this.tokens) {
sbOut.append(makeHtmlViewOfToken(t)); sbOut.append(this.makeHtmlViewOfToken(t));
} }
sbOut.append("</html>"); sbOut.append("</html>");
htmlOutput.setText(sbOut.toString()); this.htmlOutput.setText(sbOut.toString());
} }
private void updateSummaries() { private void updateSummaries() {
int[] cardsOk = new int[2]; final int[] cardsOk = new int[2];
int[] cardsUnknown = new int[2]; final int[] cardsUnknown = new int[2];
int idx = 0; int idx = 0;
for (DeckRecognizer.Token t : tokens) { for (final DeckRecognizer.Token t : this.tokens) {
if (t.getType() == TokenType.KnownCard) { if (t.getType() == TokenType.KnownCard) {
cardsOk[idx] += t.getNumber(); cardsOk[idx] += t.getNumber();
} }
if (t.getType() == TokenType.UnknownCard) { if (t.getType() == TokenType.UnknownCard) {
cardsUnknown[idx] += t.getNumber(); cardsUnknown[idx] += t.getNumber();
} }
if (t.getType() == TokenType.SectionName && t.getText().toLowerCase().contains("side")) { if ((t.getType() == TokenType.SectionName) && t.getText().toLowerCase().contains("side")) {
idx = 1; idx = 1;
} }
} }
summaryMain.setText(String.format("Main: %d cards recognized, %d unknown cards", cardsOk[0], cardsUnknown[0])); this.summaryMain.setText(String.format("Main: %d cards recognized, %d unknown cards", cardsOk[0],
summarySide.setText(String.format("Sideboard: %d cards recognized, %d unknown cards", cardsOk[1], cardsUnknown[0]));
this.summarySide.setText(String.format("Sideboard: %d cards recognized, %d unknown cards", cardsOk[1],
cardsUnknown[1])); cardsUnknown[1]));
cmdAccept.setEnabled(cardsOk[0] > 0); this.cmdAccept.setEnabled(cardsOk[0] > 0);
} }
private Deck buildDeck() { private Deck buildDeck() {
Deck result = new Deck(GameType.Constructed); final Deck result = new Deck(GameType.Constructed);
boolean isMain = true; boolean isMain = true;
for (DeckRecognizer.Token t : tokens) { for (final DeckRecognizer.Token t : this.tokens) {
DeckRecognizer.TokenType type = t.getType(); final DeckRecognizer.TokenType type = t.getType();
if (type == DeckRecognizer.TokenType.SectionName && t.getText().toLowerCase().contains("side")) { if ((type == DeckRecognizer.TokenType.SectionName) && t.getText().toLowerCase().contains("side")) {
isMain = false; isMain = false;
} }
if (type != DeckRecognizer.TokenType.KnownCard) { if (type != DeckRecognizer.TokenType.KnownCard) {
continue; continue;
} }
CardPrinted crd = t.getCard(); final CardPrinted crd = t.getCard();
if (crd.isAlternate()) { if (crd.isAlternate()) {
continue; continue;
} }
@@ -219,9 +221,9 @@ public class DeckImport extends JDialog {
*/ */
protected class OnChangeTextUpdate implements DocumentListener { protected class OnChangeTextUpdate implements DocumentListener {
private void onChange() { private void onChange() {
readInput(); DeckImport.this.readInput();
displayTokens(); DeckImport.this.displayTokens();
updateSummaries(); DeckImport.this.updateSummaries();
} }
/* /*
@@ -233,7 +235,7 @@ public class DeckImport extends JDialog {
*/ */
@Override @Override
public final void insertUpdate(final DocumentEvent e) { public final void insertUpdate(final DocumentEvent e) {
onChange(); this.onChange();
} }
/* /*
@@ -245,7 +247,7 @@ public class DeckImport extends JDialog {
*/ */
@Override @Override
public final void removeUpdate(final DocumentEvent e) { public final void removeUpdate(final DocumentEvent e) {
onChange(); this.onChange();
} }
/* /*

View File

@@ -18,50 +18,50 @@ import forge.item.CardPrinted;
class FilterCheckBoxes { class FilterCheckBoxes {
/** The white. */ /** The white. */
public final JCheckBox white; private final JCheckBox white;
/** The blue. */ /** The blue. */
public final JCheckBox blue; private final JCheckBox blue;
/** The black. */ /** The black. */
public final JCheckBox black; private final JCheckBox black;
/** The red. */ /** The red. */
public final JCheckBox red; private final JCheckBox red;
/** The green. */ /** The green. */
public final JCheckBox green; private final JCheckBox green;
/** The colorless. */ /** The colorless. */
public final JCheckBox colorless; private final JCheckBox colorless;
/** The land. */ /** The land. */
public final JCheckBox land; private final JCheckBox land;
/** The creature. */ /** The creature. */
public final JCheckBox creature; private final JCheckBox creature;
/** The sorcery. */ /** The sorcery. */
public final JCheckBox sorcery; private final JCheckBox sorcery;
/** The instant. */ /** The instant. */
public final JCheckBox instant; private final JCheckBox instant;
/** The planeswalker. */ /** The planeswalker. */
public final JCheckBox planeswalker; private final JCheckBox planeswalker;
/** The artifact. */ /** The artifact. */
public final JCheckBox artifact; private final JCheckBox artifact;
/** The enchantment. */ /** The enchantment. */
public final JCheckBox enchantment; private final JCheckBox enchantment;
// Very handy for classes using mass operations on an array of checkboxes // Very handy for classes using mass operations on an array of checkboxes
/** The all colors. */ /** The all colors. */
public final List<JCheckBox> allColors; private final List<JCheckBox> allColors;
/** The all types. */ /** The all types. */
public final List<JCheckBox> allTypes; private final List<JCheckBox> allTypes;
/** /**
* Instantiates a new filter check boxes. * Instantiates a new filter check boxes.
@@ -71,40 +71,41 @@ class FilterCheckBoxes {
*/ */
public FilterCheckBoxes(final boolean useGraphicalBoxes) { public FilterCheckBoxes(final boolean useGraphicalBoxes) {
if (useGraphicalBoxes) { if (useGraphicalBoxes) {
white = new CheckBoxWithIcon("white", "White"); this.white = new CheckBoxWithIcon("white", "White");
blue = new CheckBoxWithIcon("blue", "Blue"); this.blue = new CheckBoxWithIcon("blue", "Blue");
black = new CheckBoxWithIcon("black", "Black"); this.black = new CheckBoxWithIcon("black", "Black");
red = new CheckBoxWithIcon("red", "Red"); this.red = new CheckBoxWithIcon("red", "Red");
green = new CheckBoxWithIcon("green", "Green"); this.green = new CheckBoxWithIcon("green", "Green");
colorless = new CheckBoxWithIcon("colorless", "Colorless"); this.colorless = new CheckBoxWithIcon("colorless", "Colorless");
land = new CheckBoxWithIcon("land", "Land"); this.land = new CheckBoxWithIcon("land", "Land");
creature = new CheckBoxWithIcon("creature", "Creature"); this.creature = new CheckBoxWithIcon("creature", "Creature");
sorcery = new CheckBoxWithIcon("sorcery", "Sorcery"); this.sorcery = new CheckBoxWithIcon("sorcery", "Sorcery");
instant = new CheckBoxWithIcon("instant", "Instant"); this.instant = new CheckBoxWithIcon("instant", "Instant");
planeswalker = new CheckBoxWithIcon("planeswalker", "Planeswalker"); this.planeswalker = new CheckBoxWithIcon("planeswalker", "Planeswalker");
artifact = new CheckBoxWithIcon("artifact", "Artifact"); this.artifact = new CheckBoxWithIcon("artifact", "Artifact");
enchantment = new CheckBoxWithIcon("enchant", "Enchantment"); this.enchantment = new CheckBoxWithIcon("enchant", "Enchantment");
} else { } else {
white = new JCheckBox("W", true); this.white = new JCheckBox("W", true);
blue = new JCheckBox("U", true); this.blue = new JCheckBox("U", true);
black = new JCheckBox("B", true); this.black = new JCheckBox("B", true);
red = new JCheckBox("R", true); this.red = new JCheckBox("R", true);
green = new JCheckBox("G", true); this.green = new JCheckBox("G", true);
colorless = new JCheckBox("C", true); this.colorless = new JCheckBox("C", true);
land = new JCheckBox("Land", true); this.land = new JCheckBox("Land", true);
creature = new JCheckBox("Creature", true); this.creature = new JCheckBox("Creature", true);
sorcery = new JCheckBox("Sorcery", true); this.sorcery = new JCheckBox("Sorcery", true);
instant = new JCheckBox("Instant", true); this.instant = new JCheckBox("Instant", true);
planeswalker = new JCheckBox("Planeswalker", true); this.planeswalker = new JCheckBox("Planeswalker", true);
artifact = new JCheckBox("Artifact", true); this.artifact = new JCheckBox("Artifact", true);
enchantment = new JCheckBox("Enchant", true); this.enchantment = new JCheckBox("Enchant", true);
} }
allColors = Arrays.asList(new JCheckBox[] { white, blue, black, red, green, colorless }); this.allColors = Arrays.asList(new JCheckBox[] { this.getWhite(), this.getBlue(), this.getBlack(), this.getRed(), this.getGreen(),
allTypes = Arrays.asList(new JCheckBox[] { land, creature, sorcery, instant, planeswalker, artifact, this.getColorless() });
enchantment }); this.allTypes = Arrays.asList(new JCheckBox[] { this.getLand(), this.getCreature(), this.getSorcery(), this.getInstant(),
this.getPlaneswalker(), this.getArtifact(), this.getEnchantment() });
} }
/** /**
@@ -113,54 +114,159 @@ class FilterCheckBoxes {
* @return the predicate * @return the predicate
*/ */
public final Predicate<CardPrinted> buildFilter() { public final Predicate<CardPrinted> buildFilter() {
List<Predicate<CardRules>> colors = new ArrayList<Predicate<CardRules>>(); final List<Predicate<CardRules>> colors = new ArrayList<Predicate<CardRules>>();
if (white.isSelected()) { if (this.getWhite().isSelected()) {
colors.add(CardRules.Predicates.Presets.IS_WHITE); colors.add(CardRules.Predicates.Presets.IS_WHITE);
} }
if (blue.isSelected()) { if (this.getBlue().isSelected()) {
colors.add(CardRules.Predicates.Presets.IS_BLUE); colors.add(CardRules.Predicates.Presets.IS_BLUE);
} }
if (black.isSelected()) { if (this.getBlack().isSelected()) {
colors.add(CardRules.Predicates.Presets.IS_BLACK); colors.add(CardRules.Predicates.Presets.IS_BLACK);
} }
if (red.isSelected()) { if (this.getRed().isSelected()) {
colors.add(CardRules.Predicates.Presets.IS_RED); colors.add(CardRules.Predicates.Presets.IS_RED);
} }
if (green.isSelected()) { if (this.getGreen().isSelected()) {
colors.add(CardRules.Predicates.Presets.IS_GREEN); colors.add(CardRules.Predicates.Presets.IS_GREEN);
} }
if (colorless.isSelected()) { if (this.getColorless().isSelected()) {
colors.add(CardRules.Predicates.Presets.IS_COLORLESS); colors.add(CardRules.Predicates.Presets.IS_COLORLESS);
} }
Predicate<CardRules> filterByColor = colors.size() == 6 ? CardRules.Predicates.Presets.CONSTANT_TRUE : Predicate final Predicate<CardRules> filterByColor = colors.size() == 6 ? CardRules.Predicates.Presets.CONSTANT_TRUE
.or(colors); : Predicate.or(colors);
List<Predicate<CardRules>> types = new ArrayList<Predicate<CardRules>>(); final List<Predicate<CardRules>> types = new ArrayList<Predicate<CardRules>>();
if (land.isSelected()) { if (this.getLand().isSelected()) {
types.add(CardRules.Predicates.Presets.IS_LAND); types.add(CardRules.Predicates.Presets.IS_LAND);
} }
if (creature.isSelected()) { if (this.getCreature().isSelected()) {
types.add(CardRules.Predicates.Presets.IS_CREATURE); types.add(CardRules.Predicates.Presets.IS_CREATURE);
} }
if (sorcery.isSelected()) { if (this.getSorcery().isSelected()) {
types.add(CardRules.Predicates.Presets.IS_SORCERY); types.add(CardRules.Predicates.Presets.IS_SORCERY);
} }
if (instant.isSelected()) { if (this.getInstant().isSelected()) {
types.add(CardRules.Predicates.Presets.IS_INSTANT); types.add(CardRules.Predicates.Presets.IS_INSTANT);
} }
if (planeswalker.isSelected()) { if (this.getPlaneswalker().isSelected()) {
types.add(CardRules.Predicates.Presets.IS_PLANESWALKER); types.add(CardRules.Predicates.Presets.IS_PLANESWALKER);
} }
if (artifact.isSelected()) { if (this.getArtifact().isSelected()) {
types.add(CardRules.Predicates.Presets.IS_ARTIFACT); types.add(CardRules.Predicates.Presets.IS_ARTIFACT);
} }
if (enchantment.isSelected()) { if (this.getEnchantment().isSelected()) {
types.add(CardRules.Predicates.Presets.IS_ENCHANTMENT); types.add(CardRules.Predicates.Presets.IS_ENCHANTMENT);
} }
Predicate<CardRules> filterByType = types.size() == 7 ? CardRules.Predicates.Presets.CONSTANT_TRUE : Predicate final Predicate<CardRules> filterByType = types.size() == 7 ? CardRules.Predicates.Presets.CONSTANT_TRUE
.or(types); : Predicate.or(types);
return Predicate.brigde(Predicate.and(filterByColor, filterByType), CardPrinted.fnGetRules); return Predicate.brigde(Predicate.and(filterByColor, filterByType), CardPrinted.fnGetRules);
} }
/**
* @return the allTypes
*/
public List<JCheckBox> getAllTypes() {
return allTypes;
}
/**
* @return the white
*/
public JCheckBox getWhite() {
return white;
}
/**
* @return the blue
*/
public JCheckBox getBlue() {
return blue;
}
/**
* @return the black
*/
public JCheckBox getBlack() {
return black;
}
/**
* @return the red
*/
public JCheckBox getRed() {
return red;
}
/**
* @return the colorless
*/
public JCheckBox getColorless() {
return colorless;
}
/**
* @return the green
*/
public JCheckBox getGreen() {
return green;
}
/**
* @return the land
*/
public JCheckBox getLand() {
return land;
}
/**
* @return the allColors
*/
public List<JCheckBox> getAllColors() {
return allColors;
}
/**
* @return the creature
*/
public JCheckBox getCreature() {
return creature;
}
/**
* @return the sorcery
*/
public JCheckBox getSorcery() {
return sorcery;
}
/**
* @return the instant
*/
public JCheckBox getInstant() {
return instant;
}
/**
* @return the planeswalker
*/
public JCheckBox getPlaneswalker() {
return planeswalker;
}
/**
* @return the artifact
*/
public JCheckBox getArtifact() {
return artifact;
}
/**
* @return the enchantment
*/
public JCheckBox getEnchantment() {
return enchantment;
}
} }

View File

@@ -31,25 +31,25 @@ public class FilterNameTypeSetPanel extends JComponent {
private static final long serialVersionUID = -6409564625432765430L; private static final long serialVersionUID = -6409564625432765430L;
/** The label filter name. */ /** The label filter name. */
public final JLabel labelFilterName = new JLabel(); private final JLabel labelFilterName = new JLabel();
/** The label filter type. */ /** The label filter type. */
public final JLabel labelFilterType = new JLabel(); private final JLabel labelFilterType = new JLabel();
/** The label filter rules. */ /** The label filter rules. */
public final JLabel labelFilterRules = new JLabel(); private final JLabel labelFilterRules = new JLabel();
/** The txt card name. */ /** The txt card name. */
public final JTextField txtCardName = new JTextField(); private final JTextField txtCardName = new JTextField();
/** The txt card type. */ /** The txt card type. */
public final JTextField txtCardType = new JTextField(); private final JTextField txtCardType = new JTextField();
/** The txt card rules. */ /** The txt card rules. */
public final JTextField txtCardRules = new JTextField(); private final JTextField txtCardRules = new JTextField();
/** The search set combo. */ /** The search set combo. */
public final JComboBox searchSetCombo = new JComboBox(); private final JComboBox searchSetCombo = new JComboBox();
/** /**
* Instantiates a new filter name type set panel. * Instantiates a new filter name type set panel.
@@ -57,31 +57,31 @@ public class FilterNameTypeSetPanel extends JComponent {
public FilterNameTypeSetPanel() { public FilterNameTypeSetPanel() {
this.setLayout(new MigLayout("fill, ins 0")); this.setLayout(new MigLayout("fill, ins 0"));
labelFilterName.setText("Name:"); this.labelFilterName.setText("Name:");
labelFilterName.setToolTipText("Card names must include the text in this field"); this.labelFilterName.setToolTipText("Card names must include the text in this field");
this.add(labelFilterName, "cell 0 1, split 7"); this.add(this.labelFilterName, "cell 0 1, split 7");
this.add(txtCardName, "wmin 100, grow"); this.add(this.txtCardName, "wmin 100, grow");
labelFilterType.setText("Type:"); this.labelFilterType.setText("Type:");
labelFilterType.setToolTipText("Card types must include the text in this field"); this.labelFilterType.setToolTipText("Card types must include the text in this field");
this.add(labelFilterType, ""); this.add(this.labelFilterType, "");
this.add(txtCardType, "wmin 100, grow"); this.add(this.txtCardType, "wmin 100, grow");
labelFilterRules.setText("Text:"); this.labelFilterRules.setText("Text:");
labelFilterRules.setToolTipText("Card descriptions must include the text in this field"); this.labelFilterRules.setToolTipText("Card descriptions must include the text in this field");
this.add(labelFilterRules, ""); this.add(this.labelFilterRules, "");
this.add(txtCardRules, "wmin 200, grow"); this.add(this.txtCardRules, "wmin 200, grow");
searchSetCombo.removeAllItems(); this.searchSetCombo.removeAllItems();
searchSetCombo.addItem("(all sets and formats)"); this.searchSetCombo.addItem("(all sets and formats)");
for (GameFormat s : SetUtils.getFormats()) { for (final GameFormat s : SetUtils.getFormats()) {
searchSetCombo.addItem(s); this.searchSetCombo.addItem(s);
} }
for (CardSet s : SetUtils.getAllSets()) { for (final CardSet s : SetUtils.getAllSets()) {
searchSetCombo.addItem(s); this.searchSetCombo.addItem(s);
} }
this.add(searchSetCombo, "wmin 150, grow"); this.add(this.searchSetCombo, "wmin 150, grow");
} }
/** /**
@@ -93,10 +93,10 @@ public class FilterNameTypeSetPanel extends JComponent {
* the on combo change * the on combo change
*/ */
public final void setListeners(final DocumentListener onTextChange, final ItemListener onComboChange) { public final void setListeners(final DocumentListener onTextChange, final ItemListener onComboChange) {
txtCardType.getDocument().addDocumentListener(onTextChange); this.txtCardType.getDocument().addDocumentListener(onTextChange);
txtCardRules.getDocument().addDocumentListener(onTextChange); this.txtCardRules.getDocument().addDocumentListener(onTextChange);
txtCardName.getDocument().addDocumentListener(onTextChange); this.txtCardName.getDocument().addDocumentListener(onTextChange);
searchSetCombo.addItemListener(onComboChange); this.searchSetCombo.addItemListener(onComboChange);
} }
/** /**
@@ -105,23 +105,23 @@ public class FilterNameTypeSetPanel extends JComponent {
* @return the predicate * @return the predicate
*/ */
public final Predicate<CardPrinted> buildFilter() { public final Predicate<CardPrinted> buildFilter() {
List<Predicate<CardPrinted>> rules = new ArrayList<Predicate<CardPrinted>>(4); final List<Predicate<CardPrinted>> rules = new ArrayList<Predicate<CardPrinted>>(4);
if (StringUtils.isNotBlank(txtCardName.getText())) { if (StringUtils.isNotBlank(this.txtCardName.getText())) {
rules.add(CardPrinted.Predicates.name(StringOp.CONTAINS, txtCardName.getText())); rules.add(CardPrinted.Predicates.name(StringOp.CONTAINS, this.txtCardName.getText()));
} }
if (StringUtils.isNotBlank(txtCardType.getText())) { if (StringUtils.isNotBlank(this.txtCardType.getText())) {
rules.add(Predicate.brigde(CardRules.Predicates.joinedType(StringOp.CONTAINS, txtCardType.getText()), rules.add(Predicate.brigde(CardRules.Predicates.joinedType(StringOp.CONTAINS, this.txtCardType.getText()),
CardPrinted.fnGetRules)); CardPrinted.fnGetRules));
} }
if (StringUtils.isNotBlank(txtCardRules.getText())) { if (StringUtils.isNotBlank(this.txtCardRules.getText())) {
rules.add(Predicate.brigde(CardRules.Predicates.rules(StringOp.CONTAINS, txtCardRules.getText()), rules.add(Predicate.brigde(CardRules.Predicates.rules(StringOp.CONTAINS, this.txtCardRules.getText()),
CardPrinted.fnGetRules)); CardPrinted.fnGetRules));
} }
if (searchSetCombo.getSelectedIndex() != 0) { if (this.searchSetCombo.getSelectedIndex() != 0) {
Object selected = searchSetCombo.getSelectedItem(); final Object selected = this.searchSetCombo.getSelectedItem();
if (selected instanceof CardSet) { if (selected instanceof CardSet) {
rules.add(CardPrinted.Predicates.printedInSets(((CardSet) selected).getCode())); rules.add(CardPrinted.Predicates.printedInSets(((CardSet) selected).getCode()));
} else if (selected instanceof GameFormat) { } else if (selected instanceof GameFormat) {
@@ -145,9 +145,9 @@ public class FilterNameTypeSetPanel extends JComponent {
* TODO: Write javadoc for this method. * TODO: Write javadoc for this method.
*/ */
public final void clearFilters() { public final void clearFilters() {
txtCardName.setText(""); this.txtCardName.setText("");
txtCardType.setText(""); this.txtCardType.setText("");
txtCardRules.setText(""); this.txtCardRules.setText("");
searchSetCombo.setSelectedIndex(0); this.searchSetCombo.setSelectedIndex(0);
} }
} }

View File

@@ -27,10 +27,10 @@ public class ManaCostRenderer extends DefaultTableCellRenderer {
* (javax.swing.JTable, java.lang.Object, boolean, boolean, int, int) * (javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
*/ */
@Override @Override
public final Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, public final Component getTableCellRendererComponent(final JTable table, final Object value,
final boolean hasFocus, final int row, final int column) { final boolean isSelected, final boolean hasFocus, final int row, final int column) {
this.value = (CardManaCost) value; this.value = (CardManaCost) value;
setToolTipText(this.value.toString()); this.setToolTipText(this.value.toString());
return super.getTableCellRendererComponent(table, "", isSelected, hasFocus, row, column); return super.getTableCellRendererComponent(table, "", isSelected, hasFocus, row, column);
} }
@@ -49,23 +49,23 @@ public class ManaCostRenderer extends DefaultTableCellRenderer {
float xpos = padding; float xpos = padding;
int genericManaCost = value.getGenericCost(); final int genericManaCost = this.value.getGenericCost();
boolean hasGeneric = genericManaCost > 0 || value.isPureGeneric(); final boolean hasGeneric = (genericManaCost > 0) || this.value.isPureGeneric();
List<CardManaCostShard> shards = value.getShards(); final List<CardManaCostShard> shards = this.value.getShards();
int cellWidth = getWidth(); final int cellWidth = this.getWidth();
int cntGlyphs = hasGeneric ? shards.size() + 1 : shards.size(); final int cntGlyphs = hasGeneric ? shards.size() + 1 : shards.size();
float offsetIfNoSpace = cntGlyphs > 1 ? (cellWidth - padding - elemtWidth) / (cntGlyphs - 1f) : elemtWidth final float offsetIfNoSpace = cntGlyphs > 1 ? (cellWidth - padding - elemtWidth) / (cntGlyphs - 1f)
+ elemtGap; : elemtWidth + elemtGap;
float offset = Math.min(elemtWidth + elemtGap, offsetIfNoSpace); final float offset = Math.min(elemtWidth + elemtGap, offsetIfNoSpace);
if (hasGeneric) { if (hasGeneric) {
String sGeneric = Integer.toString(genericManaCost); final String sGeneric = Integer.toString(genericManaCost);
ManaSymbols.drawSymbol(sGeneric, g, (int) xpos, 1); ManaSymbols.drawSymbol(sGeneric, g, (int) xpos, 1);
xpos += offset; xpos += offset;
} }
for (CardManaCostShard s : shards) { for (final CardManaCostShard s : shards) {
ManaSymbols.drawSymbol(s.getImageKey(), g, (int) xpos, 1); ManaSymbols.drawSymbol(s.getImageKey(), g, (int) xpos, 1);
xpos += offset; xpos += offset;
} }

View File

@@ -20,24 +20,24 @@ public class TableColumnInfo<T> {
private final String name; private final String name;
/** The min width. */ /** The min width. */
public int minWidth; private int minWidth;
/** The max width. */ /** The max width. */
public int maxWidth; private int maxWidth;
/** The nominal width. */ /** The nominal width. */
public int nominalWidth; private int nominalWidth;
/** The is min max applied. */ /** The is min max applied. */
public boolean isMinMaxApplied = true; private boolean isMinMaxApplied = true;
/** The fn sort. */ /** The fn sort. */
public final Lambda1<Comparable, Entry<T, Integer>> fnSort; // this will be private final Lambda1<Comparable, Entry<T, Integer>> fnSort; // this will be
// used for // used for
// sorting // sorting
/** The fn display. */ /** The fn display. */
public final Lambda1<Object, Entry<T, Integer>> fnDisplay; // this is used private final Lambda1<Object, Entry<T, Integer>> fnDisplay; // this is used
// to display // to display
private TableCellRenderer cellRenderer = null; private TableCellRenderer cellRenderer = null;
@@ -48,7 +48,7 @@ public class TableColumnInfo<T> {
* @return the name * @return the name
*/ */
public final String getName() { public final String getName() {
return name; return this.name;
} }
/** /**
@@ -63,8 +63,8 @@ public class TableColumnInfo<T> {
*/ */
public TableColumnInfo(final String colName, final Lambda1<Comparable, Entry<T, Integer>> fieldSort, public TableColumnInfo(final String colName, final Lambda1<Comparable, Entry<T, Integer>> fieldSort,
final Lambda1<Object, Entry<T, Integer>> fieldDisplay) { final Lambda1<Object, Entry<T, Integer>> fieldDisplay) {
fnSort = fieldSort; this.fnSort = fieldSort;
fnDisplay = fieldDisplay; this.fnDisplay = fieldDisplay;
this.name = colName; this.name = colName;
} }
@@ -84,9 +84,9 @@ public class TableColumnInfo<T> {
final Lambda1<Comparable, Entry<T, Integer>> fieldSort, final Lambda1<Comparable, Entry<T, Integer>> fieldSort,
final Lambda1<Object, Entry<T, Integer>> fieldDisplay) { final Lambda1<Object, Entry<T, Integer>> fieldDisplay) {
this(colName, fieldSort, fieldDisplay); this(colName, fieldSort, fieldDisplay);
this.maxWidth = width; this.setMaxWidth(width);
this.minWidth = width; this.setMinWidth(width);
this.nominalWidth = width; this.setNominalWidth(width);
} }
/** /**
@@ -109,9 +109,9 @@ public class TableColumnInfo<T> {
final Lambda1<Comparable, Entry<T, Integer>> fieldSort, final Lambda1<Comparable, Entry<T, Integer>> fieldSort,
final Lambda1<Object, Entry<T, Integer>> fieldDisplay) { final Lambda1<Object, Entry<T, Integer>> fieldDisplay) {
this(colName, fieldSort, fieldDisplay); this(colName, fieldSort, fieldDisplay);
this.maxWidth = wMax; this.setMaxWidth(wMax);
this.minWidth = wMin; this.setMinWidth(wMin);
this.nominalWidth = width; this.setNominalWidth(width);
} }
/** /**
@@ -121,7 +121,7 @@ public class TableColumnInfo<T> {
* the new cell renderer * the new cell renderer
*/ */
public final void setCellRenderer(final TableCellRenderer renderer) { public final void setCellRenderer(final TableCellRenderer renderer) {
cellRenderer = renderer; this.cellRenderer = renderer;
} }
/** /**
@@ -130,6 +130,76 @@ public class TableColumnInfo<T> {
* @return the cell renderer * @return the cell renderer
*/ */
public final TableCellRenderer getCellRenderer() { public final TableCellRenderer getCellRenderer() {
return cellRenderer; return this.cellRenderer;
}
/**
* @return the minWidth
*/
public int getMinWidth() {
return minWidth;
}
/**
* @param minWidth the minWidth to set
*/
public void setMinWidth(int minWidth) {
this.minWidth = minWidth; // TODO: Add 0 to parameter's name.
}
/**
* @return the maxWidth
*/
public int getMaxWidth() {
return maxWidth;
}
/**
* @param maxWidth the maxWidth to set
*/
public void setMaxWidth(int maxWidth) {
this.maxWidth = maxWidth; // TODO: Add 0 to parameter's name.
}
/**
* @return the nominalWidth
*/
public int getNominalWidth() {
return nominalWidth;
}
/**
* @param nominalWidth the nominalWidth to set
*/
public void setNominalWidth(int nominalWidth) {
this.nominalWidth = nominalWidth; // TODO: Add 0 to parameter's name.
}
/**
* @return the isMinMaxApplied
*/
public boolean isMinMaxApplied() {
return isMinMaxApplied;
}
/**
* @param isMinMaxApplied the isMinMaxApplied to set
*/
public void setMinMaxApplied(boolean isMinMaxApplied) {
this.isMinMaxApplied = isMinMaxApplied; // TODO: Add 0 to parameter's name.
}
/**
* @return the fnSort
*/
public Lambda1<Comparable, Entry<T, Integer>> getFnSort() {
return fnSort;
}
/**
* @return the fnDisplay
*/
public Lambda1<Object, Entry<T, Integer>> getFnDisplay() {
return fnDisplay;
} }
} }

View File

@@ -39,23 +39,23 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
private final class SortOrders { private final class SortOrders {
private class Order { private class Order {
public final int sortColumn; private final int sortColumn;
public boolean isSortAsc = true; private boolean isSortAsc = true;
public Order(final int col) { public Order(final int col) {
sortColumn = col; this.sortColumn = col;
} }
}; };
private final int MAX_DEPTH = 3; private final int maxDepth = 3;
private List<Order> orders = new ArrayList<Order>(3); private final List<Order> orders = new ArrayList<Order>(3);
private TableSorterCascade<T> sorter = null; private TableSorterCascade<T> sorter = null;
private boolean isSorterReady = false; private boolean isSorterReady = false;
private int indexOfColumn(final int column) { private int indexOfColumn(final int column) {
int posColumn = orders.size() - 1; int posColumn = this.orders.size() - 1;
for (; posColumn >= 0; posColumn--) { for (; posColumn >= 0; posColumn--) {
if (orders.get(posColumn) != null && orders.get(posColumn).sortColumn == column) { if ((this.orders.get(posColumn) != null) && (this.orders.get(posColumn).sortColumn == column)) {
break; break;
} }
} }
@@ -64,47 +64,48 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
// index of column to sort by, desired direction // index of column to sort by, desired direction
public void add(final int column, final boolean wantAsc) { public void add(final int column, final boolean wantAsc) {
add(column); this.add(column);
orders.get(0).isSortAsc = wantAsc; this.orders.get(0).isSortAsc = wantAsc;
isSorterReady = false; this.isSorterReady = false;
} }
// puts desired direction on top, set "asc"; if already was on top, // puts desired direction on top, set "asc"; if already was on top,
// inverts direction; // inverts direction;
public void add(final int column) { public void add(final int column) {
int posColumn = indexOfColumn(column); final int posColumn = this.indexOfColumn(column);
switch (posColumn) { switch (posColumn) {
case -1: // no such column here - let's add then case -1: // no such column here - let's add then
orders.add(0, new Order(column)); this.orders.add(0, new Order(column));
break; break;
case 0: // found at top-level, should invert case 0: // found at top-level, should invert
orders.get(0).isSortAsc ^= true; // invert this.orders.get(0).isSortAsc ^= true; // invert
break; break;
default: // found somewhere, move down others, set this one onto default: // found somewhere, move down others, set this one onto
// top; // top;
orders.remove(posColumn); this.orders.remove(posColumn);
orders.add(0, new Order(column)); this.orders.add(0, new Order(column));
break; break;
} }
if (orders.size() > MAX_DEPTH) { if (this.orders.size() > this.maxDepth) {
orders.remove(MAX_DEPTH); this.orders.remove(this.maxDepth);
} }
isSorterReady = false; this.isSorterReady = false;
} }
public TableSorterCascade<T> getSorter() { public TableSorterCascade<T> getSorter() {
if (!isSorterReady) { if (!this.isSorterReady) {
List<TableSorter<T>> oneColSorters = new ArrayList<TableSorter<T>>(MAX_DEPTH); final List<TableSorter<T>> oneColSorters = new ArrayList<TableSorter<T>>(this.maxDepth);
for (Order order : orders) { for (final Order order : this.orders) {
oneColSorters.add(new TableSorter<T>(columns.get(order.sortColumn).fnSort, order.isSortAsc)); oneColSorters.add(new TableSorter<T>(TableModel.this.columns.get(order.sortColumn).getFnSort(),
order.isSortAsc));
} }
sorter = new TableSorterCascade<T>(oneColSorters); this.sorter = new TableSorterCascade<T>(oneColSorters);
} }
return sorter; return this.sorter;
} }
} }
private ItemPool<T> data; private final ItemPool<T> data;
private final CardPanelBase cardDisplay; private final CardPanelBase cardDisplay;
private final List<TableColumnInfo<T>> columns; private final List<TableColumnInfo<T>> columns;
private final SortOrders sortOrders = new SortOrders(); private final SortOrders sortOrders = new SortOrders();
@@ -120,10 +121,10 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* the cls * the cls
*/ */
public TableModel(final CardPanelBase cd, final List<TableColumnInfo<T>> columnsToShow, final Class<T> cls) { public TableModel(final CardPanelBase cd, final List<TableColumnInfo<T>> columnsToShow, final Class<T> cls) {
data = new ItemPool<T>(cls); this.data = new ItemPool<T>(cls);
cardDisplay = cd; this.cardDisplay = cd;
columns = columnsToShow; this.columns = columnsToShow;
columns.get(4).isMinMaxApplied = false; this.columns.get(4).setMinMaxApplied(false);
} }
/** /**
@@ -136,12 +137,12 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
TableColumn tableColumn = null; TableColumn tableColumn = null;
for (int i = 0; i < table.getColumnCount(); i++) { for (int i = 0; i < table.getColumnCount(); i++) {
tableColumn = table.getColumnModel().getColumn(i); tableColumn = table.getColumnModel().getColumn(i);
TableColumnInfo<T> colInfo = columns.get(i); final TableColumnInfo<T> colInfo = this.columns.get(i);
tableColumn.setPreferredWidth(colInfo.nominalWidth); tableColumn.setPreferredWidth(colInfo.getNominalWidth());
if (colInfo.isMinMaxApplied) { if (colInfo.isMinMaxApplied()) {
tableColumn.setMinWidth(colInfo.minWidth); tableColumn.setMinWidth(colInfo.getMinWidth());
tableColumn.setMaxWidth(colInfo.maxWidth); tableColumn.setMaxWidth(colInfo.getMaxWidth());
} }
} }
} }
@@ -150,7 +151,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* Clear. * Clear.
*/ */
public void clear() { public void clear() {
data.clear(); this.data.clear();
} }
/** /**
@@ -159,7 +160,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* @return the cards * @return the cards
*/ */
public ItemPoolView<T> getCards() { public ItemPoolView<T> getCards() {
return data.getView(); return this.data.getView();
} }
/** /**
@@ -171,10 +172,10 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* a {@link forge.Card} object. * a {@link forge.Card} object.
*/ */
public void removeCard(final T c) { public void removeCard(final T c) {
boolean wasThere = data.count(c) > 0; final boolean wasThere = this.data.count(c) > 0;
if (wasThere) { if (wasThere) {
data.remove(c); this.data.remove(c);
fireTableDataChanged(); this.fireTableDataChanged();
} }
} }
@@ -185,8 +186,8 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* the c * the c
*/ */
public void addCard(final T c) { public void addCard(final T c) {
data.add(c); this.data.add(c);
fireTableDataChanged(); this.fireTableDataChanged();
} }
/** /**
@@ -198,8 +199,8 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* the count * the count
*/ */
public void addCard(final T c, final int count) { public void addCard(final T c, final int count) {
data.add(c, count); this.data.add(c, count);
fireTableDataChanged(); this.fireTableDataChanged();
} }
/** /**
@@ -209,8 +210,8 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* the e * the e
*/ */
public void addCard(final Entry<T, Integer> e) { public void addCard(final Entry<T, Integer> e) {
data.add(e.getKey(), e.getValue()); this.data.add(e.getKey(), e.getValue());
fireTableDataChanged(); this.fireTableDataChanged();
} }
/** /**
@@ -220,8 +221,8 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* the c * the c
*/ */
public void addCards(final Iterable<Entry<T, Integer>> c) { public void addCards(final Iterable<Entry<T, Integer>> c) {
data.addAll(c); this.data.addAll(c);
fireTableDataChanged(); this.fireTableDataChanged();
} }
/** /**
@@ -231,8 +232,8 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* the c * the c
*/ */
public void addAllCards(final Iterable<T> c) { public void addAllCards(final Iterable<T> c) {
data.addAllCards(c); this.data.addAllCards(c);
fireTableDataChanged(); this.fireTableDataChanged();
} }
/** /**
@@ -243,8 +244,8 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* @return the entry * @return the entry
*/ */
public Entry<T, Integer> rowToCard(final int row) { public Entry<T, Integer> rowToCard(final int row) {
List<Entry<T, Integer>> model = data.getOrderedList(); final List<Entry<T, Integer>> model = this.data.getOrderedList();
return row >= 0 && row < model.size() ? model.get(row) : null; return (row >= 0) && (row < model.size()) ? model.get(row) : null;
} }
/* /*
@@ -253,10 +254,13 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* @see javax.swing.table.TableModel#getRowCount() * @see javax.swing.table.TableModel#getRowCount()
*/ */
/** /**
* Gets the row count.
*
* @return int * @return int
*/ */
@Override
public int getRowCount() { public int getRowCount() {
return data.countDistinct(); return this.data.countDistinct();
} }
/* /*
@@ -265,36 +269,40 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* @see javax.swing.table.TableModel#getColumnCount() * @see javax.swing.table.TableModel#getColumnCount()
*/ */
/** /**
* Gets the column count.
*
* @return int * @return int
*/ */
@Override
public int getColumnCount() { public int getColumnCount() {
return columns.size(); return this.columns.size();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public String getColumnName(final int n) { public String getColumnName(final int n) {
return columns.get(n).getName(); return this.columns.get(n).getName();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Object getValueAt(final int row, final int column) { public Object getValueAt(final int row, final int column) {
return columns.get(column).fnDisplay.apply(rowToCard(row)); return this.columns.get(column).getFnDisplay().apply(this.rowToCard(row));
} }
/** /**
* The listener interface for receiving column events. The class that is * The listener interface for receiving column events. The class that is
* interested in processing a column event implements this interface, and * interested in processing a column event implements this interface, and
* the object created with that class is registered with a component using * the object created with that class is registered with a component using
* the component's addColumnListener method. When * the component's addColumnListener method. When the column event occurs,
* the column event occurs, that object's appropriate * that object's appropriate method is invoked.
* method is invoked. *
* * @see ColumnEvent
*/ */
class ColumnListener extends MouseAdapter { class ColumnListener extends MouseAdapter {
/** The table. */ /** The table. */
protected JTable table; private JTable table;
/** /**
* Instantiates a new column listener. * Instantiates a new column listener.
@@ -303,7 +311,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* the t * the t
*/ */
public ColumnListener(final JTable t) { public ColumnListener(final JTable t) {
table = t; this.table = t;
} }
/* /*
@@ -313,29 +321,32 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent) * java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
*/ */
/** /**
* Mouse clicked.
*
* @param e MouseEvent * @param e MouseEvent
*/ */
@Override
public void mouseClicked(final MouseEvent e) { public void mouseClicked(final MouseEvent e) {
TableColumnModel colModel = table.getColumnModel(); final TableColumnModel colModel = this.table.getColumnModel();
int columnModelIndex = colModel.getColumnIndexAtX(e.getX()); final int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex(); final int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
if (modelIndex < 0) { if (modelIndex < 0) {
return; return;
} }
// This will invert if needed // This will invert if needed
sortOrders.add(modelIndex); TableModel.this.sortOrders.add(modelIndex);
for (int i = 0; i < columns.size(); i++) { for (int i = 0; i < TableModel.this.columns.size(); i++) {
TableColumn column = colModel.getColumn(i); final TableColumn column = colModel.getColumn(i);
column.setHeaderValue(getColumnName(column.getModelIndex())); column.setHeaderValue(TableModel.this.getColumnName(column.getModelIndex()));
} }
table.getTableHeader().repaint(); this.table.getTableHeader().repaint();
resort(); TableModel.this.resort();
table.tableChanged(new TableModelEvent(TableModel.this)); this.table.tableChanged(new TableModelEvent(TableModel.this));
table.repaint(); this.table.repaint();
} }
} }
@@ -346,10 +357,10 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* the table * the table
*/ */
public void showSelectedCard(final JTable table) { public void showSelectedCard(final JTable table) {
int row = table.getSelectedRow(); final int row = table.getSelectedRow();
if (row != -1) { if (row != -1) {
T cp = rowToCard(row).getKey(); final T cp = this.rowToCard(row).getKey();
cardDisplay.showCard(cp); this.cardDisplay.showCard(cp);
} }
} }
@@ -367,7 +378,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
@Override @Override
public void valueChanged(final ListSelectionEvent arg0) { public void valueChanged(final ListSelectionEvent arg0) {
showSelectedCard(table); TableModel.this.showSelectedCard(table);
} }
}); });
table.addFocusListener(new FocusListener() { table.addFocusListener(new FocusListener() {
@@ -378,7 +389,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
@Override @Override
public void focusGained(final FocusEvent e) { public void focusGained(final FocusEvent e) {
showSelectedCard(table); TableModel.this.showSelectedCard(table);
} }
}); });
@@ -390,7 +401,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* Resort. * Resort.
*/ */
public void resort() { public void resort() {
Collections.sort(data.getOrderedList(), sortOrders.getSorter()); Collections.sort(this.data.getOrderedList(), this.sortOrders.getSorter());
} }
/** /**
@@ -402,8 +413,8 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
* the is asc * the is asc
*/ */
public void sort(final int iCol, final boolean isAsc) { public void sort(final int iCol, final boolean isAsc) {
sortOrders.add(iCol, isAsc); this.sortOrders.add(iCol, isAsc);
resort(); this.resort();
} }
} // CardTableModel } // CardTableModel

View File

@@ -19,9 +19,9 @@ import forge.item.CardPrinted;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
// Comparable needs <type> // Comparable needs <type>
public class TableSorter<T> implements Comparator<Entry<T, Integer>> { public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
private boolean ascending; private final boolean ascending;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private Lambda1<Comparable, Entry<T, Integer>> field; private final Lambda1<Comparable, Entry<T, Integer>> field;
/** /**
* <p> * <p>
@@ -30,18 +30,18 @@ public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
* *
* @param field * @param field
* the field * the field
* @param in_ascending * @param inAscending
* a boolean. * a boolean.
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public TableSorter(final Lambda1<Comparable, Entry<T, Integer>> field, final boolean in_ascending) { public TableSorter(final Lambda1<Comparable, Entry<T, Integer>> field, final boolean inAscending) {
this.field = field; this.field = field;
ascending = in_ascending; this.ascending = inAscending;
} }
/** The Constant byNameThenSet. */ /** The Constant byNameThenSet. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static final TableSorter<CardPrinted> byNameThenSet = new TableSorter<CardPrinted>( public static final TableSorter<CardPrinted> BY_NAME_THEN_SET = new TableSorter<CardPrinted>(
new Lambda1<Comparable, Entry<CardPrinted, Integer>>() { new Lambda1<Comparable, Entry<CardPrinted, Integer>>() {
@Override @Override
public Comparable apply(final Entry<CardPrinted, Integer> from) { public Comparable apply(final Entry<CardPrinted, Integer> from) {
@@ -57,10 +57,10 @@ public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public final int compare(final Entry<T, Integer> arg0, final Entry<T, Integer> arg1) { public final int compare(final Entry<T, Integer> arg0, final Entry<T, Integer> arg1) {
Comparable obj1 = field.apply(arg0); final Comparable obj1 = this.field.apply(arg0);
Comparable obj2 = field.apply(arg1); final Comparable obj2 = this.field.apply(arg1);
// System.out.println(String.format("%s vs %s _______ %s vs %s", arg0, // System.out.println(String.format("%s vs %s _______ %s vs %s", arg0,
// arg1, obj1, obj2)); // arg1, obj1, obj2));
return ascending ? obj1.compareTo(obj2) : obj2.compareTo(obj1); return this.ascending ? obj1.compareTo(obj2) : obj2.compareTo(obj1);
} }
} }

View File

@@ -17,7 +17,7 @@ import forge.item.InventoryItem;
* @version $Id: TableSorter.java 10146 2011-09-01 18:11:00Z Max mtg $ * @version $Id: TableSorter.java 10146 2011-09-01 18:11:00Z Max mtg $
*/ */
public class TableSorterCascade<T extends InventoryItem> implements Comparator<Entry<T, Integer>> { public class TableSorterCascade<T extends InventoryItem> implements Comparator<Entry<T, Integer>> {
private List<TableSorter<T>> sorters; private final List<TableSorter<T>> sorters;
private final int cntFields; private final int cntFields;
/** /**
@@ -29,7 +29,7 @@ public class TableSorterCascade<T extends InventoryItem> implements Comparator<E
*/ */
public TableSorterCascade(final List<TableSorter<T>> sortersCascade) { public TableSorterCascade(final List<TableSorter<T>> sortersCascade) {
this.sorters = sortersCascade; this.sorters = sortersCascade;
cntFields = sortersCascade.size(); this.cntFields = sortersCascade.size();
} }
/* /*
@@ -41,8 +41,9 @@ public class TableSorterCascade<T extends InventoryItem> implements Comparator<E
public final int compare(final Entry<T, Integer> arg0, final Entry<T, Integer> arg1) { public final int compare(final Entry<T, Integer> arg0, final Entry<T, Integer> arg1) {
int lastCompare = 0; int lastCompare = 0;
int iField = -1; int iField = -1;
while (++iField < cntFields && lastCompare == 0) { // reverse iteration while ((++iField < this.cntFields) && (lastCompare == 0)) { // reverse
TableSorter<T> sorter = sorters.get(iField); // iteration
final TableSorter<T> sorter = this.sorters.get(iField);
if (sorter == null) { if (sorter == null) {
break; break;
} }

View File

@@ -28,28 +28,28 @@ import forge.item.ItemPoolView;
public final class TableWithCards { public final class TableWithCards {
/** The pool. */ /** The pool. */
protected ItemPool<InventoryItem> pool; private ItemPool<InventoryItem> pool;
/** The model. */ /** The model. */
protected TableModel<InventoryItem> model; private TableModel<InventoryItem> model;
/** The table. */ /** The table. */
protected JTable table = new JTable(); private JTable table = new JTable();
/** The j scroll pane. */ /** The j scroll pane. */
protected JScrollPane jScrollPane = new JScrollPane(); private JScrollPane jScrollPane = new JScrollPane();
/** The stats label. */ /** The stats label. */
protected JLabel statsLabel = new JLabel(); private JLabel statsLabel = new JLabel();
/** The filter. */ /** The filter. */
protected Predicate<InventoryItem> filter = null; private Predicate<InventoryItem> filter = null;
/** The is tracking stats. */ /** The is tracking stats. */
protected boolean isTrackingStats = false; private boolean isTrackingStats = false;
/** The want unique. */ /** The want unique. */
protected boolean wantUnique = false; private boolean wantUnique = false;
// need this to allow users place its contents // need this to allow users place its contents
/** /**
@@ -59,7 +59,7 @@ public final class TableWithCards {
* @return JComponent * @return JComponent
*/ */
public JComponent getTableDecorated() { public JComponent getTableDecorated() {
return jScrollPane; return this.jScrollPane;
} }
/** /**
@@ -69,7 +69,7 @@ public final class TableWithCards {
* @return JTable * @return JTable
*/ */
public JTable getTable() { public JTable getTable() {
return table; return this.table;
} }
/** /**
@@ -79,7 +79,7 @@ public final class TableWithCards {
* @return JComponent * @return JComponent
*/ */
public JComponent getLabel() { public JComponent getLabel() {
return statsLabel; return this.statsLabel;
} }
/** /**
@@ -108,22 +108,22 @@ public final class TableWithCards {
*/ */
public TableWithCards(final String title, final boolean showStats, final boolean forceUnique) { public TableWithCards(final String title, final boolean showStats, final boolean forceUnique) {
// components // components
Color gray = new Color(148, 145, 140); final Color gray = new Color(148, 145, 140);
TitledBorder titledBorder = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, gray), title); final TitledBorder titledBorder = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, gray), title);
String tableToolTip = "Click on the column name (like name or color) to sort the cards"; final String tableToolTip = "Click on the column name (like name or color) to sort the cards";
jScrollPane.setBorder(titledBorder); this.jScrollPane.setBorder(titledBorder);
jScrollPane.setToolTipText(tableToolTip); this.jScrollPane.setToolTipText(tableToolTip);
jScrollPane.getViewport().add(table, null); this.jScrollPane.getViewport().add(this.table, null);
if (!Singletons.getModel().getPreferences().lafFonts) { if (!Singletons.getModel().getPreferences().lafFonts) {
statsLabel.setFont(new java.awt.Font("Dialog", 0, 13)); this.statsLabel.setFont(new java.awt.Font("Dialog", 0, 13));
} }
statsLabel.setText("Total: 0, Creatures: 0, Land: 0"); this.statsLabel.setText("Total: 0, Creatures: 0, Land: 0");
// class data // class data
isTrackingStats = showStats; this.isTrackingStats = showStats;
wantUnique = forceUnique; this.wantUnique = forceUnique;
} }
/** /**
@@ -136,24 +136,25 @@ public final class TableWithCards {
* a CardPanelBase * 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); this.model = new TableModel<InventoryItem>(cardView, columns, InventoryItem.class);
model.addListeners(table); this.model.addListeners(this.table);
table.setModel(model); this.table.setModel(this.model);
model.resizeCols(table); this.model.resizeCols(this.table);
for (int idx = columns.size() - 1; idx >= 0; idx--) { for (int idx = columns.size() - 1; idx >= 0; idx--) {
TableCellRenderer renderer = columns.get(idx).getCellRenderer(); final TableCellRenderer renderer = columns.get(idx).getCellRenderer();
if (null != renderer) { if (null != renderer) {
table.getColumnModel().getColumn(idx).setCellRenderer(renderer); this.table.getColumnModel().getColumn(idx).setCellRenderer(renderer);
} }
} }
if (isTrackingStats) { if (this.isTrackingStats) {
// get stats from deck // get stats from deck
model.addTableModelListener(new TableModelListener() { this.model.addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(final TableModelEvent ev) { public void tableChanged(final TableModelEvent ev) {
ItemPoolView<InventoryItem> deck = model.getCards(); final ItemPoolView<InventoryItem> deck = TableWithCards.this.model.getCards();
statsLabel.setText(getStats(deck)); TableWithCards.this.statsLabel.setText(TableWithCards.getStats(deck));
} }
}); });
} }
@@ -169,15 +170,15 @@ public final class TableWithCards {
* @return String * @return String
*/ */
public static String getStats(final ItemPoolView<InventoryItem> deck) { public static String getStats(final ItemPoolView<InventoryItem> deck) {
int total = deck.countAll(); final int total = deck.countAll();
int creature = CardRules.Predicates.Presets.IS_CREATURE.aggregate(deck, deck.fnToCard, deck.fnToCount); final int creature = CardRules.Predicates.Presets.IS_CREATURE.aggregate(deck, deck.fnToCard, deck.fnToCount);
int land = CardRules.Predicates.Presets.IS_LAND.aggregate(deck, deck.fnToCard, deck.fnToCount); final int land = CardRules.Predicates.Presets.IS_LAND.aggregate(deck, deck.fnToCard, deck.fnToCount);
StringBuffer show = new StringBuffer(); final StringBuffer show = new StringBuffer();
show.append("Total - ").append(total).append(", Creatures - ").append(creature).append(", Land - ") show.append("Total - ").append(total).append(", Creatures - ").append(creature).append(", Land - ")
.append(land); .append(land);
String[] color = Constant.Color.ONLY_COLORS; final String[] color = Constant.Color.ONLY_COLORS;
List<Predicate<CardRules>> predicates = CardRules.Predicates.Presets.COLORS; final List<Predicate<CardRules>> predicates = CardRules.Predicates.Presets.COLORS;
for (int i = 0; i < color.length; ++i) { for (int i = 0; i < color.length; ++i) {
show.append(String.format(", %s - %d", color[i], predicates.get(i).count(deck, deck.fnToCard))); show.append(String.format(", %s - %d", color[i], predicates.get(i).count(deck, deck.fnToCard)));
} }
@@ -194,7 +195,7 @@ public final class TableWithCards {
* @return TableWithCards * @return TableWithCards
*/ */
public TableWithCards sort(final int iCol) { public TableWithCards sort(final int iCol) {
return sort(iCol, true); return this.sort(iCol, true);
} }
/** /**
@@ -208,7 +209,7 @@ public final class TableWithCards {
* @return TableWithCards * @return TableWithCards
*/ */
public TableWithCards sort(final int iCol, final boolean isAsc) { public TableWithCards sort(final int iCol, final boolean isAsc) {
model.sort(iCol, isAsc); this.model.sort(iCol, isAsc);
return this; return this;
} }
@@ -222,12 +223,12 @@ public final class TableWithCards {
public void fixSelection(final int rowLastSelected) { public void fixSelection(final int rowLastSelected) {
// 3 cases: 0 cards left, select the same row, select prev row // 3 cases: 0 cards left, select the same row, select prev row
int newRow = rowLastSelected; int newRow = rowLastSelected;
int cntRowsAbove = model.getRowCount(); final int cntRowsAbove = this.model.getRowCount();
if (cntRowsAbove != 0) { if (cntRowsAbove != 0) {
if (cntRowsAbove == newRow) { if (cntRowsAbove == newRow) {
newRow--; newRow--;
} // move selection away from the last, already missing, option } // move selection away from the last, already missing, option
table.setRowSelectionInterval(newRow, newRow); this.table.setRowSelectionInterval(newRow, newRow);
} }
} }
@@ -239,7 +240,7 @@ public final class TableWithCards {
* an Iterable<InventoryITem> * an Iterable<InventoryITem>
*/ */
public void setDeck(final Iterable<InventoryItem> cards) { public void setDeck(final Iterable<InventoryItem> cards) {
setDeckImpl(ItemPool.createFrom(cards, InventoryItem.class)); this.setDeckImpl(ItemPool.createFrom(cards, InventoryItem.class));
} }
/** /**
@@ -251,7 +252,7 @@ public final class TableWithCards {
* an ItemPoolView * an ItemPoolView
*/ */
public <T extends InventoryItem> void setDeck(final ItemPoolView<T> poolView) { public <T extends InventoryItem> void setDeck(final ItemPoolView<T> poolView) {
setDeckImpl(ItemPool.createFrom(poolView, InventoryItem.class)); this.setDeckImpl(ItemPool.createFrom(poolView, InventoryItem.class));
} }
/** /**
@@ -262,10 +263,10 @@ public final class TableWithCards {
* an ItemPool * an ItemPool
*/ */
protected void setDeckImpl(final ItemPool<InventoryItem> thePool) { protected void setDeckImpl(final ItemPool<InventoryItem> thePool) {
model.clear(); this.model.clear();
pool = thePool; this.pool = thePool;
model.addCards(pool); this.model.addCards(this.pool);
updateView(true); this.updateView(true);
} }
/** /**
@@ -275,12 +276,12 @@ public final class TableWithCards {
* @return InventoryItem * @return InventoryItem
*/ */
public InventoryItem getSelectedCard() { public InventoryItem getSelectedCard() {
int iRow = table.getSelectedRow(); final int iRow = this.table.getSelectedRow();
return iRow >= 0 ? model.rowToCard(iRow).getKey() : null; return iRow >= 0 ? this.model.rowToCard(iRow).getKey() : null;
} }
private boolean isUnfiltered() { private boolean isUnfiltered() {
return filter == null || filter.is1(); return (this.filter == null) || this.filter.is1();
} }
/** /**
@@ -291,8 +292,8 @@ public final class TableWithCards {
* a Predicate * a Predicate
*/ */
public void setFilter(final Predicate<InventoryItem> filterToSet) { public void setFilter(final Predicate<InventoryItem> filterToSet) {
filter = filterToSet; this.filter = filterToSet;
updateView(true); this.updateView(true);
} }
/** /**
@@ -304,11 +305,11 @@ public final class TableWithCards {
*/ */
public void addCard(final InventoryItem card) { public void addCard(final InventoryItem card) {
// int n = table.getSelectedRow(); // int n = table.getSelectedRow();
pool.add(card); this.pool.add(card);
if (isUnfiltered()) { if (this.isUnfiltered()) {
model.addCard(card); this.model.addCard(card);
} }
updateView(false); this.updateView(false);
} }
/** /**
@@ -319,13 +320,13 @@ public final class TableWithCards {
* an InventoryItem * an InventoryItem
*/ */
public void removeCard(final InventoryItem card) { public void removeCard(final InventoryItem card) {
int n = table.getSelectedRow(); final int n = this.table.getSelectedRow();
pool.remove(card); this.pool.remove(card);
if (isUnfiltered()) { if (this.isUnfiltered()) {
model.removeCard(card); this.model.removeCard(card);
} }
updateView(false); this.updateView(false);
fixSelection(n); this.fixSelection(n);
} }
/** /**
@@ -336,22 +337,22 @@ public final class TableWithCards {
* a boolean * a boolean
*/ */
public void updateView(final boolean bForceFilter) { public void updateView(final boolean bForceFilter) {
boolean useFilter = (bForceFilter && filter != null) || !isUnfiltered(); final boolean useFilter = (bForceFilter && (this.filter != null)) || !this.isUnfiltered();
if (useFilter || wantUnique) { if (useFilter || this.wantUnique) {
model.clear(); this.model.clear();
} }
if (useFilter && wantUnique) { if (useFilter && this.wantUnique) {
model.addCards(filter.uniqueByLast(pool, pool.fnToCardName, pool.fnToPrinted)); this.model.addCards(this.filter.uniqueByLast(this.pool, this.pool.fnToCardName, this.pool.fnToPrinted));
} else if (useFilter) { } else if (useFilter) {
model.addCards(filter.select(pool, pool.fnToPrinted)); this.model.addCards(this.filter.select(this.pool, this.pool.fnToPrinted));
} else if (wantUnique) { } else if (this.wantUnique) {
model.addCards(CardRules.Predicates.Presets.CONSTANT_TRUE.uniqueByLast(pool, pool.fnToCardName, this.model.addCards(CardRules.Predicates.Presets.CONSTANT_TRUE.uniqueByLast(this.pool,
pool.fnToCard)); this.pool.fnToCardName, this.pool.fnToCard));
} }
model.resort(); this.model.resort();
} }
/** /**
@@ -361,7 +362,7 @@ public final class TableWithCards {
* @return ItemPoolView * @return ItemPoolView
*/ */
public ItemPoolView<InventoryItem> getCards() { public ItemPoolView<InventoryItem> getCards() {
return pool; return this.pool;
} }
} }

View File

@@ -702,7 +702,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants.
editor.show(exit); editor.show(exit);
if (deck != null) { if (deck != null) {
editor.customMenu.showDeck(deck, gt); editor.getCustomMenu().showDeck(deck, gt);
} }
this.setVisible(false); this.setVisible(false);