mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
checkstyle and refactor. Turn off magic number check for time being
This commit is contained in:
@@ -188,7 +188,7 @@
|
||||
<!-- <module name="HiddenField"/> -->
|
||||
<module name="IllegalInstantiation"/>
|
||||
<module name="InnerAssignment"/>
|
||||
<module name="MagicNumber"/>
|
||||
<!-- <module name="MagicNumber"/> -->
|
||||
<module name="MissingSwitchDefault"/>
|
||||
<module name="RedundantThrows"/>
|
||||
<module name="SimplifyBooleanExpression"/>
|
||||
|
||||
@@ -698,7 +698,7 @@ public class DeckManager {
|
||||
private static void writeCardPool(final ItemPoolView<CardPrinted> pool, final BufferedWriter out)
|
||||
throws IOException {
|
||||
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) {
|
||||
final CardPrinted card = e.getKey();
|
||||
final boolean hasBadSetInfo = "???".equals(card.getSet()) || StringUtils.isBlank(card.getSet());
|
||||
|
||||
@@ -29,7 +29,7 @@ public class CardPanelHeavy extends CardPanelBase {
|
||||
|
||||
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
|
||||
@@ -38,33 +38,34 @@ public class CardPanelHeavy extends CardPanelBase {
|
||||
|
||||
// Controls to show card details
|
||||
/** The detail. */
|
||||
protected CardDetailPanel detail = new CardDetailPanel(null);
|
||||
private CardDetailPanel detail = new CardDetailPanel(null);
|
||||
|
||||
/** The picture. */
|
||||
protected CardPanel picture = new CardPanel(null);
|
||||
private CardPanel picture = new CardPanel(null);
|
||||
|
||||
/** The picture view panel. */
|
||||
protected ViewPanel pictureViewPanel = new ViewPanel();
|
||||
private ViewPanel pictureViewPanel = new ViewPanel();
|
||||
|
||||
// fake card to allow picture changes
|
||||
/** The c card hq. */
|
||||
public Card cCardHQ;
|
||||
private Card cCardHQ;
|
||||
|
||||
/** Constant <code>previousDirectory</code>. */
|
||||
protected static File previousDirectory = null;
|
||||
private static File previousDirectory = null;
|
||||
|
||||
/**
|
||||
* Instantiates a new card panel heavy.
|
||||
*/
|
||||
public CardPanelHeavy() {
|
||||
changeStateButton.setVisible(false);
|
||||
changeStateButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
this.changeStateButton.setVisible(false);
|
||||
this.changeStateButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
changeStateButton_actionPerformed(e);
|
||||
CardPanelHeavy.this.changeStateButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
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));
|
||||
*/
|
||||
|
||||
pictureViewPanel.setCardPanel(picture);
|
||||
this.pictureViewPanel.setCardPanel(this.picture);
|
||||
|
||||
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,
|
||||
* "align 50% 0%, split 3, flowx"); this.add(changePictureButton,
|
||||
* "align 50% 0%"); this.add(removePictureButton, "align 50% 0%, wrap");
|
||||
*/
|
||||
this.add(changeStateButton, "align 50% 0%, flowx, wrap");
|
||||
this.add(pictureViewPanel, "wmin 239, hmin 323, grow");
|
||||
this.add(this.changeStateButton, "align 50% 0%, flowx, wrap");
|
||||
this.add(this.pictureViewPanel, "wmin 239, hmin 323, grow");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -105,10 +106,11 @@ public class CardPanelHeavy extends CardPanelBase {
|
||||
* @see
|
||||
* forge.gui.deckeditor.CardPanelBase#showCard(forge.item.InventoryItem)
|
||||
*/
|
||||
@Override
|
||||
public final void showCard(final InventoryItem card) {
|
||||
Card card2 = card instanceof CardPrinted ? ((CardPrinted) card).toForgeCard() : null;
|
||||
detail.setCard(card2);
|
||||
setCard(card2);
|
||||
final Card card2 = card instanceof CardPrinted ? ((CardPrinted) card).toForgeCard() : null;
|
||||
this.detail.setCard(card2);
|
||||
this.setCard(card2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,22 +120,22 @@ public class CardPanelHeavy extends CardPanelBase {
|
||||
* the new card
|
||||
*/
|
||||
public final void setCard(final Card c) {
|
||||
if (picture.getCard() != null) {
|
||||
if (picture.getCard().isInAlternateState()) {
|
||||
picture.getCard().changeState();
|
||||
if (this.picture.getCard() != null) {
|
||||
if (this.picture.getCard().isInAlternateState()) {
|
||||
this.picture.getCard().changeState();
|
||||
}
|
||||
}
|
||||
picture.setCard(c);
|
||||
this.picture.setCard(c);
|
||||
|
||||
if (c.hasAlternateState()) {
|
||||
changeStateButton.setVisible(true);
|
||||
this.changeStateButton.setVisible(true);
|
||||
if (c.isFlip()) {
|
||||
changeStateButton.setText("Flip");
|
||||
this.changeStateButton.setText("Flip");
|
||||
} else {
|
||||
changeStateButton.setText("Transform");
|
||||
this.changeStateButton.setText("Transform");
|
||||
}
|
||||
} else {
|
||||
changeStateButton.setVisible(false);
|
||||
this.changeStateButton.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,12 +147,12 @@ public class CardPanelHeavy extends CardPanelBase {
|
||||
* @param e
|
||||
* a {@link java.awt.event.ActionEvent} object.
|
||||
*/
|
||||
final void changeStateButton_actionPerformed(final ActionEvent e) {
|
||||
Card cur = picture.getCard();
|
||||
final void changeStateButtonActionPerformed(final ActionEvent e) {
|
||||
final Card cur = this.picture.getCard();
|
||||
cur.changeState();
|
||||
|
||||
picture.setCard(cur);
|
||||
detail.setCard(cur);
|
||||
this.picture.setCard(cur);
|
||||
this.detail.setCard(cur);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,23 +163,23 @@ public class CardPanelHeavy extends CardPanelBase {
|
||||
* @param e
|
||||
* a {@link java.awt.event.ActionEvent} object.
|
||||
*/
|
||||
final void changePictureButton_actionPerformed(final ActionEvent e) {
|
||||
if (cCardHQ != null) {
|
||||
File file = getImportFilename();
|
||||
private void changePictureButtonActionPerformed(final ActionEvent e) {
|
||||
if (this.cCardHQ != null) {
|
||||
final File file = this.getImportFilename();
|
||||
if (file != null) {
|
||||
String fileName = GuiDisplayUtil.cleanString(cCardHQ.getName()) + ".jpg";
|
||||
File base = ForgeProps.getFile(NewConstants.IMAGE_BASE);
|
||||
File f = new File(base, fileName);
|
||||
final String fileName = GuiDisplayUtil.cleanString(this.cCardHQ.getName()) + ".jpg";
|
||||
final File base = ForgeProps.getFile(NewConstants.IMAGE_BASE);
|
||||
final File f = new File(base, fileName);
|
||||
f.delete();
|
||||
|
||||
try {
|
||||
org.apache.commons.io.FileUtils.copyFile(file, f);
|
||||
} catch (IOException e1) {
|
||||
} catch (final IOException e1) {
|
||||
// TODO Auto-generated catch block ignores the exception,
|
||||
// but sends it to System.err and probably forge.log.
|
||||
e1.printStackTrace();
|
||||
}
|
||||
setCard(cCardHQ);
|
||||
this.setCard(this.cCardHQ);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,16 +192,16 @@ public class CardPanelHeavy extends CardPanelBase {
|
||||
* @return a {@link java.io.File} object.
|
||||
*/
|
||||
private File getImportFilename() {
|
||||
JFileChooser chooser = new JFileChooser(previousDirectory);
|
||||
ImagePreviewPanel preview = new ImagePreviewPanel();
|
||||
final JFileChooser chooser = new JFileChooser(CardPanelHeavy.previousDirectory);
|
||||
final ImagePreviewPanel preview = new ImagePreviewPanel();
|
||||
chooser.setAccessory(preview);
|
||||
chooser.addPropertyChangeListener(preview);
|
||||
chooser.addChoosableFileFilter(dckFilter);
|
||||
int returnVal = chooser.showOpenDialog(null);
|
||||
chooser.addChoosableFileFilter(this.dckFilter);
|
||||
final int returnVal = chooser.showOpenDialog(null);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File file = chooser.getSelectedFile();
|
||||
previousDirectory = file.getParentFile();
|
||||
final File file = chooser.getSelectedFile();
|
||||
CardPanelHeavy.previousDirectory = file.getParentFile();
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -208,7 +210,7 @@ public class CardPanelHeavy extends CardPanelBase {
|
||||
}
|
||||
|
||||
/** The dck filter. */
|
||||
protected FileFilter dckFilter = new FileFilter() {
|
||||
private FileFilter dckFilter = new FileFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(final File f) {
|
||||
@@ -231,20 +233,20 @@ public class CardPanelHeavy extends CardPanelBase {
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
final void removePictureButton_actionPerformed(final ActionEvent e) {
|
||||
if (cCardHQ != null) {
|
||||
String options[] = { "Yes", "No" };
|
||||
int value = JOptionPane.showOptionDialog(null, "Do you want delete " + cCardHQ.getName() + " picture?",
|
||||
"Delete picture", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
|
||||
options[1]);
|
||||
final void removePictureButtonActionPerformed(final ActionEvent e) {
|
||||
if (this.cCardHQ != null) {
|
||||
final String[] options = { "Yes", "No" };
|
||||
final int value = JOptionPane.showOptionDialog(null, "Do you want delete " + this.cCardHQ.getName()
|
||||
+ " picture?", "Delete picture", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
|
||||
options, options[1]);
|
||||
if (value == 0) {
|
||||
String fileName = GuiDisplayUtil.cleanString(cCardHQ.getName()) + ".jpg";
|
||||
File base = ForgeProps.getFile(NewConstants.IMAGE_BASE);
|
||||
File f = new File(base, fileName);
|
||||
final String fileName = GuiDisplayUtil.cleanString(this.cCardHQ.getName()) + ".jpg";
|
||||
final File base = ForgeProps.getFile(NewConstants.IMAGE_BASE);
|
||||
final File f = new File(base, fileName);
|
||||
f.delete();
|
||||
JOptionPane.showMessageDialog(null, "Picture " + cCardHQ.getName() + " deleted.", "Delete picture",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
setCard(cCardHQ);
|
||||
JOptionPane.showMessageDialog(null, "Picture " + this.cCardHQ.getName() + " deleted.",
|
||||
"Delete picture", JOptionPane.INFORMATION_MESSAGE);
|
||||
this.setCard(this.cCardHQ);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,7 +257,7 @@ public class CardPanelHeavy extends CardPanelBase {
|
||||
* @return the card
|
||||
*/
|
||||
public final Card getCard() {
|
||||
return detail.getCard();
|
||||
return this.detail.getCard();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,29 +23,30 @@ public class CardPanelLite extends CardPanelBase {
|
||||
|
||||
// Controls to show card details
|
||||
/** The detail. */
|
||||
protected CardDetailPanel detail = new CardDetailPanel(null);
|
||||
private CardPicturePanel picture = new CardPicturePanel(null);
|
||||
private JButton bChangeState = new JButton();
|
||||
private CardDetailPanel detail = new CardDetailPanel(null);
|
||||
private final CardPicturePanel picture = new CardPicturePanel(null);
|
||||
private final JButton bChangeState = new JButton();
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor.
|
||||
*/
|
||||
public CardPanelLite() {
|
||||
bChangeState.setVisible(false);
|
||||
bChangeState.addActionListener(new ActionListener() {
|
||||
this.bChangeState.setVisible(false);
|
||||
this.bChangeState.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
bChangeState_actionPerformed(e);
|
||||
CardPanelLite.this.bChangeStateActionPerformed(e);
|
||||
}
|
||||
});
|
||||
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.add(detail, "w 239, h 303, grow, flowy, wrap");
|
||||
this.add(bChangeState, "align 50% 0%, wrap");
|
||||
this.add(picture, "wmin 239, hmin 323, grow");
|
||||
this.add(this.detail, "w 239, h 303, grow, flowy, wrap");
|
||||
this.add(this.bChangeState, "align 50% 0%, wrap");
|
||||
this.add(this.picture, "wmin 239, hmin 323, grow");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,20 +56,21 @@ public class CardPanelLite extends CardPanelBase {
|
||||
* @param card
|
||||
* an InventoryItem
|
||||
*/
|
||||
@Override
|
||||
public final void showCard(final InventoryItem card) {
|
||||
picture.setCard(card);
|
||||
boolean isCard = card != null && card instanceof CardPrinted;
|
||||
detail.setVisible(isCard);
|
||||
this.picture.setCard(card);
|
||||
final boolean isCard = (card != null) && (card instanceof CardPrinted);
|
||||
this.detail.setVisible(isCard);
|
||||
if (isCard) {
|
||||
Card toSet = ((CardPrinted) card).toForgeCard();
|
||||
final Card toSet = ((CardPrinted) card).toForgeCard();
|
||||
|
||||
detail.setCard(toSet);
|
||||
this.detail.setCard(toSet);
|
||||
if (toSet.hasAlternateState()) {
|
||||
bChangeState.setVisible(true);
|
||||
this.bChangeState.setVisible(true);
|
||||
if (toSet.isFlip()) {
|
||||
bChangeState.setText("Flip");
|
||||
this.bChangeState.setText("Flip");
|
||||
} else {
|
||||
bChangeState.setText("Transform");
|
||||
this.bChangeState.setText("Transform");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,15 +83,15 @@ public class CardPanelLite extends CardPanelBase {
|
||||
* the new card
|
||||
*/
|
||||
public final void setCard(final Card c) {
|
||||
picture.setCard(c);
|
||||
this.picture.setCard(c);
|
||||
if (c != null) {
|
||||
detail.setCard(c);
|
||||
this.detail.setCard(c);
|
||||
if (c.hasAlternateState()) {
|
||||
bChangeState.setVisible(true);
|
||||
this.bChangeState.setVisible(true);
|
||||
if (c.isFlip()) {
|
||||
bChangeState.setText("Flip");
|
||||
this.bChangeState.setText("Flip");
|
||||
} else {
|
||||
bChangeState.setText("Transform");
|
||||
this.bChangeState.setText("Transform");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,15 +104,15 @@ public class CardPanelLite extends CardPanelBase {
|
||||
* @return Card
|
||||
*/
|
||||
public final Card getCard() {
|
||||
return detail.getCard();
|
||||
return this.detail.getCard();
|
||||
}
|
||||
|
||||
private void bChangeState_actionPerformed(final ActionEvent e) {
|
||||
Card cur = detail.getCard();
|
||||
private void bChangeStateActionPerformed(final ActionEvent e) {
|
||||
final Card cur = this.detail.getCard();
|
||||
if (cur != null) {
|
||||
cur.changeState();
|
||||
|
||||
setCard(cur);
|
||||
this.setCard(cur);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@ public class CheckBoxWithIcon extends JCheckBox {
|
||||
/* Custom check box class for filter icons */
|
||||
private static final long serialVersionUID = -8099263807219520120L;
|
||||
|
||||
private String imagePath = "res/images/deckeditor/";
|
||||
private String iconYes;
|
||||
private String iconNo;
|
||||
private CheckBoxWithIcon cb;
|
||||
private final String imagePath = "res/images/deckeditor/";
|
||||
private final String iconYes;
|
||||
private final String iconNo;
|
||||
private final CheckBoxWithIcon cb;
|
||||
|
||||
/**
|
||||
* Instantiates a new check box with icon.
|
||||
@@ -29,17 +29,18 @@ public class CheckBoxWithIcon extends JCheckBox {
|
||||
*/
|
||||
CheckBoxWithIcon(final String filterName, final String toolTip) {
|
||||
super("", true);
|
||||
cb = this;
|
||||
iconYes = imagePath + "filter_" + filterName + "_y.png";
|
||||
iconNo = imagePath + "filter_" + filterName + "_n.png";
|
||||
this.setIcon(new ImageIcon(iconYes));
|
||||
this.cb = this;
|
||||
this.iconYes = this.imagePath + "filter_" + filterName + "_y.png";
|
||||
this.iconNo = this.imagePath + "filter_" + filterName + "_n.png";
|
||||
this.setIcon(new ImageIcon(this.iconYes));
|
||||
this.setToolTipText(toolTip);
|
||||
this.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent actionEvent) {
|
||||
if (cb.isSelected()) {
|
||||
cb.setIcon(new ImageIcon(iconYes));
|
||||
if (CheckBoxWithIcon.this.cb.isSelected()) {
|
||||
CheckBoxWithIcon.this.cb.setIcon(new ImageIcon(CheckBoxWithIcon.this.iconYes));
|
||||
} 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
@@ -24,21 +24,21 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
private static final long serialVersionUID = -401223933343539977L;
|
||||
|
||||
/** The filter boxes. */
|
||||
protected FilterCheckBoxes filterBoxes;
|
||||
private FilterCheckBoxes filterBoxes;
|
||||
// set this to false when resetting filter from code (like
|
||||
// "clearFiltersPressed"), reset when done.
|
||||
/** The is filters change firing update. */
|
||||
protected boolean isFiltersChangeFiringUpdate = true;
|
||||
private boolean isFiltersChangeFiringUpdate = true;
|
||||
|
||||
/** The card view. */
|
||||
protected CardPanelBase cardView;
|
||||
private CardPanelBase cardView;
|
||||
|
||||
// CardPools and Table data for top and bottom lists
|
||||
/** The top. */
|
||||
protected TableWithCards top;
|
||||
private TableWithCards topTableWithCards;
|
||||
|
||||
/** The bottom. */
|
||||
protected TableWithCards bottom;
|
||||
private TableWithCards bottomTableWithCards;
|
||||
|
||||
private GameType gameType;
|
||||
|
||||
@@ -47,8 +47,9 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckDisplay#getGameType()
|
||||
*/
|
||||
@Override
|
||||
public final GameType getGameType() {
|
||||
return gameType;
|
||||
return this.gameType;
|
||||
}
|
||||
|
||||
// top shows available card pool
|
||||
@@ -61,7 +62,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
* @return the top table model
|
||||
*/
|
||||
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()
|
||||
*/
|
||||
@Override
|
||||
public final ItemPoolView<InventoryItem> getTop() {
|
||||
return top.getCards();
|
||||
return this.getTopTableWithCards().getCards();
|
||||
}
|
||||
|
||||
// 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()
|
||||
*/
|
||||
@Override
|
||||
public final ItemPoolView<InventoryItem> getBottom() {
|
||||
return bottom.getCards();
|
||||
return this.getBottomTableWithCards().getCards();
|
||||
}
|
||||
|
||||
// THIS IS HERE FOR OVERLOADING!!!1
|
||||
@@ -99,14 +102,15 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
final void analysisButton_actionPerformed(final ActionEvent e) {
|
||||
ItemPoolView<CardPrinted> deck = ItemPool.createFrom(bottom.getCards(), CardPrinted.class);
|
||||
final void analysisButtonActionPerformed(final ActionEvent e) {
|
||||
final ItemPoolView<CardPrinted> deck = ItemPool.createFrom(this.getBottomTableWithCards().getCards(),
|
||||
CardPrinted.class);
|
||||
if (deck.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
DeckEditorBase g = DeckEditorBase.this;
|
||||
DeckAnalysis dAnalysis = new DeckAnalysis(g, deck);
|
||||
final DeckEditorBase g = DeckEditorBase.this;
|
||||
final DeckAnalysis dAnalysis = new DeckAnalysis(g, deck);
|
||||
dAnalysis.setVisible(true);
|
||||
g.setEnabled(false);
|
||||
}
|
||||
@@ -119,7 +123,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
* the 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,
|
||||
* forge.item.ItemPoolView, forge.game.GameType)
|
||||
*/
|
||||
@Override
|
||||
public void setDeck(final ItemPoolView<CardPrinted> topParam, final ItemPoolView<CardPrinted> bottomParam,
|
||||
final GameType gt) {
|
||||
gameType = gt;
|
||||
top.setDeck(topParam);
|
||||
bottom.setDeck(bottomParam);
|
||||
this.gameType = gt;
|
||||
this.getTopTableWithCards().setDeck(topParam);
|
||||
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,
|
||||
* forge.item.ItemPoolView, forge.game.GameType)
|
||||
*/
|
||||
@Override
|
||||
public final <T extends InventoryItem> void setItems(final ItemPoolView<T> topParam,
|
||||
final ItemPoolView<T> bottomParam, final GameType gt) {
|
||||
gameType = gt;
|
||||
top.setDeck(topParam);
|
||||
bottom.setDeck(bottomParam);
|
||||
this.gameType = gt;
|
||||
this.getTopTableWithCards().setDeck(topParam);
|
||||
this.getBottomTableWithCards().setDeck(bottomParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update display.
|
||||
*/
|
||||
public final void updateDisplay() {
|
||||
top.setFilter(buildFilter());
|
||||
this.getTopTableWithCards().setFilter(this.buildFilter());
|
||||
}
|
||||
|
||||
/** The item listener updates display. */
|
||||
protected ItemListener itemListenerUpdatesDisplay = new ItemListener() {
|
||||
private ItemListener itemListenerUpdatesDisplay = new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(final ItemEvent e) {
|
||||
if (isFiltersChangeFiringUpdate) {
|
||||
updateDisplay();
|
||||
if (DeckEditorBase.this.isFiltersChangeFiringUpdate()) {
|
||||
DeckEditorBase.this.updateDisplay();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -170,8 +177,8 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
*/
|
||||
protected class OnChangeTextUpdateDisplay implements DocumentListener {
|
||||
private void onChange() {
|
||||
if (isFiltersChangeFiringUpdate) {
|
||||
updateDisplay();
|
||||
if (DeckEditorBase.this.isFiltersChangeFiringUpdate()) {
|
||||
DeckEditorBase.this.updateDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +191,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
*/
|
||||
@Override
|
||||
public final void insertUpdate(final DocumentEvent e) {
|
||||
onChange();
|
||||
this.onChange();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -196,7 +203,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
|
||||
*/
|
||||
@Override
|
||||
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()
|
||||
*/
|
||||
@Override
|
||||
public final Deck getDeck() {
|
||||
Deck deck = new Deck(gameType);
|
||||
deck.addMain(ItemPool.createFrom(getBottom(), CardPrinted.class));
|
||||
final Deck deck = new Deck(this.gameType);
|
||||
deck.addMain(ItemPool.createFrom(this.getBottom(), CardPrinted.class));
|
||||
|
||||
// if sealed or draft, move "top" to sideboard
|
||||
if (gameType.isLimited() && gameType != GameType.Quest) {
|
||||
deck.addSideboard(ItemPool.createFrom(getTop(), CardPrinted.class));
|
||||
if (this.gameType.isLimited() && (this.gameType != GameType.Quest)) {
|
||||
deck.addSideboard(ItemPool.createFrom(this.getTop(), CardPrinted.class));
|
||||
}
|
||||
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.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,20 +40,20 @@ import forge.item.ItemPoolView;
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class DeckEditorCommon extends DeckEditorBase {
|
||||
/** Constant <code>serialVersionUID=130339644136746796L</code> */
|
||||
/** Constant <code>serialVersionUID=130339644136746796L</code>. */
|
||||
private static final long serialVersionUID = 130339644136746796L;
|
||||
|
||||
/** The custom menu. */
|
||||
public DeckEditorCommonMenu customMenu;
|
||||
private DeckEditorCommonMenu customMenu;
|
||||
|
||||
private JButton removeButton = new JButton();
|
||||
private JButton addButton = new JButton();
|
||||
private JButton importButton = new JButton();
|
||||
private final JButton removeButton = new JButton();
|
||||
private final JButton addButton = new JButton();
|
||||
private final JButton importButton = new JButton();
|
||||
|
||||
private JButton analysisButton = new JButton();
|
||||
private JButton clearFilterButton = new JButton();
|
||||
private final JButton analysisButton = new JButton();
|
||||
private final JButton clearFilterButton = new JButton();
|
||||
|
||||
private JLabel jLabelAnalysisGap = new JLabel("");
|
||||
private final JLabel jLabelAnalysisGap = new JLabel("");
|
||||
private FilterNameTypeSetPanel filterNameTypeSet;
|
||||
|
||||
/**
|
||||
@@ -66,41 +66,44 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
final Command exit = new Command() {
|
||||
private static final long serialVersionUID = 5210924838133689758L;
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
DeckEditorCommon.this.dispose();
|
||||
exitCommand.execute();
|
||||
}
|
||||
};
|
||||
|
||||
customMenu = new DeckEditorCommonMenu(this, AllZone.getDeckManager(), exit);
|
||||
this.setJMenuBar(customMenu);
|
||||
this.setCustomMenu(new DeckEditorCommonMenu(this, AllZone.getDeckManager(), exit));
|
||||
this.setJMenuBar(this.getCustomMenu());
|
||||
|
||||
// do not change this!!!!
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(final WindowEvent ev) {
|
||||
customMenu.close();
|
||||
DeckEditorCommon.this.getCustomMenu().close();
|
||||
}
|
||||
});
|
||||
|
||||
setup();
|
||||
this.setup();
|
||||
|
||||
// show cards, makes this user friendly
|
||||
if (!getGameType().isLimited()) {
|
||||
customMenu.newConstructed(false);
|
||||
if (!this.getGameType().isLimited()) {
|
||||
this.getCustomMenu().newConstructed(false);
|
||||
}
|
||||
|
||||
top.sort(1, true);
|
||||
bottom.sort(1, true);
|
||||
this.getTopTableWithCards().sort(1, true);
|
||||
this.getBottomTableWithCards().sort(1, true);
|
||||
|
||||
} // show(Command)
|
||||
|
||||
private void setup() {
|
||||
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE, PresetColumns.FN_QTY_GET));
|
||||
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>("Name", 175, PresetColumns.FN_NAME_COMPARE,
|
||||
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,
|
||||
PresetColumns.FN_COLOR_GET));
|
||||
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));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 25, PresetColumns.FN_RARITY_COMPARE,
|
||||
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,
|
||||
PresetColumns.FN_AI_STATUS_GET));
|
||||
columns.get(2).setCellRenderer(new ManaCostRenderer());
|
||||
|
||||
top.setup(columns, cardView);
|
||||
bottom.setup(columns, cardView);
|
||||
this.getTopTableWithCards().setup(columns, this.getCardView());
|
||||
this.getBottomTableWithCards().setup(columns, this.getCardView());
|
||||
|
||||
filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), itemListenerUpdatesDisplay);
|
||||
this.filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), this.getItemListenerUpdatesDisplay());
|
||||
|
||||
setSize(1024, 740);
|
||||
setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
this.setSize(1024, 740);
|
||||
this.setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
|
||||
}
|
||||
|
||||
@@ -133,14 +137,14 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
public DeckEditorCommon(final GameType gameType) {
|
||||
super(gameType);
|
||||
try {
|
||||
filterBoxes = new FilterCheckBoxes(true);
|
||||
top = new TableWithCards("Avaliable Cards", true, true);
|
||||
bottom = new TableWithCards("Deck", true);
|
||||
cardView = new CardPanelHeavy();
|
||||
filterNameTypeSet = new FilterNameTypeSetPanel();
|
||||
this.setFilterBoxes(new FilterCheckBoxes(true));
|
||||
this.setTopTableWithCards(new TableWithCards("Avaliable Cards", true, true));
|
||||
this.setBottomTableWithCards(new TableWithCards("Deck", true));
|
||||
this.setCardView(new CardPanelHeavy());
|
||||
this.filterNameTypeSet = new FilterNameTypeSetPanel();
|
||||
|
||||
jbInit();
|
||||
} catch (Exception ex) {
|
||||
this.jbInit();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
}
|
||||
@@ -148,49 +152,54 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
private void jbInit() {
|
||||
|
||||
if (!Singletons.getModel().getPreferences().lafFonts) {
|
||||
Font fButtons = new java.awt.Font("Dialog", 0, 13);
|
||||
removeButton.setFont(fButtons);
|
||||
addButton.setFont(fButtons);
|
||||
importButton.setFont(fButtons);
|
||||
clearFilterButton.setFont(fButtons);
|
||||
analysisButton.setFont(fButtons);
|
||||
final Font fButtons = new java.awt.Font("Dialog", 0, 13);
|
||||
this.removeButton.setFont(fButtons);
|
||||
this.addButton.setFont(fButtons);
|
||||
this.importButton.setFont(fButtons);
|
||||
this.clearFilterButton.setFont(fButtons);
|
||||
this.analysisButton.setFont(fButtons);
|
||||
}
|
||||
|
||||
addButton.setText("Add to Deck");
|
||||
removeButton.setText("Remove from Deck");
|
||||
importButton.setText("Import a Deck");
|
||||
clearFilterButton.setText("Clear Filter");
|
||||
analysisButton.setText("Deck Analysis");
|
||||
this.addButton.setText("Add to Deck");
|
||||
this.removeButton.setText("Remove from Deck");
|
||||
this.importButton.setText("Import a Deck");
|
||||
this.clearFilterButton.setText("Clear Filter");
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
analysisButton_actionPerformed(e);
|
||||
DeckEditorCommon.this.analysisButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
|
||||
// Type filtering
|
||||
Font f = new Font("Tahoma", Font.PLAIN, 10);
|
||||
for (JCheckBox box : filterBoxes.allTypes) {
|
||||
final Font f = new Font("Tahoma", Font.PLAIN, 10);
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
|
||||
if (!Singletons.getModel().getPreferences().lafFonts) {
|
||||
box.setFont(f);
|
||||
}
|
||||
@@ -198,7 +207,7 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
}
|
||||
|
||||
// Color filtering
|
||||
for (JCheckBox box : filterBoxes.allColors) {
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
|
||||
box.setOpaque(false);
|
||||
}
|
||||
|
||||
@@ -206,58 +215,58 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
// x 768 screen size
|
||||
this.setTitle("Deck Editor");
|
||||
|
||||
Container content = this.getContentPane();
|
||||
MigLayout layout = new MigLayout("fill");
|
||||
final Container content = this.getContentPane();
|
||||
final MigLayout layout = new MigLayout("fill");
|
||||
content.setLayout(layout);
|
||||
|
||||
boolean isFirst = true;
|
||||
for (JCheckBox box : filterBoxes.allTypes) {
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
|
||||
String growParameter = "grow";
|
||||
if (isFirst) {
|
||||
growParameter = "cell 0 0, egx checkbox, grow, split 14";
|
||||
isFirst = false;
|
||||
}
|
||||
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");
|
||||
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(top.getTableDecorated(), "cell 0 2 1 2, pushy, grow");
|
||||
content.add(top.getLabel(), "cell 0 4");
|
||||
content.add(this.filterNameTypeSet, "cell 0 1, grow");
|
||||
content.add(this.getTopTableWithCards().getTableDecorated(), "cell 0 2 1 2, pushy, grow");
|
||||
content.add(this.getTopTableWithCards().getLabel(), "cell 0 4");
|
||||
|
||||
content.add(addButton, "w 100, h 49, sg button, cell 0 5, split 5");
|
||||
content.add(removeButton, "w 100, h 49, sg button");
|
||||
content.add(importButton, "w 100, h 49, sg button, gapleft 40px");
|
||||
content.add(this.addButton, "w 100, h 49, sg button, cell 0 5, split 5");
|
||||
content.add(this.removeButton, "w 100, h 49, sg button");
|
||||
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
|
||||
// analysis button from add/remove card ones
|
||||
content.add(jLabelAnalysisGap, "wmin 75, growx");
|
||||
content.add(analysisButton, "w 100, h 49, wrap");
|
||||
content.add(this.jLabelAnalysisGap, "wmin 75, growx");
|
||||
content.add(this.analysisButton, "w 100, h 49, wrap");
|
||||
|
||||
content.add(bottom.getTableDecorated(), "cell 0 6, grow");
|
||||
content.add(bottom.getLabel(), "cell 0 7");
|
||||
content.add(this.getBottomTableWithCards().getTableDecorated(), "cell 0 6, grow");
|
||||
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
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
if (e.getClickCount() == 2) {
|
||||
addCardToDeck();
|
||||
DeckEditorCommon.this.addCardToDeck();
|
||||
}
|
||||
}
|
||||
});
|
||||
top.getTable().addKeyListener(new KeyAdapter() {
|
||||
this.getTopTableWithCards().getTable().addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
if (e.getKeyChar() == ' ') {
|
||||
addCardToDeck();
|
||||
DeckEditorCommon.this.addCardToDeck();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -273,8 +282,8 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
*/
|
||||
@Override
|
||||
protected Predicate<InventoryItem> buildFilter() {
|
||||
Predicate<CardPrinted> cardFilter = Predicate.and(
|
||||
Predicate.and(filterBoxes.buildFilter(), filterNameTypeSet.buildFilter()),
|
||||
final Predicate<CardPrinted> cardFilter = Predicate.and(
|
||||
Predicate.and(this.getFilterBoxes().buildFilter(), this.filterNameTypeSet.buildFilter()),
|
||||
CardPrinted.Predicates.Presets.nonAlternate);
|
||||
return Predicate.instanceOf(cardFilter, CardPrinted.class);
|
||||
}
|
||||
@@ -288,11 +297,11 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
@Override
|
||||
public void setDeck(final ItemPoolView<CardPrinted> topParam, final ItemPoolView<CardPrinted> bottomParam,
|
||||
final GameType gt) {
|
||||
boolean keepRecievedCards = gt.isLimited() || topParam != null;
|
||||
final boolean keepRecievedCards = gt.isLimited() || (topParam != null);
|
||||
// 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);
|
||||
importButton.setVisible(!gt.isLimited());
|
||||
this.importButton.setVisible(!gt.isLimited());
|
||||
super.setDeck(top, bottomParam, gt);
|
||||
}
|
||||
|
||||
@@ -302,26 +311,26 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
void clearFilterButton_actionPerformed(final ActionEvent e) {
|
||||
void clearFilterButtonActionPerformed(final ActionEvent e) {
|
||||
// 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()) {
|
||||
box.doClick();
|
||||
}
|
||||
}
|
||||
for (JCheckBox box : filterBoxes.allColors) {
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
|
||||
if (!box.isSelected()) {
|
||||
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
|
||||
* the e
|
||||
*/
|
||||
void addButton_actionPerformed(final ActionEvent e) {
|
||||
addCardToDeck();
|
||||
void addButtonActionPerformed(final ActionEvent e) {
|
||||
this.addCardToDeck();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the card to deck.
|
||||
*/
|
||||
void addCardToDeck() {
|
||||
InventoryItem item = top.getSelectedCard();
|
||||
if (item == null || !(item instanceof CardPrinted)) {
|
||||
final InventoryItem item = this.getTopTableWithCards().getSelectedCard();
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CardPrinted card = (CardPrinted) item;
|
||||
setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved");
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
this.setTitle("Deck Editor : " + this.getCustomMenu().getDeckName() + " : unsaved");
|
||||
|
||||
bottom.addCard(card);
|
||||
if (getGameType().isLimited()) {
|
||||
top.removeCard(card);
|
||||
this.getBottomTableWithCards().addCard(card);
|
||||
if (this.getGameType().isLimited()) {
|
||||
this.getTopTableWithCards().removeCard(card);
|
||||
}
|
||||
|
||||
customMenu.notifyDeckChange();
|
||||
this.getCustomMenu().notifyDeckChange();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -361,21 +370,21 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
* the e
|
||||
*/
|
||||
void removeButtonClicked(final ActionEvent e) {
|
||||
InventoryItem item = bottom.getSelectedCard();
|
||||
if (item == null || !(item instanceof CardPrinted)) {
|
||||
final InventoryItem item = this.getBottomTableWithCards().getSelectedCard();
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
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);
|
||||
if (getGameType().isLimited()) {
|
||||
top.addCard(card);
|
||||
this.getBottomTableWithCards().removeCard(card);
|
||||
if (this.getGameType().isLimited()) {
|
||||
this.getTopTableWithCards().addCard(card);
|
||||
}
|
||||
|
||||
customMenu.notifyDeckChange();
|
||||
this.getCustomMenu().notifyDeckChange();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -384,11 +393,26 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
void importButton_actionPerformed(final ActionEvent e) {
|
||||
DeckEditorBase g = this;
|
||||
DeckImport dImport = new DeckImport(g);
|
||||
void importButtonActionPerformed(final ActionEvent e) {
|
||||
final DeckEditorBase g = this;
|
||||
final DeckImport dImport = new DeckImport(g);
|
||||
dImport.setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
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.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,14 +49,14 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
/** Constant <code>previousDirectory</code>. */
|
||||
private static File previousDirectory = null;
|
||||
|
||||
private DeckManager deckManager;
|
||||
private final DeckManager deckManager;
|
||||
|
||||
private boolean isDeckSaved = true;
|
||||
|
||||
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
|
||||
*/
|
||||
public DeckEditorCommonMenu(final DeckDisplay inDisplay, final DeckManager dckManager, final Command exit) {
|
||||
deckDisplay = inDisplay;
|
||||
exitCommand = exit;
|
||||
deckManager = dckManager;
|
||||
this.deckDisplay = inDisplay;
|
||||
this.exitCommand = exit;
|
||||
this.deckManager = dckManager;
|
||||
|
||||
// this is added just to make save() and saveAs() work ok
|
||||
// when first started up, just a silly patch
|
||||
setDeckData("", true);
|
||||
this.setDeckData("", true);
|
||||
|
||||
setupMenu();
|
||||
setupSortMenu();
|
||||
this.setupMenu();
|
||||
this.setupSortMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,14 +88,14 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
* </p>
|
||||
*/
|
||||
private void setupSortMenu() {
|
||||
JMenuItem name = new JMenuItem("Card Name");
|
||||
JMenuItem cost = new JMenuItem("Cost");
|
||||
JMenuItem color = new JMenuItem("Color");
|
||||
JMenuItem type = new JMenuItem("Type");
|
||||
JMenuItem stats = new JMenuItem("Power/Toughness");
|
||||
JMenuItem rarity = new JMenuItem("Rarity");
|
||||
final JMenuItem name = new JMenuItem("Card Name");
|
||||
final JMenuItem cost = new JMenuItem("Cost");
|
||||
final JMenuItem color = new JMenuItem("Color");
|
||||
final JMenuItem type = new JMenuItem("Type");
|
||||
final JMenuItem stats = new JMenuItem("Power/Toughness");
|
||||
final JMenuItem rarity = new JMenuItem("Rarity");
|
||||
|
||||
JMenu menu = new JMenu("Sort By");
|
||||
final JMenu menu = new JMenu("Sort By");
|
||||
menu.add(name);
|
||||
menu.add(cost);
|
||||
menu.add(color);
|
||||
@@ -106,8 +106,9 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
this.add(menu);
|
||||
|
||||
name.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
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",
|
||||
// "Stats", "Rarity"};
|
||||
cost.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
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() {
|
||||
@Override
|
||||
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() {
|
||||
@Override
|
||||
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() {
|
||||
@Override
|
||||
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() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
// 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()
|
||||
@@ -153,27 +161,28 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
* a boolean
|
||||
*/
|
||||
public void newConstructed(final boolean careAboutOldDeck) {
|
||||
if (careAboutOldDeck && !canLeaveCurrentDeck()) {
|
||||
if (careAboutOldDeck && !this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setDeckData("", true);
|
||||
this.setDeckData("", true);
|
||||
|
||||
deckDisplay.setDeck(null, null, GameType.Constructed);
|
||||
this.deckDisplay.setDeck(null, null, GameType.Constructed);
|
||||
}
|
||||
|
||||
private void newRandomConstructed() {
|
||||
if (!canLeaveCurrentDeck()) {
|
||||
if (!this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setDeckData("", false);
|
||||
this.setDeckData("", false);
|
||||
|
||||
// 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);
|
||||
for (Card c : random) {
|
||||
final ItemPool<CardPrinted> cpRandom = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
for (final Card c : random) {
|
||||
cpRandom.add(CardDb.instance().getCard(c));
|
||||
}
|
||||
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("Terramorphic Expanse"));
|
||||
|
||||
deckDisplay.setDeck(cpRandom, null, GameType.Constructed);
|
||||
this.deckDisplay.setDeck(cpRandom, null, GameType.Constructed);
|
||||
}
|
||||
|
||||
private void newGenerateConstructed() {
|
||||
if (!canLeaveCurrentDeck()) {
|
||||
if (!this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setDeckData("", false);
|
||||
this.setDeckData("", false);
|
||||
|
||||
GenerateConstructedDeck gen = new GenerateConstructedDeck();
|
||||
final GenerateConstructedDeck gen = new GenerateConstructedDeck();
|
||||
|
||||
ItemPool<CardPrinted> generated = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
for (Card c : gen.generateDeck()) {
|
||||
final ItemPool<CardPrinted> generated = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
for (final Card c : gen.generateDeck()) {
|
||||
generated.add(CardDb.instance().getCard(c));
|
||||
}
|
||||
deckDisplay.setDeck(null, generated, GameType.Constructed);
|
||||
this.deckDisplay.setDeck(null, generated, GameType.Constructed);
|
||||
}
|
||||
|
||||
private File getImportFilename() {
|
||||
JFileChooser chooser = new JFileChooser(previousDirectory);
|
||||
final JFileChooser chooser = new JFileChooser(DeckEditorCommonMenu.previousDirectory);
|
||||
|
||||
chooser.addChoosableFileFilter(DeckManager.DCK_FILTER);
|
||||
int returnVal = chooser.showOpenDialog(null);
|
||||
final int returnVal = chooser.showOpenDialog(null);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File file = chooser.getSelectedFile();
|
||||
previousDirectory = file.getParentFile();
|
||||
final File file = chooser.getSelectedFile();
|
||||
DeckEditorCommonMenu.previousDirectory = file.getParentFile();
|
||||
return file;
|
||||
}
|
||||
return null;
|
||||
} // openFileDialog()
|
||||
|
||||
private void importDeck() {
|
||||
File file = getImportFilename();
|
||||
final File file = this.getImportFilename();
|
||||
|
||||
if (file == null) {
|
||||
} else if (file.getName().endsWith(".dck")) {
|
||||
try {
|
||||
FileChannel srcChannel = new FileInputStream(file).getChannel();
|
||||
File dst = new File(ForgeProps.getFile(NEW_DECKS).getAbsolutePath(), file.getName());
|
||||
final FileChannel srcChannel = new FileInputStream(file).getChannel();
|
||||
final File dst = new File(ForgeProps.getFile(NewConstants.NEW_DECKS).getAbsolutePath(), file.getName());
|
||||
if (!dst.createNewFile()) {
|
||||
JOptionPane.showMessageDialog(null, "Cannot import deck " + file.getName()
|
||||
+ ", a deck currently has that name.");
|
||||
return;
|
||||
}
|
||||
FileChannel dstChannel = new FileOutputStream(dst).getChannel();
|
||||
final FileChannel dstChannel = new FileOutputStream(dst).getChannel();
|
||||
dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
|
||||
srcChannel.close();
|
||||
dstChannel.close();
|
||||
|
||||
Deck newDeck = DeckManager.readDeck(file);
|
||||
deckManager.addDeck(newDeck);
|
||||
showDeck(newDeck, newDeck.getDeckType());
|
||||
final Deck newDeck = DeckManager.readDeck(file);
|
||||
this.deckManager.addDeck(newDeck);
|
||||
this.showDeck(newDeck, newDeck.getDeckType());
|
||||
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error, " + ex);
|
||||
}
|
||||
@@ -252,31 +261,31 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
* </p>
|
||||
*/
|
||||
private void exportDeck() {
|
||||
File filename = getExportFilename();
|
||||
final File filename = this.getExportFilename();
|
||||
if (filename == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Deck deck = getDeck();
|
||||
final Deck deck = this.getDeck();
|
||||
try {
|
||||
DeckManager.writeDeck(deck, filename);
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error, " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private File getExportFilename() {
|
||||
JFileChooser save = new JFileChooser(previousDirectory);
|
||||
final JFileChooser save = new JFileChooser(DeckEditorCommonMenu.previousDirectory);
|
||||
save.setDialogTitle("Export Deck Filename");
|
||||
save.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
save.setFileFilter(DeckManager.DCK_FILTER);
|
||||
|
||||
if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
File file = save.getSelectedFile();
|
||||
String check = file.getAbsolutePath();
|
||||
final File file = save.getSelectedFile();
|
||||
final String check = file.getAbsolutePath();
|
||||
|
||||
previousDirectory = file.getParentFile();
|
||||
DeckEditorCommonMenu.previousDirectory = file.getParentFile();
|
||||
|
||||
return check.endsWith(".dck") ? file : new File(check + ".dck");
|
||||
}
|
||||
@@ -289,31 +298,31 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
* </p>
|
||||
*/
|
||||
private void generateProxies() {
|
||||
File filename = getProxiesFilename();
|
||||
final File filename = this.getProxiesFilename();
|
||||
if (filename == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Deck deck = getDeck();
|
||||
final Deck deck = this.getDeck();
|
||||
try {
|
||||
DeckManager.writeDeckHtml(deck, filename);
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : printProxies() error, " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private File getProxiesFilename() {
|
||||
JFileChooser save = new JFileChooser(previousDirectory);
|
||||
final JFileChooser save = new JFileChooser(DeckEditorCommonMenu.previousDirectory);
|
||||
save.setDialogTitle("Proxy HTML Filename");
|
||||
save.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
save.setFileFilter(DeckManager.HTML_FILTER);
|
||||
|
||||
if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
File file = save.getSelectedFile();
|
||||
String check = file.getAbsolutePath();
|
||||
final File file = save.getSelectedFile();
|
||||
final String check = file.getAbsolutePath();
|
||||
|
||||
previousDirectory = file.getParentFile();
|
||||
DeckEditorCommonMenu.previousDirectory = file.getParentFile();
|
||||
|
||||
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) {
|
||||
if (!canLeaveCurrentDeck()) {
|
||||
if (!this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String name = getUserInputOpenDeck(gameType);
|
||||
final String name = this.getUserInputOpenDeck(gameType);
|
||||
|
||||
if (StringUtils.isBlank(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Deck deck = gameType == GameType.Draft ? deckManager.getDraftDeck(name)[0] : deckManager.getDeck(name);
|
||||
showDeck(deck, gameType);
|
||||
final Deck deck = gameType == GameType.Draft ? this.deckManager.getDraftDeck(name)[0] : this.deckManager
|
||||
.getDeck(name);
|
||||
this.showDeck(deck, gameType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -345,83 +355,83 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
* a GameType
|
||||
*/
|
||||
public void showDeck(final Deck deck, final GameType gameType) {
|
||||
setDeckData(deck.getName(), true);
|
||||
this.setDeckData(deck.getName(), true);
|
||||
if (gameType.isLimited()) {
|
||||
deckDisplay.setDeck(deck.getSideboard(), deck.getMain(), gameType);
|
||||
this.deckDisplay.setDeck(deck.getSideboard(), deck.getMain(), gameType);
|
||||
} else {
|
||||
deckDisplay.setDeck(null, deck.getMain(), gameType);
|
||||
this.deckDisplay.setDeck(null, deck.getMain(), gameType);
|
||||
}
|
||||
}
|
||||
|
||||
private void save() {
|
||||
|
||||
if (currentDeckName.equals("")) {
|
||||
saveAs();
|
||||
if (this.currentDeckName.equals("")) {
|
||||
this.saveAs();
|
||||
return;
|
||||
}
|
||||
|
||||
Deck deck = getDeck();
|
||||
if (deckDisplay.getGameType().equals(GameType.Draft)) {
|
||||
setDeckData(currentDeckName, true);
|
||||
final Deck deck = this.getDeck();
|
||||
if (this.deckDisplay.getGameType().equals(GameType.Draft)) {
|
||||
this.setDeckData(this.currentDeckName, true);
|
||||
// write booster deck
|
||||
Deck[] all = deckManager.getDraftDeck(currentDeckName);
|
||||
final Deck[] all = this.deckManager.getDraftDeck(this.currentDeckName);
|
||||
all[0] = deck;
|
||||
deckManager.addDraftDeck(all);
|
||||
this.deckManager.addDraftDeck(all);
|
||||
DeckManager.writeDraftDecks(all);
|
||||
} else { // constructed or sealed
|
||||
setDeckData(currentDeckName, true);
|
||||
deckManager.addDeck(deck);
|
||||
this.setDeckData(this.currentDeckName, true);
|
||||
this.deckManager.addDeck(deck);
|
||||
DeckManager.writeDeck(deck, DeckManager.makeFileName(deck));
|
||||
}
|
||||
isDeckSaved = true;
|
||||
this.isDeckSaved = true;
|
||||
}
|
||||
|
||||
private void saveAs() {
|
||||
String name = getDeckNameFromDialog();
|
||||
final String name = this.getDeckNameFromDialog();
|
||||
|
||||
if (name.equals("")) {
|
||||
return;
|
||||
}
|
||||
setDeckData(name, true);
|
||||
this.setDeckData(name, true);
|
||||
|
||||
Deck deck = getDeck();
|
||||
if (deckDisplay.getGameType().equals(GameType.Draft)) {
|
||||
final Deck deck = this.getDeck();
|
||||
if (this.deckDisplay.getGameType().equals(GameType.Draft)) {
|
||||
// MUST copy array
|
||||
Deck[] read = deckManager.getDraftDeck(currentDeckName);
|
||||
Deck[] all = new Deck[read.length];
|
||||
final Deck[] read = this.deckManager.getDraftDeck(this.currentDeckName);
|
||||
final Deck[] all = new Deck[read.length];
|
||||
|
||||
System.arraycopy(read, 0, all, 0, read.length);
|
||||
|
||||
all[0] = deck;
|
||||
deckManager.addDraftDeck(all);
|
||||
this.deckManager.addDraftDeck(all);
|
||||
DeckManager.writeDraftDecks(all);
|
||||
} else { // constructed and sealed
|
||||
deckManager.addDeck(deck);
|
||||
this.deckManager.addDeck(deck);
|
||||
DeckManager.writeDeck(deck, DeckManager.makeFileName(deck));
|
||||
}
|
||||
isDeckSaved = true;
|
||||
this.isDeckSaved = true;
|
||||
}
|
||||
|
||||
private void delete() {
|
||||
if (StringUtils.isBlank(currentDeckName)) {
|
||||
if (StringUtils.isBlank(this.currentDeckName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int n = JOptionPane.showConfirmDialog(null, "Do you want to delete this deck " + currentDeckName + " ?",
|
||||
"Delete", JOptionPane.YES_NO_OPTION);
|
||||
final int n = JOptionPane.showConfirmDialog(null, "Do you want to delete this deck " + this.currentDeckName
|
||||
+ " ?", "Delete", JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if (n == JOptionPane.NO_OPTION) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (deckDisplay.getGameType().equals(GameType.Draft)) {
|
||||
deckManager.deleteDraftDeck(currentDeckName);
|
||||
if (this.deckDisplay.getGameType().equals(GameType.Draft)) {
|
||||
this.deckManager.deleteDraftDeck(this.currentDeckName);
|
||||
} else {
|
||||
deckManager.deleteDeck(currentDeckName);
|
||||
this.deckManager.deleteDeck(this.currentDeckName);
|
||||
}
|
||||
|
||||
setDeckData("", true);
|
||||
deckDisplay.setDeck(null, null, deckDisplay.getGameType());
|
||||
this.setDeckData("", true);
|
||||
this.deckDisplay.setDeck(null, null, this.deckDisplay.getGameType());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -429,20 +439,20 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
* close window.
|
||||
*/
|
||||
public void close() {
|
||||
if (!canLeaveCurrentDeck()) {
|
||||
if (!this.canLeaveCurrentDeck()) {
|
||||
return;
|
||||
}
|
||||
exitCommand.execute();
|
||||
this.exitCommand.execute();
|
||||
}
|
||||
|
||||
private boolean canLeaveCurrentDeck() {
|
||||
if (isSaved()) {
|
||||
if (this.isSaved()) {
|
||||
return true;
|
||||
}
|
||||
String message = String.format("Do you wish to save changes you made to your current deck '%s'?",
|
||||
currentDeckName);
|
||||
int choice = JOptionPane
|
||||
.showConfirmDialog((Component) deckDisplay, message, "You have unsaved changes in your deck",
|
||||
final String message = String.format("Do you wish to save changes you made to your current deck '%s'?",
|
||||
this.currentDeckName);
|
||||
final int choice = JOptionPane
|
||||
.showConfirmDialog((Component) this.deckDisplay, message, "You have unsaved changes in your deck",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
if (JOptionPane.CANCEL_OPTION == choice) {
|
||||
return false;
|
||||
@@ -451,23 +461,23 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
return true;
|
||||
}
|
||||
|
||||
Deck deck = getDeck();
|
||||
deck.setName(currentDeckName);
|
||||
final Deck deck = this.getDeck();
|
||||
deck.setName(this.currentDeckName);
|
||||
DeckManager.writeDeck(deck, DeckManager.makeFileName(deck));
|
||||
return true;
|
||||
}
|
||||
|
||||
private Deck getDeck() {
|
||||
Deck deck = deckDisplay.getDeck();
|
||||
deck.setName(currentDeckName);
|
||||
final Deck deck = this.deckDisplay.getDeck();
|
||||
deck.setName(this.currentDeckName);
|
||||
return deck;
|
||||
}
|
||||
|
||||
private void setDeckData(final String deckName, final boolean inDeckSaved) {
|
||||
currentDeckName = deckName;
|
||||
isDeckSaved = inDeckSaved;
|
||||
this.currentDeckName = deckName;
|
||||
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
|
||||
*/
|
||||
public String getDeckName() {
|
||||
return currentDeckName;
|
||||
return this.currentDeckName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -487,7 +497,7 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
* @return a boolean
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String deckName = DeckManager.cleanDeckName(o.toString());
|
||||
boolean isDraft = deckDisplay.getGameType() == GameType.Draft;
|
||||
boolean isUniqueName = isDraft ? deckManager.isUniqueDraft(deckName) : deckManager.isUnique(deckName);
|
||||
boolean isGoodName = isUniqueName && StringUtils.isNotBlank(deckName);
|
||||
final String deckName = DeckManager.cleanDeckName(o.toString());
|
||||
final boolean isDraft = this.deckDisplay.getGameType() == GameType.Draft;
|
||||
final boolean isUniqueName = isDraft ? this.deckManager.isUniqueDraft(deckName) : this.deckManager
|
||||
.isUnique(deckName);
|
||||
final boolean isGoodName = isUniqueName && StringUtils.isNotBlank(deckName);
|
||||
|
||||
if (isGoodName) {
|
||||
return deckName;
|
||||
}
|
||||
|
||||
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) {
|
||||
ArrayList<String> choices = deckManager.getDeckNames(deckType);
|
||||
final ArrayList<String> choices = this.deckManager.getDeckNames(deckType);
|
||||
if (choices.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE);
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -535,35 +546,35 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
* Notify of a Deck Change.
|
||||
*/
|
||||
public void notifyDeckChange() {
|
||||
isDeckSaved = false;
|
||||
this.isDeckSaved = false;
|
||||
}
|
||||
|
||||
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 newDraft = new JMenuItem("New Deck - Draft");
|
||||
|
||||
JMenuItem newRandomConstructed = new JMenuItem("New Deck - Generate Random Constructed Cardpool");
|
||||
JMenuItem newGenerateConstructed = new JMenuItem("New Deck - Generate Constructed Deck");
|
||||
final JMenuItem newRandomConstructed = new JMenuItem("New Deck - Generate Random Constructed Cardpool");
|
||||
final JMenuItem newGenerateConstructed = new JMenuItem("New Deck - Generate Constructed Deck");
|
||||
|
||||
JMenuItem importDeck = new JMenuItem("Import Deck...");
|
||||
JMenuItem exportDeck = new JMenuItem("Export Deck...");
|
||||
final JMenuItem importDeck = new JMenuItem("Import Deck...");
|
||||
final JMenuItem exportDeck = new JMenuItem("Export Deck...");
|
||||
// JMenuItem downloadDeck = new JMenuItem("Download Deck");
|
||||
|
||||
JMenuItem openConstructed = new JMenuItem("Open Deck - Constructed...");
|
||||
JMenuItem openSealed = new JMenuItem("Open Deck - Sealed");
|
||||
JMenuItem openDraft = new JMenuItem("Open Deck - Draft");
|
||||
final JMenuItem openConstructed = new JMenuItem("Open Deck - Constructed...");
|
||||
final JMenuItem openSealed = new JMenuItem("Open Deck - Sealed");
|
||||
final JMenuItem openDraft = new JMenuItem("Open Deck - Draft");
|
||||
|
||||
// newDraftItem = newDraft;
|
||||
// newDraftItem.setEnabled(false);
|
||||
|
||||
JMenuItem save = new JMenuItem("Save");
|
||||
JMenuItem saveAs = new JMenuItem("Save As...");
|
||||
JMenuItem delete = new JMenuItem("Delete");
|
||||
JMenuItem close = new JMenuItem("Close");
|
||||
final JMenuItem save = new JMenuItem("Save");
|
||||
final JMenuItem saveAs = new JMenuItem("Save As...");
|
||||
final JMenuItem delete = new JMenuItem("Delete");
|
||||
final JMenuItem close = new JMenuItem("Close");
|
||||
|
||||
JMenu fileMenu = new JMenu("Deck Actions");
|
||||
final JMenu fileMenu = new JMenu("Deck Actions");
|
||||
fileMenu.add(newConstructed);
|
||||
|
||||
// fileMenu.add(newSealed);
|
||||
@@ -578,18 +589,20 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
fileMenu.add(importDeck);
|
||||
fileMenu.add(exportDeck);
|
||||
|
||||
JMenuItem generateProxies = new JMenuItem("Generate Proxies...");
|
||||
final JMenuItem generateProxies = new JMenuItem("Generate Proxies...");
|
||||
fileMenu.add(generateProxies);
|
||||
|
||||
generateProxies.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
generateProxies();
|
||||
DeckEditorCommonMenu.this.generateProxies();
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : generateProxies() error - " + ex);
|
||||
}
|
||||
@@ -613,14 +626,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
|
||||
// add listeners
|
||||
exportDeck.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
exportDeck();
|
||||
DeckEditorCommonMenu.this.exportDeck();
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(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() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
importDeck();
|
||||
DeckEditorCommonMenu.this.importDeck();
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error - " + ex);
|
||||
}
|
||||
@@ -652,14 +669,16 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
||||
* ex); } } });
|
||||
*/
|
||||
newConstructed.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
newConstructed(true);
|
||||
DeckEditorCommonMenu.this.newConstructed(true);
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(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() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
newRandomConstructed();
|
||||
DeckEditorCommonMenu.this.newRandomConstructed();
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(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() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
newGenerateConstructed();
|
||||
DeckEditorCommonMenu.this.newGenerateConstructed();
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(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() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
openDeck(GameType.Constructed);
|
||||
DeckEditorCommonMenu.this.openDeck(GameType.Constructed);
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(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() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
openDeck(GameType.Sealed);
|
||||
DeckEditorCommonMenu.this.openDeck(GameType.Sealed);
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(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() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
openDeck(GameType.Draft);
|
||||
DeckEditorCommonMenu.this.openDeck(GameType.Draft);
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(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() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
save();
|
||||
DeckEditorCommonMenu.this.save();
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(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() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
saveAs();
|
||||
DeckEditorCommonMenu.this.saveAs();
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(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() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delete();
|
||||
DeckEditorCommonMenu.this.delete();
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(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() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
try {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
close();
|
||||
DeckEditorCommonMenu.this.close();
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_DeckEditor_Menu : close() error - " + ex);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.List;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
import net.slightlymagic.maxmtg.Predicate;
|
||||
import forge.AllZone;
|
||||
@@ -34,6 +35,7 @@ import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.properties.NewConstants.LANG.Gui_BoosterDraft;
|
||||
import forge.view.swing.Gui_HomeScreen;
|
||||
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 {
|
||||
/**
|
||||
* Constant <code>serialVersionUID=-6055633915602448260L</code>
|
||||
* Constant <code>serialVersionUID=-6055633915602448260L</code>.
|
||||
*/
|
||||
private static final long serialVersionUID = -6055633915602448260L;
|
||||
|
||||
private BoosterDraft boosterDraft;
|
||||
|
||||
private JButton jButtonPick = new JButton();
|
||||
private final JButton jButtonPick = new JButton();
|
||||
|
||||
private CardPanelLite cardView = new CardPanelLite();
|
||||
|
||||
private MouseListener pickWithMouse = new MouseAdapter() {
|
||||
private final MouseListener pickWithMouse = new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
// Pick on left-button double click
|
||||
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0 && e.getClickCount() == 2) {
|
||||
jButtonPickClicked(null);
|
||||
if (((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) && (e.getClickCount() == 2)) {
|
||||
DeckEditorDraft.this.jButtonPickClicked(null);
|
||||
} else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { // pick
|
||||
// on
|
||||
// right
|
||||
// click
|
||||
JTable table = top.getTable();
|
||||
int rowNumber = table.rowAtPoint(e.getPoint());
|
||||
final JTable table = DeckEditorDraft.this.getTopTableWithCards().getTable();
|
||||
final int rowNumber = table.rowAtPoint(e.getPoint());
|
||||
// after hittest - if it was outside of rows - discard this
|
||||
// click
|
||||
if (rowNumber == -1) {
|
||||
@@ -79,7 +81,7 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
|
||||
if (rowNumber != table.getSelectedRow()) {
|
||||
table.getSelectionModel().setSelectionInterval(rowNumber, rowNumber);
|
||||
} else {
|
||||
jButtonPickClicked(null);
|
||||
DeckEditorDraft.this.jButtonPickClicked(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,20 +90,20 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
|
||||
/**
|
||||
* Show gui.
|
||||
*
|
||||
* @param in_boosterDraft
|
||||
* @param inBoosterDraft
|
||||
* the in_booster draft
|
||||
*/
|
||||
public final void showGui(final BoosterDraft in_boosterDraft) {
|
||||
boosterDraft = in_boosterDraft;
|
||||
public final void showGui(final BoosterDraft inBoosterDraft) {
|
||||
this.boosterDraft = inBoosterDraft;
|
||||
|
||||
setup();
|
||||
showChoices(boosterDraft.nextChoice());
|
||||
bottom.setDeck((Iterable<InventoryItem>) null);
|
||||
this.setup();
|
||||
this.showChoices(this.boosterDraft.nextChoice());
|
||||
this.getBottomTableWithCards().setDeck((Iterable<InventoryItem>) null);
|
||||
|
||||
top.sort(1, true);
|
||||
bottom.sort(1, true);
|
||||
this.getTopTableWithCards().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() {
|
||||
@Override
|
||||
public void windowClosing(final WindowEvent ev) {
|
||||
int n = JOptionPane.showConfirmDialog(null, ForgeProps.getLocalized(CLOSE_MESSAGE), "",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
final int n = JOptionPane.showConfirmDialog(null,
|
||||
ForgeProps.getLocalized(Gui_BoosterDraft.CLOSE_MESSAGE), "", JOptionPane.YES_NO_OPTION);
|
||||
if (n == JOptionPane.YES_OPTION) {
|
||||
dispose();
|
||||
DeckEditorDraft.this.dispose();
|
||||
|
||||
if (System.getenv("NG2") != null) {
|
||||
if (System.getenv("NG2").equalsIgnoreCase("true")) {
|
||||
String[] argz = {};
|
||||
final String[] argz = {};
|
||||
Gui_HomeScreen.main(argz);
|
||||
} else {
|
||||
new OldGuiNewGame();
|
||||
@@ -130,9 +132,9 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
|
||||
}
|
||||
|
||||
}
|
||||
}// windowClosing()
|
||||
} // windowClosing()
|
||||
});
|
||||
}// addListeners()
|
||||
} // addListeners()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -140,14 +142,16 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
|
||||
* </p>
|
||||
*/
|
||||
private void setup() {
|
||||
addListeners();
|
||||
this.addListeners();
|
||||
// setupMenu();
|
||||
|
||||
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE, PresetColumns.FN_QTY_GET));
|
||||
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>("Name", 180, PresetColumns.FN_NAME_COMPARE,
|
||||
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,
|
||||
PresetColumns.FN_COLOR_GET));
|
||||
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));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.FN_RARITY_COMPARE,
|
||||
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,
|
||||
PresetColumns.FN_AI_STATUS_GET));
|
||||
columns.get(2).setCellRenderer(new ManaCostRenderer());
|
||||
|
||||
top.setup(columns, cardView);
|
||||
bottom.setup(columns, cardView);
|
||||
this.getTopTableWithCards().setup(columns, this.cardView);
|
||||
this.getBottomTableWithCards().setup(columns, this.cardView);
|
||||
|
||||
this.setSize(980, 740);
|
||||
GuiUtils.centerFrame(this);
|
||||
this.setResizable(false);
|
||||
|
||||
top.getTable().addMouseListener(pickWithMouse);
|
||||
top.getTable().addKeyListener(new KeyAdapter() {
|
||||
this.getTopTableWithCards().getTable().addMouseListener(this.pickWithMouse);
|
||||
this.getTopTableWithCards().getTable().addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
if (e.getKeyChar() == ' ') {
|
||||
jButtonPickClicked(null);
|
||||
DeckEditorDraft.this.jButtonPickClicked(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -186,12 +191,12 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
|
||||
public DeckEditorDraft() {
|
||||
super(GameType.Draft);
|
||||
try {
|
||||
top = new TableWithCards("Choose one card", false);
|
||||
bottom = new TableWithCards("Previously picked cards", true);
|
||||
filterBoxes = null;
|
||||
cardView = new CardPanelLite();
|
||||
jbInit();
|
||||
} catch (Exception ex) {
|
||||
this.setTopTableWithCards(new TableWithCards("Choose one card", false));
|
||||
this.setBottomTableWithCards(new TableWithCards("Previously picked cards", true));
|
||||
this.setFilterBoxes(null);
|
||||
this.cardView = new CardPanelLite();
|
||||
this.jbInit();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
}
|
||||
@@ -207,29 +212,30 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
|
||||
private void jbInit() throws Exception {
|
||||
this.getContentPane().setLayout(null);
|
||||
|
||||
top.getTableDecorated().setBounds(new Rectangle(19, 28, 680, 344));
|
||||
bottom.getTableDecorated().setBounds(new Rectangle(19, 478, 680, 184));
|
||||
bottom.getLabel().setBounds(new Rectangle(19, 680, 665, 31));
|
||||
this.getTopTableWithCards().getTableDecorated().setBounds(new Rectangle(19, 28, 680, 344));
|
||||
this.getBottomTableWithCards().getTableDecorated().setBounds(new Rectangle(19, 478, 680, 184));
|
||||
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");
|
||||
|
||||
jButtonPick.setBounds(new Rectangle(238, 418, 147, 44));
|
||||
jButtonPick.setFont(new java.awt.Font("Dialog", 0, 16));
|
||||
jButtonPick.setText("Choose Card");
|
||||
jButtonPick.addActionListener(new ActionListener() {
|
||||
this.jButtonPick.setBounds(new Rectangle(238, 418, 147, 44));
|
||||
this.jButtonPick.setFont(new java.awt.Font("Dialog", 0, 16));
|
||||
this.jButtonPick.setText("Choose Card");
|
||||
this.jButtonPick.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
jButtonPickClicked(e);
|
||||
DeckEditorDraft.this.jButtonPickClicked(e);
|
||||
}
|
||||
});
|
||||
|
||||
this.getContentPane().add(cardView, null);
|
||||
this.getContentPane().add(top.getTableDecorated(), null);
|
||||
this.getContentPane().add(bottom.getLabel(), null);
|
||||
this.getContentPane().add(bottom.getTableDecorated(), null);
|
||||
this.getContentPane().add(jButtonPick, null);
|
||||
this.getContentPane().add(this.cardView, null);
|
||||
this.getContentPane().add(this.getTopTableWithCards().getTableDecorated(), null);
|
||||
this.getContentPane().add(this.getBottomTableWithCards().getLabel(), null);
|
||||
this.getContentPane().add(this.getBottomTableWithCards().getTableDecorated(), 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.
|
||||
*/
|
||||
final void jButtonPickClicked(final ActionEvent e) {
|
||||
InventoryItem item = top.getSelectedCard();
|
||||
if (item == null || !(item instanceof CardPrinted)) {
|
||||
final InventoryItem item = this.getTopTableWithCards().getSelectedCard();
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CardPrinted card = (CardPrinted) item;
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
|
||||
bottom.addCard(card);
|
||||
this.getBottomTableWithCards().addCard(card);
|
||||
|
||||
// get next booster pack
|
||||
boosterDraft.setChoice(card);
|
||||
if (boosterDraft.hasNextChoice()) {
|
||||
showChoices(boosterDraft.nextChoice());
|
||||
this.boosterDraft.setChoice(card);
|
||||
if (this.boosterDraft.hasNextChoice()) {
|
||||
this.showChoices(this.boosterDraft.nextChoice());
|
||||
} else {
|
||||
boosterDraft.finishedDrafting();
|
||||
this.boosterDraft.finishedDrafting();
|
||||
|
||||
// quit
|
||||
saveDraft();
|
||||
dispose();
|
||||
this.saveDraft();
|
||||
this.dispose();
|
||||
}
|
||||
}/* OK Button */
|
||||
} /* OK Button */
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -272,10 +278,10 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
private void showChoices(final ItemPoolView<CardPrinted> list) {
|
||||
top.setDeck(list);
|
||||
cardView.showCard(null);
|
||||
top.fixSelection(0);
|
||||
}// showChoices()
|
||||
this.getTopTableWithCards().setDeck(list);
|
||||
this.cardView.showCard(null);
|
||||
this.getTopTableWithCards().fixSelection(0);
|
||||
} // showChoices()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -285,23 +291,23 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
private Deck getPlayersDeck() {
|
||||
Deck deck = new Deck(GameType.Draft);
|
||||
final Deck deck = new Deck(GameType.Draft);
|
||||
Constant.Runtime.HUMAN_DECK[0] = 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);
|
||||
|
||||
String landSet = BoosterDraft.LAND_SET_CODE[0];
|
||||
final int LANDS_COUNT = 20;
|
||||
deck.addSideboard(CardDb.instance().getCard("Forest", landSet), LANDS_COUNT);
|
||||
deck.addSideboard(CardDb.instance().getCard("Mountain", landSet), LANDS_COUNT);
|
||||
deck.addSideboard(CardDb.instance().getCard("Swamp", landSet), LANDS_COUNT);
|
||||
deck.addSideboard(CardDb.instance().getCard("Island", landSet), LANDS_COUNT);
|
||||
deck.addSideboard(CardDb.instance().getCard("Plains", landSet), LANDS_COUNT);
|
||||
final String landSet = BoosterDraft.LAND_SET_CODE[0];
|
||||
final int landsCount = 20;
|
||||
deck.addSideboard(CardDb.instance().getCard("Forest", landSet), landsCount);
|
||||
deck.addSideboard(CardDb.instance().getCard("Mountain", landSet), landsCount);
|
||||
deck.addSideboard(CardDb.instance().getCard("Swamp", landSet), landsCount);
|
||||
deck.addSideboard(CardDb.instance().getCard("Island", landSet), landsCount);
|
||||
deck.addSideboard(CardDb.instance().getCard("Plains", landSet), landsCount);
|
||||
|
||||
return deck;
|
||||
}// getPlayersDeck()
|
||||
} // getPlayersDeck()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -310,21 +316,22 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
|
||||
*/
|
||||
private void saveDraft() {
|
||||
String s = "";
|
||||
while (s == null || s.length() == 0) {
|
||||
s = JOptionPane.showInputDialog(null, ForgeProps.getLocalized(SAVE_DRAFT_MESSAGE),
|
||||
ForgeProps.getLocalized(SAVE_DRAFT_TITLE), JOptionPane.QUESTION_MESSAGE);
|
||||
while ((s == null) || (s.length() == 0)) {
|
||||
s = JOptionPane.showInputDialog(null, ForgeProps.getLocalized(Gui_BoosterDraft.SAVE_DRAFT_MESSAGE),
|
||||
ForgeProps.getLocalized(Gui_BoosterDraft.SAVE_DRAFT_TITLE), JOptionPane.QUESTION_MESSAGE);
|
||||
}
|
||||
// TODO: check if overwriting the same name, and let the user delete old
|
||||
// drafts
|
||||
|
||||
// construct computer's decks
|
||||
// save draft
|
||||
Deck[] computer = boosterDraft.getDecks();
|
||||
final Deck[] computer = this.boosterDraft.getDecks();
|
||||
|
||||
Deck human = getPlayersDeck();
|
||||
final Deck human = this.getPlayersDeck();
|
||||
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++) {
|
||||
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(ForgeProps.getFile(NEW_DECKS));
|
||||
DeckManager deckManager = AllZone.getDeckManager();
|
||||
final DeckManager deckManager = AllZone.getDeckManager();
|
||||
deckManager.addDraftDeck(all);
|
||||
|
||||
// write file
|
||||
DeckManager.writeDraftDecks(all);
|
||||
|
||||
// close and open next screen
|
||||
dispose();
|
||||
this.dispose();
|
||||
|
||||
if (System.getenv("NG2") != null) {
|
||||
if (System.getenv("NG2").equalsIgnoreCase("true")) {
|
||||
String[] argz = {};
|
||||
final String[] argz = {};
|
||||
Gui_HomeScreen.main(argz);
|
||||
} else {
|
||||
new OldGuiNewGame();
|
||||
@@ -352,7 +359,7 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
|
||||
new OldGuiNewGame();
|
||||
}
|
||||
|
||||
}/* saveDraft() */
|
||||
} /* saveDraft() */
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
||||
@@ -40,23 +40,23 @@ import forge.quest.data.QuestData;
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class DeckEditorQuest extends DeckEditorBase implements NewConstants {
|
||||
/** Constant <code>serialVersionUID=152061168634545L</code> */
|
||||
/** Constant <code>serialVersionUID=152061168634545L</code>. */
|
||||
private static final long serialVersionUID = 152061168634545L;
|
||||
|
||||
/** The custom menu. */
|
||||
DeckEditorQuestMenu customMenu;
|
||||
private DeckEditorQuestMenu customMenu;
|
||||
|
||||
// private ImageIcon upIcon = Constant.IO.upIcon;
|
||||
// private ImageIcon downIcon = Constant.IO.downIcon;
|
||||
|
||||
// private JLabel labelSortHint = new JLabel();
|
||||
private JButton addButton = new JButton();
|
||||
private JButton removeButton = new JButton();
|
||||
private JButton analysisButton = new JButton();
|
||||
private final JButton addButton = new JButton();
|
||||
private final JButton removeButton = new JButton();
|
||||
private final JButton analysisButton = new JButton();
|
||||
|
||||
private FilterNameTypeSetPanel filterNameTypeSet;
|
||||
|
||||
private QuestData questData;
|
||||
private final QuestData questData;
|
||||
|
||||
/**
|
||||
* Show.
|
||||
@@ -68,6 +68,7 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
|
||||
final Command exit = new Command() {
|
||||
private static final long serialVersionUID = -7428793574300520612L;
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
DeckEditorQuest.this.dispose();
|
||||
exitCommand.execute();
|
||||
@@ -78,44 +79,44 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(final WindowEvent ev) {
|
||||
customMenu.close();
|
||||
DeckEditorQuest.this.customMenu.close();
|
||||
}
|
||||
});
|
||||
|
||||
setup();
|
||||
this.setup();
|
||||
|
||||
customMenu = new DeckEditorQuestMenu(questData, this, exit);
|
||||
this.setJMenuBar(customMenu);
|
||||
this.customMenu = new DeckEditorQuestMenu(this.questData, this, exit);
|
||||
this.setJMenuBar(this.customMenu);
|
||||
|
||||
Deck deck = null;
|
||||
|
||||
// open deck that the player used if QuestData has it
|
||||
if (Constant.Runtime.HUMAN_DECK[0] != null
|
||||
&& questData.getDeckNames().contains(Constant.Runtime.HUMAN_DECK[0].getName())) {
|
||||
deck = questData.getDeck(Constant.Runtime.HUMAN_DECK[0].getName());
|
||||
if ((Constant.Runtime.HUMAN_DECK[0] != null)
|
||||
&& this.questData.getDeckNames().contains(Constant.Runtime.HUMAN_DECK[0].getName())) {
|
||||
deck = this.questData.getDeck(Constant.Runtime.HUMAN_DECK[0].getName());
|
||||
} else {
|
||||
deck = new Deck(GameType.Sealed);
|
||||
deck.setName("");
|
||||
}
|
||||
|
||||
// tell Gui_Quest_DeckEditor the name of the deck
|
||||
customMenu.setPlayerDeckName(deck.getName());
|
||||
this.customMenu.setPlayerDeckName(deck.getName());
|
||||
|
||||
ItemPoolView<CardPrinted> bottomPool = deck.getMain();
|
||||
ItemPool<CardPrinted> cardpool = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
cardpool.addAll(questData.getCards().getCardpool());
|
||||
final ItemPoolView<CardPrinted> bottomPool = deck.getMain();
|
||||
final ItemPool<CardPrinted> cardpool = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
cardpool.addAll(this.questData.getCards().getCardpool());
|
||||
|
||||
// remove bottom cards that are in the deck from the card pool
|
||||
cardpool.removeAll(bottomPool);
|
||||
|
||||
// show cards, makes this user friendly
|
||||
setDeck(cardpool, bottomPool, GameType.Quest);
|
||||
this.setDeck(cardpool, bottomPool, GameType.Quest);
|
||||
|
||||
// this affects the card pool
|
||||
top.sort(4, true); // sort by type
|
||||
top.sort(3, true); // then sort by color
|
||||
this.getTopTableWithCards().sort(4, true); // sort by type
|
||||
this.getTopTableWithCards().sort(3, true); // then sort by color
|
||||
|
||||
bottom.sort(1, true);
|
||||
this.getBottomTableWithCards().sort(1, true);
|
||||
} // show(Command)
|
||||
|
||||
/**
|
||||
@@ -126,11 +127,13 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
|
||||
public void setup() {
|
||||
this.setLayout(null);
|
||||
|
||||
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE, PresetColumns.FN_QTY_GET));
|
||||
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>("Name", 180, PresetColumns.FN_NAME_COMPARE,
|
||||
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,
|
||||
PresetColumns.FN_COLOR_GET));
|
||||
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));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.FN_RARITY_COMPARE,
|
||||
PresetColumns.FN_RARITY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE, PresetColumns.FN_SET_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("New", 30, questData.getCards().fnNewCompare, questData
|
||||
.getCards().fnNewGet));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE,
|
||||
PresetColumns.FN_SET_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("New", 30, this.questData.getCards().fnNewCompare,
|
||||
this.questData.getCards().fnNewGet));
|
||||
|
||||
columns.get(2).setCellRenderer(new ManaCostRenderer());
|
||||
|
||||
top.setup(columns, cardView);
|
||||
bottom.setup(columns, cardView);
|
||||
this.getTopTableWithCards().setup(columns, this.getCardView());
|
||||
this.getBottomTableWithCards().setup(columns, this.getCardView());
|
||||
|
||||
filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), itemListenerUpdatesDisplay);
|
||||
this.filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), this.getItemListenerUpdatesDisplay());
|
||||
|
||||
this.setSize(1024, 768);
|
||||
GuiUtils.centerFrame(this);
|
||||
@@ -168,15 +172,15 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
|
||||
*/
|
||||
public DeckEditorQuest(final QuestData questData2) {
|
||||
super(GameType.Quest);
|
||||
questData = questData2;
|
||||
this.questData = questData2;
|
||||
try {
|
||||
filterBoxes = new FilterCheckBoxes(false);
|
||||
top = new TableWithCards("All Cards", true);
|
||||
bottom = new TableWithCards("Your deck", true);
|
||||
cardView = new CardPanelHeavy();
|
||||
filterNameTypeSet = new FilterNameTypeSetPanel();
|
||||
jbInit();
|
||||
} catch (Exception ex) {
|
||||
this.setFilterBoxes(new FilterCheckBoxes(false));
|
||||
this.setTopTableWithCards(new TableWithCards("All Cards", true));
|
||||
this.setBottomTableWithCards(new TableWithCards("Your deck", true));
|
||||
this.setCardView(new CardPanelHeavy());
|
||||
this.filterNameTypeSet = new FilterNameTypeSetPanel();
|
||||
this.jbInit();
|
||||
} catch (final Exception 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.setBounds(new Rectangle(20, 27, 400, 19));
|
||||
|
||||
filterNameTypeSet.setBounds(new Rectangle(19, 10, 726, 25));
|
||||
top.getTableDecorated().setBounds(new Rectangle(19, 40, 726, 316));
|
||||
bottom.getTableDecorated().setBounds(new Rectangle(19, 458, 726, 218));
|
||||
this.filterNameTypeSet.setBounds(new Rectangle(19, 10, 726, 25));
|
||||
this.getTopTableWithCards().getTableDecorated().setBounds(new Rectangle(19, 40, 726, 316));
|
||||
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);
|
||||
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");
|
||||
removeButton.addActionListener(new ActionListener() {
|
||||
this.removeButton.setText("Remove Card");
|
||||
this.removeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
removeButtonActionPerformed(e);
|
||||
DeckEditorQuest.this.removeButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
addButton.setText("Add Card");
|
||||
addButton.addActionListener(new ActionListener() {
|
||||
this.addButton.setText("Add Card");
|
||||
this.addButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
addButtonActionPerformed(e);
|
||||
DeckEditorQuest.this.addButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
// addButton.setIcon(downIcon);
|
||||
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");
|
||||
analysisButton.addActionListener(new ActionListener() {
|
||||
this.analysisButton.setText("Deck Analysis");
|
||||
this.analysisButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
analysisButton_actionPerformed(e);
|
||||
DeckEditorQuest.this.analysisButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
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
|
||||
*/
|
||||
filterBoxes.land.setBounds(340, 400, 48, 20);
|
||||
filterBoxes.creature.setBounds(385, 400, 65, 20);
|
||||
filterBoxes.sorcery.setBounds(447, 400, 62, 20);
|
||||
filterBoxes.instant.setBounds(505, 400, 60, 20);
|
||||
filterBoxes.planeswalker.setBounds(558, 400, 85, 20);
|
||||
filterBoxes.artifact.setBounds(638, 400, 58, 20);
|
||||
filterBoxes.enchantment.setBounds(692, 400, 80, 20);
|
||||
this.getFilterBoxes().getLand().setBounds(340, 400, 48, 20);
|
||||
this.getFilterBoxes().getCreature().setBounds(385, 400, 65, 20);
|
||||
this.getFilterBoxes().getSorcery().setBounds(447, 400, 62, 20);
|
||||
this.getFilterBoxes().getInstant().setBounds(505, 400, 60, 20);
|
||||
this.getFilterBoxes().getPlaneswalker().setBounds(558, 400, 85, 20);
|
||||
this.getFilterBoxes().getArtifact().setBounds(638, 400, 58, 20);
|
||||
this.getFilterBoxes().getEnchantment().setBounds(692, 400, 80, 20);
|
||||
|
||||
Font f = new Font("Tahoma", Font.PLAIN, 10);
|
||||
for (JCheckBox box : filterBoxes.allTypes) {
|
||||
final Font f = new Font("Tahoma", Font.PLAIN, 10);
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
|
||||
if (!Singletons.getModel().getPreferences().lafFonts) {
|
||||
box.setFont(f);
|
||||
}
|
||||
box.setOpaque(false);
|
||||
box.addItemListener(itemListenerUpdatesDisplay);
|
||||
box.addItemListener(this.getItemListenerUpdatesDisplay());
|
||||
}
|
||||
|
||||
/**
|
||||
* Color filtering
|
||||
*/
|
||||
filterBoxes.white.setBounds(340, 430, 40, 20);
|
||||
filterBoxes.blue.setBounds(380, 430, 40, 20);
|
||||
filterBoxes.black.setBounds(420, 430, 40, 20);
|
||||
filterBoxes.red.setBounds(460, 430, 40, 20);
|
||||
filterBoxes.green.setBounds(500, 430, 40, 20);
|
||||
filterBoxes.colorless.setBounds(540, 430, 40, 20);
|
||||
this.getFilterBoxes().getWhite().setBounds(340, 430, 40, 20);
|
||||
this.getFilterBoxes().getBlue().setBounds(380, 430, 40, 20);
|
||||
this.getFilterBoxes().getBlack().setBounds(420, 430, 40, 20);
|
||||
this.getFilterBoxes().getRed().setBounds(460, 430, 40, 20);
|
||||
this.getFilterBoxes().getGreen().setBounds(500, 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.addItemListener(itemListenerUpdatesDisplay);
|
||||
box.addItemListener(this.getItemListenerUpdatesDisplay());
|
||||
}
|
||||
/**
|
||||
* Other
|
||||
*/
|
||||
cardView.setBounds(new Rectangle(765, 23, 239, 687));
|
||||
top.getLabel().setBounds(new Rectangle(19, 365, 720, 31));
|
||||
bottom.getLabel().setBounds(new Rectangle(19, 672, 720, 31));
|
||||
this.getCardView().setBounds(new Rectangle(765, 23, 239, 687));
|
||||
this.getTopTableWithCards().getLabel().setBounds(new Rectangle(19, 365, 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
|
||||
// x 768 screen size
|
||||
this.setTitle("Deck Editor");
|
||||
|
||||
this.getContentPane().add(filterNameTypeSet, null);
|
||||
this.getContentPane().add(top.getTableDecorated(), null);
|
||||
this.getContentPane().add(bottom.getTableDecorated(), null);
|
||||
this.getContentPane().add(addButton, null);
|
||||
this.getContentPane().add(removeButton, null);
|
||||
this.getContentPane().add(analysisButton, null);
|
||||
this.getContentPane().add(bottom.getLabel(), null);
|
||||
this.getContentPane().add(top.getLabel(), null);
|
||||
this.getContentPane().add(this.filterNameTypeSet, null);
|
||||
this.getContentPane().add(this.getTopTableWithCards().getTableDecorated(), null);
|
||||
this.getContentPane().add(this.getBottomTableWithCards().getTableDecorated(), null);
|
||||
this.getContentPane().add(this.addButton, null);
|
||||
this.getContentPane().add(this.removeButton, null);
|
||||
this.getContentPane().add(this.analysisButton, null);
|
||||
this.getContentPane().add(this.getBottomTableWithCards().getLabel(), null);
|
||||
this.getContentPane().add(this.getTopTableWithCards().getLabel(), 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);
|
||||
}
|
||||
|
||||
for (JCheckBox box : filterBoxes.allColors) {
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
|
||||
this.getContentPane().add(box, null);
|
||||
}
|
||||
|
||||
top.getTable().addKeyListener(new KeyAdapter() {
|
||||
this.getTopTableWithCards().getTable().addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
if (e.getKeyChar() == ' ') {
|
||||
addButtonActionPerformed(null);
|
||||
DeckEditorQuest.this.addButtonActionPerformed(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -306,36 +313,37 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
|
||||
*/
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
private void addButtonActionPerformed(final ActionEvent e) {
|
||||
InventoryItem item = top.getSelectedCard();
|
||||
if (item == null || !(item instanceof CardPrinted)) {
|
||||
final InventoryItem item = this.getTopTableWithCards().getSelectedCard();
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
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);
|
||||
bottom.addCard(card);
|
||||
this.getTopTableWithCards().removeCard(card);
|
||||
this.getBottomTableWithCards().addCard(card);
|
||||
}
|
||||
|
||||
private void removeButtonActionPerformed(final ActionEvent e) {
|
||||
InventoryItem item = bottom.getSelectedCard();
|
||||
if (item == null || !(item instanceof CardPrinted)) {
|
||||
final InventoryItem item = this.getBottomTableWithCards().getSelectedCard();
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
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);
|
||||
bottom.removeCard(card);
|
||||
this.getTopTableWithCards().addCard(card);
|
||||
this.getBottomTableWithCards().removeCard(card);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -345,8 +353,8 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
|
||||
* the card
|
||||
*/
|
||||
public void addCheatCard(final CardPrinted card) {
|
||||
top.addCard(card);
|
||||
questData.getCards().getCardpool().add(card);
|
||||
this.getTopTableWithCards().addCard(card);
|
||||
this.questData.getCards().getCardpool().add(card);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,18 +51,18 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
private static final long serialVersionUID = -4052319220021158574L;
|
||||
|
||||
/** 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
|
||||
/** Constant <code>previousDirectory</code>. */
|
||||
private static File previousDirectory = null;
|
||||
|
||||
private Command exitCommand;
|
||||
private forge.quest.data.QuestData questData;
|
||||
private final Command exitCommand;
|
||||
private final forge.quest.data.QuestData questData;
|
||||
private Deck currentDeck;
|
||||
|
||||
// the class DeckDisplay is in the file "Gui_DeckEditor_Menu.java"
|
||||
private DeckDisplay deckDisplay;
|
||||
private final DeckDisplay deckDisplay;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -78,14 +78,14 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
*/
|
||||
public DeckEditorQuestMenu(final QuestData q, final DeckDisplay d, final Command exit) {
|
||||
|
||||
deckDisplay = d;
|
||||
questData = q;
|
||||
this.deckDisplay = d;
|
||||
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.
|
||||
*/
|
||||
private void addImportExport(final JMenu menu, final boolean isHumanMenu) {
|
||||
JMenuItem import2 = new JMenuItem("Import");
|
||||
JMenuItem export = new JMenuItem("Export");
|
||||
final JMenuItem import2 = new JMenuItem("Import");
|
||||
final JMenuItem export = new JMenuItem("Export");
|
||||
|
||||
import2.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
importDeck(); // importDeck(isHumanMenu);
|
||||
DeckEditorQuestMenu.this.importDeck(); // importDeck(isHumanMenu);
|
||||
}
|
||||
}); // import
|
||||
|
||||
export.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
exportDeck();
|
||||
DeckEditorQuestMenu.this.exportDeck();
|
||||
}
|
||||
}); // export
|
||||
|
||||
@@ -125,7 +127,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
* </p>
|
||||
*/
|
||||
private void exportDeck() {
|
||||
File filename = getExportFilename();
|
||||
final File filename = this.getExportFilename();
|
||||
|
||||
if (filename == null) {
|
||||
return;
|
||||
@@ -133,21 +135,21 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
|
||||
// write is an Object variable because you might just
|
||||
// write one Deck object
|
||||
Deck deck = cardPoolToDeck(deckDisplay.getBottom());
|
||||
final Deck deck = this.cardPoolToDeck(this.deckDisplay.getBottom());
|
||||
|
||||
deck.setName(filename.getName());
|
||||
|
||||
try {
|
||||
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename));
|
||||
final ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename));
|
||||
out.writeObject(deck);
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeck() error, " + ex);
|
||||
}
|
||||
|
||||
exportDeckText(getExportDeckText(deck), filename.getAbsolutePath());
|
||||
this.exportDeckText(this.getExportDeckText(deck), filename.getAbsolutePath());
|
||||
|
||||
} // exportDeck()
|
||||
|
||||
@@ -164,16 +166,16 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
private void exportDeckText(final String deckText, String filename) {
|
||||
|
||||
// remove ".deck" extension
|
||||
int cut = filename.indexOf(".");
|
||||
final int cut = filename.indexOf(".");
|
||||
filename = filename.substring(0, cut);
|
||||
|
||||
try {
|
||||
FileWriter writer = new FileWriter(filename + ".txt");
|
||||
final FileWriter writer = new FileWriter(filename + ".txt");
|
||||
writer.write(deckText);
|
||||
|
||||
writer.flush();
|
||||
writer.close();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeckText() error, " + ex.getMessage() + " : "
|
||||
+ Arrays.toString(ex.getStackTrace()));
|
||||
@@ -191,12 +193,12 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
*/
|
||||
private String getExportDeckText(final Deck aDeck) {
|
||||
// convert Deck into CardList
|
||||
ItemPoolView<CardPrinted> all = aDeck.getMain();
|
||||
final ItemPoolView<CardPrinted> all = aDeck.getMain();
|
||||
// sort by card name
|
||||
Collections.sort(all.getOrderedList(), TableSorter.byNameThenSet);
|
||||
Collections.sort(all.getOrderedList(), TableSorter.BY_NAME_THEN_SET);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String newLine = "\r\n";
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
final String newLine = "\r\n";
|
||||
|
||||
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",
|
||||
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()));
|
||||
}
|
||||
|
||||
// spells
|
||||
sb.append(String.format("%d Spells%n----------%n",
|
||||
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()));
|
||||
}
|
||||
|
||||
// lands
|
||||
sb.append(String.format("%d Land%n--------%n",
|
||||
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()));
|
||||
}
|
||||
|
||||
@@ -235,7 +238,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
* @return a {@link javax.swing.filechooser.FileFilter} object.
|
||||
*/
|
||||
private FileFilter getFileFilter() {
|
||||
FileFilter filter = new FileFilter() {
|
||||
final FileFilter filter = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f) {
|
||||
return f.getName().endsWith(".dck") || f.isDirectory();
|
||||
@@ -260,20 +263,20 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
private File getExportFilename() {
|
||||
// Object o = null; // unused
|
||||
|
||||
JFileChooser save = new JFileChooser(previousDirectory);
|
||||
final JFileChooser save = new JFileChooser(DeckEditorQuestMenu.previousDirectory);
|
||||
|
||||
save.setDialogTitle("Export Deck Filename");
|
||||
save.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
save.addChoosableFileFilter(getFileFilter());
|
||||
save.setSelectedFile(new File(currentDeck.getName() + ".deck"));
|
||||
save.addChoosableFileFilter(this.getFileFilter());
|
||||
save.setSelectedFile(new File(this.currentDeck.getName() + ".deck"));
|
||||
|
||||
int returnVal = save.showSaveDialog(null);
|
||||
final int returnVal = save.showSaveDialog(null);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File file = save.getSelectedFile();
|
||||
String check = file.getAbsolutePath();
|
||||
final File file = save.getSelectedFile();
|
||||
final String check = file.getAbsolutePath();
|
||||
|
||||
previousDirectory = file.getParentFile();
|
||||
DeckEditorQuestMenu.previousDirectory = file.getParentFile();
|
||||
|
||||
if (check.endsWith(".deck")) {
|
||||
return file;
|
||||
@@ -291,26 +294,26 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
* </p>
|
||||
*/
|
||||
private void importDeck() {
|
||||
File file = getImportFilename();
|
||||
final File file = this.getImportFilename();
|
||||
|
||||
if (file == null) {
|
||||
} else if (file.getName().endsWith(".dck")) {
|
||||
try {
|
||||
Deck newDeck = DeckManager.readDeck(file);
|
||||
questData.addDeck(newDeck);
|
||||
final Deck newDeck = DeckManager.readDeck(file);
|
||||
this.questData.addDeck(newDeck);
|
||||
|
||||
ItemPool<CardPrinted> cardpool = ItemPool.createFrom(questData.getCards().getCardpool(),
|
||||
final ItemPool<CardPrinted> cardpool = ItemPool.createFrom(this.questData.getCards().getCardpool(),
|
||||
CardPrinted.class);
|
||||
ItemPool<CardPrinted> decklist = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
for (Entry<CardPrinted, Integer> s : newDeck.getMain()) {
|
||||
CardPrinted cp = s.getKey();
|
||||
final ItemPool<CardPrinted> decklist = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
for (final Entry<CardPrinted, Integer> s : newDeck.getMain()) {
|
||||
final CardPrinted cp = s.getKey();
|
||||
decklist.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);
|
||||
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.
|
||||
*/
|
||||
private File getImportFilename() {
|
||||
JFileChooser chooser = new JFileChooser(previousDirectory);
|
||||
final JFileChooser chooser = new JFileChooser(DeckEditorQuestMenu.previousDirectory);
|
||||
|
||||
chooser.addChoosableFileFilter(getFileFilter());
|
||||
int returnVal = chooser.showOpenDialog(null);
|
||||
chooser.addChoosableFileFilter(this.getFileFilter());
|
||||
final int returnVal = chooser.showOpenDialog(null);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File file = chooser.getSelectedFile();
|
||||
previousDirectory = file.getParentFile();
|
||||
final File file = chooser.getSelectedFile();
|
||||
DeckEditorQuestMenu.previousDirectory = file.getParentFile();
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -341,57 +344,64 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
} // openFileDialog()
|
||||
|
||||
private final ActionListener addCardActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
|
||||
// Provide a model here: all unique cards to be displayed by only
|
||||
// name (unlike default toString)
|
||||
Iterable<CardPrinted> uniqueCards = CardDb.instance().getAllUniqueCards();
|
||||
List<String> cards = new ArrayList<String>();
|
||||
for (CardPrinted c : uniqueCards) {
|
||||
final Iterable<CardPrinted> uniqueCards = CardDb.instance().getAllUniqueCards();
|
||||
final List<String> cards = new ArrayList<String>();
|
||||
for (final CardPrinted c : uniqueCards) {
|
||||
cards.add(c.getName());
|
||||
}
|
||||
Collections.sort(cards);
|
||||
|
||||
// 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()) {
|
||||
String cardName = c.getSelectedValue();
|
||||
DeckEditorQuest g = (DeckEditorQuest) deckDisplay;
|
||||
final String cardName = c.getSelectedValue();
|
||||
final DeckEditorQuest g = (DeckEditorQuest) DeckEditorQuestMenu.this.deckDisplay;
|
||||
g.addCheatCard(CardDb.instance().getCard(cardName));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final ActionListener openDeckActionListener = new ActionListener() {
|
||||
@Override
|
||||
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"
|
||||
if (StringUtils.isBlank(deckName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
setPlayerDeckName(deckName);
|
||||
ItemPool<CardPrinted> cards = ItemPool.createFrom(questData.getCards().getCardpool().getView(),
|
||||
CardPrinted.class);
|
||||
ItemPoolView<CardPrinted> deck = questData.getDeck(deckName).getMain();
|
||||
DeckEditorQuestMenu.this.setPlayerDeckName(deckName);
|
||||
final ItemPool<CardPrinted> cards = ItemPool.createFrom(DeckEditorQuestMenu.this.questData.getCards()
|
||||
.getCardpool().getView(), CardPrinted.class);
|
||||
final ItemPoolView<CardPrinted> deck = DeckEditorQuestMenu.this.questData.getDeck(deckName).getMain();
|
||||
|
||||
// show in pool all cards except ones used in deck
|
||||
cards.removeAll(deck);
|
||||
deckDisplay.setDeck(cards, deck, GameType.Quest);
|
||||
DeckEditorQuestMenu.this.deckDisplay.setDeck(cards, deck, GameType.Quest);
|
||||
}
|
||||
};
|
||||
|
||||
private final ActionListener newDeckActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
deckDisplay.setItems(questData.getCards().getCardpool().getView(), null, GameType.Quest);
|
||||
setPlayerDeckName("");
|
||||
DeckEditorQuestMenu.this.deckDisplay.setItems(DeckEditorQuestMenu.this.questData.getCards().getCardpool()
|
||||
.getView(), null, GameType.Quest);
|
||||
DeckEditorQuestMenu.this.setPlayerDeckName("");
|
||||
}
|
||||
};
|
||||
|
||||
private final ActionListener renameDeckActionListener = new ActionListener() {
|
||||
@Override
|
||||
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
|
||||
if (StringUtils.isBlank(deckName)) {
|
||||
@@ -399,27 +409,30 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
}
|
||||
|
||||
// is the current deck already saved and in QuestData?
|
||||
if (questData.getDeckNames().contains(currentDeck.getName())) {
|
||||
questData.removeDeck(currentDeck.getName());
|
||||
if (DeckEditorQuestMenu.this.questData.getDeckNames().contains(
|
||||
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);
|
||||
questData.addDeck(deck);
|
||||
DeckEditorQuestMenu.this.questData.addDeck(deck);
|
||||
|
||||
setPlayerDeckName(deckName);
|
||||
DeckEditorQuestMenu.this.setPlayerDeckName(deckName);
|
||||
}
|
||||
};
|
||||
|
||||
private final ActionListener saveDeckActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
String name = currentDeck.getName();
|
||||
String name = DeckEditorQuestMenu.this.currentDeck.getName();
|
||||
|
||||
// check to see if name is set
|
||||
if (name.equals("")) {
|
||||
name = getUserInput_GetDeckName(questData.getDeckNames());
|
||||
name = DeckEditorQuestMenu.this.getUserInputGetDeckName(DeckEditorQuestMenu.this.questData
|
||||
.getDeckNames());
|
||||
|
||||
// check if user cancels
|
||||
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);
|
||||
|
||||
questData.addDeck(deck);
|
||||
DeckEditorQuestMenu.this.questData.addDeck(deck);
|
||||
}
|
||||
};
|
||||
|
||||
private final ActionListener copyDeckActionListener = new ActionListener() {
|
||||
@Override
|
||||
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
|
||||
if (name.equals("")) {
|
||||
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);
|
||||
|
||||
questData.addDeck(deck);
|
||||
DeckEditorQuestMenu.this.questData.addDeck(deck);
|
||||
}
|
||||
};
|
||||
|
||||
private final ActionListener deleteDeckActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
if (currentDeck.getName().equals("")) {
|
||||
if (DeckEditorQuestMenu.this.currentDeck.getName().equals("")) {
|
||||
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);
|
||||
if (check == JOptionPane.NO_OPTION) {
|
||||
return; // stop here
|
||||
}
|
||||
|
||||
questData.removeDeck(currentDeck.getName());
|
||||
DeckEditorQuestMenu.this.questData.removeDeck(DeckEditorQuestMenu.this.currentDeck.getName());
|
||||
|
||||
// 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>
|
||||
*/
|
||||
private void setupMenu() {
|
||||
JMenuItem openDeck = new JMenuItem("Open");
|
||||
JMenuItem newDeck = new JMenuItem("New");
|
||||
JMenuItem rename = new JMenuItem("Rename");
|
||||
JMenuItem save = new JMenuItem("Save");
|
||||
JMenuItem copy = new JMenuItem("Copy");
|
||||
JMenuItem delete = new JMenuItem("Delete");
|
||||
JMenuItem exit = new JMenuItem("Exit");
|
||||
final JMenuItem openDeck = new JMenuItem("Open");
|
||||
final JMenuItem newDeck = new JMenuItem("New");
|
||||
final JMenuItem rename = new JMenuItem("Rename");
|
||||
final JMenuItem save = new JMenuItem("Save");
|
||||
final JMenuItem copy = new JMenuItem("Copy");
|
||||
final JMenuItem delete = new JMenuItem("Delete");
|
||||
final JMenuItem exit = new JMenuItem("Exit");
|
||||
|
||||
JMenuItem addCard = new JMenuItem("Cheat - Add Card");
|
||||
final JMenuItem addCard = new JMenuItem("Cheat - Add Card");
|
||||
|
||||
addCard.addActionListener(addCardActionListener);
|
||||
openDeck.addActionListener(openDeckActionListener);
|
||||
newDeck.addActionListener(newDeckActionListener);
|
||||
rename.addActionListener(renameDeckActionListener);
|
||||
save.addActionListener(saveDeckActionListener);
|
||||
copy.addActionListener(copyDeckActionListener);
|
||||
delete.addActionListener(deleteDeckActionListener);
|
||||
addCard.addActionListener(this.addCardActionListener);
|
||||
openDeck.addActionListener(this.openDeckActionListener);
|
||||
newDeck.addActionListener(this.newDeckActionListener);
|
||||
rename.addActionListener(this.renameDeckActionListener);
|
||||
save.addActionListener(this.saveDeckActionListener);
|
||||
copy.addActionListener(this.copyDeckActionListener);
|
||||
delete.addActionListener(this.deleteDeckActionListener);
|
||||
|
||||
// human
|
||||
exit.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent a) {
|
||||
DeckEditorQuestMenu.this.close();
|
||||
}
|
||||
});
|
||||
|
||||
JMenu deckMenu = new JMenu("Deck");
|
||||
final JMenu deckMenu = new JMenu("Deck");
|
||||
deckMenu.add(openDeck);
|
||||
deckMenu.add(newDeck);
|
||||
deckMenu.add(rename);
|
||||
@@ -520,7 +538,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
}
|
||||
|
||||
deckMenu.addSeparator();
|
||||
addImportExport(deckMenu, true);
|
||||
this.addImportExport(deckMenu, true);
|
||||
|
||||
deckMenu.addSeparator();
|
||||
deckMenu.add(delete);
|
||||
@@ -542,7 +560,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
*/
|
||||
private Deck cardPoolToDeck(final ItemPoolView<InventoryItem> list) {
|
||||
// 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));
|
||||
return deck;
|
||||
}
|
||||
@@ -558,10 +576,10 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
*/
|
||||
public final void setPlayerDeckName(final String deckName) {
|
||||
// the gui uses this, Gui_Quest_DeckEditor
|
||||
currentDeck = new Deck(GameType.Sealed);
|
||||
currentDeck.setName(deckName);
|
||||
this.currentDeck = new Deck(GameType.Sealed);
|
||||
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
|
||||
@@ -575,11 +593,11 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
private String cleanString(final String in) {
|
||||
StringBuffer out = new StringBuffer();
|
||||
char[] c = in.toCharArray();
|
||||
final StringBuffer out = new StringBuffer();
|
||||
final char[] c = in.toCharArray();
|
||||
|
||||
for (int i = 0; i < c.length && i < 20; i++) {
|
||||
if (Character.isLetterOrDigit(c[i]) || c[i] == '-' || c[i] == '_' || c[i] == ' ') {
|
||||
for (int i = 0; (i < c.length) && (i < 20); i++) {
|
||||
if (Character.isLetterOrDigit(c[i]) || (c[i] == '-') || (c[i] == '_') || (c[i] == ' ')) {
|
||||
out.append(c[i]);
|
||||
}
|
||||
}
|
||||
@@ -597,18 +615,18 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
* a {@link java.util.List} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
private String getUserInput_GetDeckName(final List<String> nameList) {
|
||||
Object o = JOptionPane.showInputDialog(null, "", "Deck Name", JOptionPane.OK_CANCEL_OPTION);
|
||||
private String getUserInputGetDeckName(final List<String> nameList) {
|
||||
final Object o = JOptionPane.showInputDialog(null, "", "Deck Name", JOptionPane.OK_CANCEL_OPTION);
|
||||
|
||||
if (o == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String deckName = cleanString(o.toString());
|
||||
final String deckName = this.cleanString(o.toString());
|
||||
|
||||
if (nameList.contains(deckName) || deckName.equals("")) {
|
||||
JOptionPane.showMessageDialog(null, "Please pick another deck name, a deck currently has that name.");
|
||||
return getUserInput_GetDeckName(nameList);
|
||||
return this.getUserInputGetDeckName(nameList);
|
||||
}
|
||||
|
||||
return deckName;
|
||||
@@ -624,8 +642,8 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
* a {@link java.util.List} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
private String getUserInput_OpenDeck(final List<String> deckNameList) {
|
||||
List<String> choices = deckNameList;
|
||||
private String getUserInputOpenDeck(final List<String> deckNameList) {
|
||||
final List<String> choices = deckNameList;
|
||||
if (choices.size() == 0) {
|
||||
JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE);
|
||||
return "";
|
||||
@@ -634,7 +652,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
// Object o = JOptionPane.showInputDialog(null, "Deck Name",
|
||||
// "Open Deck", JOptionPane.OK_CANCEL_OPTION, null,
|
||||
// choices.toArray(), choices.toArray()[0]);
|
||||
Object o = GuiUtils.getChoiceOptional("Select Deck", choices.toArray());
|
||||
final Object o = GuiUtils.getChoiceOptional("Select Deck", choices.toArray());
|
||||
|
||||
if (o == null) {
|
||||
return "";
|
||||
@@ -650,7 +668,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
* </p>
|
||||
*/
|
||||
public final void close() {
|
||||
exitCommand.execute();
|
||||
this.exitCommand.execute();
|
||||
}
|
||||
|
||||
// used by Gui_Quest_DeckEditor
|
||||
@@ -662,7 +680,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public final String getDeckName() {
|
||||
return currentDeck.getName();
|
||||
return this.currentDeck.getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,21 +45,21 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
/** Constant <code>serialVersionUID=3988857075791576483L</code>. */
|
||||
private static final long serialVersionUID = 3988857075791576483L;
|
||||
|
||||
private JButton buyButton = new JButton();
|
||||
private JButton sellButton = new JButton();
|
||||
private final JButton buyButton = new JButton();
|
||||
private final JButton sellButton = new JButton();
|
||||
|
||||
private JLabel creditsLabel = new JLabel();
|
||||
private JLabel jLabel1 = new JLabel();
|
||||
private JLabel sellPercentageLabel = new JLabel();
|
||||
private final JLabel creditsLabel = new JLabel();
|
||||
private final JLabel jLabel1 = new JLabel();
|
||||
private final JLabel sellPercentageLabel = new JLabel();
|
||||
|
||||
private double multiplier;
|
||||
|
||||
private QuestData questData;
|
||||
private final QuestData questData;
|
||||
// private CardPoolView newCardsList;
|
||||
|
||||
// get pricelist:
|
||||
private ReadPriceList r = new ReadPriceList();
|
||||
private Map<String, Integer> mapPrices = r.getPriceList();
|
||||
private final ReadPriceList r = new ReadPriceList();
|
||||
private final Map<String, Integer> mapPrices = this.r.getPriceList();
|
||||
private Map<CardPrinted, Integer> decksUsingMyCards;
|
||||
|
||||
/**
|
||||
@@ -72,6 +72,7 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
final Command exit = new Command() {
|
||||
private static final long serialVersionUID = -7428793574300520612L;
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
DeckEditorShop.this.dispose();
|
||||
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()) {
|
||||
questData.getCards().generateCardsInShop();
|
||||
forSale = questData.getCards().getShopList();
|
||||
this.questData.getCards().generateCardsInShop();
|
||||
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();
|
||||
|
||||
setItems(forSale, owned, GameType.Quest);
|
||||
this.setItems(forSale, owned, GameType.Quest);
|
||||
|
||||
double multiPercent = multiplier * 100;
|
||||
NumberFormat formatter = new DecimalFormat("#0.00");
|
||||
final double multiPercent = this.multiplier * 100;
|
||||
final NumberFormat formatter = new DecimalFormat("#0.00");
|
||||
String maxSellingPrice = "";
|
||||
int maxSellPrice = questData.getCards().getSellPriceLimit();
|
||||
final int maxSellPrice = this.questData.getCards().getSellPriceLimit();
|
||||
|
||||
if (maxSellPrice < Integer.MAX_VALUE) {
|
||||
maxSellingPrice = String.format("Max selling price: %d", maxSellPrice);
|
||||
}
|
||||
sellPercentageLabel.setText("<html>(You can sell cards at " + formatter.format(multiPercent)
|
||||
this.sellPercentageLabel.setText("<html>(You can sell cards at " + formatter.format(multiPercent)
|
||||
+ "% of their value)<br>" + maxSellingPrice + "</html>");
|
||||
|
||||
top.sort(1, true);
|
||||
bottom.sort(1, true);
|
||||
this.getTopTableWithCards().sort(1, true);
|
||||
this.getBottomTableWithCards().sort(1, true);
|
||||
} // show(Command)
|
||||
|
||||
// fills number of decks using each card
|
||||
private Map<CardPrinted, Integer> countDecksForEachCard() {
|
||||
Map<CardPrinted, Integer> result = new HashMap<CardPrinted, Integer>();
|
||||
for (String deckName : questData.getDeckNames()) {
|
||||
Deck deck = questData.getDeck(deckName);
|
||||
for (Entry<CardPrinted, Integer> e : deck.getMain()) {
|
||||
CardPrinted card = e.getKey();
|
||||
Integer iValue = result.get(card);
|
||||
int cntDecks = iValue == null ? 1 : 1 + iValue.intValue();
|
||||
final Map<CardPrinted, Integer> result = new HashMap<CardPrinted, Integer>();
|
||||
for (final String deckName : this.questData.getDeckNames()) {
|
||||
final Deck deck = this.questData.getDeck(deckName);
|
||||
for (final Entry<CardPrinted, Integer> e : deck.getMain()) {
|
||||
final CardPrinted card = e.getKey();
|
||||
final Integer iValue = result.get(card);
|
||||
final int cntDecks = iValue == null ? 1 : 1 + iValue.intValue();
|
||||
result.put(card, Integer.valueOf(cntDecks));
|
||||
}
|
||||
}
|
||||
@@ -138,11 +139,13 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
* </p>
|
||||
*/
|
||||
private void setup() {
|
||||
List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE, PresetColumns.FN_QTY_GET));
|
||||
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>("Name", 180, PresetColumns.FN_NAME_COMPARE,
|
||||
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,
|
||||
PresetColumns.FN_COLOR_GET));
|
||||
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));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 30, PresetColumns.FN_RARITY_COMPARE,
|
||||
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());
|
||||
|
||||
List<TableColumnInfo<InventoryItem>> columnsBelow = new ArrayList<TableColumnInfo<InventoryItem>>(columns);
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Price", 36, fnPriceCompare, fnPriceGet));
|
||||
top.setup(columns, cardView);
|
||||
final List<TableColumnInfo<InventoryItem>> columnsBelow = new ArrayList<TableColumnInfo<InventoryItem>>(columns);
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Price", 36, this.fnPriceCompare, this.fnPriceGet));
|
||||
this.getTopTableWithCards().setup(columns, this.getCardView());
|
||||
|
||||
columnsBelow.add(new TableColumnInfo<InventoryItem>("Dks", 30, fnDeckCompare, fnDeckGet));
|
||||
columnsBelow.add(new TableColumnInfo<InventoryItem>("New", 35, questData.getCards().fnNewCompare, questData
|
||||
.getCards().fnNewGet));
|
||||
columnsBelow.add(new TableColumnInfo<InventoryItem>("Price", 36, fnPriceCompare, fnPriceSellGet));
|
||||
bottom.setup(columnsBelow, cardView);
|
||||
columnsBelow.add(new TableColumnInfo<InventoryItem>("Dks", 30, this.fnDeckCompare, this.fnDeckGet));
|
||||
columnsBelow.add(new TableColumnInfo<InventoryItem>("New", 35, this.questData.getCards().fnNewCompare,
|
||||
this.questData.getCards().fnNewGet));
|
||||
columnsBelow.add(new TableColumnInfo<InventoryItem>("Price", 36, this.fnPriceCompare, this.fnPriceSellGet));
|
||||
this.getBottomTableWithCards().setup(columnsBelow, this.getCardView());
|
||||
|
||||
this.setSize(1024, 768);
|
||||
GuiUtils.centerFrame(this);
|
||||
@@ -179,14 +183,14 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
*/
|
||||
public DeckEditorShop(final QuestData qd) {
|
||||
super(GameType.Quest);
|
||||
questData = qd;
|
||||
this.questData = qd;
|
||||
try {
|
||||
filterBoxes = null;
|
||||
top = new TableWithCards("Cards for sale", false);
|
||||
bottom = new TableWithCards("Owned Cards", false);
|
||||
cardView = new CardPanelLite();
|
||||
jbInit();
|
||||
} catch (Exception ex) {
|
||||
this.setFilterBoxes(null);
|
||||
this.setTopTableWithCards(new TableWithCards("Cards for sale", false));
|
||||
this.setBottomTableWithCards(new TableWithCards("Owned Cards", false));
|
||||
this.setCardView(new CardPanelLite());
|
||||
this.jbInit();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
}
|
||||
@@ -202,64 +206,66 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
private void jbInit() throws Exception {
|
||||
|
||||
this.setLayout(null);
|
||||
top.getTableDecorated().setBounds(new Rectangle(19, 20, 726, 346));
|
||||
bottom.getTableDecorated().setBounds(new Rectangle(19, 458, 726, 276));
|
||||
this.getTopTableWithCards().getTableDecorated().setBounds(new Rectangle(19, 20, 726, 346));
|
||||
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);
|
||||
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");
|
||||
sellButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
this.sellButton.setText("Sell Card");
|
||||
this.sellButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
sellButtonActionPerformed(e);
|
||||
DeckEditorShop.this.sellButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
buyButton.setText("Buy Card");
|
||||
buyButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
this.buyButton.setText("Buy Card");
|
||||
this.buyButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
buyButtonActionPerformed(e);
|
||||
DeckEditorShop.this.buyButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
|
||||
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
|
||||
// x 768 screen size
|
||||
this.setTitle("Card Shop");
|
||||
|
||||
creditsLabel.setBounds(new Rectangle(19, 365, 720, 31));
|
||||
creditsLabel.setText("Total credits: " + questData.getCredits());
|
||||
this.creditsLabel.setBounds(new Rectangle(19, 365, 720, 31));
|
||||
this.creditsLabel.setText("Total credits: " + this.questData.getCredits());
|
||||
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));
|
||||
sellPercentageLabel.setText("(Sell percentage: " + multiplier + ")");
|
||||
this.sellPercentageLabel.setBounds(new Rectangle(350, 403, 450, 31));
|
||||
this.sellPercentageLabel.setText("(Sell percentage: " + this.multiplier + ")");
|
||||
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");
|
||||
jLabel1.setBounds(new Rectangle(20, 1, 400, 19));
|
||||
this.jLabel1.setText("Click on the column name (like name or color) to sort the cards");
|
||||
this.jLabel1.setBounds(new Rectangle(20, 1, 400, 19));
|
||||
|
||||
this.getContentPane().add(cardView, null);
|
||||
this.getContentPane().add(top.getTableDecorated(), null);
|
||||
this.getContentPane().add(bottom.getTableDecorated(), null);
|
||||
this.getContentPane().add(creditsLabel, null);
|
||||
this.getContentPane().add(buyButton, null);
|
||||
this.getContentPane().add(sellButton, null);
|
||||
this.getContentPane().add(sellPercentageLabel, null);
|
||||
this.getContentPane().add(jLabel1, null);
|
||||
this.getContentPane().add(this.getCardView(), null);
|
||||
this.getContentPane().add(this.getTopTableWithCards().getTableDecorated(), null);
|
||||
this.getContentPane().add(this.getBottomTableWithCards().getTableDecorated(), null);
|
||||
this.getContentPane().add(this.creditsLabel, null);
|
||||
this.getContentPane().add(this.buyButton, null);
|
||||
this.getContentPane().add(this.sellButton, null);
|
||||
this.getContentPane().add(this.sellPercentageLabel, null);
|
||||
this.getContentPane().add(this.jLabel1, null);
|
||||
}
|
||||
|
||||
// TODO: move to cardshop
|
||||
private Integer getCardValue(final InventoryItem card) {
|
||||
if (mapPrices.containsKey(card.getName())) {
|
||||
return mapPrices.get(card.getName());
|
||||
if (this.mapPrices.containsKey(card.getName())) {
|
||||
return this.mapPrices.get(card.getName());
|
||||
} else if (card instanceof CardPrinted) {
|
||||
switch (((CardPrinted) card).getRarity()) {
|
||||
case BasicLand:
|
||||
@@ -282,34 +288,34 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
}
|
||||
|
||||
private void buyButtonActionPerformed(final ActionEvent e) {
|
||||
InventoryItem item = top.getSelectedCard();
|
||||
final InventoryItem item = this.getTopTableWithCards().getSelectedCard();
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int value = getCardValue(item);
|
||||
final int value = this.getCardValue(item);
|
||||
|
||||
if (value <= questData.getCredits()) {
|
||||
if (value <= this.questData.getCredits()) {
|
||||
if (item instanceof CardPrinted) {
|
||||
CardPrinted card = (CardPrinted) item;
|
||||
bottom.addCard(card);
|
||||
top.removeCard(card);
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
this.getBottomTableWithCards().addCard(card);
|
||||
this.getTopTableWithCards().removeCard(card);
|
||||
|
||||
questData.getCards().buyCard(card, value);
|
||||
this.questData.getCards().buyCard(card, value);
|
||||
} else if (item instanceof BoosterPack) {
|
||||
top.removeCard(item);
|
||||
BoosterPack booster = (BoosterPack) ((BoosterPack) item).clone();
|
||||
questData.getCards().buyBooster(booster, value);
|
||||
List<CardPrinted> newCards = booster.getCards();
|
||||
for (CardPrinted card : newCards) {
|
||||
bottom.addCard(card);
|
||||
this.getTopTableWithCards().removeCard(item);
|
||||
final BoosterPack booster = (BoosterPack) ((BoosterPack) item).clone();
|
||||
this.questData.getCards().buyBooster(booster, value);
|
||||
final List<CardPrinted> newCards = booster.getCards();
|
||||
for (final CardPrinted card : newCards) {
|
||||
this.getBottomTableWithCards().addCard(card);
|
||||
}
|
||||
CardListViewer c = new CardListViewer(booster.getName(), "You have found the following cards inside:",
|
||||
newCards);
|
||||
final CardListViewer c = new CardListViewer(booster.getName(),
|
||||
"You have found the following cards inside:", newCards);
|
||||
c.show();
|
||||
}
|
||||
|
||||
creditsLabel.setText("Total credits: " + questData.getCredits());
|
||||
this.creditsLabel.setText("Total credits: " + this.questData.getCredits());
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Not enough credits!");
|
||||
}
|
||||
@@ -326,38 +332,39 @@ public final class DeckEditorShop extends DeckEditorBase {
|
||||
}
|
||||
|
||||
private void sellButtonActionPerformed(final ActionEvent e) {
|
||||
InventoryItem item = bottom.getSelectedCard();
|
||||
if (item == null || !(item instanceof CardPrinted)) {
|
||||
final InventoryItem item = this.getBottomTableWithCards().getSelectedCard();
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CardPrinted card = (CardPrinted) item;
|
||||
bottom.removeCard(card);
|
||||
top.addCard(card);
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
this.getBottomTableWithCards().removeCard(card);
|
||||
this.getTopTableWithCards().addCard(card);
|
||||
|
||||
int price = Math.min((int) (multiplier * getCardValue(card)), questData.getCards().getSellPriceLimit());
|
||||
questData.getCards().sellCard(card, price);
|
||||
final int price = Math.min((int) (this.multiplier * this.getCardValue(card)), this.questData.getCards()
|
||||
.getSellPriceLimit());
|
||||
this.questData.getCards().sellCard(card, price);
|
||||
|
||||
creditsLabel.setText("Total credits: " + questData.getCredits());
|
||||
this.creditsLabel.setText("Total credits: " + this.questData.getCredits());
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnPriceCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return getCardValue(from.getKey());
|
||||
return DeckEditorShop.this.getCardValue(from.getKey());
|
||||
}
|
||||
};
|
||||
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return getCardValue(from.getKey());
|
||||
return DeckEditorShop.this.getCardValue(from.getKey());
|
||||
}
|
||||
};
|
||||
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceSellGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return (int) (multiplier * getCardValue(from.getKey()));
|
||||
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>>() {
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
};
|
||||
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnDeckGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
Integer iValue = decksUsingMyCards.get(from.getKey());
|
||||
final Integer iValue = DeckEditorShop.this.decksUsingMyCards.get(from.getKey());
|
||||
return iValue == null ? "" : iValue.toString();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -37,17 +37,18 @@ import forge.item.CardPrinted;
|
||||
public class DeckImport extends JDialog {
|
||||
private static final long serialVersionUID = -5837776824284093004L;
|
||||
|
||||
private JTextArea txtInput = new JTextArea();
|
||||
private static final String stylesheet = "<style>"
|
||||
+ "body, h1, h2, h3, h4, h5, h6, table, tr, td, p {margin: 1px; padding: 0; font-weight: normal; font-style: normal; text-decoration: none; font-family: Arial; font-size: 10px;} "
|
||||
private final JTextArea txtInput = new JTextArea();
|
||||
private static final String STYLESHEET = "<style>"
|
||||
+ "body, h1, h2, h3, h4, h5, h6, table, tr, td, p {margin: 1px; padding: 0; font-weight: "
|
||||
+ "normal; font-style: normal; text-decoration: none; font-family: Arial; font-size: 10px;} "
|
||||
+
|
||||
// "h1 {border-bottom: solid 1px black; color: blue; font-size: 12px; margin: 3px 0 9px 0; } "
|
||||
// +
|
||||
".comment {color: #666666;} " + ".knowncard {color: #009900;} " + ".unknowncard {color: #990000;} "
|
||||
+ ".section {padding: 3px 10px; margin: 3px 0; font-weight: 700; background-color: #DDDDDD; } "
|
||||
+ "</style>";
|
||||
private static final String htmlWelcomeText = "<html>"
|
||||
+ stylesheet
|
||||
private static final String HTML_WELCOME_TEXT = "<html>"
|
||||
+ DeckImport.STYLESHEET
|
||||
+ "<h3>You'll see recognized cards here</h3>"
|
||||
+ "<div class='section'>Legend</div>"
|
||||
+ "<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'>Post bug-reports to http://cardforge.org/bugz/</div>" + "</html>";
|
||||
|
||||
private JEditorPane htmlOutput = new JEditorPane("text/html", htmlWelcomeText);
|
||||
private JScrollPane scrollInput = new JScrollPane(txtInput);
|
||||
private JScrollPane scrollOutput = new JScrollPane(htmlOutput);
|
||||
private JLabel summaryMain = new JLabel("Imported deck summary will appear here");
|
||||
private JLabel summarySide = new JLabel("This is second line");
|
||||
private JButton cmdAccept = new JButton("Import Deck");
|
||||
private JButton cmdCancel = new JButton("Cancel");
|
||||
private final JEditorPane htmlOutput = new JEditorPane("text/html", DeckImport.HTML_WELCOME_TEXT);
|
||||
private final JScrollPane scrollInput = new JScrollPane(this.txtInput);
|
||||
private final JScrollPane scrollOutput = new JScrollPane(this.htmlOutput);
|
||||
private final JLabel summaryMain = new JLabel("Imported deck summary will appear here");
|
||||
private final JLabel summarySide = new JLabel("This is second line");
|
||||
private final JButton cmdAccept = new JButton("Import Deck");
|
||||
private final JButton cmdCancel = new JButton("Cancel");
|
||||
|
||||
/** The tokens. */
|
||||
List<DeckRecognizer.Token> tokens = new ArrayList<DeckRecognizer.Token>();
|
||||
private List<DeckRecognizer.Token> tokens = new ArrayList<DeckRecognizer.Token>();
|
||||
|
||||
private final DeckEditorBase host;
|
||||
|
||||
@@ -77,131 +78,132 @@ public class DeckImport extends JDialog {
|
||||
* the g
|
||||
*/
|
||||
public DeckImport(final DeckEditorBase g) {
|
||||
host = g;
|
||||
this.host = g;
|
||||
|
||||
int wWidth = 600;
|
||||
int wHeight = 600;
|
||||
final int wWidth = 600;
|
||||
final int wHeight = 600;
|
||||
|
||||
setPreferredSize(new java.awt.Dimension(wWidth, wHeight));
|
||||
setSize(wWidth, wHeight);
|
||||
this.setPreferredSize(new java.awt.Dimension(wWidth, wHeight));
|
||||
this.setSize(wWidth, wHeight);
|
||||
GuiUtils.centerFrame(this);
|
||||
setResizable(false);
|
||||
setTitle("Deck Import (wip)");
|
||||
this.setResizable(false);
|
||||
this.setTitle("Deck Import (wip)");
|
||||
|
||||
if (!Singletons.getModel().getPreferences().lafFonts) {
|
||||
Font fButtons = new java.awt.Font("Dialog", 0, 13);
|
||||
cmdAccept.setFont(fButtons);
|
||||
cmdCancel.setFont(fButtons);
|
||||
final Font fButtons = new java.awt.Font("Dialog", 0, 13);
|
||||
this.cmdAccept.setFont(fButtons);
|
||||
this.cmdCancel.setFont(fButtons);
|
||||
|
||||
txtInput.setFont(fButtons);
|
||||
this.txtInput.setFont(fButtons);
|
||||
// htmlOutput.setFont(fButtons);
|
||||
}
|
||||
|
||||
htmlOutput.setEditable(false);
|
||||
this.htmlOutput.setEditable(false);
|
||||
|
||||
scrollInput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(), "Paste or type a decklist"));
|
||||
scrollOutput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(),
|
||||
this.scrollInput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(), "Paste or type a decklist"));
|
||||
this.scrollOutput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(),
|
||||
"Expect the recognized lines to appear"));
|
||||
scrollInput.setViewportBorder(BorderFactory.createLoweredBevelBorder());
|
||||
scrollOutput.setViewportBorder(BorderFactory.createLoweredBevelBorder());
|
||||
this.scrollInput.setViewportBorder(BorderFactory.createLoweredBevelBorder());
|
||||
this.scrollOutput.setViewportBorder(BorderFactory.createLoweredBevelBorder());
|
||||
|
||||
getContentPane().setLayout(new MigLayout("fill"));
|
||||
getContentPane().add(scrollInput, "cell 0 0, w 50%, sy 4, growy, pushy");
|
||||
getContentPane().add(scrollOutput, "cell 1 0, w 50%, growy, pushy");
|
||||
this.getContentPane().setLayout(new MigLayout("fill"));
|
||||
this.getContentPane().add(this.scrollInput, "cell 0 0, w 50%, sy 4, growy, pushy");
|
||||
this.getContentPane().add(this.scrollOutput, "cell 1 0, w 50%, growy, pushy");
|
||||
|
||||
getContentPane().add(summaryMain, "cell 1 1, label");
|
||||
getContentPane().add(summarySide, "cell 1 2, label");
|
||||
this.getContentPane().add(this.summaryMain, "cell 1 1, label");
|
||||
this.getContentPane().add(this.summarySide, "cell 1 2, label");
|
||||
|
||||
getContentPane().add(cmdAccept, "cell 1 3, split 2, w 100, align c");
|
||||
getContentPane().add(cmdCancel, "w 100");
|
||||
this.getContentPane().add(this.cmdAccept, "cell 1 3, split 2, w 100, align c");
|
||||
this.getContentPane().add(this.cmdCancel, "w 100");
|
||||
|
||||
cmdCancel.addActionListener(new ActionListener() {
|
||||
this.cmdCancel.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
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
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
String warning = "This will replace contents of your currently open deck with whatever you are importing. Proceed?";
|
||||
int answer = JOptionPane.showConfirmDialog(DeckImport.this, warning, "Replacing old deck",
|
||||
final String warning = "This will replace contents of your currently open deck with whatever you are importing. Proceed?";
|
||||
final int answer = JOptionPane.showConfirmDialog(DeckImport.this, warning, "Replacing old deck",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (JOptionPane.NO_OPTION == answer) {
|
||||
return;
|
||||
}
|
||||
Deck toSet = buildDeck();
|
||||
host.setDeck(null, toSet.getMain(), toSet.getDeckType());
|
||||
processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING));
|
||||
final Deck toSet = DeckImport.this.buildDeck();
|
||||
DeckImport.this.host.setDeck(null, toSet.getMain(), toSet.getDeckType());
|
||||
DeckImport.this.processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING));
|
||||
}
|
||||
});
|
||||
|
||||
txtInput.getDocument().addDocumentListener(new OnChangeTextUpdate());
|
||||
cmdAccept.setEnabled(false);
|
||||
this.txtInput.getDocument().addDocumentListener(new OnChangeTextUpdate());
|
||||
this.cmdAccept.setEnabled(false);
|
||||
}
|
||||
|
||||
private void readInput() {
|
||||
tokens.clear();
|
||||
ElementIterator it = new ElementIterator(txtInput.getDocument().getDefaultRootElement());
|
||||
this.tokens.clear();
|
||||
final ElementIterator it = new ElementIterator(this.txtInput.getDocument().getDefaultRootElement());
|
||||
Element e;
|
||||
while ((e = it.next()) != null) {
|
||||
if (!e.isLeaf()) {
|
||||
continue;
|
||||
}
|
||||
int rangeStart = e.getStartOffset();
|
||||
int rangeEnd = e.getEndOffset();
|
||||
final int rangeStart = e.getStartOffset();
|
||||
final int rangeEnd = e.getEndOffset();
|
||||
try {
|
||||
String line = txtInput.getText(rangeStart, rangeEnd - rangeStart);
|
||||
tokens.add(DeckRecognizer.recognizeLine(line));
|
||||
} catch (BadLocationException ex) {
|
||||
final String line = this.txtInput.getText(rangeStart, rangeEnd - rangeStart);
|
||||
this.tokens.add(DeckRecognizer.recognizeLine(line));
|
||||
} catch (final BadLocationException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void displayTokens() {
|
||||
StringBuilder sbOut = new StringBuilder("<html>");
|
||||
sbOut.append(stylesheet);
|
||||
for (DeckRecognizer.Token t : tokens) {
|
||||
sbOut.append(makeHtmlViewOfToken(t));
|
||||
final StringBuilder sbOut = new StringBuilder("<html>");
|
||||
sbOut.append(DeckImport.STYLESHEET);
|
||||
for (final DeckRecognizer.Token t : this.tokens) {
|
||||
sbOut.append(this.makeHtmlViewOfToken(t));
|
||||
}
|
||||
sbOut.append("</html>");
|
||||
htmlOutput.setText(sbOut.toString());
|
||||
this.htmlOutput.setText(sbOut.toString());
|
||||
}
|
||||
|
||||
private void updateSummaries() {
|
||||
int[] cardsOk = new int[2];
|
||||
int[] cardsUnknown = new int[2];
|
||||
final int[] cardsOk = new int[2];
|
||||
final int[] cardsUnknown = new int[2];
|
||||
int idx = 0;
|
||||
for (DeckRecognizer.Token t : tokens) {
|
||||
for (final DeckRecognizer.Token t : this.tokens) {
|
||||
if (t.getType() == TokenType.KnownCard) {
|
||||
cardsOk[idx] += t.getNumber();
|
||||
}
|
||||
if (t.getType() == TokenType.UnknownCard) {
|
||||
cardsUnknown[idx] += t.getNumber();
|
||||
}
|
||||
if (t.getType() == TokenType.SectionName && t.getText().toLowerCase().contains("side")) {
|
||||
if ((t.getType() == TokenType.SectionName) && t.getText().toLowerCase().contains("side")) {
|
||||
idx = 1;
|
||||
}
|
||||
}
|
||||
summaryMain.setText(String.format("Main: %d cards recognized, %d unknown cards", cardsOk[0], cardsUnknown[0]));
|
||||
summarySide.setText(String.format("Sideboard: %d cards recognized, %d unknown cards", cardsOk[1],
|
||||
this.summaryMain.setText(String.format("Main: %d cards recognized, %d unknown cards", cardsOk[0],
|
||||
cardsUnknown[0]));
|
||||
this.summarySide.setText(String.format("Sideboard: %d cards recognized, %d unknown cards", cardsOk[1],
|
||||
cardsUnknown[1]));
|
||||
cmdAccept.setEnabled(cardsOk[0] > 0);
|
||||
this.cmdAccept.setEnabled(cardsOk[0] > 0);
|
||||
}
|
||||
|
||||
private Deck buildDeck() {
|
||||
Deck result = new Deck(GameType.Constructed);
|
||||
final Deck result = new Deck(GameType.Constructed);
|
||||
boolean isMain = true;
|
||||
for (DeckRecognizer.Token t : tokens) {
|
||||
DeckRecognizer.TokenType type = t.getType();
|
||||
if (type == DeckRecognizer.TokenType.SectionName && t.getText().toLowerCase().contains("side")) {
|
||||
for (final DeckRecognizer.Token t : this.tokens) {
|
||||
final DeckRecognizer.TokenType type = t.getType();
|
||||
if ((type == DeckRecognizer.TokenType.SectionName) && t.getText().toLowerCase().contains("side")) {
|
||||
isMain = false;
|
||||
}
|
||||
if (type != DeckRecognizer.TokenType.KnownCard) {
|
||||
continue;
|
||||
}
|
||||
CardPrinted crd = t.getCard();
|
||||
final CardPrinted crd = t.getCard();
|
||||
if (crd.isAlternate()) {
|
||||
continue;
|
||||
}
|
||||
@@ -219,9 +221,9 @@ public class DeckImport extends JDialog {
|
||||
*/
|
||||
protected class OnChangeTextUpdate implements DocumentListener {
|
||||
private void onChange() {
|
||||
readInput();
|
||||
displayTokens();
|
||||
updateSummaries();
|
||||
DeckImport.this.readInput();
|
||||
DeckImport.this.displayTokens();
|
||||
DeckImport.this.updateSummaries();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -233,7 +235,7 @@ public class DeckImport extends JDialog {
|
||||
*/
|
||||
@Override
|
||||
public final void insertUpdate(final DocumentEvent e) {
|
||||
onChange();
|
||||
this.onChange();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -245,7 +247,7 @@ public class DeckImport extends JDialog {
|
||||
*/
|
||||
@Override
|
||||
public final void removeUpdate(final DocumentEvent e) {
|
||||
onChange();
|
||||
this.onChange();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -18,50 +18,50 @@ import forge.item.CardPrinted;
|
||||
class FilterCheckBoxes {
|
||||
|
||||
/** The white. */
|
||||
public final JCheckBox white;
|
||||
private final JCheckBox white;
|
||||
|
||||
/** The blue. */
|
||||
public final JCheckBox blue;
|
||||
private final JCheckBox blue;
|
||||
|
||||
/** The black. */
|
||||
public final JCheckBox black;
|
||||
private final JCheckBox black;
|
||||
|
||||
/** The red. */
|
||||
public final JCheckBox red;
|
||||
private final JCheckBox red;
|
||||
|
||||
/** The green. */
|
||||
public final JCheckBox green;
|
||||
private final JCheckBox green;
|
||||
|
||||
/** The colorless. */
|
||||
public final JCheckBox colorless;
|
||||
private final JCheckBox colorless;
|
||||
|
||||
/** The land. */
|
||||
public final JCheckBox land;
|
||||
private final JCheckBox land;
|
||||
|
||||
/** The creature. */
|
||||
public final JCheckBox creature;
|
||||
private final JCheckBox creature;
|
||||
|
||||
/** The sorcery. */
|
||||
public final JCheckBox sorcery;
|
||||
private final JCheckBox sorcery;
|
||||
|
||||
/** The instant. */
|
||||
public final JCheckBox instant;
|
||||
private final JCheckBox instant;
|
||||
|
||||
/** The planeswalker. */
|
||||
public final JCheckBox planeswalker;
|
||||
private final JCheckBox planeswalker;
|
||||
|
||||
/** The artifact. */
|
||||
public final JCheckBox artifact;
|
||||
private final JCheckBox artifact;
|
||||
|
||||
/** The enchantment. */
|
||||
public final JCheckBox enchantment;
|
||||
private final JCheckBox enchantment;
|
||||
|
||||
// Very handy for classes using mass operations on an array of checkboxes
|
||||
/** The all colors. */
|
||||
public final List<JCheckBox> allColors;
|
||||
private final List<JCheckBox> allColors;
|
||||
|
||||
/** The all types. */
|
||||
public final List<JCheckBox> allTypes;
|
||||
private final List<JCheckBox> allTypes;
|
||||
|
||||
/**
|
||||
* Instantiates a new filter check boxes.
|
||||
@@ -71,40 +71,41 @@ class FilterCheckBoxes {
|
||||
*/
|
||||
public FilterCheckBoxes(final boolean useGraphicalBoxes) {
|
||||
if (useGraphicalBoxes) {
|
||||
white = new CheckBoxWithIcon("white", "White");
|
||||
blue = new CheckBoxWithIcon("blue", "Blue");
|
||||
black = new CheckBoxWithIcon("black", "Black");
|
||||
red = new CheckBoxWithIcon("red", "Red");
|
||||
green = new CheckBoxWithIcon("green", "Green");
|
||||
colorless = new CheckBoxWithIcon("colorless", "Colorless");
|
||||
this.white = new CheckBoxWithIcon("white", "White");
|
||||
this.blue = new CheckBoxWithIcon("blue", "Blue");
|
||||
this.black = new CheckBoxWithIcon("black", "Black");
|
||||
this.red = new CheckBoxWithIcon("red", "Red");
|
||||
this.green = new CheckBoxWithIcon("green", "Green");
|
||||
this.colorless = new CheckBoxWithIcon("colorless", "Colorless");
|
||||
|
||||
land = new CheckBoxWithIcon("land", "Land");
|
||||
creature = new CheckBoxWithIcon("creature", "Creature");
|
||||
sorcery = new CheckBoxWithIcon("sorcery", "Sorcery");
|
||||
instant = new CheckBoxWithIcon("instant", "Instant");
|
||||
planeswalker = new CheckBoxWithIcon("planeswalker", "Planeswalker");
|
||||
artifact = new CheckBoxWithIcon("artifact", "Artifact");
|
||||
enchantment = new CheckBoxWithIcon("enchant", "Enchantment");
|
||||
this.land = new CheckBoxWithIcon("land", "Land");
|
||||
this.creature = new CheckBoxWithIcon("creature", "Creature");
|
||||
this.sorcery = new CheckBoxWithIcon("sorcery", "Sorcery");
|
||||
this.instant = new CheckBoxWithIcon("instant", "Instant");
|
||||
this.planeswalker = new CheckBoxWithIcon("planeswalker", "Planeswalker");
|
||||
this.artifact = new CheckBoxWithIcon("artifact", "Artifact");
|
||||
this.enchantment = new CheckBoxWithIcon("enchant", "Enchantment");
|
||||
} else {
|
||||
white = new JCheckBox("W", true);
|
||||
blue = new JCheckBox("U", true);
|
||||
black = new JCheckBox("B", true);
|
||||
red = new JCheckBox("R", true);
|
||||
green = new JCheckBox("G", true);
|
||||
colorless = new JCheckBox("C", true);
|
||||
this.white = new JCheckBox("W", true);
|
||||
this.blue = new JCheckBox("U", true);
|
||||
this.black = new JCheckBox("B", true);
|
||||
this.red = new JCheckBox("R", true);
|
||||
this.green = new JCheckBox("G", true);
|
||||
this.colorless = new JCheckBox("C", true);
|
||||
|
||||
land = new JCheckBox("Land", true);
|
||||
creature = new JCheckBox("Creature", true);
|
||||
sorcery = new JCheckBox("Sorcery", true);
|
||||
instant = new JCheckBox("Instant", true);
|
||||
planeswalker = new JCheckBox("Planeswalker", true);
|
||||
artifact = new JCheckBox("Artifact", true);
|
||||
enchantment = new JCheckBox("Enchant", true);
|
||||
this.land = new JCheckBox("Land", true);
|
||||
this.creature = new JCheckBox("Creature", true);
|
||||
this.sorcery = new JCheckBox("Sorcery", true);
|
||||
this.instant = new JCheckBox("Instant", true);
|
||||
this.planeswalker = new JCheckBox("Planeswalker", true);
|
||||
this.artifact = new JCheckBox("Artifact", true);
|
||||
this.enchantment = new JCheckBox("Enchant", true);
|
||||
}
|
||||
|
||||
allColors = Arrays.asList(new JCheckBox[] { white, blue, black, red, green, colorless });
|
||||
allTypes = Arrays.asList(new JCheckBox[] { land, creature, sorcery, instant, planeswalker, artifact,
|
||||
enchantment });
|
||||
this.allColors = Arrays.asList(new JCheckBox[] { this.getWhite(), this.getBlue(), this.getBlack(), this.getRed(), this.getGreen(),
|
||||
this.getColorless() });
|
||||
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
|
||||
*/
|
||||
public final Predicate<CardPrinted> buildFilter() {
|
||||
List<Predicate<CardRules>> colors = new ArrayList<Predicate<CardRules>>();
|
||||
if (white.isSelected()) {
|
||||
final List<Predicate<CardRules>> colors = new ArrayList<Predicate<CardRules>>();
|
||||
if (this.getWhite().isSelected()) {
|
||||
colors.add(CardRules.Predicates.Presets.IS_WHITE);
|
||||
}
|
||||
if (blue.isSelected()) {
|
||||
if (this.getBlue().isSelected()) {
|
||||
colors.add(CardRules.Predicates.Presets.IS_BLUE);
|
||||
}
|
||||
if (black.isSelected()) {
|
||||
if (this.getBlack().isSelected()) {
|
||||
colors.add(CardRules.Predicates.Presets.IS_BLACK);
|
||||
}
|
||||
if (red.isSelected()) {
|
||||
if (this.getRed().isSelected()) {
|
||||
colors.add(CardRules.Predicates.Presets.IS_RED);
|
||||
}
|
||||
if (green.isSelected()) {
|
||||
if (this.getGreen().isSelected()) {
|
||||
colors.add(CardRules.Predicates.Presets.IS_GREEN);
|
||||
}
|
||||
if (colorless.isSelected()) {
|
||||
if (this.getColorless().isSelected()) {
|
||||
colors.add(CardRules.Predicates.Presets.IS_COLORLESS);
|
||||
}
|
||||
Predicate<CardRules> filterByColor = colors.size() == 6 ? CardRules.Predicates.Presets.CONSTANT_TRUE : Predicate
|
||||
.or(colors);
|
||||
final Predicate<CardRules> filterByColor = colors.size() == 6 ? CardRules.Predicates.Presets.CONSTANT_TRUE
|
||||
: Predicate.or(colors);
|
||||
|
||||
List<Predicate<CardRules>> types = new ArrayList<Predicate<CardRules>>();
|
||||
if (land.isSelected()) {
|
||||
final List<Predicate<CardRules>> types = new ArrayList<Predicate<CardRules>>();
|
||||
if (this.getLand().isSelected()) {
|
||||
types.add(CardRules.Predicates.Presets.IS_LAND);
|
||||
}
|
||||
if (creature.isSelected()) {
|
||||
if (this.getCreature().isSelected()) {
|
||||
types.add(CardRules.Predicates.Presets.IS_CREATURE);
|
||||
}
|
||||
if (sorcery.isSelected()) {
|
||||
if (this.getSorcery().isSelected()) {
|
||||
types.add(CardRules.Predicates.Presets.IS_SORCERY);
|
||||
}
|
||||
if (instant.isSelected()) {
|
||||
if (this.getInstant().isSelected()) {
|
||||
types.add(CardRules.Predicates.Presets.IS_INSTANT);
|
||||
}
|
||||
if (planeswalker.isSelected()) {
|
||||
if (this.getPlaneswalker().isSelected()) {
|
||||
types.add(CardRules.Predicates.Presets.IS_PLANESWALKER);
|
||||
}
|
||||
if (artifact.isSelected()) {
|
||||
if (this.getArtifact().isSelected()) {
|
||||
types.add(CardRules.Predicates.Presets.IS_ARTIFACT);
|
||||
}
|
||||
if (enchantment.isSelected()) {
|
||||
if (this.getEnchantment().isSelected()) {
|
||||
types.add(CardRules.Predicates.Presets.IS_ENCHANTMENT);
|
||||
}
|
||||
Predicate<CardRules> filterByType = types.size() == 7 ? CardRules.Predicates.Presets.CONSTANT_TRUE : Predicate
|
||||
.or(types);
|
||||
final Predicate<CardRules> filterByType = types.size() == 7 ? CardRules.Predicates.Presets.CONSTANT_TRUE
|
||||
: Predicate.or(types);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,25 +31,25 @@ public class FilterNameTypeSetPanel extends JComponent {
|
||||
private static final long serialVersionUID = -6409564625432765430L;
|
||||
|
||||
/** The label filter name. */
|
||||
public final JLabel labelFilterName = new JLabel();
|
||||
private final JLabel labelFilterName = new JLabel();
|
||||
|
||||
/** The label filter type. */
|
||||
public final JLabel labelFilterType = new JLabel();
|
||||
private final JLabel labelFilterType = new JLabel();
|
||||
|
||||
/** The label filter rules. */
|
||||
public final JLabel labelFilterRules = new JLabel();
|
||||
private final JLabel labelFilterRules = new JLabel();
|
||||
|
||||
/** The txt card name. */
|
||||
public final JTextField txtCardName = new JTextField();
|
||||
private final JTextField txtCardName = new JTextField();
|
||||
|
||||
/** The txt card type. */
|
||||
public final JTextField txtCardType = new JTextField();
|
||||
private final JTextField txtCardType = new JTextField();
|
||||
|
||||
/** The txt card rules. */
|
||||
public final JTextField txtCardRules = new JTextField();
|
||||
private final JTextField txtCardRules = new JTextField();
|
||||
|
||||
/** The search set combo. */
|
||||
public final JComboBox searchSetCombo = new JComboBox();
|
||||
private final JComboBox searchSetCombo = new JComboBox();
|
||||
|
||||
/**
|
||||
* Instantiates a new filter name type set panel.
|
||||
@@ -57,31 +57,31 @@ public class FilterNameTypeSetPanel extends JComponent {
|
||||
public FilterNameTypeSetPanel() {
|
||||
this.setLayout(new MigLayout("fill, ins 0"));
|
||||
|
||||
labelFilterName.setText("Name:");
|
||||
labelFilterName.setToolTipText("Card names must include the text in this field");
|
||||
this.add(labelFilterName, "cell 0 1, split 7");
|
||||
this.add(txtCardName, "wmin 100, grow");
|
||||
this.labelFilterName.setText("Name:");
|
||||
this.labelFilterName.setToolTipText("Card names must include the text in this field");
|
||||
this.add(this.labelFilterName, "cell 0 1, split 7");
|
||||
this.add(this.txtCardName, "wmin 100, grow");
|
||||
|
||||
labelFilterType.setText("Type:");
|
||||
labelFilterType.setToolTipText("Card types must include the text in this field");
|
||||
this.add(labelFilterType, "");
|
||||
this.add(txtCardType, "wmin 100, grow");
|
||||
this.labelFilterType.setText("Type:");
|
||||
this.labelFilterType.setToolTipText("Card types must include the text in this field");
|
||||
this.add(this.labelFilterType, "");
|
||||
this.add(this.txtCardType, "wmin 100, grow");
|
||||
|
||||
labelFilterRules.setText("Text:");
|
||||
labelFilterRules.setToolTipText("Card descriptions must include the text in this field");
|
||||
this.add(labelFilterRules, "");
|
||||
this.add(txtCardRules, "wmin 200, grow");
|
||||
this.labelFilterRules.setText("Text:");
|
||||
this.labelFilterRules.setToolTipText("Card descriptions must include the text in this field");
|
||||
this.add(this.labelFilterRules, "");
|
||||
this.add(this.txtCardRules, "wmin 200, grow");
|
||||
|
||||
searchSetCombo.removeAllItems();
|
||||
searchSetCombo.addItem("(all sets and formats)");
|
||||
for (GameFormat s : SetUtils.getFormats()) {
|
||||
searchSetCombo.addItem(s);
|
||||
this.searchSetCombo.removeAllItems();
|
||||
this.searchSetCombo.addItem("(all sets and formats)");
|
||||
for (final GameFormat s : SetUtils.getFormats()) {
|
||||
this.searchSetCombo.addItem(s);
|
||||
}
|
||||
for (CardSet s : SetUtils.getAllSets()) {
|
||||
searchSetCombo.addItem(s);
|
||||
for (final CardSet s : SetUtils.getAllSets()) {
|
||||
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
|
||||
*/
|
||||
public final void setListeners(final DocumentListener onTextChange, final ItemListener onComboChange) {
|
||||
txtCardType.getDocument().addDocumentListener(onTextChange);
|
||||
txtCardRules.getDocument().addDocumentListener(onTextChange);
|
||||
txtCardName.getDocument().addDocumentListener(onTextChange);
|
||||
searchSetCombo.addItemListener(onComboChange);
|
||||
this.txtCardType.getDocument().addDocumentListener(onTextChange);
|
||||
this.txtCardRules.getDocument().addDocumentListener(onTextChange);
|
||||
this.txtCardName.getDocument().addDocumentListener(onTextChange);
|
||||
this.searchSetCombo.addItemListener(onComboChange);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,23 +105,23 @@ public class FilterNameTypeSetPanel extends JComponent {
|
||||
* @return the predicate
|
||||
*/
|
||||
public final Predicate<CardPrinted> buildFilter() {
|
||||
List<Predicate<CardPrinted>> rules = new ArrayList<Predicate<CardPrinted>>(4);
|
||||
if (StringUtils.isNotBlank(txtCardName.getText())) {
|
||||
rules.add(CardPrinted.Predicates.name(StringOp.CONTAINS, txtCardName.getText()));
|
||||
final List<Predicate<CardPrinted>> rules = new ArrayList<Predicate<CardPrinted>>(4);
|
||||
if (StringUtils.isNotBlank(this.txtCardName.getText())) {
|
||||
rules.add(CardPrinted.Predicates.name(StringOp.CONTAINS, this.txtCardName.getText()));
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(txtCardType.getText())) {
|
||||
rules.add(Predicate.brigde(CardRules.Predicates.joinedType(StringOp.CONTAINS, txtCardType.getText()),
|
||||
if (StringUtils.isNotBlank(this.txtCardType.getText())) {
|
||||
rules.add(Predicate.brigde(CardRules.Predicates.joinedType(StringOp.CONTAINS, this.txtCardType.getText()),
|
||||
CardPrinted.fnGetRules));
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(txtCardRules.getText())) {
|
||||
rules.add(Predicate.brigde(CardRules.Predicates.rules(StringOp.CONTAINS, txtCardRules.getText()),
|
||||
if (StringUtils.isNotBlank(this.txtCardRules.getText())) {
|
||||
rules.add(Predicate.brigde(CardRules.Predicates.rules(StringOp.CONTAINS, this.txtCardRules.getText()),
|
||||
CardPrinted.fnGetRules));
|
||||
}
|
||||
|
||||
if (searchSetCombo.getSelectedIndex() != 0) {
|
||||
Object selected = searchSetCombo.getSelectedItem();
|
||||
if (this.searchSetCombo.getSelectedIndex() != 0) {
|
||||
final Object selected = this.searchSetCombo.getSelectedItem();
|
||||
if (selected instanceof CardSet) {
|
||||
rules.add(CardPrinted.Predicates.printedInSets(((CardSet) selected).getCode()));
|
||||
} else if (selected instanceof GameFormat) {
|
||||
@@ -145,9 +145,9 @@ public class FilterNameTypeSetPanel extends JComponent {
|
||||
* TODO: Write javadoc for this method.
|
||||
*/
|
||||
public final void clearFilters() {
|
||||
txtCardName.setText("");
|
||||
txtCardType.setText("");
|
||||
txtCardRules.setText("");
|
||||
searchSetCombo.setSelectedIndex(0);
|
||||
this.txtCardName.setText("");
|
||||
this.txtCardType.setText("");
|
||||
this.txtCardRules.setText("");
|
||||
this.searchSetCombo.setSelectedIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ public class ManaCostRenderer extends DefaultTableCellRenderer {
|
||||
* (javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
|
||||
*/
|
||||
@Override
|
||||
public final Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected,
|
||||
final boolean hasFocus, final int row, final int column) {
|
||||
public final Component getTableCellRendererComponent(final JTable table, final Object value,
|
||||
final boolean isSelected, final boolean hasFocus, final int row, final int column) {
|
||||
this.value = (CardManaCost) value;
|
||||
setToolTipText(this.value.toString());
|
||||
this.setToolTipText(this.value.toString());
|
||||
return super.getTableCellRendererComponent(table, "", isSelected, hasFocus, row, column);
|
||||
}
|
||||
|
||||
@@ -49,23 +49,23 @@ public class ManaCostRenderer extends DefaultTableCellRenderer {
|
||||
|
||||
float xpos = padding;
|
||||
|
||||
int genericManaCost = value.getGenericCost();
|
||||
boolean hasGeneric = genericManaCost > 0 || value.isPureGeneric();
|
||||
List<CardManaCostShard> shards = value.getShards();
|
||||
final int genericManaCost = this.value.getGenericCost();
|
||||
final boolean hasGeneric = (genericManaCost > 0) || this.value.isPureGeneric();
|
||||
final List<CardManaCostShard> shards = this.value.getShards();
|
||||
|
||||
int cellWidth = getWidth();
|
||||
int cntGlyphs = hasGeneric ? shards.size() + 1 : shards.size();
|
||||
float offsetIfNoSpace = cntGlyphs > 1 ? (cellWidth - padding - elemtWidth) / (cntGlyphs - 1f) : elemtWidth
|
||||
+ elemtGap;
|
||||
float offset = Math.min(elemtWidth + elemtGap, offsetIfNoSpace);
|
||||
final int cellWidth = this.getWidth();
|
||||
final int cntGlyphs = hasGeneric ? shards.size() + 1 : shards.size();
|
||||
final float offsetIfNoSpace = cntGlyphs > 1 ? (cellWidth - padding - elemtWidth) / (cntGlyphs - 1f)
|
||||
: elemtWidth + elemtGap;
|
||||
final float offset = Math.min(elemtWidth + elemtGap, offsetIfNoSpace);
|
||||
|
||||
if (hasGeneric) {
|
||||
String sGeneric = Integer.toString(genericManaCost);
|
||||
final String sGeneric = Integer.toString(genericManaCost);
|
||||
ManaSymbols.drawSymbol(sGeneric, g, (int) xpos, 1);
|
||||
xpos += offset;
|
||||
}
|
||||
|
||||
for (CardManaCostShard s : shards) {
|
||||
for (final CardManaCostShard s : shards) {
|
||||
ManaSymbols.drawSymbol(s.getImageKey(), g, (int) xpos, 1);
|
||||
xpos += offset;
|
||||
}
|
||||
|
||||
@@ -20,24 +20,24 @@ public class TableColumnInfo<T> {
|
||||
private final String name;
|
||||
|
||||
/** The min width. */
|
||||
public int minWidth;
|
||||
private int minWidth;
|
||||
|
||||
/** The max width. */
|
||||
public int maxWidth;
|
||||
private int maxWidth;
|
||||
|
||||
/** The nominal width. */
|
||||
public int nominalWidth;
|
||||
private int nominalWidth;
|
||||
|
||||
/** The is min max applied. */
|
||||
public boolean isMinMaxApplied = true;
|
||||
private boolean isMinMaxApplied = true;
|
||||
|
||||
/** 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
|
||||
// sorting
|
||||
|
||||
/** 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
|
||||
|
||||
private TableCellRenderer cellRenderer = null;
|
||||
@@ -48,7 +48,7 @@ public class TableColumnInfo<T> {
|
||||
* @return the name
|
||||
*/
|
||||
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,
|
||||
final Lambda1<Object, Entry<T, Integer>> fieldDisplay) {
|
||||
fnSort = fieldSort;
|
||||
fnDisplay = fieldDisplay;
|
||||
this.fnSort = fieldSort;
|
||||
this.fnDisplay = fieldDisplay;
|
||||
this.name = colName;
|
||||
}
|
||||
|
||||
@@ -84,9 +84,9 @@ public class TableColumnInfo<T> {
|
||||
final Lambda1<Comparable, Entry<T, Integer>> fieldSort,
|
||||
final Lambda1<Object, Entry<T, Integer>> fieldDisplay) {
|
||||
this(colName, fieldSort, fieldDisplay);
|
||||
this.maxWidth = width;
|
||||
this.minWidth = width;
|
||||
this.nominalWidth = width;
|
||||
this.setMaxWidth(width);
|
||||
this.setMinWidth(width);
|
||||
this.setNominalWidth(width);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,9 +109,9 @@ public class TableColumnInfo<T> {
|
||||
final Lambda1<Comparable, Entry<T, Integer>> fieldSort,
|
||||
final Lambda1<Object, Entry<T, Integer>> fieldDisplay) {
|
||||
this(colName, fieldSort, fieldDisplay);
|
||||
this.maxWidth = wMax;
|
||||
this.minWidth = wMin;
|
||||
this.nominalWidth = width;
|
||||
this.setMaxWidth(wMax);
|
||||
this.setMinWidth(wMin);
|
||||
this.setNominalWidth(width);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,7 +121,7 @@ public class TableColumnInfo<T> {
|
||||
* the new cell 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,23 +39,23 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
|
||||
private final class SortOrders {
|
||||
private class Order {
|
||||
public final int sortColumn;
|
||||
public boolean isSortAsc = true;
|
||||
private final int sortColumn;
|
||||
private boolean isSortAsc = true;
|
||||
|
||||
public Order(final int col) {
|
||||
sortColumn = col;
|
||||
this.sortColumn = col;
|
||||
}
|
||||
};
|
||||
|
||||
private final int MAX_DEPTH = 3;
|
||||
private List<Order> orders = new ArrayList<Order>(3);
|
||||
private final int maxDepth = 3;
|
||||
private final List<Order> orders = new ArrayList<Order>(3);
|
||||
private TableSorterCascade<T> sorter = null;
|
||||
private boolean isSorterReady = false;
|
||||
|
||||
private int indexOfColumn(final int column) {
|
||||
int posColumn = orders.size() - 1;
|
||||
int posColumn = this.orders.size() - 1;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -64,47 +64,48 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
|
||||
// index of column to sort by, desired direction
|
||||
public void add(final int column, final boolean wantAsc) {
|
||||
add(column);
|
||||
orders.get(0).isSortAsc = wantAsc;
|
||||
isSorterReady = false;
|
||||
this.add(column);
|
||||
this.orders.get(0).isSortAsc = wantAsc;
|
||||
this.isSorterReady = false;
|
||||
}
|
||||
|
||||
// puts desired direction on top, set "asc"; if already was on top,
|
||||
// inverts direction;
|
||||
public void add(final int column) {
|
||||
int posColumn = indexOfColumn(column);
|
||||
final int posColumn = this.indexOfColumn(column);
|
||||
switch (posColumn) {
|
||||
case -1: // no such column here - let's add then
|
||||
orders.add(0, new Order(column));
|
||||
this.orders.add(0, new Order(column));
|
||||
break;
|
||||
case 0: // found at top-level, should invert
|
||||
orders.get(0).isSortAsc ^= true; // invert
|
||||
this.orders.get(0).isSortAsc ^= true; // invert
|
||||
break;
|
||||
default: // found somewhere, move down others, set this one onto
|
||||
// top;
|
||||
orders.remove(posColumn);
|
||||
orders.add(0, new Order(column));
|
||||
this.orders.remove(posColumn);
|
||||
this.orders.add(0, new Order(column));
|
||||
break;
|
||||
}
|
||||
if (orders.size() > MAX_DEPTH) {
|
||||
orders.remove(MAX_DEPTH);
|
||||
if (this.orders.size() > this.maxDepth) {
|
||||
this.orders.remove(this.maxDepth);
|
||||
}
|
||||
isSorterReady = false;
|
||||
this.isSorterReady = false;
|
||||
}
|
||||
|
||||
public TableSorterCascade<T> getSorter() {
|
||||
if (!isSorterReady) {
|
||||
List<TableSorter<T>> oneColSorters = new ArrayList<TableSorter<T>>(MAX_DEPTH);
|
||||
for (Order order : orders) {
|
||||
oneColSorters.add(new TableSorter<T>(columns.get(order.sortColumn).fnSort, order.isSortAsc));
|
||||
if (!this.isSorterReady) {
|
||||
final List<TableSorter<T>> oneColSorters = new ArrayList<TableSorter<T>>(this.maxDepth);
|
||||
for (final Order order : this.orders) {
|
||||
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 List<TableColumnInfo<T>> columns;
|
||||
private final SortOrders sortOrders = new SortOrders();
|
||||
@@ -120,10 +121,10 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
* the cls
|
||||
*/
|
||||
public TableModel(final CardPanelBase cd, final List<TableColumnInfo<T>> columnsToShow, final Class<T> cls) {
|
||||
data = new ItemPool<T>(cls);
|
||||
cardDisplay = cd;
|
||||
columns = columnsToShow;
|
||||
columns.get(4).isMinMaxApplied = false;
|
||||
this.data = new ItemPool<T>(cls);
|
||||
this.cardDisplay = cd;
|
||||
this.columns = columnsToShow;
|
||||
this.columns.get(4).setMinMaxApplied(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,12 +137,12 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
TableColumn tableColumn = null;
|
||||
for (int i = 0; i < table.getColumnCount(); i++) {
|
||||
tableColumn = table.getColumnModel().getColumn(i);
|
||||
TableColumnInfo<T> colInfo = columns.get(i);
|
||||
final TableColumnInfo<T> colInfo = this.columns.get(i);
|
||||
|
||||
tableColumn.setPreferredWidth(colInfo.nominalWidth);
|
||||
if (colInfo.isMinMaxApplied) {
|
||||
tableColumn.setMinWidth(colInfo.minWidth);
|
||||
tableColumn.setMaxWidth(colInfo.maxWidth);
|
||||
tableColumn.setPreferredWidth(colInfo.getNominalWidth());
|
||||
if (colInfo.isMinMaxApplied()) {
|
||||
tableColumn.setMinWidth(colInfo.getMinWidth());
|
||||
tableColumn.setMaxWidth(colInfo.getMaxWidth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,7 +151,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
* 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
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
public void removeCard(final T c) {
|
||||
boolean wasThere = data.count(c) > 0;
|
||||
final boolean wasThere = this.data.count(c) > 0;
|
||||
if (wasThere) {
|
||||
data.remove(c);
|
||||
fireTableDataChanged();
|
||||
this.data.remove(c);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,8 +186,8 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
* the c
|
||||
*/
|
||||
public void addCard(final T c) {
|
||||
data.add(c);
|
||||
fireTableDataChanged();
|
||||
this.data.add(c);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,8 +199,8 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
* the count
|
||||
*/
|
||||
public void addCard(final T c, final int count) {
|
||||
data.add(c, count);
|
||||
fireTableDataChanged();
|
||||
this.data.add(c, count);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,8 +210,8 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
* the e
|
||||
*/
|
||||
public void addCard(final Entry<T, Integer> e) {
|
||||
data.add(e.getKey(), e.getValue());
|
||||
fireTableDataChanged();
|
||||
this.data.add(e.getKey(), e.getValue());
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,8 +221,8 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
* the c
|
||||
*/
|
||||
public void addCards(final Iterable<Entry<T, Integer>> c) {
|
||||
data.addAll(c);
|
||||
fireTableDataChanged();
|
||||
this.data.addAll(c);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,8 +232,8 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
* the c
|
||||
*/
|
||||
public void addAllCards(final Iterable<T> c) {
|
||||
data.addAllCards(c);
|
||||
fireTableDataChanged();
|
||||
this.data.addAllCards(c);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,8 +244,8 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
* @return the entry
|
||||
*/
|
||||
public Entry<T, Integer> rowToCard(final int row) {
|
||||
List<Entry<T, Integer>> model = data.getOrderedList();
|
||||
return row >= 0 && row < model.size() ? model.get(row) : null;
|
||||
final List<Entry<T, Integer>> model = this.data.getOrderedList();
|
||||
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()
|
||||
*/
|
||||
/**
|
||||
* Gets the row count.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@Override
|
||||
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()
|
||||
*/
|
||||
/**
|
||||
* Gets the column count.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return columns.size();
|
||||
return this.columns.size();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String getColumnName(final int n) {
|
||||
return columns.get(n).getName();
|
||||
return this.columns.get(n).getName();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
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
|
||||
* interested in processing a column event implements this interface, and
|
||||
* the object created with that class is registered with a component using
|
||||
* the component's addColumnListener method. When
|
||||
* the column event occurs, that object's appropriate
|
||||
* method is invoked.
|
||||
*
|
||||
* the component's addColumnListener method. When the column event occurs,
|
||||
* that object's appropriate method is invoked.
|
||||
*
|
||||
* @see ColumnEvent
|
||||
*/
|
||||
class ColumnListener extends MouseAdapter {
|
||||
|
||||
/** The table. */
|
||||
protected JTable table;
|
||||
private JTable table;
|
||||
|
||||
/**
|
||||
* Instantiates a new column listener.
|
||||
@@ -303,7 +311,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
* the 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)
|
||||
*/
|
||||
/**
|
||||
* Mouse clicked.
|
||||
*
|
||||
* @param e MouseEvent
|
||||
*/
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
TableColumnModel colModel = table.getColumnModel();
|
||||
int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
|
||||
int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
|
||||
final TableColumnModel colModel = this.table.getColumnModel();
|
||||
final int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
|
||||
final int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
|
||||
|
||||
if (modelIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// This will invert if needed
|
||||
sortOrders.add(modelIndex);
|
||||
TableModel.this.sortOrders.add(modelIndex);
|
||||
|
||||
for (int i = 0; i < columns.size(); i++) {
|
||||
TableColumn column = colModel.getColumn(i);
|
||||
column.setHeaderValue(getColumnName(column.getModelIndex()));
|
||||
for (int i = 0; i < TableModel.this.columns.size(); i++) {
|
||||
final TableColumn column = colModel.getColumn(i);
|
||||
column.setHeaderValue(TableModel.this.getColumnName(column.getModelIndex()));
|
||||
}
|
||||
table.getTableHeader().repaint();
|
||||
this.table.getTableHeader().repaint();
|
||||
|
||||
resort();
|
||||
table.tableChanged(new TableModelEvent(TableModel.this));
|
||||
table.repaint();
|
||||
TableModel.this.resort();
|
||||
this.table.tableChanged(new TableModelEvent(TableModel.this));
|
||||
this.table.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,10 +357,10 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
* the table
|
||||
*/
|
||||
public void showSelectedCard(final JTable table) {
|
||||
int row = table.getSelectedRow();
|
||||
final int row = table.getSelectedRow();
|
||||
if (row != -1) {
|
||||
T cp = rowToCard(row).getKey();
|
||||
cardDisplay.showCard(cp);
|
||||
final T cp = this.rowToCard(row).getKey();
|
||||
this.cardDisplay.showCard(cp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,7 +378,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
|
||||
@Override
|
||||
public void valueChanged(final ListSelectionEvent arg0) {
|
||||
showSelectedCard(table);
|
||||
TableModel.this.showSelectedCard(table);
|
||||
}
|
||||
});
|
||||
table.addFocusListener(new FocusListener() {
|
||||
@@ -378,7 +389,7 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
|
||||
|
||||
@Override
|
||||
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.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public void sort(final int iCol, final boolean isAsc) {
|
||||
sortOrders.add(iCol, isAsc);
|
||||
resort();
|
||||
this.sortOrders.add(iCol, isAsc);
|
||||
this.resort();
|
||||
}
|
||||
|
||||
} // CardTableModel
|
||||
|
||||
@@ -19,9 +19,9 @@ import forge.item.CardPrinted;
|
||||
@SuppressWarnings("unchecked")
|
||||
// Comparable needs <type>
|
||||
public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
|
||||
private boolean ascending;
|
||||
private final boolean ascending;
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Lambda1<Comparable, Entry<T, Integer>> field;
|
||||
private final Lambda1<Comparable, Entry<T, Integer>> field;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -30,18 +30,18 @@ public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
|
||||
*
|
||||
* @param field
|
||||
* the field
|
||||
* @param in_ascending
|
||||
* @param inAscending
|
||||
* a boolean.
|
||||
*/
|
||||
@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;
|
||||
ascending = in_ascending;
|
||||
this.ascending = inAscending;
|
||||
}
|
||||
|
||||
/** The Constant byNameThenSet. */
|
||||
@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>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<CardPrinted, Integer> from) {
|
||||
@@ -57,10 +57,10 @@ public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public final int compare(final Entry<T, Integer> arg0, final Entry<T, Integer> arg1) {
|
||||
Comparable obj1 = field.apply(arg0);
|
||||
Comparable obj2 = field.apply(arg1);
|
||||
final Comparable obj1 = this.field.apply(arg0);
|
||||
final Comparable obj2 = this.field.apply(arg1);
|
||||
// System.out.println(String.format("%s vs %s _______ %s vs %s", arg0,
|
||||
// arg1, obj1, obj2));
|
||||
return ascending ? obj1.compareTo(obj2) : obj2.compareTo(obj1);
|
||||
return this.ascending ? obj1.compareTo(obj2) : obj2.compareTo(obj1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import forge.item.InventoryItem;
|
||||
* @version $Id: TableSorter.java 10146 2011-09-01 18:11:00Z Max mtg $
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,7 @@ public class TableSorterCascade<T extends InventoryItem> implements Comparator<E
|
||||
*/
|
||||
public TableSorterCascade(final List<TableSorter<T>> 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) {
|
||||
int lastCompare = 0;
|
||||
int iField = -1;
|
||||
while (++iField < cntFields && lastCompare == 0) { // reverse iteration
|
||||
TableSorter<T> sorter = sorters.get(iField);
|
||||
while ((++iField < this.cntFields) && (lastCompare == 0)) { // reverse
|
||||
// iteration
|
||||
final TableSorter<T> sorter = this.sorters.get(iField);
|
||||
if (sorter == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -28,28 +28,28 @@ import forge.item.ItemPoolView;
|
||||
public final class TableWithCards {
|
||||
|
||||
/** The pool. */
|
||||
protected ItemPool<InventoryItem> pool;
|
||||
private ItemPool<InventoryItem> pool;
|
||||
|
||||
/** The model. */
|
||||
protected TableModel<InventoryItem> model;
|
||||
private TableModel<InventoryItem> model;
|
||||
|
||||
/** The table. */
|
||||
protected JTable table = new JTable();
|
||||
private JTable table = new JTable();
|
||||
|
||||
/** The j scroll pane. */
|
||||
protected JScrollPane jScrollPane = new JScrollPane();
|
||||
private JScrollPane jScrollPane = new JScrollPane();
|
||||
|
||||
/** The stats label. */
|
||||
protected JLabel statsLabel = new JLabel();
|
||||
private JLabel statsLabel = new JLabel();
|
||||
|
||||
/** The filter. */
|
||||
protected Predicate<InventoryItem> filter = null;
|
||||
private Predicate<InventoryItem> filter = null;
|
||||
|
||||
/** The is tracking stats. */
|
||||
protected boolean isTrackingStats = false;
|
||||
private boolean isTrackingStats = false;
|
||||
|
||||
/** The want unique. */
|
||||
protected boolean wantUnique = false;
|
||||
private boolean wantUnique = false;
|
||||
|
||||
// need this to allow users place its contents
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ public final class TableWithCards {
|
||||
* @return JComponent
|
||||
*/
|
||||
public JComponent getTableDecorated() {
|
||||
return jScrollPane;
|
||||
return this.jScrollPane;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ public final class TableWithCards {
|
||||
* @return JTable
|
||||
*/
|
||||
public JTable getTable() {
|
||||
return table;
|
||||
return this.table;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +79,7 @@ public final class TableWithCards {
|
||||
* @return JComponent
|
||||
*/
|
||||
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) {
|
||||
// components
|
||||
Color gray = new Color(148, 145, 140);
|
||||
TitledBorder titledBorder = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, gray), title);
|
||||
final Color gray = new Color(148, 145, 140);
|
||||
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";
|
||||
jScrollPane.setBorder(titledBorder);
|
||||
jScrollPane.setToolTipText(tableToolTip);
|
||||
jScrollPane.getViewport().add(table, null);
|
||||
final String tableToolTip = "Click on the column name (like name or color) to sort the cards";
|
||||
this.jScrollPane.setBorder(titledBorder);
|
||||
this.jScrollPane.setToolTipText(tableToolTip);
|
||||
this.jScrollPane.getViewport().add(this.table, null);
|
||||
|
||||
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
|
||||
isTrackingStats = showStats;
|
||||
wantUnique = forceUnique;
|
||||
this.isTrackingStats = showStats;
|
||||
this.wantUnique = forceUnique;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,24 +136,25 @@ public final class TableWithCards {
|
||||
* a CardPanelBase
|
||||
*/
|
||||
public void setup(final List<TableColumnInfo<InventoryItem>> columns, final CardPanelBase cardView) {
|
||||
model = new TableModel<InventoryItem>(cardView, columns, InventoryItem.class);
|
||||
model.addListeners(table);
|
||||
table.setModel(model);
|
||||
model.resizeCols(table);
|
||||
this.model = new TableModel<InventoryItem>(cardView, columns, InventoryItem.class);
|
||||
this.model.addListeners(this.table);
|
||||
this.table.setModel(this.model);
|
||||
this.model.resizeCols(this.table);
|
||||
|
||||
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) {
|
||||
table.getColumnModel().getColumn(idx).setCellRenderer(renderer);
|
||||
this.table.getColumnModel().getColumn(idx).setCellRenderer(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
if (isTrackingStats) {
|
||||
if (this.isTrackingStats) {
|
||||
// get stats from deck
|
||||
model.addTableModelListener(new TableModelListener() {
|
||||
this.model.addTableModelListener(new TableModelListener() {
|
||||
@Override
|
||||
public void tableChanged(final TableModelEvent ev) {
|
||||
ItemPoolView<InventoryItem> deck = model.getCards();
|
||||
statsLabel.setText(getStats(deck));
|
||||
final ItemPoolView<InventoryItem> deck = TableWithCards.this.model.getCards();
|
||||
TableWithCards.this.statsLabel.setText(TableWithCards.getStats(deck));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -169,15 +170,15 @@ public final class TableWithCards {
|
||||
* @return String
|
||||
*/
|
||||
public static String getStats(final ItemPoolView<InventoryItem> deck) {
|
||||
int total = deck.countAll();
|
||||
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 total = deck.countAll();
|
||||
final int creature = CardRules.Predicates.Presets.IS_CREATURE.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 - ")
|
||||
.append(land);
|
||||
String[] color = Constant.Color.ONLY_COLORS;
|
||||
List<Predicate<CardRules>> predicates = CardRules.Predicates.Presets.COLORS;
|
||||
final String[] color = Constant.Color.ONLY_COLORS;
|
||||
final List<Predicate<CardRules>> predicates = CardRules.Predicates.Presets.COLORS;
|
||||
for (int i = 0; i < color.length; ++i) {
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public TableWithCards sort(final int iCol, final boolean isAsc) {
|
||||
model.sort(iCol, isAsc);
|
||||
this.model.sort(iCol, isAsc);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -222,12 +223,12 @@ public final class TableWithCards {
|
||||
public void fixSelection(final int rowLastSelected) {
|
||||
// 3 cases: 0 cards left, select the same row, select prev row
|
||||
int newRow = rowLastSelected;
|
||||
int cntRowsAbove = model.getRowCount();
|
||||
final int cntRowsAbove = this.model.getRowCount();
|
||||
if (cntRowsAbove != 0) {
|
||||
if (cntRowsAbove == newRow) {
|
||||
newRow--;
|
||||
} // 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>
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
protected void setDeckImpl(final ItemPool<InventoryItem> thePool) {
|
||||
model.clear();
|
||||
pool = thePool;
|
||||
model.addCards(pool);
|
||||
updateView(true);
|
||||
this.model.clear();
|
||||
this.pool = thePool;
|
||||
this.model.addCards(this.pool);
|
||||
this.updateView(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,12 +276,12 @@ public final class TableWithCards {
|
||||
* @return InventoryItem
|
||||
*/
|
||||
public InventoryItem getSelectedCard() {
|
||||
int iRow = table.getSelectedRow();
|
||||
return iRow >= 0 ? model.rowToCard(iRow).getKey() : null;
|
||||
final int iRow = this.table.getSelectedRow();
|
||||
return iRow >= 0 ? this.model.rowToCard(iRow).getKey() : null;
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
public void setFilter(final Predicate<InventoryItem> filterToSet) {
|
||||
filter = filterToSet;
|
||||
updateView(true);
|
||||
this.filter = filterToSet;
|
||||
this.updateView(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,11 +305,11 @@ public final class TableWithCards {
|
||||
*/
|
||||
public void addCard(final InventoryItem card) {
|
||||
// int n = table.getSelectedRow();
|
||||
pool.add(card);
|
||||
if (isUnfiltered()) {
|
||||
model.addCard(card);
|
||||
this.pool.add(card);
|
||||
if (this.isUnfiltered()) {
|
||||
this.model.addCard(card);
|
||||
}
|
||||
updateView(false);
|
||||
this.updateView(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,13 +320,13 @@ public final class TableWithCards {
|
||||
* an InventoryItem
|
||||
*/
|
||||
public void removeCard(final InventoryItem card) {
|
||||
int n = table.getSelectedRow();
|
||||
pool.remove(card);
|
||||
if (isUnfiltered()) {
|
||||
model.removeCard(card);
|
||||
final int n = this.table.getSelectedRow();
|
||||
this.pool.remove(card);
|
||||
if (this.isUnfiltered()) {
|
||||
this.model.removeCard(card);
|
||||
}
|
||||
updateView(false);
|
||||
fixSelection(n);
|
||||
this.updateView(false);
|
||||
this.fixSelection(n);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,22 +337,22 @@ public final class TableWithCards {
|
||||
* a boolean
|
||||
*/
|
||||
public void updateView(final boolean bForceFilter) {
|
||||
boolean useFilter = (bForceFilter && filter != null) || !isUnfiltered();
|
||||
final boolean useFilter = (bForceFilter && (this.filter != null)) || !this.isUnfiltered();
|
||||
|
||||
if (useFilter || wantUnique) {
|
||||
model.clear();
|
||||
if (useFilter || this.wantUnique) {
|
||||
this.model.clear();
|
||||
}
|
||||
|
||||
if (useFilter && wantUnique) {
|
||||
model.addCards(filter.uniqueByLast(pool, pool.fnToCardName, pool.fnToPrinted));
|
||||
if (useFilter && this.wantUnique) {
|
||||
this.model.addCards(this.filter.uniqueByLast(this.pool, this.pool.fnToCardName, this.pool.fnToPrinted));
|
||||
} else if (useFilter) {
|
||||
model.addCards(filter.select(pool, pool.fnToPrinted));
|
||||
} else if (wantUnique) {
|
||||
model.addCards(CardRules.Predicates.Presets.CONSTANT_TRUE.uniqueByLast(pool, pool.fnToCardName,
|
||||
pool.fnToCard));
|
||||
this.model.addCards(this.filter.select(this.pool, this.pool.fnToPrinted));
|
||||
} else if (this.wantUnique) {
|
||||
this.model.addCards(CardRules.Predicates.Presets.CONSTANT_TRUE.uniqueByLast(this.pool,
|
||||
this.pool.fnToCardName, this.pool.fnToCard));
|
||||
}
|
||||
|
||||
model.resort();
|
||||
this.model.resort();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -361,7 +362,7 @@ public final class TableWithCards {
|
||||
* @return ItemPoolView
|
||||
*/
|
||||
public ItemPoolView<InventoryItem> getCards() {
|
||||
return pool;
|
||||
return this.pool;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -702,7 +702,7 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants.
|
||||
editor.show(exit);
|
||||
|
||||
if (deck != null) {
|
||||
editor.customMenu.showDeck(deck, gt);
|
||||
editor.getCustomMenu().showDeck(deck, gt);
|
||||
}
|
||||
|
||||
this.setVisible(false);
|
||||
|
||||
Reference in New Issue
Block a user