moved infiniteSupply flag into table model, since remove (that should not remove cards when supply is endless) method belongs to model layer.

This commit is contained in:
Maxmtg
2013-02-08 00:16:30 +00:00
parent 41b78e7313
commit 7b23e9d868
3 changed files with 31 additions and 11 deletions

View File

@@ -104,8 +104,7 @@ public enum CDeckEditorUI implements CardContainer {
void move(InventoryItem item, int qty); void move(InventoryItem item, int qty);
} }
private void moveSelectedCards( private void moveSelectedCards(EditorTableView<InventoryItem> table, _MoveAction moveAction, int maxQty) {
EditorTableView<InventoryItem> table, _MoveAction moveAction, int maxQty) {
List<InventoryItem> items = table.getSelectedCards(); List<InventoryItem> items = table.getSelectedCards();
if (items.isEmpty()) { if (items.isEmpty()) {

View File

@@ -68,6 +68,17 @@ public final class EditorTableModel<T extends InventoryItem> extends AbstractTab
private final JTable table; private final JTable table;
private final CascadeManager cascadeManager = new CascadeManager(); private final CascadeManager cascadeManager = new CascadeManager();
private final int maxSortDepth = 3; private final int maxSortDepth = 3;
private boolean infiniteSupply;
/**
* @return the infiniteSupply
*/
public boolean isInfinite() {
return infiniteSupply;
}
/** /**
* Instantiates a new table model, using a JTable, * Instantiates a new table model, using a JTable,
@@ -140,6 +151,9 @@ public final class EditorTableModel<T extends InventoryItem> extends AbstractTab
* @param card0 &emsp; {@link forge.Card} object * @param card0 &emsp; {@link forge.Card} object
*/ */
public void removeCard(final T card0, int qty) { public void removeCard(final T card0, int qty) {
if ( isInfinite() )
return;
final boolean wasThere = this.data.count(card0) > 0; final boolean wasThere = this.data.count(card0) > 0;
if (wasThere) { if (wasThere) {
this.data.remove(card0, qty); this.data.remove(card0, qty);
@@ -392,4 +406,13 @@ public final class EditorTableModel<T extends InventoryItem> extends AbstractTab
(Entry<InventoryItem, Integer>) o1, (Entry<InventoryItem, Integer>) o2); (Entry<InventoryItem, Integer>) o1, (Entry<InventoryItem, Integer>) o2);
} }
} }
/**
* TODO: Write javadoc for this method.
* @param infinite
*/
public void setInfinite(boolean infinite) {
// TODO Auto-generated method stub
this.infiniteSupply = infinite;
}
} // CardTableModel } // CardTableModel

View File

@@ -67,7 +67,6 @@ public final class EditorTableView<T extends InventoryItem> {
private boolean alwaysNonUnique = false; private boolean alwaysNonUnique = false;
private final Class<T> genericType; private final Class<T> genericType;
private boolean infiniteSupply;
/** /**
* *
@@ -279,8 +278,7 @@ public final class EditorTableView<T extends InventoryItem> {
* an Iterable<InventoryITem> * an Iterable<InventoryITem>
*/ */
public void setDeck(final Iterable<InventoryItem> cards) { public void setDeck(final Iterable<InventoryItem> cards) {
this.setDeckImpl(ItemPool.createFrom(cards, this.genericType)); this.setDeckImpl(ItemPool.createFrom(cards, this.genericType), false);
this.infiniteSupply = false;
} }
/** /**
@@ -290,8 +288,8 @@ public final class EditorTableView<T extends InventoryItem> {
* an ItemPoolView * an ItemPoolView
*/ */
public void setDeck(final ItemPoolView<T> poolView, boolean infinite) { public void setDeck(final ItemPoolView<T> poolView, boolean infinite) {
this.setDeckImpl(ItemPool.createFrom(poolView, this.genericType)); this.setDeckImpl(ItemPool.createFrom(poolView, this.genericType), infinite);
this.infiniteSupply = infinite;
} }
public void setDeck(final ItemPoolView<T> poolView) { public void setDeck(final ItemPoolView<T> poolView) {
this.setDeck(poolView, false); this.setDeck(poolView, false);
@@ -303,8 +301,7 @@ public final class EditorTableView<T extends InventoryItem> {
* the new deck * the new deck
*/ */
public void setDeck(final ItemPool<T> pool) { public void setDeck(final ItemPool<T> pool) {
this.setDeckImpl(pool); this.setDeckImpl(pool, false);
this.infiniteSupply = false;
} }
/** /**
@@ -314,10 +311,11 @@ public final class EditorTableView<T extends InventoryItem> {
* @param thePool * @param thePool
* an ItemPool * an ItemPool
*/ */
protected void setDeckImpl(final ItemPool<T> thePool) { protected void setDeckImpl(final ItemPool<T> thePool, boolean infinite) {
this.model.clear(); this.model.clear();
this.pool = thePool; this.pool = thePool;
this.model.addCards(this.pool); this.model.addCards(this.pool);
this.model.setInfinite(infinite);
this.updateView(true); this.updateView(true);
} }
@@ -432,7 +430,7 @@ public final class EditorTableView<T extends InventoryItem> {
} }
public int getCardCount(final T card) { 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<T> getFilter() { public Predicate<T> getFilter() {