From 7b23e9d868e8c7d5fbc2b375326ba9a6fb24b30e Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Fri, 8 Feb 2013 00:16:30 +0000 Subject: [PATCH] moved infiniteSupply flag into table model, since remove (that should not remove cards when supply is endless) method belongs to model layer. --- .../forge/gui/deckeditor/CDeckEditorUI.java | 3 +-- .../deckeditor/tables/EditorTableModel.java | 23 +++++++++++++++++++ .../deckeditor/tables/EditorTableView.java | 16 ++++++------- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/main/java/forge/gui/deckeditor/CDeckEditorUI.java b/src/main/java/forge/gui/deckeditor/CDeckEditorUI.java index ab2c6eec43e..db5944c8707 100644 --- a/src/main/java/forge/gui/deckeditor/CDeckEditorUI.java +++ b/src/main/java/forge/gui/deckeditor/CDeckEditorUI.java @@ -104,8 +104,7 @@ public enum CDeckEditorUI implements CardContainer { void move(InventoryItem item, int qty); } - private void moveSelectedCards( - EditorTableView table, _MoveAction moveAction, int maxQty) { + private void moveSelectedCards(EditorTableView table, _MoveAction moveAction, int maxQty) { List items = table.getSelectedCards(); if (items.isEmpty()) { diff --git a/src/main/java/forge/gui/deckeditor/tables/EditorTableModel.java b/src/main/java/forge/gui/deckeditor/tables/EditorTableModel.java index b3dcf6d5b54..c82dd66764b 100644 --- a/src/main/java/forge/gui/deckeditor/tables/EditorTableModel.java +++ b/src/main/java/forge/gui/deckeditor/tables/EditorTableModel.java @@ -68,6 +68,17 @@ public final class EditorTableModel extends AbstractTab private final JTable table; private final CascadeManager cascadeManager = new CascadeManager(); private final int maxSortDepth = 3; + private boolean infiniteSupply; + + /** + * @return the infiniteSupply + */ + public boolean isInfinite() { + return infiniteSupply; + } + + + /** * Instantiates a new table model, using a JTable, @@ -140,6 +151,9 @@ public final class EditorTableModel extends AbstractTab * @param card0   {@link forge.Card} object */ public void removeCard(final T card0, int qty) { + if ( isInfinite() ) + return; + final boolean wasThere = this.data.count(card0) > 0; if (wasThere) { this.data.remove(card0, qty); @@ -392,4 +406,13 @@ public final class EditorTableModel extends AbstractTab (Entry) o1, (Entry) o2); } } + + /** + * TODO: Write javadoc for this method. + * @param infinite + */ + public void setInfinite(boolean infinite) { + // TODO Auto-generated method stub + this.infiniteSupply = infinite; + } } // CardTableModel diff --git a/src/main/java/forge/gui/deckeditor/tables/EditorTableView.java b/src/main/java/forge/gui/deckeditor/tables/EditorTableView.java index f5385c3af52..c4e27e2bf02 100644 --- a/src/main/java/forge/gui/deckeditor/tables/EditorTableView.java +++ b/src/main/java/forge/gui/deckeditor/tables/EditorTableView.java @@ -67,7 +67,6 @@ public final class EditorTableView { private boolean alwaysNonUnique = false; private final Class genericType; - private boolean infiniteSupply; /** * @@ -279,8 +278,7 @@ public final class EditorTableView { * an Iterable */ public void setDeck(final Iterable cards) { - this.setDeckImpl(ItemPool.createFrom(cards, this.genericType)); - this.infiniteSupply = false; + this.setDeckImpl(ItemPool.createFrom(cards, this.genericType), false); } /** @@ -290,8 +288,8 @@ public final class EditorTableView { * an ItemPoolView */ public void setDeck(final ItemPoolView poolView, boolean infinite) { - this.setDeckImpl(ItemPool.createFrom(poolView, this.genericType)); - this.infiniteSupply = infinite; + this.setDeckImpl(ItemPool.createFrom(poolView, this.genericType), infinite); + } public void setDeck(final ItemPoolView poolView) { this.setDeck(poolView, false); @@ -303,8 +301,7 @@ public final class EditorTableView { * the new deck */ public void setDeck(final ItemPool pool) { - this.setDeckImpl(pool); - this.infiniteSupply = false; + this.setDeckImpl(pool, false); } /** @@ -314,10 +311,11 @@ public final class EditorTableView { * @param thePool * an ItemPool */ - protected void setDeckImpl(final ItemPool thePool) { + protected void setDeckImpl(final ItemPool thePool, boolean infinite) { this.model.clear(); this.pool = thePool; this.model.addCards(this.pool); + this.model.setInfinite(infinite); this.updateView(true); } @@ -432,7 +430,7 @@ public final class EditorTableView { } public int getCardCount(final T card) { - return infiniteSupply ? Integer.MAX_VALUE : this.pool.count(card); + return model.isInfinite() ? Integer.MAX_VALUE : this.pool.count(card); } public Predicate getFilter() {