getSealed() {
+ return sealed;
+ }
+
+
+
+}
diff --git a/src/main/java/forge/game/limited/CustomLimited.java b/src/main/java/forge/deck/CustomLimited.java
similarity index 89%
rename from src/main/java/forge/game/limited/CustomLimited.java
rename to src/main/java/forge/deck/CustomLimited.java
index 3a25081c761..6ceddad9f6c 100644
--- a/src/main/java/forge/game/limited/CustomLimited.java
+++ b/src/main/java/forge/deck/CustomLimited.java
@@ -15,11 +15,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package forge.game.limited;
+package forge.deck;
import java.util.List;
+import java.util.Map;
import forge.AllZone;
+import forge.item.CardPrinted;
+import forge.item.ItemPoolView;
+import forge.util.SectionUtil;
/**
*
@@ -29,10 +33,17 @@ import forge.AllZone;
* @author Forge
* @version $Id$
*/
-class CustomLimited {
+public class CustomLimited extends DeckBase {
- /** The Name. */
- private String name;
+ /**
+ * TODO: Write javadoc for Constructor.
+ * @param name0
+ */
+ public CustomLimited(String name0) {
+ super(name0);
+ }
+
+ private static final long serialVersionUID = 7435640939026612173L;
/** The Type. */
// private String type;
@@ -70,6 +81,8 @@ class CustomLimited {
/** The Num packs. */
private int numPacks = 3;
+ private DeckSection cardPool;
+
/** The Land set code. */
private String landSetCode = AllZone.getCardFactory().getCard("Plains", AllZone.getHumanPlayer())
.getMostRecentSet();
@@ -92,19 +105,16 @@ class CustomLimited {
* @return the custom limited
*/
public static CustomLimited parse(final List dfData) {
- final CustomLimited cd = new CustomLimited();
+
+ Map data = SectionUtil.parseKvPairs(dfData, ":");
+
+ final CustomLimited cd = new CustomLimited(data.get("Name"));
for (final String dd : dfData) {
final String[] v = dd.split(":", 2);
final String key = v[0];
final String value = v.length > 1 ? v[1].trim() : "";
- if (key.equalsIgnoreCase("Name")) {
- cd.setName(value);
- }
- if (key.equalsIgnoreCase("Type")) {
- // cd.type = value;
- }
if (key.equalsIgnoreCase("DeckFile")) {
cd.setDeckFile(value);
}
@@ -374,18 +384,22 @@ class CustomLimited {
this.numDoubleFaced = numDoubleFacedIn;
}
- /**
- * @return the name
+ /* (non-Javadoc)
+ * @see forge.item.CardCollectionBase#getCardPool()
*/
- private String getName() {
- return this.name;
+ @Override
+ public ItemPoolView getCardPool() {
+ return cardPool;
}
- /**
- * @param nameIn
- * the name to set
+ /* (non-Javadoc)
+ * @see forge.deck.DeckBase#getInstance(java.lang.String)
*/
- private void setName(final String nameIn) {
- this.name = nameIn;
+ @Override
+ protected DeckBase newInstance(String name0) {
+ return new CustomLimited(name0);
}
+
+
+
}
diff --git a/src/main/java/forge/deck/Deck.java b/src/main/java/forge/deck/Deck.java
index 347d700eadb..62751ddf189 100644
--- a/src/main/java/forge/deck/Deck.java
+++ b/src/main/java/forge/deck/Deck.java
@@ -19,8 +19,9 @@ package forge.deck;
import java.io.Serializable;
-import forge.PlayerType;
-import forge.game.GameType;
+import forge.item.CardPrinted;
+import forge.item.IHasName;
+import forge.item.ItemPoolView;
/**
*
@@ -34,155 +35,29 @@ import forge.game.GameType;
* @author Forge
* @version $Id$
*/
-public final class Deck implements Comparable, Serializable {
+public class Deck extends DeckBase implements Serializable, IHasName {
/**
*
*/
private static final long serialVersionUID = -7478025567887481994L;
- // gameType is from Constant.GameType, like GameType.Regular
-
- private String name;
- private GameType deckType;
- private String comment = null;
- private PlayerType playerType = null;
-
- private boolean customPool = false;
-
private final DeckSection main;
private final DeckSection sideboard;
// gameType is from Constant.GameType, like GameType.Regular
/**
*
- * Constructor for Deck.
+ * Decks have their named finalled
*
*/
- public Deck() {
+ public Deck() { this(""); }
+
+ public Deck(String name0) {
+ super(name0);
this.main = new DeckSection();
this.sideboard = new DeckSection();
}
- /**
- *
- * Constructor for Deck.
- *
- *
- * @param type
- * a {@link java.lang.String} object.
- */
- public Deck(final GameType type) {
- this();
- this.setDeckType(type);
- }
-
- /**
- *
- * getDeckType.
- *
- *
- * @return a {@link java.lang.String} object.
- */
- public GameType getDeckType() {
- return this.deckType;
- }
-
- // can only call this method ONCE
- /**
- *
- * setDeckType.
- *
- *
- * @param deckType
- * a {@link java.lang.String} object.
- */
- public void setDeckType(final GameType deckType) {
- if (this.getDeckType() != null) {
- throw new IllegalStateException("Deck : setDeckType() error, deck type has already been set");
- }
-
- this.deckType = deckType;
- }
-
- /**
- *
- * setName.
- *
- *
- * @param s
- * a {@link java.lang.String} object.
- */
- public void setName(final String s) {
- this.name = s;
- }
-
- /**
- *
- * getName.
- *
- *
- * @return a {@link java.lang.String} object.
- */
- public String getName() {
- return this.name;
- }
-
- /**
- *
- * setComment.
- *
- *
- * @param comment
- * a {@link java.lang.String} object.
- */
- public void setComment(final String comment) {
- this.comment = comment;
- }
-
- /**
- *
- * getComment.
- *
- *
- * @return a {@link java.lang.String} object.
- */
- public String getComment() {
- return this.comment;
- }
-
- /**
- *
- * isDraft.
- *
- *
- * @return a boolean.
- */
- public boolean isDraft() {
- return this.getDeckType().equals(GameType.Draft);
- }
-
- /**
- *
- * isSealed.
- *
- *
- * @return a boolean.
- */
- public boolean isSealed() {
- return this.getDeckType().equals(GameType.Sealed);
- }
-
- /**
- *
- * isRegular.
- *
- *
- * @return a boolean.
- */
- public boolean isRegular() {
- return this.getDeckType().equals(GameType.Constructed);
- }
-
/**
*
* hashCode.
@@ -201,67 +76,6 @@ public final class Deck implements Comparable, Serializable {
return this.getName();
}
- /**
- *
- * compareTo.
- *
- *
- * @param d
- * a {@link forge.deck.Deck} object.
- * @return a int.
- */
- @Override
- public int compareTo(final Deck d) {
- return this.getName().compareTo(d.getName());
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean equals(final Object o) {
- if (o instanceof Deck) {
- final Deck d = (Deck) o;
- return this.getName().equals(d.getName());
- }
- return false;
- }
-
- /**
- * Gets the player type.
- *
- * @return the player type
- */
- public PlayerType getPlayerType() {
- return this.playerType;
- }
-
- /**
- * Sets the player type.
- *
- * @param recommendedPlayer0
- * the new player type
- */
- public void setPlayerType(final PlayerType recommendedPlayer0) {
- this.playerType = recommendedPlayer0;
- }
-
- /**
- * Checks if is custom pool.
- *
- * @return true, if is custom pool
- */
- public boolean isCustomPool() {
- return this.customPool;
- }
-
- /**
- * Sets the custom pool.
- *
- * @param cp
- * the new custom pool
- */
- public void setCustomPool(final boolean cp) {
- this.customPool = cp;
- }
/**
*
@@ -284,4 +98,27 @@ public final class Deck implements Comparable, Serializable {
public DeckSection getSideboard() {
return this.sideboard;
}
+
+ /* (non-Javadoc)
+ * @see forge.item.CardCollectionBase#getCardPool()
+ */
+ @Override
+ public ItemPoolView getCardPool() {
+ return main;
+ }
+
+ protected void cloneFieldsTo(DeckBase clone) {
+ super.cloneFieldsTo(clone);
+ Deck result = (Deck)clone;
+ result.main.addAll(this.main);
+ result.sideboard.addAll(this.sideboard);
+ }
+
+ /* (non-Javadoc)
+ * @see forge.deck.DeckBase#newInstance(java.lang.String)
+ */
+ @Override
+ protected DeckBase newInstance(String name0) {
+ return new Deck(name0);
+ }
}
diff --git a/src/main/java/forge/deck/DeckBase.java b/src/main/java/forge/deck/DeckBase.java
new file mode 100644
index 00000000000..da85a7d0c4a
--- /dev/null
+++ b/src/main/java/forge/deck/DeckBase.java
@@ -0,0 +1,71 @@
+package forge.deck;
+
+import java.io.Serializable;
+import forge.item.CardPrinted;
+import forge.item.IHasName;
+import forge.item.ItemPoolView;
+
+/**
+ * TODO: Write javadoc for this type.
+ *
+ */
+public abstract class DeckBase implements IHasName, Serializable, Comparable {
+ private static final long serialVersionUID = -7538150536939660052L;
+ // gameType is from Constant.GameType, like GameType.Regular
+
+ private final String name;
+ private String comment = null;
+
+ public DeckBase(String name0) {
+ name = name0;
+ }
+
+ @Override
+ public int compareTo(final DeckBase d) {
+ return this.getName().compareTo(d.getName());
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean equals(final Object o) {
+ if (o instanceof Deck) {
+ final Deck d = (Deck) o;
+ return this.getName().equals(d.getName());
+ }
+ return false;
+ }
+
+ @Override
+ public String getName() {
+ return this.name;
+ }
+
+ public abstract ItemPoolView getCardPool();
+
+ public void setComment(final String comment) {
+ this.comment = comment;
+ }
+
+ /**
+ *
+ * getComment.
+ *
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getComment() {
+ return this.comment;
+ }
+
+ protected abstract DeckBase newInstance(String name0);
+
+ protected void cloneFieldsTo(DeckBase clone) {
+ clone.comment = this.comment;
+ }
+
+ public DeckBase copyTo(String name0) {
+ DeckBase obj = newInstance(name0);
+ cloneFieldsTo(obj);
+ return obj;
+ }
+}
diff --git a/src/main/java/forge/deck/DeckIO.java b/src/main/java/forge/deck/DeckIO.java
deleted file mode 100644
index a709f4140e5..00000000000
--- a/src/main/java/forge/deck/DeckIO.java
+++ /dev/null
@@ -1,552 +0,0 @@
-/*
- * Forge: Play Magic: the Gathering.
- * Copyright (C) 2011 Nate
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package forge.deck;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.NoSuchElementException;
-import java.util.TreeMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.swing.JOptionPane;
-import javax.swing.filechooser.FileFilter;
-
-import org.apache.commons.lang3.StringUtils;
-
-import forge.Card;
-import forge.PlayerType;
-import forge.game.GameType;
-import forge.gui.deckeditor.TableSorter;
-import forge.item.CardPrinted;
-import forge.item.ItemPoolView;
-import forge.properties.ForgeProps;
-import forge.properties.NewConstants;
-import forge.util.FileUtil;
-import forge.util.SectionUtil;
-import freemarker.template.Configuration;
-import freemarker.template.DefaultObjectWrapper;
-import freemarker.template.Template;
-import freemarker.template.TemplateException;
-
-/**
- * TODO: Write javadoc for this type.
- *
- */
-public class DeckIO {
-
- private static final String NAME = "Name";
- private static final String DECK_TYPE = "Deck Type";
- private static final String COMMENT = "Comment";
- private static final String PLAYER = "Player";
- private static final String CSTM_POOL = "Custom Pool";
- /** Constant BDKFileFilter. */
- private static FilenameFilter bdkFileFilter = new FilenameFilter() {
- @Override
- public boolean accept(final File dir, final String name) {
- return name.endsWith(".bdk");
- }
- };
- /** Constant DCKFileFilter. */
- public static final FilenameFilter DCK_FILE_FILTER = new FilenameFilter() {
- @Override
- public boolean accept(final File dir, final String name) {
- return name.endsWith(".dck");
- }
- };
- /** The Constant DCK_FILTER. */
- public static final FileFilter DCK_FILTER = new FileFilter() {
- @Override
- public boolean accept(final File f) {
- return f.getName().endsWith(".dck") || f.isDirectory();
- }
-
- @Override
- public String getDescription() {
- return "Simple Deck File .dck";
- }
- };
- /** The Constant HTML_FILTER. */
- public static final FileFilter HTML_FILTER = new FileFilter() {
- @Override
- public boolean accept(final File f) {
- return f.getName().endsWith(".html") || f.isDirectory();
- }
-
- @Override
- public String getDescription() {
- return "Simple Deck File .html";
- }
- };
-
- /**
- *
- * readDeck.
- *
- *
- * @param deckFile
- * a {@link java.io.File} object.
- * @return a {@link forge.deck.Deck} object.
- */
-
- public static Deck readDeck(final File deckFile) {
- return DeckIO.readDeck(FileUtil.readFile(deckFile));
- }
-
- /**
- * Read deck.
- *
- * @param deckFileLines the deck file lines
- * @return the deck
- */
- public static Deck readDeck(final List deckFileLines) {
- final Map> sections = SectionUtil.parseSections(deckFileLines);
- if (sections.isEmpty()) {
- return null;
- }
-
- final Deck d = new Deck();
-
- final String firstLine = deckFileLines.get(0);
- if (!firstLine.startsWith("[") || firstLine.equalsIgnoreCase("[general]")) {
- DeckIO.readDeckOldMetadata(deckFileLines.iterator(), d);
- } else {
- DeckIO.readDeckMetadata(sections.get("metadata"), d);
- }
- d.getMain().set(DeckIO.readCardList(sections.get("main")));
- d.getSideboard().set(DeckIO.readCardList(sections.get("sideboard")));
-
- return d;
- }
-
- private static void readDeckMetadata(final Iterable lines, final Deck d) {
- if (lines == null) {
- return;
- }
- final Iterator lineIterator = lines.iterator();
- while (lineIterator.hasNext()) {
- final String line = lineIterator.next();
-
- final String[] linedata = line.split("=", 2);
- final String field = linedata[0].toLowerCase();
- String value = "";
-
- if (linedata.length > 1) {
- value = linedata[1];
- }
-
- if (DeckIO.NAME.equalsIgnoreCase(field)) {
- d.setName(value);
-
- } else if (DeckIO.COMMENT.equalsIgnoreCase(field)) {
- d.setComment(value);
-
- } else if (DeckIO.DECK_TYPE.equalsIgnoreCase(field)) {
- d.setDeckType(GameType.smartValueOf(value));
-
- } else if (DeckIO.CSTM_POOL.equalsIgnoreCase(field)) {
- d.setCustomPool(value.equalsIgnoreCase("true"));
-
- } else if (DeckIO.PLAYER.equalsIgnoreCase(field)) {
- if ("human".equalsIgnoreCase(value)) {
- d.setPlayerType(PlayerType.HUMAN);
-
- } else {
- d.setPlayerType(PlayerType.COMPUTER);
- }
- }
- }
- }
-
- /**
- *
- * readDeckOld.
- *
- *
- * @param iterator
- * a {@link java.util.ListIterator} object.
- * @return a {@link forge.deck.Deck} object.
- */
- private static void readDeckOldMetadata(final Iterator iterator, final Deck d) {
-
- String line;
- // readDeck name
- final String name = iterator.next();
-
- // readDeck comments
- String comment = null;
- while (iterator.hasNext()) {
- line = iterator.next();
- if ((line != null) && !line.equals("[general")) {
- if (comment == null) {
- comment = line;
- } else {
- comment += "\n" + line;
- }
- }
- }
-
- // readDeck deck type
-
- final GameType deckType = iterator.hasNext() ? GameType.smartValueOf(iterator.next()) : GameType.Constructed;
-
- d.setName(name);
- d.setComment(comment);
- d.setDeckType(deckType);
- }
-
- // Precondition: iterator should point at the first line of cards list
- private static List readCardList(final Iterable lines) {
- final List result = new ArrayList();
- final Pattern p = Pattern.compile("((\\d+)\\s+)?(.*?)");
-
- if (lines == null) {
- return result;
- }
-
- final Iterator lineIterator = lines.iterator();
- while (lineIterator.hasNext()) {
- final String line = lineIterator.next();
- if (line.startsWith("[")) {
- break;
- } // there comes another section
-
- final Matcher m = p.matcher(line.trim());
- m.matches();
- final String sCnt = m.group(2);
- final String cardName = m.group(3);
- if (StringUtils.isBlank(cardName)) {
- continue;
- }
-
- final int count = sCnt == null ? 1 : Integer.parseInt(sCnt);
- for (int i = 0; i < count; i++) {
- result.add(cardName);
- }
- }
- return result;
- }
-
- private static String deriveFileName(final String deckName) {
- // skips all but the listed characters
- return deckName.replaceAll("[^-_$#@.{[()]} a-zA-Z0-9]", "");
- }
-
- // only accepts numbers, letters or dashes up to 20 characters in length
- /**
- *
- * Clean deck name.
- *
- * @param in
- * a String
- * @return a String
- */
- public static String cleanDeckName(final String in) {
- final char[] c = in.toCharArray();
- final StringBuilder sb = new StringBuilder();
- for (int i = 0; (i < c.length) && (i < 20); i++) {
- if (Character.isLetterOrDigit(c[i]) || (c[i] == '-')) {
- sb.append(c[i]);
- }
- }
- return sb.toString();
- }
-
- /**
- *
- * Make file name.
- *
- * @param deckName
- * a String
- * @param deckType
- * a GameType
- * @return a File
- */
- public static File makeFileName(final String deckName, final GameType deckType) {
- final File path = ForgeProps.getFile(NewConstants.NEW_DECKS);
- if (deckType == GameType.Draft) {
- return new File(path, DeckIO.deriveFileName(deckName) + ".bdk");
- } else {
- return new File(path, DeckIO.deriveFileName(deckName) + ".dck");
- }
- }
-
- /**
- *
- * Make file name.
- *
- * @param deck
- * a Deck
- * @return a File
- */
- public static File makeFileName(final Deck deck) {
- return DeckIO.makeFileName(deck.getName(), deck.getDeckType());
- }
-
- /**
- *
- * Write draft Decks.
- *
- * @param drafts
- * a Deck[]
- */
- public static void writeDraftDecks(final Deck[] drafts) {
- final File f = DeckIO.makeFileName(drafts[0]);
- f.mkdir();
- for (int i = 0; i < drafts.length; i++) {
- FileUtil.writeFile(new File(f, i + ".dck"), DeckIO.serializeDeck(drafts[i]));
- }
- }
-
- /**
- *
- * writeDeck.
- *
- *
- * @param d
- * a {@link forge.deck.Deck} object.
- * @param out
- * a {@link java.io.BufferedWriter} object.
- * @throws java.io.IOException
- * if any.
- */
- private static List serializeDeck(final Deck d) {
- final List out = new ArrayList();
- out.add(String.format("[metadata]"));
-
- out.add(String.format("%s=%s", DeckIO.NAME, d.getName().replaceAll("\n", "")));
- out.add(String.format("%s=%s", DeckIO.DECK_TYPE, d.getDeckType()));
- // these are optional
- if (d.getComment() != null) {
- out.add(String.format("%s=%s", DeckIO.COMMENT, d.getComment().replaceAll("\n", "")));
- }
- if (d.getPlayerType() != null) {
- out.add(String.format("%s=%s", DeckIO.PLAYER, d.getPlayerType()));
- }
-
- if (d.isCustomPool()) {
- out.add(String.format("%s=%s", DeckIO.CSTM_POOL, "true"));
- }
-
- out.add(String.format("%s", "[main]"));
- out.addAll(DeckIO.writeCardPool(d.getMain()));
-
- out.add(String.format("%s", "[sideboard]"));
- out.addAll(DeckIO.writeCardPool(d.getSideboard()));
- return out;
- }
-
- /**
- *
- * writeDeck.
- *
- *
- * @param d
- * a {@link forge.deck.Deck} object.
- * @param out
- * a {@link java.io.BufferedWriter} object.
- * @throws java.io.IOException
- * if any.
- */
- private static void writeDeckHtml(final Deck d, final BufferedWriter out) throws IOException {
- Template temp = null;
- final int cardBorder = 0;
- final int height = 319;
- final int width = 222;
-
- /* Create and adjust the configuration */
- final Configuration cfg = new Configuration();
- try {
- cfg.setClassForTemplateLoading(d.getClass(), "/");
- cfg.setObjectWrapper(new DefaultObjectWrapper());
-
- /*
- * ------------------------------------------------------------------
- * -
- */
- /*
- * You usually do these for many times in the application
- * life-cycle:
- */
-
- /* Get or create a template */
- temp = cfg.getTemplate("proxy-template.ftl");
-
- /* Create a data-model */
- final Map root = new HashMap();
- root.put("title", d.getName());
- final List list = new ArrayList();
- for (final Card card : d.getMain().toForgeCardList().toArray()) {
- // System.out.println(card.getSets().get(card.getSets().size() -
- // 1).URL);
- list.add(card.getSets().get(card.getSets().size() - 1).getUrl());
- }
- /*
- * List nameList = new ArrayList(); for (Card card :
- * d.getMain().toForgeCardList().toArray()) {
- * //System.out.println(card.getSets().get(card.getSets().size() -
- * 1).URL); nameList.add(card.getName()); }
- */
-
- final TreeMap map = new TreeMap();
- for (final Entry entry : d.getMain().getOrderedList()) {
- map.put(entry.getKey().getName(), entry.getValue());
- // System.out.println(entry.getValue() + " " +
- // entry.getKey().getName());
- }
-
- root.put("urls", list);
- root.put("cardBorder", cardBorder);
- root.put("height", height);
- root.put("width", width);
- root.put("cardlistWidth", width - 11);
- // root.put("nameList", nameList);
- root.put("cardList", map);
-
- /* Merge data-model with template */
- // StringWriter sw = new StringWriter();
- temp.process(root, out);
- out.flush();
- } catch (final IOException e) {
- System.out.println(e.toString());
- } catch (final TemplateException e) {
- System.out.println(e.toString());
- }
- }
-
- private static List writeCardPool(final ItemPoolView pool) {
- final List> main2sort = pool.getOrderedList();
- Collections.sort(main2sort, TableSorter.BY_NAME_THEN_SET);
- final List out = new ArrayList();
- for (final Entry e : main2sort) {
- final CardPrinted card = e.getKey();
- final boolean hasBadSetInfo = "???".equals(card.getSet()) || StringUtils.isBlank(card.getSet());
- if (hasBadSetInfo) {
- out.add(String.format("%d %s", e.getValue(), card.getName()));
- } else {
- out.add(String.format("%d %s|%s", e.getValue(), card.getName(), card.getSet()));
- }
- }
- return out;
- }
-
- /**
- *
- * writeDeck.
- *
- *
- * @param d
- * a {@link forge.deck.Deck} object.
- * @param f
- * a {@link java.io.File} object.
- */
- public static void writeDeck(final Deck d, final File f) {
- FileUtil.writeFile(f, DeckIO.serializeDeck(d));
- }
-
- /**
- *
- * Write deck to HTML.
- *
- *
- * @param d
- * a {@link forge.deck.Deck} object.
- * @param f
- * a {@link java.io.File} object.
- */
- public static void writeDeckHtml(final Deck d, final File f) {
- try {
- final BufferedWriter writer = new BufferedWriter(new FileWriter(f));
- DeckIO.writeDeckHtml(d, writer);
- writer.close();
- } catch (final IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- *
- * readAllDecks.
- *
- *
- * @param deckDir the deck dir
- * @return the map
- */
- public static final Map readAllDecks(final File deckDir) {
- final Map result = new HashMap();
- final List decksThatFailedToLoad = new ArrayList();
- final File[] files = deckDir.listFiles(DeckIO.DCK_FILE_FILTER);
- for (final File file : files) {
- try {
- final Deck newDeck = DeckIO.readDeck(file);
- result.put(newDeck.getName(), newDeck);
- } catch (final NoSuchElementException ex) {
- final String message = String.format("%s failed to load because ---- %s", file.getName(),
- ex.getMessage());
- decksThatFailedToLoad.add(message);
- }
- }
-
- if (!decksThatFailedToLoad.isEmpty()) {
- JOptionPane.showMessageDialog(null,
- StringUtils.join(decksThatFailedToLoad, System.getProperty("line.separator")),
- "Some of your decks were not loaded.", JOptionPane.WARNING_MESSAGE);
- }
-
- return result;
- }
-
- /**
- * Read all draft decks.
- *
- * @param deckDir the deck dir
- * @return the map
- */
- public static final Map readAllDraftDecks(final File deckDir) {
- final Map result = new HashMap();
- final File[] files = deckDir.listFiles(DeckIO.bdkFileFilter);
- for (final File file : files) {
- final Deck[] d = new Deck[8];
-
- boolean gotError = false;
- for (int i = 0; i < d.length; i++) {
- d[i] = DeckIO.readDeck(new File(file, i + ".dck"));
- if (d[i] == null) {
- gotError = true;
- break;
- }
- }
-
- if (!gotError) {
- result.put(d[0].getName(), d);
- }
- }
- return result;
- }
-
-}
diff --git a/src/main/java/forge/deck/DeckManager.java b/src/main/java/forge/deck/DeckManager.java
deleted file mode 100644
index 814772d8c6b..00000000000
--- a/src/main/java/forge/deck/DeckManager.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * Forge: Play Magic: the Gathering.
- * Copyright (C) 2011 Forge Team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package forge.deck;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-
-
-import forge.error.ErrorViewer;
-import forge.game.GameType;
-
-//reads and writeDeck Deck objects
-/**
- *
- * DeckManager class.
- *
- *
- * @author Forge
- * @version $Id$
- */
-public class DeckManager {
- private Map deckMap;
- private Map draftMap;
-
- /**
- *
- * Constructor for DeckManager.
- *
- *
- * @param deckDir
- * a {@link java.io.File} object.
- */
- public DeckManager(final File deckDir) {
- if (deckDir == null) {
- throw new IllegalArgumentException("No deck directory specified");
- }
- try {
- if (deckDir.isFile()) {
- throw new IOException("Not a directory");
- } else {
- deckDir.mkdirs();
- if (!deckDir.isDirectory()) {
- throw new IOException("Directory can't be created");
- }
- this.deckMap = DeckIO.readAllDecks(deckDir);
- this.draftMap = DeckIO.readAllDraftDecks(deckDir);
- }
- } catch (final IOException ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage());
- }
- }
-
- /**
- *
- * isUnique.
- *
- *
- * @param deckName
- * a {@link java.lang.String} object.
- * @return a boolean.
- */
- public final boolean isUnique(final String deckName) {
- return !this.deckMap.containsKey(deckName);
- }
-
- /**
- *
- * isUniqueDraft.
- *
- *
- * @param deckName
- * a {@link java.lang.String} object.
- * @return a boolean.
- */
- public final boolean isUniqueDraft(final String deckName) {
- return !this.draftMap.keySet().contains(deckName);
- }
-
- /**
- *
- * getDeck.
- *
- *
- * @param deckName
- * a {@link java.lang.String} object.
- * @return a {@link forge.deck.Deck} object.
- */
- public final Deck getDeck(final String deckName) {
- return this.deckMap.get(deckName);
- }
-
- /**
- *
- * addDeck.
- *
- *
- * @param deck
- * a {@link forge.deck.Deck} object.
- */
- public final void addDeck(final Deck deck) {
- if (deck.getDeckType().equals(GameType.Draft)) {
- throw new RuntimeException("DeckManager : addDeck() error, deck type is Draft");
- }
-
- this.deckMap.put(deck.getName(), deck);
- }
-
- /**
- *
- * deleteDeck.
- *
- *
- * @param deckName
- * a {@link java.lang.String} object.
- */
- public final void deleteDeck(final String deckName) {
- this.deckMap.remove(deckName);
- }
-
- /**
- *
- * getDraftDeck.
- *
- *
- * @param deckName
- * a {@link java.lang.String} object.
- * @return an array of {@link forge.deck.Deck} objects.
- */
- public final Deck[] getDraftDeck(final String deckName) {
- if (!this.draftMap.containsKey(deckName)) {
- throw new RuntimeException("DeckManager : getDraftDeck() error, deck name not found - " + deckName);
- }
-
- return this.draftMap.get(deckName);
- }
-
- /**
- *
- * addDraftDeck.
- *
- *
- * @param deck
- * an array of {@link forge.deck.Deck} objects.
- */
- public final void addDraftDeck(final Deck[] deck) {
- this.checkDraftDeck(deck);
-
- this.draftMap.put(deck[0].toString(), deck);
- }
-
- /**
- *
- * deleteDraftDeck.
- *
- *
- * @param deckName
- * a {@link java.lang.String} object.
- */
- public final void deleteDraftDeck(final String deckName) {
- if (!this.draftMap.containsKey(deckName)) {
- throw new RuntimeException("DeckManager : deleteDraftDeck() error, deck name not found - " + deckName);
- }
-
- this.draftMap.remove(deckName);
- }
-
- /**
- *
- * checkDraftDeck.
- *
- *
- * @param deck
- * an array of {@link forge.deck.Deck} objects.
- */
- private void checkDraftDeck(final Deck[] deck) {
- if ((deck == null) || (deck.length != 8) || deck[0].getName().equals("")
- || (!deck[0].getDeckType().equals(GameType.Draft))) {
- throw new RuntimeException("DeckManager : checkDraftDeck() error, invalid deck");
- }
- }
-
- /**
- *
- * Get Decks.
- *
- * @return a Collection
- */
- public final Collection getDecks() {
- return this.deckMap.values();
- }
-
- /**
- *
- * Get Constructed Decks.
- *
- * @return a Collection
- */
- public final Collection getConstructedDecks() {
- final ArrayList list = new ArrayList();
- for (final Deck l : this.deckMap.values()) {
- if (l.getDeckType().equals(GameType.Constructed) && !l.isCustomPool()) {
- list.add(l);
- }
- }
- Collections.sort(list);
- return list;
- }
-
- /**
- *
- * Get draft decks.
- *
- * @return a Map
- */
- public final Map getDraftDecks() {
- return new HashMap(this.draftMap);
- }
-
- /**
- *
- * Get names of decks.
- *
- * @param deckType
- * a GameType
- * @return a ArrayList
- */
- public final ArrayList getDeckNames(final GameType deckType) {
- final ArrayList list = new ArrayList();
-
- // only get decks according to the OldGuiNewGame screen option
- if (deckType.equals(GameType.Draft)) {
- for (final String s : this.getDraftDecks().keySet()) {
- list.add(s);
- }
- } else {
- for (final Deck deck : this.getDecks()) {
- if (deckType.equals(deck.getDeckType())) {
- list.add(deck.toString());
- }
- }
- }
-
- Collections.sort(list);
- return list;
- }
-}
diff --git a/src/main/java/forge/deck/DeckSection.java b/src/main/java/forge/deck/DeckSection.java
index 93abb7da5d8..b94e64d81e0 100644
--- a/src/main/java/forge/deck/DeckSection.java
+++ b/src/main/java/forge/deck/DeckSection.java
@@ -17,6 +17,8 @@
*/
package forge.deck;
+import java.util.Map.Entry;
+
import forge.Card;
import forge.CardList;
import forge.item.CardDb;
@@ -24,7 +26,7 @@ import forge.item.CardPrinted;
import forge.item.ItemPool;
/**
- * TODO: Write javadoc for this type.
+ * Deck section
*
*/
public class DeckSection extends ItemPool {
@@ -35,13 +37,10 @@ public class DeckSection extends ItemPool {
public DeckSection() {
super(CardPrinted.class);
}
-
- /**
- * Clear main.
- */
- public void clearMain() {
- this.clear();
-
+
+ public DeckSection(Iterable> cards) {
+ this();
+ addAll(cards);
}
/**
@@ -51,7 +50,7 @@ public class DeckSection extends ItemPool {
*/
public void set(final Iterable cardNames) {
this.clear();
- this.addAllCards(CardDb.instance().getCards(cardNames));
+ this.addAllFlat(CardDb.instance().getCards(cardNames));
}
/**
@@ -73,6 +72,16 @@ public class DeckSection extends ItemPool {
this.add(CardDb.instance().getCard(cardName, setCode));
}
+ /**
+ * Adds the.
+ *
+ * @param cardName the card name
+ * @param setCode the set code
+ */
+ public void add(final String cardName, final String setCode, int amount) {
+ this.add(CardDb.instance().getCard(cardName, setCode), amount);
+ }
+
/**
* Adds the.
*
@@ -84,4 +93,12 @@ public class DeckSection extends ItemPool {
}
}
+ /**
+ * TODO: Write javadoc for this method.
+ * @param string
+ */
+ public void add(String cardName) {
+ this.add(CardDb.instance().getCard(cardName));
+ }
+
}
diff --git a/src/main/java/forge/deck/DeckSet.java b/src/main/java/forge/deck/DeckSet.java
new file mode 100644
index 00000000000..3bad774bb86
--- /dev/null
+++ b/src/main/java/forge/deck/DeckSet.java
@@ -0,0 +1,52 @@
+package forge.deck;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import forge.item.CardPrinted;
+import forge.item.IHasName;
+import forge.item.ItemPoolView;
+
+
+/**
+ * TODO: Write javadoc for this type.
+ *
+ */
+public class DeckSet extends DeckBase implements IHasName {
+
+ public DeckSet(String name0) {
+ super(name0);
+ }
+
+ private static final long serialVersionUID = -1628725522049635829L;
+ private Deck humanDeck;
+ private List aiDecks = new ArrayList();
+
+ public final Deck getHumanDeck() {
+ return humanDeck;
+ }
+ public final List getAiDecks() {
+ return aiDecks;
+ }
+ public final void setHumanDeck(Deck humanDeck) { this.humanDeck = humanDeck; }
+
+ public final void addAiDeck(Deck aiDeck) { if ( aiDeck != null ) this.aiDecks.add(aiDeck); }
+
+ @Override
+ public ItemPoolView getCardPool() {
+ return getHumanDeck().getMain();
+ }
+
+ public void addAiDecks(Deck[] computer) {
+ for(int i = 0; i < computer.length; i++)
+ aiDecks.add(computer[i]);
+ }
+ /* (non-Javadoc)
+ * @see forge.deck.DeckBase#newInstance(java.lang.String)
+ */
+ @Override
+ protected DeckBase newInstance(String name0) {
+ return new DeckSet(name0);
+ }
+
+}
diff --git a/src/main/java/forge/deck/FolderMap.java b/src/main/java/forge/deck/FolderMap.java
new file mode 100644
index 00000000000..c935a120abc
--- /dev/null
+++ b/src/main/java/forge/deck/FolderMap.java
@@ -0,0 +1,70 @@
+/*
+ * Forge: Play Magic: the Gathering.
+ * Copyright (C) 2011 Forge Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package forge.deck;
+
+import forge.deck.io.IDeckSerializer;
+import forge.item.IHasName;
+
+//reads and writeDeck Deck objects
+/**
+ *
+ * DeckManager class.
+ *
+ *
+ * @author Forge
+ * @version $Id$
+ */
+public class FolderMap extends FolderMapView implements IFolderMap {
+
+ private IDeckSerializer serializer;
+ /**
+ *
+ * Constructor for DeckManager.
+ *
+ *
+ * @param deckDir
+ * a {@link java.io.File} object.
+ */
+ public FolderMap(IDeckSerializer io ) {
+ super(io);
+ serializer = io;
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see forge.deck.IFolderMap#add(T)
+ */
+ @Override
+ public final void add(final T deck) {
+ this.getMap().put(deck.getName(), deck);
+ serializer.save(deck);
+ }
+
+ /* (non-Javadoc)
+ * @see forge.deck.IFolderMap#delete(java.lang.String)
+ */
+ @Override
+ public final void delete(final String deckName) {
+ serializer.erase(this.getMap().remove(deckName));
+ }
+
+
+
+
+}
diff --git a/src/main/java/forge/deck/FolderMapView.java b/src/main/java/forge/deck/FolderMapView.java
new file mode 100644
index 00000000000..de0d634adcd
--- /dev/null
+++ b/src/main/java/forge/deck/FolderMapView.java
@@ -0,0 +1,90 @@
+/*
+ * Forge: Play Magic: the Gathering.
+ * Copyright (C) 2011 Forge Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package forge.deck;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import forge.deck.io.IDeckReader;
+import forge.item.IHasName;
+
+//reads and writeDeck Deck objects
+/**
+ *
+ * DeckManager class.
+ *
+ *
+ * @author Forge
+ * @version $Id: DeckManager.java 13590 2012-01-27 20:46:27Z Max mtg $
+ */
+public class FolderMapView implements Iterable, IFolderMapView {
+ private final Map map;
+
+ /**
+ *
+ * Constructor for DeckManager.
+ *
+ *
+ * @param deckDir
+ * a {@link java.io.File} object.
+ */
+ public FolderMapView(IDeckReader io ) {
+ this.map = io.readAll();
+ }
+
+ /* (non-Javadoc)
+ * @see forge.deck.IFolderMapView#isUnique(java.lang.String)
+ */
+ @Override
+ public final boolean isUnique(final String name) {
+ return !this.map.containsKey(name);
+ }
+
+ /* (non-Javadoc)
+ * @see forge.deck.IFolderMapView#get(java.lang.String)
+ */
+ @Override
+ public final T get(final String name) {
+ return this.map.get(name);
+ }
+
+ /* (non-Javadoc)
+ * @see forge.deck.IFolderMapView#getNames()
+ */
+ @Override
+ public final Collection getNames() {
+ return new ArrayList(map.keySet());
+ }
+
+ protected final Map getMap() {
+ return map;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Iterable#iterator()
+ */
+ /* (non-Javadoc)
+ * @see forge.deck.IFolderMapView#iterator()
+ */
+ @Override
+ public Iterator iterator() {
+ return this.map.values().iterator();
+ }
+}
diff --git a/src/main/java/forge/deck/IFolderMap.java b/src/main/java/forge/deck/IFolderMap.java
new file mode 100644
index 00000000000..f5df2f90a38
--- /dev/null
+++ b/src/main/java/forge/deck/IFolderMap.java
@@ -0,0 +1,32 @@
+package forge.deck;
+
+import forge.item.IHasName;
+
+/**
+ * TODO: Write javadoc for this type.
+ *
+ * @param
+ */
+public interface IFolderMap extends IFolderMapView {
+
+ /**
+ *
+ * addDeck.
+ *
+ *
+ * @param deck
+ * a {@link forge.deck.Deck} object.
+ */
+ public abstract void add(final T deck);
+
+ /**
+ *
+ * deleteDeck.
+ *
+ *
+ * @param deckName
+ * a {@link java.lang.String} object.
+ */
+ public abstract void delete(final String deckName);
+
+}
\ No newline at end of file
diff --git a/src/main/java/forge/deck/IFolderMapView.java b/src/main/java/forge/deck/IFolderMapView.java
new file mode 100644
index 00000000000..f5efded8b13
--- /dev/null
+++ b/src/main/java/forge/deck/IFolderMapView.java
@@ -0,0 +1,48 @@
+package forge.deck;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import forge.item.IHasName;
+
+/**
+ * TODO: Write javadoc for this type.
+ *
+ * @param
+ */
+public interface IFolderMapView extends Iterable {
+
+ /**
+ *
+ * isUnique.
+ *
+ *
+ * @param deckName
+ * a {@link java.lang.String} object.
+ * @return a boolean.
+ */
+ public abstract boolean isUnique(final String name);
+
+ /**
+ *
+ * getDeck.
+ *
+ *
+ * @param deckName
+ * a {@link java.lang.String} object.
+ * @return a {@link forge.deck.Deck} object.
+ */
+ public abstract T get(final String name);
+
+ /**
+ *
+ * Get names of decks.
+ *
+ * @param deckType
+ * a GameType
+ * @return a ArrayList
+ */
+ public abstract Collection getNames();
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/forge/deck/OldDeckParser.java b/src/main/java/forge/deck/OldDeckParser.java
new file mode 100644
index 00000000000..d360f39eb1f
--- /dev/null
+++ b/src/main/java/forge/deck/OldDeckParser.java
@@ -0,0 +1,206 @@
+package forge.deck;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.TreeMap;
+
+import javax.swing.JOptionPane;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.MutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+
+import forge.PlayerType;
+import forge.deck.io.DeckFileHeader;
+import forge.deck.io.DeckIOCore;
+import forge.deck.io.DeckSetSerializer;
+import forge.util.FileUtil;
+import forge.util.SectionUtil;
+
+/**
+ * TODO: Write javadoc for this type.
+ *
+ */
+public class OldDeckParser {
+
+ /** Constant BDKFileFilter. */
+ public final static FilenameFilter bdkFileFilter = new FilenameFilter() {
+ @Override
+ public boolean accept(final File dir, final String name) {
+ return name.endsWith(".bdk");
+ }
+ };
+
+ /**
+ * TODO: Write javadoc for Constructor.
+ * @param file
+ * @param constructed2
+ * @param draft2
+ * @param sealed2
+ * @param cube2
+ */
+ public OldDeckParser(File file, IFolderMap constructed2, IFolderMap draft2,
+ IFolderMap sealed2, IFolderMap cube2) {
+ deckDir = file;
+ sealed = sealed2;
+ constructed = constructed2;
+ cube = cube2;
+ draft = draft2;
+ }
+
+ protected final IFolderMap getSealed() {
+ return sealed;
+ }
+ protected final IFolderMap getConstructed() {
+ return constructed;
+ }
+ protected final IFolderMap getDraft() {
+ return draft;
+ }
+ protected final IFolderMap getCube() {
+ return cube;
+ }
+ protected final File getDeckDir() {
+ return deckDir;
+ }
+
+ private final IFolderMap sealed;
+ private final IFolderMap constructed;
+ private final IFolderMap draft;
+ private final IFolderMap cube;
+ private final File deckDir;
+ /**
+ * TODO: Write javadoc for this method.
+ */
+ public void tryParse() {
+ convertConstructedAndSealed();
+ convertDrafts();
+ }
+
+ private void convertDrafts()
+ {
+ for( File f : deckDir.listFiles(bdkFileFilter))
+ {
+ boolean gotError = false;
+ Deck human = DeckIOCore.readDeck(new File(f, "0.dck"));
+ final DeckSet d = new DeckSet(human.getName());
+ d.setHumanDeck(human);
+
+
+ for (int i = 1; i < DeckSetSerializer.MAX_DRAFT_PLAYERS; i++) {
+ Deck nextAi = DeckIOCore.readDeck(new File(f, i + ".dck"));
+ if (nextAi == null) {
+ gotError = true;
+ break;
+ }
+ d.addAiDeck(nextAi);
+ }
+
+ boolean mayDelete = !gotError;
+ if (!gotError) {
+ draft.add(d);
+ } else {
+ String msg = String.format("Draft '%s' lacked some decks.%n%nShould it be deleted?");
+ mayDelete = JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, msg, "Draft loading error", JOptionPane.YES_NO_OPTION);
+ }
+
+ if( mayDelete ) {
+ for( File f1 : f.listFiles() )
+ f1.delete();
+ f.delete();
+ }
+
+ }
+ }
+
+ private void convertConstructedAndSealed()
+ {
+ boolean allowDeleteUnsupportedConstructed = false;
+ Map>> sealedDecks = new TreeMap>>(String.CASE_INSENSITIVE_ORDER);
+
+ for( File f : deckDir.listFiles(DeckIOCore.DCK_FILE_FILTER))
+ {
+ boolean importedOk = false;
+
+ List fileLines = FileUtil.readFile(f);
+ Map> sections = SectionUtil.parseSections(fileLines);
+ DeckFileHeader dh = DeckIOCore.readDeckMetadata(sections);
+ String name = dh.getName();
+ if ( dh.isCustomPool() ) { continue; }
+
+ switch(dh.getDeckType()) {
+ case Constructed:
+ try {
+ constructed.add(DeckIOCore.readDeck(fileLines));
+ importedOk = true;
+ } catch( NoSuchElementException ex) {
+ if( !allowDeleteUnsupportedConstructed ) {
+ String msg = String.format("Can not convert deck '%s' for some unsupported cards it contains. %n%s%n%nMay Forge delete all such decks?", name, ex.getMessage());
+ allowDeleteUnsupportedConstructed = JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, msg, "Problem converting decks", JOptionPane.YES_NO_OPTION);
+ }
+ }
+ if( importedOk || allowDeleteUnsupportedConstructed )
+ f.delete();
+ break;
+
+ case Sealed:
+ boolean isAi = dh.getPlayerType() == PlayerType.COMPUTER;
+ name = name.startsWith("AI_") ? name.replace("AI_", "") : name;
+
+ Pair> stored = sealedDecks.get(name);
+ if( null == stored )
+ stored = ImmutablePair.of(new DeckSet(name), MutablePair.of((File)null, (File)null));
+
+ Deck deck = DeckIOCore.readDeck(fileLines);
+ if( isAi ) {
+ stored.getLeft().addAiDeck(deck);
+ stored.getRight().setRight(f);
+ } else {
+ stored.getLeft().setHumanDeck(deck);
+ stored.getRight().setLeft(f);
+ }
+
+ if( stored.getLeft().getHumanDeck() != null && !stored.getLeft().getAiDecks().isEmpty() ) {
+ // have both parts of sealed deck, may convert
+ sealed.add(stored.getLeft());
+ stored.getRight().getLeft().delete();
+ stored.getRight().getRight().delete();
+
+ // there stay only orphans
+ sealedDecks.remove(name);
+ } else
+ sealedDecks.put(name, stored);
+ break;
+ }
+ }
+
+ // advise to kill orphaned decks
+ if( !sealedDecks.isEmpty() )
+ {
+ StringBuilder sb = new StringBuilder();
+ for(Pair> s : sealedDecks.values()) {
+ String missingPart = s.getRight().getLeft() == null ? "human" : "computer";
+ sb.append(String.format("Sealed deck '%s' has no matching '%s' deck.%n", s.getKey().getName(), missingPart));
+ }
+ sb.append(System.getProperty("line.separator"));
+ sb.append("May Forge delete these decks?");
+ int response = JOptionPane.showConfirmDialog(null, sb.toString(), "Some of your sealed decks are orphaned", JOptionPane.YES_NO_OPTION);
+ if( response == JOptionPane.YES_OPTION )
+ {
+ for(Pair> s : sealedDecks.values()) {
+ if( s.getRight().getLeft() != null ) { s.getRight().getLeft().delete(); }
+ if( s.getRight().getRight() != null ) { s.getRight().getRight().delete(); }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * @return the deckDir
+ */
+
+}
diff --git a/src/main/java/forge/deck/DeckGeneration.java b/src/main/java/forge/deck/generate/DeckGenerator.java
similarity index 84%
rename from src/main/java/forge/deck/DeckGeneration.java
rename to src/main/java/forge/deck/generate/DeckGenerator.java
index 05a86cd55a4..b0d27288d47 100644
--- a/src/main/java/forge/deck/DeckGeneration.java
+++ b/src/main/java/forge/deck/generate/DeckGenerator.java
@@ -15,20 +15,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package forge.deck;
+package forge.deck.generate;
import java.util.ArrayList;
import java.util.Random;
import forge.Constant;
import forge.PlayerType;
-import forge.deck.generate.Generate2ColorDeck;
-import forge.deck.generate.Generate3ColorDeck;
-import forge.deck.generate.Generate5ColorDeck;
-import forge.deck.generate.GenerateConstructedDeck;
-import forge.deck.generate.GenerateConstructedMultiColorDeck;
-import forge.deck.generate.GenerateThemeDeck;
-import forge.game.GameType;
+import forge.deck.Deck;
import forge.gui.GuiUtils;
import forge.util.MyRandom;
@@ -37,7 +31,7 @@ import forge.util.MyRandom;
* OldGuiNewGame.
*
*/
-public abstract class DeckGeneration {
+public abstract class DeckGenerator {
/**
*
@@ -66,19 +60,19 @@ public abstract class DeckGeneration {
final Object o = GuiUtils.getChoice(prompt, decks.toArray());
if (o.toString().equals(decks.get(0))) {
- d = DeckGeneration.generate2ColorDeck(playerType);
+ d = DeckGenerator.generate2ColorDeck(playerType);
} else if (o.toString().equals(decks.get(1))) {
- d = DeckGeneration.generate3ColorDeck(playerType);
+ d = DeckGenerator.generate3ColorDeck(playerType);
} else if (o.toString().equals(decks.get(2))) {
- d = DeckGeneration.generate5ColorDeck(playerType);
+ d = DeckGenerator.generate5ColorDeck(playerType);
} else if (o.toString().equals(decks.get(3))) {
- d = DeckGeneration.generateConstructedDeck();
+ d = DeckGenerator.generateConstructedDeck();
} else if (o.toString().equals(decks.get(4))) {
- d = DeckGeneration.generateConstructed3ColorDeck();
+ d = DeckGenerator.generateConstructed3ColorDeck();
} else if (o.toString().equals(decks.get(5))) {
- d = DeckGeneration.generateConstructed5ColorDeck();
+ d = DeckGenerator.generateConstructed5ColorDeck();
} else if (o.toString().equals(decks.get(6))) {
- d = DeckGeneration.generateConstructedThemeDeck();
+ d = DeckGenerator.generateConstructedThemeDeck();
}
if (playerType.equals(PlayerType.HUMAN)) {
@@ -97,7 +91,7 @@ public abstract class DeckGeneration {
*/
private static Deck generateConstructedDeck() {
final GenerateConstructedDeck gen = new GenerateConstructedDeck();
- final Deck deck = new Deck(GameType.Constructed);
+ final Deck deck = new Deck();
deck.getMain().add(gen.generateDeck());
return deck;
}
@@ -111,7 +105,7 @@ public abstract class DeckGeneration {
*/
private static Deck generateConstructed3ColorDeck() {
final GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck();
- final Deck deck = new Deck(GameType.Constructed);
+ final Deck deck = new Deck();
deck.getMain().add(gen.generate3ColorDeck());
return deck;
}
@@ -125,7 +119,7 @@ public abstract class DeckGeneration {
*/
private static Deck generateConstructed5ColorDeck() {
final GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck();
- final Deck deck = new Deck(GameType.Constructed);
+ final Deck deck = new Deck();
deck.getMain().add(gen.generate5ColorDeck());
return deck;
}
@@ -151,7 +145,7 @@ public abstract class DeckGeneration {
stDeck = o.toString();
}
- final Deck deck = new Deck(GameType.Constructed);
+ final Deck deck = new Deck();
deck.getMain().add(gen.getThemeDeck(stDeck, 60));
return deck;
@@ -201,7 +195,7 @@ public abstract class DeckGeneration {
}
final Generate2ColorDeck gen = new Generate2ColorDeck(c1, c2);
- final Deck deck = new Deck(GameType.Constructed);
+ final Deck deck = new Deck();
deck.getMain().add(gen.get2ColorDeck(60, p));
return deck;
}
@@ -260,7 +254,7 @@ public abstract class DeckGeneration {
c3 = colors.get(r.nextInt(colors.size() - 1) + 1);
}
final Generate3ColorDeck gen = new Generate3ColorDeck(c1, c2, c3);
- final Deck deck = new Deck(GameType.Constructed);
+ final Deck deck = new Deck();
deck.getMain().add(gen.get3ColorDeck(60, p));
return deck;
}
@@ -286,7 +280,7 @@ public abstract class DeckGeneration {
// colors.add("green");
final Generate5ColorDeck gen = new Generate5ColorDeck("white", "blue", "black", "red", "green");
- final Deck deck = new Deck(GameType.Constructed);
+ final Deck deck = new Deck();
deck.getMain().add(gen.get5ColorDeck(60, p));
return deck;
diff --git a/src/main/java/forge/deck/io/CubeSerializer.java b/src/main/java/forge/deck/io/CubeSerializer.java
new file mode 100644
index 00000000000..ea6f442e30f
--- /dev/null
+++ b/src/main/java/forge/deck/io/CubeSerializer.java
@@ -0,0 +1,89 @@
+/*
+ * Forge: Play Magic: the Gathering.
+ * Copyright (C) 2011 Nate
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package forge.deck.io;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+import forge.deck.CustomLimited;
+
+/**
+ * TODO: Write javadoc for this type.
+ *
+ */
+public class CubeSerializer extends DeckSerializerBase {
+
+ public CubeSerializer(File deckDir0)
+ {
+ super(deckDir0);
+ }
+
+
+ /* (non-Javadoc)
+ * @see forge.deck.IDeckSerializer#save(forge.item.CardCollectionBase, java.io.File)
+ */
+ @Override
+ public void save(CustomLimited unit) {
+
+ }
+
+ /* (non-Javadoc)
+ * @see forge.deck.IDeckSerializer#erase(forge.item.CardCollectionBase, java.io.File)
+ */
+ @Override
+ public void erase(CustomLimited unit) {
+ }
+
+
+
+ /**
+ *
+ * Make file name.
+ *
+ * @param deckName
+ * @param deckType
+ * a GameType
+ * @return a File
+ */
+ public File makeFileFor(final CustomLimited deck) {
+ return new File(getDirectory(), DeckIOCore.deriveFileName(cleanDeckName(deck.getName())) + ".cub");
+ }
+
+ /* (non-Javadoc)
+ * @see forge.deck.io.DeckSerializerBase#read(java.io.File)
+ */
+ @Override
+ protected CustomLimited read(File file) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see forge.deck.io.DeckSerializerBase#getFileFilter()
+ */
+ @Override
+ protected FilenameFilter getFileFilter() {
+ return new FilenameFilter() {
+
+ @Override
+ public boolean accept(File dir, String name) {
+ return dir.getPath().endsWith(".cub");
+ }
+ };
+ }
+
+}
diff --git a/src/main/java/forge/deck/io/DeckFileHeader.java b/src/main/java/forge/deck/io/DeckFileHeader.java
new file mode 100644
index 00000000000..532892efc62
--- /dev/null
+++ b/src/main/java/forge/deck/io/DeckFileHeader.java
@@ -0,0 +1,62 @@
+package forge.deck.io;
+
+import java.util.Map;
+
+import forge.PlayerType;
+import forge.game.GameType;
+
+/**
+ * TODO: Write javadoc for this type.
+ *
+ */
+public class DeckFileHeader {
+
+ private static final String NAME = "Name";
+ private static final String DECK_TYPE = "Deck Type";
+ private static final String COMMENT = "Comment";
+ private static final String PLAYER = "Player";
+ private static final String CSTM_POOL = "Custom Pool";
+ private static final String PLAYER_TYPE = "PlayerType";
+
+ private final GameType deckType;
+ private final PlayerType playerType;
+ private final boolean customPool;
+
+ private final String name;
+ private final String comment;
+
+
+ /**
+ * TODO: Write javadoc for Constructor.
+ * @param parseKvPairs
+ */
+ public DeckFileHeader(Map kvPairs) {
+ name = kvPairs.get(NAME);
+ comment = kvPairs.get(COMMENT);
+ deckType = GameType.smartValueOf(kvPairs.get(DECK_TYPE), GameType.Constructed);
+ customPool = "true".equalsIgnoreCase(kvPairs.get(CSTM_POOL));
+ playerType = "computer".equalsIgnoreCase(kvPairs.get(PLAYER)) || "ai".equalsIgnoreCase(kvPairs.get(PLAYER_TYPE)) ? PlayerType.COMPUTER : PlayerType.HUMAN;
+ }
+
+
+ public final PlayerType getPlayerType() {
+ return playerType;
+ }
+ public final boolean isCustomPool() {
+ return customPool;
+ }
+ public final String getName() {
+ return name;
+ }
+ public final String getComment() {
+ return comment;
+ }
+
+
+ public final GameType getDeckType() {
+ return deckType;
+ }
+
+
+
+}
diff --git a/src/main/java/forge/deck/io/DeckIOCore.java b/src/main/java/forge/deck/io/DeckIOCore.java
new file mode 100644
index 00000000000..f933d271cef
--- /dev/null
+++ b/src/main/java/forge/deck/io/DeckIOCore.java
@@ -0,0 +1,241 @@
+/*
+ * Forge: Play Magic: the Gathering.
+ * Copyright (C) 2011 Nate
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package forge.deck.io;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.swing.filechooser.FileFilter;
+
+import org.apache.commons.lang3.StringUtils;
+
+import forge.deck.Deck;
+import forge.game.GameType;
+import forge.gui.deckeditor.elements.TableSorter;
+import forge.item.CardPrinted;
+import forge.item.ItemPoolView;
+import forge.util.FileUtil;
+import forge.util.SectionUtil;
+
+/**
+ * TODO: Write javadoc for this type.
+ *
+ */
+public class DeckIOCore {
+
+ private static final String NAME = "Name";
+ private static final String DECK_TYPE = "Deck Type";
+ private static final String COMMENT = "Comment";
+ /** Constant DCKFileFilter. */
+ public static final FilenameFilter DCK_FILE_FILTER = new FilenameFilter() {
+ @Override
+ public boolean accept(final File dir, final String name) {
+ return name.endsWith(".dck");
+ }
+ };
+ /** The Constant DCK_FILTER. */
+ public static final FileFilter DCK_FILTER = new FileFilter() {
+ @Override
+ public boolean accept(final File f) {
+ return f.getName().endsWith(".dck") || f.isDirectory();
+ }
+
+ @Override
+ public String getDescription() {
+ return "Simple Deck File .dck";
+ }
+ };
+ /** The Constant HTML_FILTER. */
+ public static final FileFilter HTML_FILTER = new FileFilter() {
+ @Override
+ public boolean accept(final File f) {
+ return f.getName().endsWith(".html") || f.isDirectory();
+ }
+
+ @Override
+ public String getDescription() {
+ return "Simple Deck File .html";
+ }
+ };
+
+
+ public static DeckFileHeader readDeckMetadata(final Map> map) {
+ List lines = map.get("metadata");
+ if (lines == null) {
+ return null;
+ }
+ DeckFileHeader d = new DeckFileHeader(SectionUtil.parseKvPairs(lines, "="));
+
+
+ return d;
+ }
+
+
+ // Precondition: iterator should point at the first line of cards list
+ public static List readCardList(final Iterable lines) {
+ final List result = new ArrayList();
+ final Pattern p = Pattern.compile("((\\d+)\\s+)?(.*?)");
+
+ if (lines == null) {
+ return result;
+ }
+
+ final Iterator lineIterator = lines.iterator();
+ while (lineIterator.hasNext()) {
+ final String line = lineIterator.next();
+ if (line.startsWith("[")) {
+ break;
+ } // there comes another section
+
+ final Matcher m = p.matcher(line.trim());
+ m.matches();
+ final String sCnt = m.group(2);
+ final String cardName = m.group(3);
+ if (StringUtils.isBlank(cardName)) {
+ continue;
+ }
+
+ final int count = sCnt == null ? 1 : Integer.parseInt(sCnt);
+ for (int i = 0; i < count; i++) {
+ result.add(cardName);
+ }
+ }
+ return result;
+ }
+
+ public static String deriveFileName(final String deckName) {
+ // skips all but the listed characters
+ return deckName.replaceAll("[^-_$#@.{[()]} a-zA-Z0-9]", "");
+ }
+
+ // only accepts numbers, letters or dashes up to 20 characters in length
+ /**
+ *
+ * Clean deck name.
+ *
+ * @param in
+ * a String
+ * @return a String
+ */
+ public static String cleanDeckName(final String in) {
+ final char[] c = in.toCharArray();
+ final StringBuilder sb = new StringBuilder();
+ for (int i = 0; (i < c.length) && (i < 20); i++) {
+ if (Character.isLetterOrDigit(c[i]) || (c[i] == '-')) {
+ sb.append(c[i]);
+ }
+ }
+ return sb.toString();
+ }
+
+ public static List writeCardPool(final ItemPoolView pool) {
+ final List> main2sort = pool.getOrderedList();
+ Collections.sort(main2sort, TableSorter.BY_NAME_THEN_SET);
+ final List out = new ArrayList();
+ for (final Entry e : main2sort) {
+ final CardPrinted card = e.getKey();
+ final boolean hasBadSetInfo = "???".equals(card.getSet()) || StringUtils.isBlank(card.getSet());
+ if (hasBadSetInfo) {
+ out.add(String.format("%d %s", e.getValue(), card.getName()));
+ } else {
+ out.add(String.format("%d %s|%s", e.getValue(), card.getName(), card.getSet()));
+ }
+ }
+ return out;
+ }
+
+
+ /**
+ *
+ * readDeck.
+ *
+ *
+ * @param deckFile
+ * a {@link java.io.File} object.
+ * @return a {@link forge.deck.Deck} object.
+ */
+
+ public static Deck readDeck(final File deckFile) {
+ return readDeck(FileUtil.readFile(deckFile));
+ }
+
+
+ /**
+ * Read deck.
+ *
+ * @param deckFileLines the deck file lines
+ * @return the deck
+ */
+ public static Deck readDeck(final List deckFileLines) {
+ final Map> sections = SectionUtil.parseSections(deckFileLines);
+ if (sections.isEmpty()) {
+ return null;
+ }
+
+ DeckFileHeader dh = readDeckMetadata(sections);
+
+ final Deck d = new Deck(dh.getName());
+ d.setComment(dh.getComment());
+ d.getMain().set(readCardList(sections.get("main")));
+ d.getSideboard().set(readCardList(sections.get("sideboard")));
+
+ return d;
+ }
+
+
+ /**
+ *
+ * writeDeck.
+ *
+ *
+ * @param d
+ * a {@link forge.deck.Deck} object.
+ * @param out
+ * a {@link java.io.BufferedWriter} object.
+ * @throws java.io.IOException
+ * if any.
+ */
+ public static List saveDeck(final Deck d) {
+ final List out = new ArrayList();
+ out.add(String.format("[metadata]"));
+
+ out.add(String.format("%s=%s", NAME, d.getName().replaceAll("\n", "")));
+ // these are optional
+ if (d.getComment() != null) {
+ out.add(String.format("%s=%s", COMMENT, d.getComment().replaceAll("\n", "")));
+ }
+
+ out.add(String.format("%s", "[main]"));
+ out.addAll(writeCardPool(d.getMain()));
+
+ out.add(String.format("%s", "[sideboard]"));
+ out.addAll(writeCardPool(d.getSideboard()));
+ return out;
+ }
+
+
+
+}
diff --git a/src/main/java/forge/deck/io/DeckSerializer.java b/src/main/java/forge/deck/io/DeckSerializer.java
new file mode 100644
index 00000000000..7f56d830de9
--- /dev/null
+++ b/src/main/java/forge/deck/io/DeckSerializer.java
@@ -0,0 +1,248 @@
+/*
+ * Forge: Play Magic: the Gathering.
+ * Copyright (C) 2011 Nate
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package forge.deck.io;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+
+import javax.swing.filechooser.FileFilter;
+
+import forge.Card;
+import forge.deck.Deck;
+import forge.item.CardPrinted;
+import forge.util.FileUtil;
+import freemarker.template.Configuration;
+import freemarker.template.DefaultObjectWrapper;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+/**
+ * TODO: Write javadoc for this type.
+ *
+ */
+public class DeckSerializer extends DeckSerializerBase {
+
+ public DeckSerializer(File deckDir0)
+ {
+ super(deckDir0);
+ }
+
+
+ /** Constant DCKFileFilter. */
+ public static final FilenameFilter DCK_FILE_FILTER = new FilenameFilter() {
+ @Override
+ public boolean accept(final File dir, final String name) {
+ return name.endsWith(".dck");
+ }
+ };
+ /** The Constant DCK_FILTER. */
+ public static final FileFilter DCK_FILTER = new FileFilter() {
+ @Override
+ public boolean accept(final File f) {
+ return f.getName().endsWith(".dck") || f.isDirectory();
+ }
+
+ @Override
+ public String getDescription() {
+ return "Simple Deck File .dck";
+ }
+ };
+ /** The Constant HTML_FILTER. */
+ public static final FileFilter HTML_FILTER = new FileFilter() {
+ @Override
+ public boolean accept(final File f) {
+ return f.getName().endsWith(".html") || f.isDirectory();
+ }
+
+ @Override
+ public String getDescription() {
+ return "Simple Deck File .html";
+ }
+ };
+
+
+ /**
+ *
+ * writeDeck.
+ *
+ *
+ * @param d
+ * a {@link forge.deck.Deck} object.
+ * @param out
+ * a {@link java.io.BufferedWriter} object.
+ * @throws java.io.IOException
+ * if any.
+ */
+ private static void writeDeckHtml(final Deck d, final BufferedWriter out) throws IOException {
+ Template temp = null;
+ final int cardBorder = 0;
+ final int height = 319;
+ final int width = 222;
+
+ /* Create and adjust the configuration */
+ final Configuration cfg = new Configuration();
+ try {
+ cfg.setClassForTemplateLoading(d.getClass(), "/");
+ cfg.setObjectWrapper(new DefaultObjectWrapper());
+
+ /*
+ * ------------------------------------------------------------------
+ * -
+ */
+ /*
+ * You usually do these for many times in the application
+ * life-cycle:
+ */
+
+ /* Get or create a template */
+ temp = cfg.getTemplate("proxy-template.ftl");
+
+ /* Create a data-model */
+ final Map root = new HashMap();
+ root.put("title", d.getName());
+ final List list = new ArrayList();
+ for (final Card card : d.getMain().toForgeCardList().toArray()) {
+ // System.out.println(card.getSets().get(card.getSets().size() -
+ // 1).URL);
+ list.add(card.getSets().get(card.getSets().size() - 1).getUrl());
+ }
+ /*
+ * List nameList = new ArrayList(); for (Card card :
+ * d.getMain().toForgeCardList().toArray()) {
+ * //System.out.println(card.getSets().get(card.getSets().size() -
+ * 1).URL); nameList.add(card.getName()); }
+ */
+
+ final TreeMap map = new TreeMap();
+ for (final Entry entry : d.getMain().getOrderedList()) {
+ map.put(entry.getKey().getName(), entry.getValue());
+ // System.out.println(entry.getValue() + " " +
+ // entry.getKey().getName());
+ }
+
+ root.put("urls", list);
+ root.put("cardBorder", cardBorder);
+ root.put("height", height);
+ root.put("width", width);
+ root.put("cardlistWidth", width - 11);
+ // root.put("nameList", nameList);
+ root.put("cardList", map);
+
+ /* Merge data-model with template */
+ // StringWriter sw = new StringWriter();
+ temp.process(root, out);
+ out.flush();
+ } catch (final IOException e) {
+ System.out.println(e.toString());
+ } catch (final TemplateException e) {
+ System.out.println(e.toString());
+ }
+ }
+
+ /**
+ *
+ * writeDeck.
+ *
+ *
+ * @param d
+ * a {@link forge.deck.Deck} object.
+ * @param f
+ * a {@link java.io.File} object.
+ */
+ public static void writeDeck(final Deck d, final File f) {
+ FileUtil.writeFile(f, DeckIOCore.saveDeck(d));
+ }
+
+ /**
+ *
+ * Write deck to HTML.
+ *
+ *
+ * @param d
+ * a {@link forge.deck.Deck} object.
+ * @param f
+ * a {@link java.io.File} object.
+ */
+ public static void writeDeckHtml(final Deck d, final File f) {
+ try {
+ final BufferedWriter writer = new BufferedWriter(new FileWriter(f));
+ DeckSerializer.writeDeckHtml(d, writer);
+ writer.close();
+ } catch (final IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see forge.deck.IDeckSerializer#save(forge.item.CardCollectionBase, java.io.File)
+ */
+ @Override
+ public void save(Deck unit) {
+ FileUtil.writeFile(makeFileFor(unit), DeckIOCore.saveDeck(unit));
+ }
+
+ /* (non-Javadoc)
+ * @see forge.deck.IDeckSerializer#erase(forge.item.CardCollectionBase, java.io.File)
+ */
+ @Override
+ public void erase(Deck unit) {
+ }
+
+
+
+ /**
+ *
+ * Make file name.
+ *
+ * @param deckName
+ * a String
+ * @param deckType
+ * a GameType
+ * @return a File
+ */
+ public File makeFileFor(final Deck deck) {
+ return new File(getDirectory(), DeckIOCore.deriveFileName(cleanDeckName(deck.getName())) + ".dck");
+ }
+
+ /* (non-Javadoc)
+ * @see forge.deck.io.DeckSerializerBase#read(java.io.File)
+ */
+ @Override
+ protected Deck read(File file) {
+ return DeckIOCore.readDeck(file);
+ }
+
+ /* (non-Javadoc)
+ * @see forge.deck.io.DeckSerializerBase#getFileFilter()
+ */
+ @Override
+ protected FilenameFilter getFileFilter() {
+ return DCK_FILE_FILTER;
+ }
+
+}
diff --git a/src/main/java/forge/deck/io/DeckSerializerBase.java b/src/main/java/forge/deck/io/DeckSerializerBase.java
new file mode 100644
index 00000000000..fabdeaf5e13
--- /dev/null
+++ b/src/main/java/forge/deck/io/DeckSerializerBase.java
@@ -0,0 +1,134 @@
+/*
+ * Forge: Play Magic: the Gathering.
+ * Copyright (C) 2011 Nate
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package forge.deck.io;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.TreeMap;
+
+import javax.swing.JOptionPane;
+
+import org.apache.commons.lang3.StringUtils;
+
+import forge.error.ErrorViewer;
+import forge.item.IHasName;
+
+/**
+ * TODO: Write javadoc for this type.
+ *
+ */
+public abstract class DeckSerializerBase implements IDeckSerializer {
+
+ private final File directory;
+
+ protected final File getDirectory() {
+ return directory;
+ }
+
+
+ public DeckSerializerBase(File deckDir0)
+ {
+ directory = deckDir0;
+
+ if (directory == null) {
+ throw new IllegalArgumentException("No deck directory specified");
+ }
+ try {
+ if (directory.isFile()) {
+ throw new IOException("Not a directory");
+ } else {
+ directory.mkdirs();
+ if (!directory.isDirectory()) {
+ throw new IOException("Directory can't be created");
+ }
+ }
+ } catch (final IOException ex) {
+ ErrorViewer.showError(ex);
+ throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage());
+ }
+ }
+
+
+ // only accepts numbers, letters or dashes up to 20 characters in length
+ /**
+ *
+ * Clean deck name.
+ *
+ * @param in
+ * a String
+ * @return a String
+ */
+ protected String cleanDeckName(final String in) {
+ final char[] c = in.toCharArray();
+ final StringBuilder sb = new StringBuilder();
+ for (int i = 0; (i < c.length) && (i < 20); i++) {
+ if (Character.isLetterOrDigit(c[i]) || (c[i] == '-')) {
+ sb.append(c[i]);
+ }
+ }
+ return sb.toString();
+ }
+
+
+
+ @Override
+ public Map readAll() {
+ final Map result = new TreeMap();
+ final List decksThatFailedToLoad = new ArrayList();
+ final File[] files = directory.listFiles(getFileFilter());
+ for (final File file : files) {
+ try {
+ final T newDeck = read(file);
+ result.put(newDeck.getName(), newDeck);
+ } catch (final NoSuchElementException ex) {
+ final String message = String.format("%s failed to load because ---- %s", file.getName(),
+ ex.getMessage());
+ decksThatFailedToLoad.add(message);
+ }
+ }
+
+ if (!decksThatFailedToLoad.isEmpty()) {
+ JOptionPane.showMessageDialog(null,
+ StringUtils.join(decksThatFailedToLoad, System.getProperty("line.separator")),
+ "Some of your decks were not loaded.", JOptionPane.WARNING_MESSAGE);
+ }
+
+ return result;
+ }
+
+
+ /**
+ * TODO: Write javadoc for this method.
+ * @param file
+ * @return
+ */
+ protected abstract T read(File file);
+
+
+ /**
+ * TODO: Write javadoc for this method.
+ * @return
+ */
+ protected abstract FilenameFilter getFileFilter();
+
+}
diff --git a/src/main/java/forge/deck/io/DeckSetSerializer.java b/src/main/java/forge/deck/io/DeckSetSerializer.java
new file mode 100644
index 00000000000..22c2ad59fc8
--- /dev/null
+++ b/src/main/java/forge/deck/io/DeckSetSerializer.java
@@ -0,0 +1,107 @@
+/*
+ * Forge: Play Magic: the Gathering.
+ * Copyright (C) 2011 Nate
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package forge.deck.io;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.List;
+import forge.deck.Deck;
+import forge.deck.DeckSet;
+import forge.util.FileUtil;
+
+/**
+ * TODO: Write javadoc for this type.
+ *
+ */
+public class DeckSetSerializer extends DeckSerializerBase {
+ /**
+ * TODO: Write javadoc for Constructor.
+ * @param deckDir0
+ */
+ public DeckSetSerializer(File deckDir0) {
+ super(deckDir0);
+ }
+
+ public final static int MAX_DRAFT_PLAYERS = 8;
+
+ /**
+ *
+ * Write draft Decks.
+ *
+ * @param drafts
+ * a Deck[]
+ */
+ @Override
+ public void save(DeckSet unit) {
+ final File f = makeFileFor(unit);
+ f.mkdir();
+ FileUtil.writeFile(new File(f, "human.dck"), DeckIOCore.saveDeck(unit.getHumanDeck()));
+ List aiDecks = unit.getAiDecks();
+ for (int i = 1; i <= aiDecks.size(); i++) {
+ FileUtil.writeFile(new File(f, "ai-" + i + ".dck"), DeckIOCore.saveDeck(aiDecks.get(i-1)));
+ }
+ }
+
+ protected final DeckSet read(File file)
+ {
+ Deck human = DeckIOCore.readDeck(new File(file, "human.dck"));
+ final DeckSet d = new DeckSet(human.getName());
+ d.setHumanDeck(human);
+ for (int i = 1; i < MAX_DRAFT_PLAYERS; i++) {
+ File theFile = new File(file, "ai-" + i + ".dck");
+ if( !theFile.exists() )
+ break;
+
+ d.addAiDeck(DeckIOCore.readDeck(theFile));
+ }
+ return d;
+ }
+
+
+ /* (non-Javadoc)
+ * @see forge.deck.IDeckSerializer#erase(forge.item.CardCollectionBase, java.io.File)
+ */
+ @Override
+ public void erase(DeckSet unit) {
+ File dir = makeFileFor(unit);
+ final File[] files = dir.listFiles();
+ for(File f : files) {
+ f.delete();
+ }
+ dir.delete();
+ }
+
+ public File makeFileFor(final DeckSet decks) {
+ return new File(getDirectory(), DeckIOCore.deriveFileName(decks.getName()));
+ }
+
+ /* (non-Javadoc)
+ * @see forge.deck.io.DeckSerializerBase#getFileFilter()
+ */
+ @Override
+ protected FilenameFilter getFileFilter() {
+ return new FilenameFilter() {
+
+ @Override
+ public boolean accept(File dir, String name) {
+ return dir.isDirectory();
+ }
+ };
+ }
+
+}
diff --git a/src/main/java/forge/deck/io/IDeckReader.java b/src/main/java/forge/deck/io/IDeckReader.java
new file mode 100644
index 00000000000..84917c21db0
--- /dev/null
+++ b/src/main/java/forge/deck/io/IDeckReader.java
@@ -0,0 +1,12 @@
+package forge.deck.io;
+
+import java.util.Map;
+
+import forge.item.IHasName;
+
+
+public interface IDeckReader {
+ Map readAll();
+ //T read(File file);
+}
+
diff --git a/src/main/java/forge/deck/io/IDeckSerializer.java b/src/main/java/forge/deck/io/IDeckSerializer.java
new file mode 100644
index 00000000000..3b394483b01
--- /dev/null
+++ b/src/main/java/forge/deck/io/IDeckSerializer.java
@@ -0,0 +1,15 @@
+package forge.deck.io;
+
+import forge.item.IHasName;
+
+
+/**
+ * TODO: Write javadoc for this type.
+ *
+ */
+public interface IDeckSerializer extends IDeckReader {
+ void save(T unit);
+ void erase(T unit);
+}
+
+
diff --git a/src/main/java/forge/game/GameType.java b/src/main/java/forge/game/GameType.java
index 3fb2423e43e..749907f4ef7 100644
--- a/src/main/java/forge/game/GameType.java
+++ b/src/main/java/forge/game/GameType.java
@@ -61,7 +61,9 @@ public enum GameType {
* the value
* @return the game type
*/
- public static GameType smartValueOf(final String value) {
+ public static GameType smartValueOf(final String value, GameType defaultValue) {
+ if ( null == value ) return defaultValue;
+
final String valToCompate = value.trim();
for (final GameType v : GameType.values()) {
if (v.name().compareToIgnoreCase(valToCompate) == 0) {
diff --git a/src/main/java/forge/game/limited/BoosterDraft.java b/src/main/java/forge/game/limited/BoosterDraft.java
index 8a6deabf842..4d6cc208781 100644
--- a/src/main/java/forge/game/limited/BoosterDraft.java
+++ b/src/main/java/forge/game/limited/BoosterDraft.java
@@ -31,7 +31,6 @@ import javax.swing.JOptionPane;
import net.slightlymagic.braids.util.lambda.Lambda1;
import net.slightlymagic.maxmtg.Closure1;
-import forge.AllZone;
import forge.Card;
import forge.CardList;
import forge.Constant;
@@ -39,8 +38,8 @@ import forge.SetUtils;
import forge.card.BoosterGenerator;
import forge.card.CardBlock;
import forge.card.CardSet;
+import forge.deck.CustomLimited;
import forge.deck.Deck;
-import forge.deck.DeckManager;
import forge.gui.GuiUtils;
import forge.item.CardDb;
import forge.item.CardPrinted;
@@ -161,8 +160,7 @@ public final class BoosterDraft implements IBoosterDraft {
}
private void setupCustomDraft(final CustomLimited draft) {
- final DeckManager dio = AllZone.getDeckManager();
- final Deck dPool = dio.getDeck(draft.getDeckFile());
+ final ItemPoolView dPool = draft.getCardPool();
if (dPool == null) {
throw new RuntimeException("BoosterGenerator : deck not found - " + draft.getDeckFile());
}
diff --git a/src/main/java/forge/game/limited/BoosterDraftAI.java b/src/main/java/forge/game/limited/BoosterDraftAI.java
index 9917b782dbf..85a44959a95 100644
--- a/src/main/java/forge/game/limited/BoosterDraftAI.java
+++ b/src/main/java/forge/game/limited/BoosterDraftAI.java
@@ -33,7 +33,6 @@ import forge.CardListUtil;
import forge.Constant;
import forge.card.spellability.AbilityMana;
import forge.deck.Deck;
-import forge.game.GameType;
import forge.util.MyRandom;
/**
@@ -361,7 +360,7 @@ public class BoosterDraftAI {
* @return a {@link forge.deck.Deck} object.
*/
private Deck buildDeck(final CardList dList, final DeckColors pClrs) {
- final Deck out = new Deck(GameType.Draft);
+
final CardList outList = new CardList();
int cardsNeeded = 22;
int landsNeeded = 18;
@@ -618,15 +617,13 @@ public class BoosterDraftAI {
}
}
if (outList.size() == 40) {
+ final Deck out = new Deck();
out.getMain().add(outList);
out.getSideboard().add(aiPlayables);
out.getSideboard().add(dList);
-
- } else {
- throw new RuntimeException("BoosterDraftAI : buildDeck() error, decksize not 40");
- }
-
- return out;
+ return out;
+ }
+ throw new RuntimeException("BoosterDraftAI : buildDeck() error, decksize not 40");
}
/*
diff --git a/src/main/java/forge/game/limited/SealedDeck.java b/src/main/java/forge/game/limited/SealedDeck.java
index b325a045ce4..4f920e09aa3 100644
--- a/src/main/java/forge/game/limited/SealedDeck.java
+++ b/src/main/java/forge/game/limited/SealedDeck.java
@@ -36,9 +36,8 @@ import forge.card.BoosterGenerator;
import forge.card.CardBlock;
import forge.card.CardSet;
import forge.card.spellability.AbilityMana;
+import forge.deck.CustomLimited;
import forge.deck.Deck;
-import forge.deck.DeckManager;
-import forge.game.GameType;
import forge.gui.GuiUtils;
import forge.item.CardDb;
import forge.item.CardPrinted;
@@ -154,13 +153,7 @@ public class SealedDeck {
final CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Sealed Pool",
customs.toArray());
- final DeckManager dio = AllZone.getDeckManager();
- final Deck dPool = dio.getDeck(draft.getDeckFile());
- if (dPool == null) {
- throw new RuntimeException("BoosterGenerator : deck not found - " + draft.getDeckFile());
- }
-
- final BoosterGenerator bpCustom = new BoosterGenerator(dPool);
+ final BoosterGenerator bpCustom = new BoosterGenerator(draft.getCardPool());
final Lambda1, BoosterGenerator> fnPick = new Lambda1, BoosterGenerator>() {
@Override
public List apply(final BoosterGenerator pack) {
@@ -200,7 +193,7 @@ public class SealedDeck {
final ItemPool pool = new ItemPool(CardPrinted.class);
for (int i = 0; i < this.packs.size(); i++) {
- pool.addAllCards(this.packs.get(i).apply());
+ pool.addAllFlat(this.packs.get(i).apply());
}
return pool;
@@ -433,7 +426,7 @@ public class SealedDeck {
}
}
- final Deck aiDeck = new Deck(GameType.Sealed);
+ final Deck aiDeck = new Deck();
for (i = 0; i < deck.size(); i++) {
if (deck.get(i).getName().equals("Plains") || deck.get(i).getName().equals("Island")
diff --git a/src/main/java/forge/gui/deckeditor/DeckDisplay.java b/src/main/java/forge/gui/deckeditor/DeckDisplay.java
deleted file mode 100644
index 20496fa187b..00000000000
--- a/src/main/java/forge/gui/deckeditor/DeckDisplay.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Forge: Play Magic: the Gathering.
- * Copyright (C) 2011 Forge Team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package forge.gui.deckeditor;
-
-import forge.deck.Deck;
-import forge.game.GameType;
-import forge.item.CardPrinted;
-import forge.item.InventoryItem;
-import forge.item.ItemPoolView;
-
-/**
- * Created by IntelliJ IDEA. User: dhudson Date: 6/24/11
- *
- * @author Forge
- * @version $Id$
- */
-public interface DeckDisplay {
- /**
- *
- * setDeck.
- *
- * @param top
- * ItemPoolView
- * @param bottom
- * ItemPoolView
- * @param gameType
- * GameType
- */
- void setDeck(ItemPoolView top, ItemPoolView bottom, GameType gameType);
-
- /**
- *
- * setItems.
- *
- * @param
- * InventoryItem
- * @param topParam
- * ItemPoolView
- * @param bottomParam
- * ItemPoolView
- * @param gt
- * GameType
- */
- void setItems(ItemPoolView topParam, ItemPoolView bottomParam, GameType gt);
-
- /**
- *
- * Top shows available card pool. if constructed, top shows all cards if
- * sealed, top shows 5 booster packs if draft, top shows cards that were
- * chosen
- *
- * @return ItemPoolView
- */
- ItemPoolView getTop();
-
- //
- /**
- *
- * Bottom shows cards that the user has chosen for his library.
- *
- * @return ItemPoolView
- */
- ItemPoolView getBottom();
-
- /**
- *
- * Set title.
- *
- * @param message
- * String
- */
- void setTitle(String message);
-
- /**
- *
- * Get deck.
- *
- * @return Deck
- */
- Deck getDeck();
-
- /**
- *
- * Get game type.
- *
- * @return GameType
- */
- GameType getGameType();
-}
diff --git a/src/main/java/forge/gui/deckeditor/DeckEditorBase.java b/src/main/java/forge/gui/deckeditor/DeckEditorBase.java
index c14ebac7dbe..a50383ec0d5 100644
--- a/src/main/java/forge/gui/deckeditor/DeckEditorBase.java
+++ b/src/main/java/forge/gui/deckeditor/DeckEditorBase.java
@@ -27,8 +27,11 @@ import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import net.slightlymagic.maxmtg.Predicate;
-import forge.deck.Deck;
-import forge.game.GameType;
+import forge.Command;
+import forge.gui.deckeditor.elements.CardPanelBase;
+import forge.gui.deckeditor.elements.DeckAnalysis;
+import forge.gui.deckeditor.elements.FilterCheckBoxes;
+import forge.gui.deckeditor.elements.TableView;
import forge.item.CardPrinted;
import forge.item.InventoryItem;
import forge.item.ItemPool;
@@ -37,7 +40,7 @@ import forge.item.ItemPoolView;
/**
* The Class DeckEditorBase.
*/
-public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
+public abstract class DeckEditorBase extends JFrame {
private static final long serialVersionUID = -401223933343539977L;
/** The filter boxes. */
@@ -52,22 +55,10 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
// CardPools and Table data for top and bottom lists
/** The top. */
- private TableWithCards topTableWithCards;
+ private TableView topTableWithCards;
/** The bottom. */
- private TableWithCards bottomTableWithCards;
-
- private GameType gameType;
-
- /*
- * (non-Javadoc)
- *
- * @see forge.gui.deckeditor.DeckDisplay#getGameType()
- */
- @Override
- public final GameType getGameType() {
- return this.gameType;
- }
+ private TableView bottomTableWithCards;
// top shows available card pool
// if constructed, top shows all cards
@@ -78,7 +69,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
*
* @return the top table model
*/
- public final TableWithCards getTopTableModel() {
+ public final TableView getTopTableModel() {
return this.getTopTableWithCards();
}
@@ -87,8 +78,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
*
* @see forge.gui.deckeditor.DeckDisplay#getTop()
*/
- @Override
- public final ItemPoolView getTop() {
+ public final ItemPoolView getTop() {
return this.getTopTableWithCards().getCards();
}
@@ -98,11 +88,13 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
*
* @see forge.gui.deckeditor.DeckDisplay#getBottom()
*/
- @Override
- public final ItemPoolView getBottom() {
+ public final ItemPoolView getBottom() {
return this.getBottomTableWithCards().getCards();
}
+
+ public abstract IDeckManager getController();
+
// THIS IS HERE FOR OVERLOADING!!!1
// or may be return abstract getFilter from derived class + this filter ...
// virtual protected member, but later
@@ -111,8 +103,9 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
*
* @return the predicate
*/
- protected abstract Predicate buildFilter();
+ protected abstract Predicate buildFilter();
+ public abstract void show(final Command exitCommand);
/**
* Analysis button_action performed.
*
@@ -126,36 +119,13 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck",
JOptionPane.INFORMATION_MESSAGE);
} else {
- final DeckEditorBase g = DeckEditorBase.this;
+ final DeckEditorBase g = DeckEditorBase.this;
final DeckAnalysis dAnalysis = new DeckAnalysis(g, deck);
dAnalysis.setVisible(true);
g.setEnabled(false);
}
}
- /**
- * Instantiates a new deck editor base.
- *
- * @param gametype
- * the gametype
- */
- public DeckEditorBase(final GameType gametype) {
- this.gameType = gametype;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see forge.gui.deckeditor.DeckDisplay#setDeck(forge.item.ItemPoolView,
- * forge.item.ItemPoolView, forge.game.GameType)
- */
- @Override
- public void setDeck(final ItemPoolView topParam, final ItemPoolView bottomParam,
- final GameType gt) {
- this.gameType = gt;
- this.getTopTableWithCards().setDeck(topParam);
- this.getBottomTableWithCards().setDeck(bottomParam);
- }
/*
* (non-Javadoc)
@@ -163,13 +133,9 @@ 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 void setItems(final ItemPoolView topParam,
- final ItemPoolView bottomParam, final GameType gt) {
- this.gameType = gt;
- this.getTopTableWithCards().setDeck(topParam);
- this.getBottomTableWithCards().setDeck(bottomParam);
- }
+ public abstract void updateView();
+
+
/**
* Update display.
@@ -235,23 +201,6 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
} // Happend only on ENTER pressed
}
- /*
- * (non-Javadoc)
- *
- * @see forge.gui.deckeditor.DeckDisplay#getDeck()
- */
- @Override
- public final Deck getDeck() {
- final Deck deck = new Deck(this.gameType);
- deck.getMain().addAll(this.getBottom());
-
- // if sealed or draft, move "top" to sideboard
- if (this.gameType.isLimited() && (this.gameType != GameType.Quest)) {
- deck.getSideboard().addAll(this.getTop());
- }
- return deck;
- } // getDeck()
-
/**
* Gets the item listener updates display.
*
@@ -313,7 +262,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
* @param cardView0
* the cardView to set
*/
- public void setCardView(final CardPanelBase cardView0) {
+ protected void setCardView(final CardPanelBase cardView0) {
this.cardView = cardView0;
}
@@ -341,7 +290,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
*
* @return the bottomTableWithCards
*/
- public TableWithCards getBottomTableWithCards() {
+ public TableView getBottomTableWithCards() {
return this.bottomTableWithCards;
}
@@ -351,7 +300,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
* @param bottomTableWithCards0
* the bottomTableWithCards to set
*/
- public void setBottomTableWithCards(final TableWithCards bottomTableWithCards0) {
+ public void setBottomTableWithCards(final TableView bottomTableWithCards0) {
this.bottomTableWithCards = bottomTableWithCards0;
}
@@ -360,7 +309,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
*
* @return the topTableWithCards
*/
- public TableWithCards getTopTableWithCards() {
+ public TableView getTopTableWithCards() {
return this.topTableWithCards;
}
@@ -370,7 +319,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
* @param topTableWithCards0
* the topTableWithCards to set
*/
- public void setTopTableWithCards(final TableWithCards topTableWithCards0) {
+ public void setTopTableWithCards(final TableView topTableWithCards0) {
this.topTableWithCards = topTableWithCards0;
}
diff --git a/src/main/java/forge/gui/deckeditor/DeckEditorCommonMenu.java b/src/main/java/forge/gui/deckeditor/DeckEditorCommonMenu.java
deleted file mode 100644
index 72196a809bd..00000000000
--- a/src/main/java/forge/gui/deckeditor/DeckEditorCommonMenu.java
+++ /dev/null
@@ -1,859 +0,0 @@
-/*
- * Forge: Play Magic: the Gathering.
- * Copyright (C) 2011 Forge Team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package forge.gui.deckeditor;
-
-import java.awt.Component;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.nio.channels.FileChannel;
-import java.util.ArrayList;
-
-import javax.swing.JFileChooser;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.SwingUtilities;
-
-import org.apache.commons.lang3.StringUtils;
-
-import forge.Card;
-import forge.CardList;
-import forge.Command;
-import forge.deck.Deck;
-import forge.deck.DeckIO;
-import forge.deck.DeckManager;
-import forge.deck.generate.GenerateConstructedDeck;
-import forge.error.ErrorViewer;
-import forge.game.GameType;
-import forge.gui.GuiUtils;
-import forge.item.CardDb;
-import forge.item.CardPrinted;
-import forge.item.ItemPool;
-import forge.properties.ForgeProps;
-import forge.properties.NewConstants;
-
-/**
- *
- * Gui_DeckEditor_Menu class.
- *
- *
- * @author Forge
- * @version $Id$
- */
-public final class DeckEditorCommonMenu extends JMenuBar {
-
- /** Constant serialVersionUID=-4037993759604768755L. */
- private static final long serialVersionUID = -4037993759604768755L;
-
- /** Constant previousDirectory. */
- private static File previousDirectory = null;
-
- private final DeckManager deckManager;
-
- private boolean isDeckSaved = true;
-
- private String currentDeckName;
- private final DeckDisplay deckDisplay;
-
- private final Command exitCommand;
-
- /**
- *
- * Menu for Deck Editor.
- *
- * @param inDisplay
- * a DeckDisplay
- * @param dckManager
- * a DeckManager
- * @param exit
- * a Command
- */
- public DeckEditorCommonMenu(final DeckDisplay inDisplay, final DeckManager dckManager, final Command exit) {
- 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
- this.setDeckData("", true);
-
- this.setupMenu();
- this.setupSortMenu();
- }
-
- /**
- *
- * setupSortMenu.
- *
- */
- private void setupSortMenu() {
- 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");
-
- final JMenu menu = new JMenu("Sort By");
- menu.add(name);
- menu.add(cost);
- menu.add(color);
- menu.add(type);
- menu.add(stats);
- menu.add(rarity);
-
- this.add(menu);
-
- name.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- ((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(1, true);
- }
- });
-
- // 0 1 2 3 4 5 6
- // private String column[] = {"Qty", "Name", "Cost", "Color", "Type",
- // "Stats", "Rarity"};
- cost.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- ((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(4).sort(3).sort(2);
- }
- });
-
- color.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- ((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(4).sort(2).sort(3);
- }
- });
-
- type.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- ((DeckEditorCommon) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(2).sort(3).sort(4);
- }
- });
-
- stats.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- ((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) DeckEditorCommonMenu.this.deckDisplay).getTopTableModel().sort(2).sort(4).sort(3)
- .sort(6);
- }
- });
- } // setupSortMenu()
-
- /**
- * New constructed.
- *
- * @param careAboutOldDeck
- * a boolean
- */
- public void newConstructed(final boolean careAboutOldDeck) {
- if (careAboutOldDeck && !this.canLeaveCurrentDeck()) {
- return;
- }
-
- this.setDeckData("", true);
-
- this.deckDisplay.setDeck(null, null, GameType.Constructed);
- }
-
- private void newRandomConstructed() {
- if (!this.canLeaveCurrentDeck()) {
- return;
- }
-
- this.setDeckData("", false);
-
- // The only remaining reference to global variable!
- final CardList random = new CardList(forge.AllZone.getCardFactory().getRandomCombinationWithoutRepetition(
- 15 * 5));
-
- final ItemPool cpRandom = new ItemPool(CardPrinted.class);
- for (final Card c : random) {
- cpRandom.add(CardDb.instance().getCard(c));
- }
- cpRandom.add(CardDb.instance().getCard("Forest"));
- cpRandom.add(CardDb.instance().getCard("Island"));
- cpRandom.add(CardDb.instance().getCard("Plains"));
- cpRandom.add(CardDb.instance().getCard("Swamp"));
- cpRandom.add(CardDb.instance().getCard("Mountain"));
- cpRandom.add(CardDb.instance().getCard("Terramorphic Expanse"));
-
- this.deckDisplay.setDeck(cpRandom, null, GameType.Constructed);
- }
-
- private void newGenerateConstructed() {
- if (!this.canLeaveCurrentDeck()) {
- return;
- }
-
- this.setDeckData("", false);
-
- final GenerateConstructedDeck gen = new GenerateConstructedDeck();
-
- final ItemPool generated = new ItemPool(CardPrinted.class);
- for (final Card c : gen.generateDeck()) {
- generated.add(CardDb.instance().getCard(c));
- }
- this.deckDisplay.setDeck(null, generated, GameType.Constructed);
- }
-
- private File getImportFilename() {
- final JFileChooser chooser = new JFileChooser(DeckEditorCommonMenu.previousDirectory);
-
- chooser.addChoosableFileFilter(DeckIO.DCK_FILTER);
- final int returnVal = chooser.showOpenDialog(null);
-
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- final File file = chooser.getSelectedFile();
- DeckEditorCommonMenu.previousDirectory = file.getParentFile();
- return file;
- }
- return null;
- } // openFileDialog()
-
- private void importDeck() {
- final File file = this.getImportFilename();
-
- if (file == null) {
- } else if (file.getName().endsWith(".dck")) {
- try {
- 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;
- }
- final FileChannel dstChannel = new FileOutputStream(dst).getChannel();
- dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
- srcChannel.close();
- dstChannel.close();
-
- final Deck newDeck = DeckIO.readDeck(file);
- this.deckManager.addDeck(newDeck);
- this.showDeck(newDeck, newDeck.getDeckType());
-
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error, " + ex);
- }
- }
-
- }
-
- /**
- *
- * exportDeck.
- *
- */
- private void exportDeck() {
- final File filename = this.getExportFilename();
- if (filename == null) {
- return;
- }
-
- final Deck deck = this.getDeck();
- try {
- DeckIO.writeDeck(deck, filename);
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error, " + ex);
- }
- }
-
- private File getExportFilename() {
- final JFileChooser save = new JFileChooser(DeckEditorCommonMenu.previousDirectory);
- save.setDialogTitle("Export Deck Filename");
- save.setDialogType(JFileChooser.SAVE_DIALOG);
- save.setFileFilter(DeckIO.DCK_FILTER);
-
- if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
- final File file = save.getSelectedFile();
- final String check = file.getAbsolutePath();
-
- DeckEditorCommonMenu.previousDirectory = file.getParentFile();
-
- return check.endsWith(".dck") ? file : new File(check + ".dck");
- }
- return null;
- }
-
- /**
- *
- * Generate Proxy for a Deck.
- *
- */
- private void generateProxies() {
- final File filename = this.getProxiesFilename();
- if (filename == null) {
- return;
- }
-
- final Deck deck = this.getDeck();
- try {
- DeckIO.writeDeckHtml(deck, filename);
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : printProxies() error, " + ex);
- }
- }
-
- private File getProxiesFilename() {
- final JFileChooser save = new JFileChooser(DeckEditorCommonMenu.previousDirectory);
- save.setDialogTitle("Proxy HTML Filename");
- save.setDialogType(JFileChooser.SAVE_DIALOG);
- save.setFileFilter(DeckIO.HTML_FILTER);
-
- if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
- final File file = save.getSelectedFile();
- final String check = file.getAbsolutePath();
-
- DeckEditorCommonMenu.previousDirectory = file.getParentFile();
-
- return check.endsWith(".html") ? file : new File(check + ".html");
- }
- return null;
- }
-
- private void openDeck(final GameType gameType) {
- if (!this.canLeaveCurrentDeck()) {
- return;
- }
-
- final String name = this.getUserInputOpenDeck(gameType);
-
- if (StringUtils.isBlank(name)) {
- return;
- }
-
- final Deck deck = gameType == GameType.Draft ? this.deckManager.getDraftDeck(name)[0] : this.deckManager
- .getDeck(name);
- this.showDeck(deck, gameType);
- }
-
- /**
- *
- * showDeck.
- *
- * @param deck
- * a Deck
- * @param gameType
- * a GameType
- */
- public void showDeck(final Deck deck, final GameType gameType) {
- this.setDeckData(deck.getName(), true);
- if (gameType.isLimited()) {
- this.deckDisplay.setDeck(deck.getSideboard(), deck.getMain(), gameType);
- } else {
- this.deckDisplay.setDeck(null, deck.getMain(), gameType);
- }
- }
-
- private void save() {
-
- if (this.currentDeckName.equals("")) {
- this.saveAs();
- return;
- }
-
- final Deck deck = this.getDeck();
- if (this.deckDisplay.getGameType().equals(GameType.Draft)) {
- this.setDeckData(this.currentDeckName, true);
- // write booster deck
- final Deck[] all = this.deckManager.getDraftDeck(this.currentDeckName);
- all[0] = deck;
- this.deckManager.addDraftDeck(all);
- DeckIO.writeDraftDecks(all);
- } else { // constructed or sealed
- this.setDeckData(this.currentDeckName, true);
- this.deckManager.addDeck(deck);
- DeckIO.writeDeck(deck, DeckIO.makeFileName(deck));
- }
- this.isDeckSaved = true;
- }
-
- private void saveAs() {
- final String name = this.getDeckNameFromDialog();
-
- if (name.equals("")) {
- return;
- }
- this.setDeckData(name, true);
-
- final Deck deck = this.getDeck();
- if (this.deckDisplay.getGameType().equals(GameType.Draft)) {
- // MUST copy array
- 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;
- this.deckManager.addDraftDeck(all);
- DeckIO.writeDraftDecks(all);
- } else { // constructed and sealed
- this.deckManager.addDeck(deck);
- DeckIO.writeDeck(deck, DeckIO.makeFileName(deck));
- }
- this.isDeckSaved = true;
- }
-
- private void delete() {
- if (StringUtils.isBlank(this.currentDeckName)) {
- return;
- }
-
- 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 (this.deckDisplay.getGameType().equals(GameType.Draft)) {
- this.deckManager.deleteDraftDeck(this.currentDeckName);
- } else {
- this.deckManager.deleteDeck(this.currentDeckName);
- }
-
- this.setDeckData("", true);
- this.deckDisplay.setDeck(null, null, this.deckDisplay.getGameType());
- }
-
- /**
- *
- * close window.
- */
- public void close() {
- if (!this.canLeaveCurrentDeck()) {
- return;
- }
- this.exitCommand.execute();
- }
-
- private boolean canLeaveCurrentDeck() {
- if (this.isSaved()) {
- return true;
- }
- 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;
- }
- if (JOptionPane.NO_OPTION == choice) {
- return true;
- }
-
- final Deck deck = this.getDeck();
- deck.setName(this.currentDeckName);
- DeckIO.writeDeck(deck, DeckIO.makeFileName(deck));
- return true;
- }
-
- private Deck getDeck() {
- final Deck deck = this.deckDisplay.getDeck();
- deck.setName(this.currentDeckName);
- return deck;
- }
-
- private void setDeckData(final String deckName, final boolean inDeckSaved) {
- this.currentDeckName = deckName;
- this.isDeckSaved = inDeckSaved;
-
- this.deckDisplay.setTitle("Deck Editor : " + this.currentDeckName);
- }
-
- /**
- *
- * Get Deck Name.
- *
- * @return a String
- */
- public String getDeckName() {
- return this.currentDeckName;
- }
-
- /**
- *
- * Is Saved.
- *
- * @return a boolean
- */
- public boolean isSaved() {
- return this.isDeckSaved;
- }
-
- /**
- *
- * getUserInput_GetDeckName.
- *
- *
- * @return a {@link java.lang.String} object.
- */
- private String getDeckNameFromDialog() {
- final Object o = JOptionPane.showInputDialog(null, "Save As", "Deck Name", JOptionPane.OK_CANCEL_OPTION);
-
- if (o == null) {
- return "";
- }
-
- final String deckName = DeckIO.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 this.getDeckNameFromDialog();
- }
-
- private String getUserInputOpenDeck(final GameType deckType) {
- final ArrayList choices = this.deckManager.getDeckNames(deckType);
- if (choices.isEmpty()) {
- JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE);
- return null;
- }
-
- final Object o = GuiUtils.getChoiceOptional("Open Deck", choices.toArray());
- return o == null ? null : o.toString();
- }
-
- // deck.setName(currentDeckName);
-
- /**
- *
- * Notify of a Deck Change.
- */
- public void notifyDeckChange() {
- this.isDeckSaved = false;
- }
-
- private void setupMenu() {
- final JMenuItem newConstructed = new JMenuItem("New Deck - Constructed");
-
- // JMenuItem newSealed = new JMenuItem("New Deck - Sealed");
- // JMenuItem newDraft = new JMenuItem("New Deck - Draft");
-
- final JMenuItem newRandomConstructed = new JMenuItem("New Deck - Generate Random Constructed Cardpool");
- final JMenuItem newGenerateConstructed = new JMenuItem("New Deck - Generate Constructed Deck");
-
- final JMenuItem importDeck = new JMenuItem("Import Deck...");
- final JMenuItem exportDeck = new JMenuItem("Export Deck...");
- // JMenuItem downloadDeck = new JMenuItem("Download Deck");
-
- 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);
-
- 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");
-
- final JMenu fileMenu = new JMenu("Deck Actions");
- fileMenu.add(newConstructed);
-
- // fileMenu.add(newSealed);
- // fileMenu.add(newDraft);
- fileMenu.addSeparator();
-
- fileMenu.add(openConstructed);
- fileMenu.add(openSealed);
- fileMenu.add(openDraft);
- fileMenu.addSeparator();
-
- fileMenu.add(importDeck);
- fileMenu.add(exportDeck);
-
- 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() {
- DeckEditorCommonMenu.this.generateProxies();
- }
- });
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : generateProxies() error - " + ex);
- }
- }
- });
- // fileMenu.add(downloadDeck);
- fileMenu.addSeparator();
-
- fileMenu.add(newRandomConstructed);
- fileMenu.add(newGenerateConstructed);
- fileMenu.addSeparator();
-
- fileMenu.add(save);
- fileMenu.add(saveAs);
- fileMenu.add(delete);
- fileMenu.addSeparator();
-
- fileMenu.add(close);
-
- this.add(fileMenu);
-
- // add listeners
- exportDeck.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- try {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- DeckEditorCommonMenu.this.exportDeck();
- }
- });
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error - " + ex);
- }
- }
- });
-
- importDeck.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- try {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- DeckEditorCommonMenu.this.importDeck();
- }
- });
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error - " + ex);
- }
- }
- });
-
- /*
- * downloadDeck.addActionListener(new ActionListener() { public void
- * actionPerformed(final ActionEvent ev) { try {
- * SwingUtilities.invokeLater(new Runnable() { public void run() {
- * downloadDeck(); } }); } catch (Exception ex) {
- * ErrorViewer.showError(ex); throw new
- * RuntimeException("Gui_DeckEditor_Menu : downloadDeck() error - " +
- * ex); } } });
- */
- newConstructed.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- try {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- DeckEditorCommonMenu.this.newConstructed(true);
- }
- });
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : newConstructed() error - " + ex);
- }
- }
- });
-
- newRandomConstructed.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- try {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- DeckEditorCommonMenu.this.newRandomConstructed();
- }
- });
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : newRandomConstructed() error - " + ex);
- }
- }
- });
-
- newGenerateConstructed.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- try {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- DeckEditorCommonMenu.this.newGenerateConstructed();
- }
- });
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : newRandomConstructed() error - " + ex);
- }
- }
- });
-
- openConstructed.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- try {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- DeckEditorCommonMenu.this.openDeck(GameType.Constructed);
- }
- });
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : openConstructed() error - " + ex);
- }
- }
- });
-
- openSealed.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- try {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- DeckEditorCommonMenu.this.openDeck(GameType.Sealed);
- }
- });
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : openSealed() error - " + ex);
- }
- }
- });
-
- openDraft.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- try {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- DeckEditorCommonMenu.this.openDeck(GameType.Draft);
- }
- });
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : openDraft() error - " + ex);
- }
- }
- });
-
- save.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- try {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- DeckEditorCommonMenu.this.save();
- }
- });
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : save() error - " + ex);
- }
- }
- });
-
- saveAs.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- try {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- DeckEditorCommonMenu.this.saveAs();
- }
- });
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : saveAs() error - " + ex);
- }
- }
- });
-
- delete.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- try {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- DeckEditorCommonMenu.this.delete();
- }
- });
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : delete() error - " + ex);
- }
- }
- });
-
- close.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent ev) {
- try {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- DeckEditorCommonMenu.this.close();
- }
- });
- } catch (final Exception ex) {
- ErrorViewer.showError(ex);
- throw new RuntimeException("Gui_DeckEditor_Menu : close() error - " + ex);
- }
- }
- });
- } // setupMenu()
-}
diff --git a/src/main/java/forge/gui/deckeditor/DeckEditorCommon.java b/src/main/java/forge/gui/deckeditor/DeckEditorConstructed.java
similarity index 75%
rename from src/main/java/forge/gui/deckeditor/DeckEditorCommon.java
rename to src/main/java/forge/gui/deckeditor/DeckEditorConstructed.java
index 499c6e3e45a..5558c3089e8 100644
--- a/src/main/java/forge/gui/deckeditor/DeckEditorCommon.java
+++ b/src/main/java/forge/gui/deckeditor/DeckEditorConstructed.java
@@ -36,16 +36,22 @@ import javax.swing.JCheckBox;
import javax.swing.JLabel;
import net.miginfocom.swing.MigLayout;
+import net.slightlymagic.braids.util.lambda.Lambda0;
import net.slightlymagic.maxmtg.Predicate;
import forge.AllZone;
import forge.Command;
+import forge.deck.Deck;
import forge.error.ErrorViewer;
-import forge.game.GameType;
+import forge.gui.deckeditor.elements.CardPanelHeavy;
+import forge.gui.deckeditor.elements.FilterCheckBoxes;
+import forge.gui.deckeditor.elements.FilterNameTypeSetPanel;
+import forge.gui.deckeditor.elements.ManaCostRenderer;
+import forge.gui.deckeditor.elements.TableColumnInfo;
+import forge.gui.deckeditor.elements.TableView;
import forge.item.CardDb;
import forge.item.CardPrinted;
import forge.item.InventoryItem;
import forge.item.ItemPool;
-import forge.item.ItemPoolView;
/**
*
@@ -55,13 +61,10 @@ import forge.item.ItemPoolView;
* @author Forge
* @version $Id$
*/
-public final class DeckEditorCommon extends DeckEditorBase {
+public final class DeckEditorConstructed extends DeckEditorBase {
/** Constant serialVersionUID=130339644136746796L. */
private static final long serialVersionUID = 130339644136746796L;
- /** The custom menu. */
- private DeckEditorCommonMenu customMenu;
-
private final JButton removeButton = new JButton();
private final JButton addButton = new JButton();
private final JButton importButton = new JButton();
@@ -72,6 +75,7 @@ public final class DeckEditorCommon extends DeckEditorBase {
private final JLabel jLabelAnalysisGap = new JLabel("");
private FilterNameTypeSetPanel filterNameTypeSet;
+ private final IDeckManager controller;
/**
* Show.
*
@@ -84,29 +88,24 @@ public final class DeckEditorCommon extends DeckEditorBase {
@Override
public void execute() {
- DeckEditorCommon.this.dispose();
+ DeckEditorConstructed.this.dispose();
exitCommand.execute();
}
};
- this.setCustomMenu(new DeckEditorCommonMenu(this, AllZone.getDeckManager(), exit));
- this.setJMenuBar(this.getCustomMenu());
+ final MenuCommon menu = new MenuCommon(getController(), exit);
+ this.setJMenuBar(menu);
// do not change this!!!!
this.addWindowListener(new WindowAdapter() {
@Override
- public void windowClosing(final WindowEvent ev) {
- DeckEditorCommon.this.getCustomMenu().close();
- }
+ public void windowClosing(final WindowEvent ev) {menu.close(); }
});
this.setup();
-
- // show cards, makes this user friendly
- if (!this.getGameType().isLimited()) {
- this.getCustomMenu().newConstructed(false);
- }
-
+
+ this.controller.newModel();
+
this.getTopTableWithCards().sort(1, true);
this.getBottomTableWithCards().sort(1, true);
@@ -114,24 +113,15 @@ public final class DeckEditorCommon extends DeckEditorBase {
private void setup() {
final List> columns = new ArrayList>();
- columns.add(new TableColumnInfo("Qty", 30, PresetColumns.FN_QTY_COMPARE,
- PresetColumns.FN_QTY_GET));
- columns.add(new TableColumnInfo("Name", 175, PresetColumns.FN_NAME_COMPARE,
- PresetColumns.FN_NAME_GET));
- columns.add(new TableColumnInfo("Cost", 75, PresetColumns.FN_COST_COMPARE,
- PresetColumns.FN_COST_GET));
- columns.add(new TableColumnInfo("Color", 60, PresetColumns.FN_COLOR_COMPARE,
- PresetColumns.FN_COLOR_GET));
- columns.add(new TableColumnInfo("Type", 100, PresetColumns.FN_TYPE_COMPARE,
- PresetColumns.FN_TYPE_GET));
- columns.add(new TableColumnInfo("Stats", 60, PresetColumns.FN_STATS_COMPARE,
- PresetColumns.FN_STATS_GET));
- columns.add(new TableColumnInfo("R", 25, PresetColumns.FN_RARITY_COMPARE,
- PresetColumns.FN_RARITY_GET));
- columns.add(new TableColumnInfo("Set", 40, PresetColumns.FN_SET_COMPARE,
- PresetColumns.FN_SET_GET));
- columns.add(new TableColumnInfo("AI", 30, PresetColumns.FN_AI_STATUS_COMPARE,
- PresetColumns.FN_AI_STATUS_GET));
+ columns.add(new TableColumnInfo("Qty", 30, PresetColumns.FN_QTY_COMPARE, PresetColumns.FN_QTY_GET));
+ columns.add(new TableColumnInfo("Name", 175, PresetColumns.FN_NAME_COMPARE, PresetColumns.FN_NAME_GET));
+ columns.add(new TableColumnInfo("Cost", 75, PresetColumns.FN_COST_COMPARE, PresetColumns.FN_COST_GET));
+ columns.add(new TableColumnInfo("Color", 60, PresetColumns.FN_COLOR_COMPARE, PresetColumns.FN_COLOR_GET));
+ columns.add(new TableColumnInfo