diff --git a/forge-core/src/main/java/forge/deck/Deck.java b/forge-core/src/main/java/forge/deck/Deck.java index b25847a5588..ceddc208f4b 100644 --- a/forge-core/src/main/java/forge/deck/Deck.java +++ b/forge-core/src/main/java/forge/deck/Deck.java @@ -106,8 +106,9 @@ public class Deck extends DeckBase implements Iterable kv : parts.entrySet()) { + for (Entry kv : parts.entrySet()) { CardPool cp = new CardPool(); result.parts.put(kv.getKey(), cp); cp.addAll(kv.getValue()); @@ -165,7 +166,7 @@ public class Deck extends DeckBase implements Iterable> sections, final boolean canThrowExtendedErrors) { - if ((sections == null) || sections.isEmpty()) { + if (sections == null || sections.isEmpty()) { return null; } @@ -178,18 +179,21 @@ public class Deck extends DeckBase implements Iterable> s : sections.entrySet()) { + for (Entry> s : sections.entrySet()) { DeckSection sec = DeckSection.smartValueOf(s.getKey()); - if ( null == sec ) + if (sec == null) { continue; - + } + CardPool pool = CardPool.fromCardList(s.getValue()); // I used to store planes and schemes under sideboard header, so this will assign them to a correct section IPaperCard sample = pool.get(0); - if ( sample != null && ( sample.getRules().getType().isPlane() || sample.getRules().getType().isPhenomenon() ) ) + if (sample != null && ( sample.getRules().getType().isPlane() || sample.getRules().getType().isPhenomenon())) { sec = DeckSection.Planes; - if ( sample != null && sample.getRules().getType().isScheme() ) + } + if (sample != null && sample.getRules().getType().isScheme()) { sec = DeckSection.Schemes; + } d.parts.put(sec, pool); } diff --git a/forge-gui/src/main/java/forge/gui/deckeditor/controllers/ACEditorBase.java b/forge-gui/src/main/java/forge/gui/deckeditor/controllers/ACEditorBase.java index 0807f5ee48f..4947064cc9c 100644 --- a/forge-gui/src/main/java/forge/gui/deckeditor/controllers/ACEditorBase.java +++ b/forge-gui/src/main/java/forge/gui/deckeditor/controllers/ACEditorBase.java @@ -23,6 +23,7 @@ import javax.swing.SwingUtilities; import forge.Command; import forge.deck.DeckBase; +import forge.deck.DeckSection; import forge.gui.deckeditor.CDeckEditorUI; import forge.gui.framework.DragCell; import forge.gui.framework.FScreen; @@ -69,6 +70,7 @@ public abstract class ACEditorBase catalogManager; private ItemManager deckManager; + protected DeckSection sectionMode = DeckSection.Main; // card transfer buttons private final FLabel btnAdd = new FLabel.Builder() @@ -113,6 +115,10 @@ public abstract class ACEditorBase { private DragCell deckGenParent = null; private List allSections = new ArrayList(); - private DeckSection sectionMode = DeckSection.Main; private final ItemPoolView commanderPool; private final ItemPoolView normalPool; @@ -162,6 +159,7 @@ public final class CEditorCommander extends ACEditorBase { */ @Override public void resetTables() { + this.sectionMode = DeckSection.Main; this.getCatalogManager().setPool(normalPool,false); this.getDeckManager().setPool(this.controller.getModel().getOrCreate(DeckSection.Main)); } @@ -240,52 +238,29 @@ public final class CEditorCommander extends ACEditorBase { final List> lstCatalogCols = SColumnUtil.getCatalogDefaultColumns(); - String title = ""; - String tabtext = ""; - Boolean showOptions = true; - switch(sectionMode) - { + switch(sectionMode) { case Main: lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY)); this.getCatalogManager().getTable().setAvailableColumns(lstCatalogCols); this.getCatalogManager().setPool(normalPool, false); this.getDeckManager().setPool(this.controller.getModel().getMain()); - showOptions = true; - title = "Title: "; - tabtext = "Main Deck"; break; case Sideboard: lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY)); this.getCatalogManager().getTable().setAvailableColumns(lstCatalogCols); this.getCatalogManager().setPool(normalPool, false); this.getDeckManager().setPool(this.controller.getModel().getOrCreate(DeckSection.Sideboard)); - showOptions = false; - title = "Sideboard"; - tabtext = "Card Catalog"; break; case Commander: lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY)); this.getCatalogManager().getTable().setAvailableColumns(lstCatalogCols); this.getCatalogManager().setPool(commanderPool, true); this.getDeckManager().setPool(this.controller.getModel().getOrCreate(DeckSection.Commander)); - showOptions = false; - title = "Commander"; - tabtext = "Card Catalog"; break; default: break; } - VCardCatalog.SINGLETON_INSTANCE.getTabLabel().setText(tabtext); - VCurrentDeck.SINGLETON_INSTANCE.getBtnNew().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getBtnOpen().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getBtnSave().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getBtnSaveAs().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getBtnPrintProxies().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getBtnImport().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getLblTitle().setText(title); - - this.controller.notifyModelChanged(); + this.controller.updateCaptions(); } } diff --git a/forge-gui/src/main/java/forge/gui/deckeditor/controllers/CEditorConstructed.java b/forge-gui/src/main/java/forge/gui/deckeditor/controllers/CEditorConstructed.java index cdd0bca708f..ef10f5619bc 100644 --- a/forge-gui/src/main/java/forge/gui/deckeditor/controllers/CEditorConstructed.java +++ b/forge-gui/src/main/java/forge/gui/deckeditor/controllers/CEditorConstructed.java @@ -30,8 +30,6 @@ import forge.card.CardRulesPredicates; import forge.deck.Deck; import forge.deck.DeckSection; import forge.gui.deckeditor.SEditorIO; -import forge.gui.deckeditor.views.VCardCatalog; -import forge.gui.deckeditor.views.VCurrentDeck; import forge.gui.framework.FScreen; import forge.gui.toolbox.itemmanager.CardManager; import forge.gui.toolbox.itemmanager.SItemManagerIO; @@ -57,14 +55,8 @@ import forge.util.ItemPoolView; */ public final class CEditorConstructed extends ACEditorBase { private final DeckController controller; - //private boolean sideboardMode = false; - - private List allSections = new ArrayList(); - private DeckSection sectionMode = DeckSection.Main; - - private final ItemPoolView avatarPool; - private final ItemPoolView planePool; - private final ItemPoolView schemePool; + private final List allSections = new ArrayList(); + private final ItemPoolView normalPool, avatarPool, planePool, schemePool; //=========== Constructor /** @@ -82,6 +74,7 @@ public final class CEditorConstructed extends ACEditorBase { allSections.add(DeckSection.Planes); //allSections.add(DeckSection.Commander); + normalPool = ItemPool.createFrom(Singletons.getMagicDb().getCommonCards().getAllCards(), PaperCard.class); avatarPool = ItemPool.createFrom(Singletons.getMagicDb().getVariantCards().getAllCards(Predicates.compose(CardRulesPredicates.Presets.IS_VANGUARD, PaperCard.FN_GET_RULES)),PaperCard.class); planePool = ItemPool.createFrom(Singletons.getMagicDb().getVariantCards().getAllCards(Predicates.compose(CardRulesPredicates.Presets.IS_PLANE_OR_PHENOMENON, PaperCard.FN_GET_RULES)),PaperCard.class); schemePool = ItemPool.createFrom(Singletons.getMagicDb().getVariantCards().getAllCards(Predicates.compose(CardRulesPredicates.Presets.IS_SCHEME, PaperCard.FN_GET_RULES)),PaperCard.class); @@ -176,7 +169,8 @@ public final class CEditorConstructed extends ACEditorBase { @Override public void resetTables() { // Constructed mode can use all cards, no limitations. - this.getCatalogManager().setPool(ItemPool.createFrom(Singletons.getMagicDb().getCommonCards().getAllCards(), PaperCard.class), true); + this.sectionMode = DeckSection.Main; + this.getCatalogManager().setPool(normalPool, true); this.getDeckManager().setPool(this.controller.getModel().getMain()); } @@ -201,26 +195,18 @@ public final class CEditorConstructed extends ACEditorBase { final List> lstCatalogCols = SColumnUtil.getCatalogDefaultColumns(); - String title = ""; - String tabtext = ""; - Boolean showOptions = true; switch(sectionMode) { case Main: lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY)); this.getCatalogManager().getTable().setAvailableColumns(lstCatalogCols); - this.getCatalogManager().setPool(ItemPool.createFrom(Singletons.getMagicDb().getCommonCards().getAllCards(), PaperCard.class), true); + this.getCatalogManager().setPool(normalPool, true); this.getDeckManager().setPool(this.controller.getModel().getMain()); - showOptions = true; - title = "Title: "; - tabtext = "Main Deck"; break; case Sideboard: + lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY)); this.getCatalogManager().getTable().setAvailableColumns(lstCatalogCols); - this.getCatalogManager().setPool(this.controller.getModel().getMain()); + this.getCatalogManager().setPool(normalPool, true); this.getDeckManager().setPool(this.controller.getModel().getOrCreate(DeckSection.Sideboard)); - showOptions = false; - title = "Sideboard"; - tabtext = "Card Catalog"; break; case Avatar: lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY)); @@ -232,9 +218,6 @@ public final class CEditorConstructed extends ACEditorBase { this.getCatalogManager().getTable().setAvailableColumns(lstCatalogCols); this.getCatalogManager().setPool(avatarPool, true); this.getDeckManager().setPool(this.controller.getModel().getOrCreate(DeckSection.Avatar)); - showOptions = false; - title = "Vanguard"; - tabtext = "Card Catalog"; break; case Planes: lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY)); @@ -246,9 +229,6 @@ public final class CEditorConstructed extends ACEditorBase { this.getCatalogManager().getTable().setAvailableColumns(lstCatalogCols); this.getCatalogManager().setPool(planePool,true); this.getDeckManager().setPool(this.controller.getModel().getOrCreate(DeckSection.Planes)); - showOptions = false; - title = "Planar"; - tabtext = "Card Catalog"; break; case Schemes: lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY)); @@ -260,25 +240,12 @@ public final class CEditorConstructed extends ACEditorBase { this.getCatalogManager().getTable().setAvailableColumns(lstCatalogCols); this.getCatalogManager().setPool(schemePool,true); this.getDeckManager().setPool(this.controller.getModel().getOrCreate(DeckSection.Schemes)); - showOptions = false; - title = "Scheme"; - tabtext = "Card Catalog"; break; case Commander: break; //do nothing for Commander here } - VCardCatalog.SINGLETON_INSTANCE.getTabLabel().setText(tabtext); - VCurrentDeck.SINGLETON_INSTANCE.getBtnNew().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getBtnOpen().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getBtnSave().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getBtnSaveAs().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getBtnPrintProxies().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getBtnImport().setVisible(showOptions); - VCurrentDeck.SINGLETON_INSTANCE.getLblTitle().setText(title); - - this.controller.notifyModelChanged(); + this.controller.updateCaptions(); } /* (non-Javadoc) diff --git a/forge-gui/src/main/java/forge/gui/deckeditor/controllers/DeckController.java b/forge-gui/src/main/java/forge/gui/deckeditor/controllers/DeckController.java index 9469bf3c7f7..0dcf8e91df2 100644 --- a/forge-gui/src/main/java/forge/gui/deckeditor/controllers/DeckController.java +++ b/forge-gui/src/main/java/forge/gui/deckeditor/controllers/DeckController.java @@ -33,15 +33,8 @@ import forge.util.storage.IStorage; * * @param the generic type */ -/** - * TODO: Write javadoc for this type. - * - * @param - */ public class DeckController { - private T model; - private String modelName; private boolean saved; private boolean modelInStore; private final IStorage folder; @@ -60,7 +53,6 @@ public class DeckController { this.folder = folder0; this.view = view0; this.model = null; - this.modelName = null; this.saved = true; this.modelInStore = false; this.newModelCreator = newModelCreator0; @@ -78,22 +70,13 @@ public class DeckController { /** * Sets the model. * - * @param document the new model */ public void setModel(final T document) { this.setModel(document, false); } - - /** - * Sets the model. - * - * @param document the document - * @param isStored the is stored - */ public void setModel(final T document, final boolean isStored) { this.modelInStore = isStored; this.model = document; - this.modelName = document.getName(); this.view.resetTables(); CStatistics.SINGLETON_INSTANCE.update(); @@ -101,7 +84,8 @@ public class DeckController { if (this.isModelInSyncWithFolder()) { _setSaved(true); - } else { + } + else { this.notifyModelChanged(); } } @@ -116,7 +100,7 @@ public class DeckController { if (modelStored == this.model) { return true; } - if (null == modelStored) { + if (modelStored == null) { return false; } @@ -132,11 +116,6 @@ public class DeckController { return this.view; } - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.IDeckController#notifyModelChanged() - */ /** * Notify model changed. */ @@ -148,12 +127,7 @@ public class DeckController { saved = val; updateCaptions(); } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.IDeckController#getSavedModelNames() - */ + /** * Gets the saved names. * @@ -163,11 +137,6 @@ public class DeckController { return new ArrayList(this.folder.getItemNames()); } - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.IDeckController#load(java.lang.String) - */ /** * Load. * @@ -176,38 +145,30 @@ public class DeckController { @SuppressWarnings("unchecked") public void load(final String name) { T newModel = this.folder.get(name); - if (null != newModel) { + if (newModel != null) { this.setModel((T) newModel.copyTo(name), true); } - _setSaved(true); + else { + _setSaved(true); + } } - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.IDeckController#save() - */ /** * Save. */ @SuppressWarnings("unchecked") public void save() { - if (null == model) { + if (model == null) { return; } this.folder.add(this.model); // copy to new instance which will be edited and left if unsaved - this.setModel((T) this.model.copyTo(this.model.getName()), true); + this.model = (T)this.model.copyTo(this.model.getName()); this.modelInStore = true; _setSaved(true); } - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.IDeckController#rename(java.lang.String) - */ /** * Save as. * @@ -215,16 +176,11 @@ public class DeckController { */ @SuppressWarnings("unchecked") public void saveAs(final String name0) { - this.setModel((T) this.model.copyTo(name0), false); + this.model = (T)this.model.copyTo(name0); + this.modelInStore = false; this.save(); } - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.IDeckController#isSaved() - */ - /** * Checks if is saved. * @@ -234,12 +190,6 @@ public class DeckController { return this.saved; } - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.IDeckController#delete() - */ - /** * Delete. */ @@ -251,12 +201,6 @@ public class DeckController { this.newModel(); } - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.IDeckController#isGoodName(java.lang.String) - */ - /** * File exists. * @@ -267,12 +211,6 @@ public class DeckController { return this.folder.contains(deckName); } - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.IDeckController#importDeck(forge.deck.Deck) - */ - /** * Import deck. * @@ -282,12 +220,6 @@ public class DeckController { this.setModel(newDeck); } - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.IDeckController#isModelInStore() - */ - /** * Checks if is model in store. * @@ -319,17 +251,20 @@ public class DeckController { } public String getModelName() { - return modelName; + return this.model != null ? this.model.getName() : ""; } - - private void updateCaptions() { + + public void updateCaptions() { String tabCaption = "Current Deck"; String title = this.model.getName(); String itemManagerCaption = title.isEmpty() ? "[Untitled]" : title; + if (!saved) { tabCaption = "*" + tabCaption; itemManagerCaption = "*" + itemManagerCaption; } + itemManagerCaption += " - " + this.view.getSectionMode().name(); + VCurrentDeck.SINGLETON_INSTANCE.getTabLabel().setText(tabCaption); VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().setText(title); VCurrentDeck.SINGLETON_INSTANCE.getItemManager().setCaption(itemManagerCaption);