mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
Remove need for ITableContainer
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -15002,7 +15002,6 @@ src/main/java/forge/gui/toolbox/itemmanager/SItemManagerIO.java -text
|
||||
src/main/java/forge/gui/toolbox/itemmanager/SItemManagerUtil.java -text
|
||||
src/main/java/forge/gui/toolbox/itemmanager/package-info.java -text
|
||||
src/main/java/forge/gui/toolbox/itemmanager/table/AlwaysShowToolTip.java -text
|
||||
src/main/java/forge/gui/toolbox/itemmanager/table/ITableContainer.java -text
|
||||
src/main/java/forge/gui/toolbox/itemmanager/table/IntegerRenderer.java -text
|
||||
src/main/java/forge/gui/toolbox/itemmanager/table/ItemTable.java -text
|
||||
src/main/java/forge/gui/toolbox/itemmanager/table/ItemTableModel.java -text
|
||||
|
||||
@@ -108,7 +108,7 @@ public enum CCardCatalog implements ICDoc {
|
||||
}
|
||||
};
|
||||
|
||||
for (Map.Entry<SItemManagerUtil.StatTypes, FLabel> entry : VCardCatalog.SINGLETON_INSTANCE.getStatLabels().entrySet()) {
|
||||
for (Map.Entry<SItemManagerUtil.StatTypes, FLabel> entry : VCardCatalog.SINGLETON_INSTANCE.getItemManager().getStatLabels().entrySet()) {
|
||||
final FLabel statLabel = entry.getValue();
|
||||
statLabel.setCommand(updateFilterCommand);
|
||||
|
||||
@@ -123,7 +123,7 @@ public enum CCardCatalog implements ICDoc {
|
||||
disableFiltering = true;
|
||||
for (SItemManagerUtil.StatTypes s : SItemManagerUtil.StatTypes.values()) {
|
||||
if (s.group == group && s != st) {
|
||||
VCardCatalog.SINGLETON_INSTANCE.getStatLabel(s).setSelected(false);
|
||||
VCardCatalog.SINGLETON_INSTANCE.getItemManager().getStatLabel(s).setSelected(false);
|
||||
}
|
||||
}
|
||||
statLabel.setSelected(true);
|
||||
@@ -135,7 +135,7 @@ public enum CCardCatalog implements ICDoc {
|
||||
}
|
||||
}
|
||||
|
||||
VCardCatalog.SINGLETON_INSTANCE.getStatLabel(SItemManagerUtil.StatTypes.TOTAL).setCommand(new Command() {
|
||||
VCardCatalog.SINGLETON_INSTANCE.getItemManager().getStatLabel(SItemManagerUtil.StatTypes.TOTAL).setCommand(new Command() {
|
||||
private boolean lastToggle = true;
|
||||
|
||||
@Override
|
||||
@@ -144,7 +144,7 @@ public enum CCardCatalog implements ICDoc {
|
||||
lastToggle = !lastToggle;
|
||||
for (SItemManagerUtil.StatTypes s : SItemManagerUtil.StatTypes.values()) {
|
||||
if (SItemManagerUtil.StatTypes.TOTAL != s) {
|
||||
VCardCatalog.SINGLETON_INSTANCE.getStatLabel(s).setSelected(lastToggle);
|
||||
VCardCatalog.SINGLETON_INSTANCE.getItemManager().getStatLabel(s).setSelected(lastToggle);
|
||||
}
|
||||
}
|
||||
disableFiltering = false;
|
||||
@@ -351,7 +351,7 @@ public enum CCardCatalog implements ICDoc {
|
||||
|
||||
List<Predicate<? super PaperCard>> cardPredicates = new ArrayList<Predicate<? super PaperCard>>();
|
||||
cardPredicates.add(Predicates.instanceOf(PaperCard.class));
|
||||
cardPredicates.add(SFilterUtil.buildColorAndTypeFilter(VCardCatalog.SINGLETON_INSTANCE.getStatLabels()));
|
||||
cardPredicates.add(SFilterUtil.buildColorAndTypeFilter(VCardCatalog.SINGLETON_INSTANCE.getItemManager().getStatLabels()));
|
||||
cardPredicates.addAll(activePredicates);
|
||||
|
||||
// apply current values in the range filters
|
||||
@@ -373,7 +373,7 @@ public enum CCardCatalog implements ICDoc {
|
||||
|
||||
// show packs and decks in the card shop according to the toggle setting
|
||||
// this is special-cased apart from the buildColorAndTypeFilter() above
|
||||
if (VCardCatalog.SINGLETON_INSTANCE.getStatLabel(StatTypes.PACK).getSelected()) {
|
||||
if (VCardCatalog.SINGLETON_INSTANCE.getItemManager().getStatLabel(StatTypes.PACK).getSelected()) {
|
||||
List<Predicate<? super PaperCard>> itemPredicates = new ArrayList<Predicate<? super PaperCard>>();
|
||||
itemPredicates.add(cardFilter);
|
||||
itemPredicates.add(ItemPredicate.Presets.IS_PACK);
|
||||
|
||||
@@ -125,7 +125,7 @@ public final class CEditorConstructed extends ACEditorBase<PaperCard, Deck> {
|
||||
}
|
||||
|
||||
if (sectionMode == DeckSection.Avatar || sectionMode == DeckSection.Commander) {
|
||||
for(Map.Entry<PaperCard, Integer> cp : getDeckManager().getItems()) {
|
||||
for(Map.Entry<PaperCard, Integer> cp : getDeckManager().getPool()) {
|
||||
getDeckManager().removeItem(cp.getKey(), cp.getValue());
|
||||
}
|
||||
}
|
||||
@@ -310,8 +310,8 @@ public final class CEditorConstructed extends ACEditorBase<PaperCard, Deck> {
|
||||
final List<TableColumnInfo<InventoryItem>> lstCatalogCols = SColumnUtil.getCatalogDefaultColumns();
|
||||
lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY));
|
||||
|
||||
this.getCatalogManager().getTable().setup(VCardCatalog.SINGLETON_INSTANCE, lstCatalogCols);
|
||||
this.getDeckManager().getTable().setup(VCurrentDeck.SINGLETON_INSTANCE, SColumnUtil.getDeckDefaultColumns());
|
||||
this.getCatalogManager().getTable().setup(lstCatalogCols);
|
||||
this.getDeckManager().getTable().setup(SColumnUtil.getDeckDefaultColumns());
|
||||
|
||||
SItemManagerUtil.resetUI();
|
||||
|
||||
|
||||
@@ -93,8 +93,8 @@ public class CEditorDraftingProcess extends ACEditorBase<PaperCard, DeckGroup> {
|
||||
* </p>
|
||||
*/
|
||||
private void setup() {
|
||||
this.getCatalogManager().getTable().setup(VCardCatalog.SINGLETON_INSTANCE, SColumnUtil.getCatalogDefaultColumns());
|
||||
this.getDeckManager().getTable().setup(VCurrentDeck.SINGLETON_INSTANCE, SColumnUtil.getDeckDefaultColumns());
|
||||
this.getCatalogManager().getTable().setup(SColumnUtil.getCatalogDefaultColumns());
|
||||
this.getDeckManager().getTable().setup(SColumnUtil.getDeckDefaultColumns());
|
||||
|
||||
ccAddLabel = VCardCatalog.SINGLETON_INSTANCE.getBtnAdd().getText();
|
||||
VCardCatalog.SINGLETON_INSTANCE.getBtnAdd().setText("Choose Card");
|
||||
@@ -171,7 +171,7 @@ public class CEditorDraftingProcess extends ACEditorBase<PaperCard, DeckGroup> {
|
||||
|
||||
// add sideboard to deck
|
||||
CardPool side = deck.getOrCreate(DeckSection.Sideboard);
|
||||
side.addAll(this.getDeckManager().getItems());
|
||||
side.addAll(this.getDeckManager().getPool());
|
||||
|
||||
final CardEdition landSet = IBoosterDraft.LAND_SET_CODE[0];
|
||||
final int landsCount = 20;
|
||||
|
||||
@@ -160,8 +160,8 @@ public final class CEditorLimited extends ACEditorBase<PaperCard, DeckGroup> {
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
this.getCatalogManager().getTable().setup(VCardCatalog.SINGLETON_INSTANCE, SColumnUtil.getCatalogDefaultColumns());
|
||||
this.getDeckManager().getTable().setup(VCurrentDeck.SINGLETON_INSTANCE, SColumnUtil.getDeckDefaultColumns());
|
||||
this.getCatalogManager().getTable().setup(SColumnUtil.getCatalogDefaultColumns());
|
||||
this.getDeckManager().getTable().setup(SColumnUtil.getDeckDefaultColumns());
|
||||
|
||||
SItemManagerUtil.resetUI();
|
||||
|
||||
|
||||
@@ -278,8 +278,8 @@ public final class CEditorQuest extends ACEditorBase<PaperCard, Deck> {
|
||||
columnsDeck.get(columnsDeck.size() - 1).setSortAndDisplayFunctions(
|
||||
this.fnDeckCompare, this.fnDeckGet);
|
||||
|
||||
this.getCatalogManager().getTable().setup(VCardCatalog.SINGLETON_INSTANCE, columnsCatalog);
|
||||
this.getDeckManager().getTable().setup(VCurrentDeck.SINGLETON_INSTANCE, columnsDeck);
|
||||
this.getCatalogManager().getTable().setup(columnsCatalog);
|
||||
this.getDeckManager().getTable().setup(columnsDeck);
|
||||
|
||||
Deck deck = new Deck();
|
||||
|
||||
|
||||
@@ -188,8 +188,8 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
columnsDeck.remove(SColumnUtil.getColumn(ColumnName.DECK_AI));
|
||||
|
||||
// Setup with current column set
|
||||
this.getCatalogManager().getTable().setup(VCardCatalog.SINGLETON_INSTANCE, columnsCatalog);
|
||||
this.getDeckManager().getTable().setup(VCurrentDeck.SINGLETON_INSTANCE, columnsDeck);
|
||||
this.getCatalogManager().getTable().setup(columnsCatalog);
|
||||
this.getDeckManager().getTable().setup(columnsDeck);
|
||||
|
||||
SItemManagerUtil.resetUI();
|
||||
|
||||
@@ -505,7 +505,7 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
@Override
|
||||
public void run() {
|
||||
List<Map.Entry<InventoryItem, Integer>> cardsToRemove = new LinkedList<Map.Entry<InventoryItem,Integer>>();
|
||||
for (Map.Entry<InventoryItem, Integer> item : getDeckManager().getItems()) {
|
||||
for (Map.Entry<InventoryItem, Integer> item : getDeckManager().getPool()) {
|
||||
PaperCard card = (PaperCard)item.getKey();
|
||||
int numToKeep = card.getRules().getType().isBasic() ? 50 : 4;
|
||||
if ("Relentless Rats".equals(card.getName())) {
|
||||
@@ -536,7 +536,7 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
this.sellPercentageLabel.setText("<html>Selling cards at " + formatter.format(multiPercent)
|
||||
+ "% of their value.<br>" + maxSellingPrice + "</html>");
|
||||
|
||||
VCardCatalog.SINGLETON_INSTANCE.getStatLabel(SItemManagerUtil.StatTypes.PACK).setVisible(true);
|
||||
VCardCatalog.SINGLETON_INSTANCE.getItemManager().getStatLabel(SItemManagerUtil.StatTypes.PACK).setVisible(true);
|
||||
|
||||
deckGenParent = removeTab(VDeckgen.SINGLETON_INSTANCE);
|
||||
allDecksParent = removeTab(VAllDecks.SINGLETON_INSTANCE);
|
||||
@@ -571,7 +571,7 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
VCardCatalog.SINGLETON_INSTANCE.getBtnAdd().setText(CCAddLabel);
|
||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove().setText(CDRemLabel);
|
||||
|
||||
VCardCatalog.SINGLETON_INSTANCE.getStatLabel(SItemManagerUtil.StatTypes.PACK).setVisible(false);
|
||||
VCardCatalog.SINGLETON_INSTANCE.getItemManager().getStatLabel(SItemManagerUtil.StatTypes.PACK).setVisible(false);
|
||||
|
||||
//Re-add tabs
|
||||
if (deckGenParent != null) {
|
||||
|
||||
@@ -165,8 +165,8 @@ public final class CEditorVariant extends ACEditorBase<PaperCard, Deck> {
|
||||
final List<TableColumnInfo<InventoryItem>> lstCatalogCols = SColumnUtil.getCatalogDefaultColumns();
|
||||
lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY));
|
||||
|
||||
this.getCatalogManager().getTable().setup(VCardCatalog.SINGLETON_INSTANCE, lstCatalogCols);
|
||||
this.getDeckManager().getTable().setup(VCurrentDeck.SINGLETON_INSTANCE, SColumnUtil.getDeckDefaultColumns());
|
||||
this.getCatalogManager().getTable().setup(lstCatalogCols);
|
||||
this.getDeckManager().getTable().setup(SColumnUtil.getDeckDefaultColumns());
|
||||
|
||||
SItemManagerUtil.resetUI();
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public enum CProbabilities implements ICDoc {
|
||||
|
||||
if (ed == null) { return new ArrayList<String>(); }
|
||||
|
||||
final ItemPoolView<PaperCard> deck = ItemPool.createFrom(ed.getDeckManager().getItems(), PaperCard.class);
|
||||
final ItemPoolView<PaperCard> deck = ItemPool.createFrom(ed.getDeckManager().getPool(), PaperCard.class);
|
||||
|
||||
final List<String> cardProbabilities = new ArrayList<String>();
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public enum CStatistics implements ICDoc {
|
||||
|
||||
if (ed == null) { return; }
|
||||
|
||||
final ItemPoolView<PaperCard> deck = ItemPool.createFrom(ed.getDeckManager().getItems(), PaperCard.class);
|
||||
final ItemPoolView<PaperCard> deck = ItemPool.createFrom(ed.getDeckManager().getPool(), PaperCard.class);
|
||||
|
||||
int total = deck.countAll();
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ import forge.gui.toolbox.FTextField;
|
||||
import forge.gui.toolbox.ToolTipListener;
|
||||
import forge.gui.toolbox.itemmanager.ItemManager;
|
||||
import forge.gui.toolbox.itemmanager.SItemManagerUtil;
|
||||
import forge.gui.toolbox.itemmanager.table.ITableContainer;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
@@ -47,7 +46,7 @@ import forge.util.TextUtil;
|
||||
* <br><br><i>(V at beginning of class name denotes a view class.)</i>
|
||||
*
|
||||
*/
|
||||
public enum VCardCatalog implements IVDoc<CCardCatalog>, ITableContainer {
|
||||
public enum VCardCatalog implements IVDoc<CCardCatalog> {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
@@ -237,14 +236,10 @@ public enum VCardCatalog implements IVDoc<CCardCatalog>, ITableContainer {
|
||||
|
||||
public void setItemManager(final ItemManager<? extends InventoryItem> itemManager0) {
|
||||
this.itemManager = itemManager0;
|
||||
itemManager0.setStatLabels(this.statLabels);
|
||||
scroller.setViewportView(itemManager0.getTable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FLabel getStatLabel(SItemManagerUtil.StatTypes s) {
|
||||
return statLabels.get(s);
|
||||
}
|
||||
|
||||
//========== Accessor/mutator methods
|
||||
public JPanel getPnlHeader() { return pnlHeader; }
|
||||
public FLabel getLblTitle() { return lblTitle; }
|
||||
@@ -259,9 +254,6 @@ public enum VCardCatalog implements IVDoc<CCardCatalog>, ITableContainer {
|
||||
public JComboBox<String> getCbSearchMode() { return cbSearchMode; }
|
||||
public JTextField getTxfSearch() { return txfSearch; }
|
||||
|
||||
public Map<SItemManagerUtil.StatTypes, FLabel> getStatLabels() {
|
||||
return statLabels;
|
||||
}
|
||||
public Map<RangeTypes, Pair<FSpinner, FSpinner>> getSpinners() {
|
||||
return spinners;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import forge.gui.toolbox.FTextField;
|
||||
import forge.gui.toolbox.ToolTipListener;
|
||||
import forge.gui.toolbox.itemmanager.ItemManager;
|
||||
import forge.gui.toolbox.itemmanager.SItemManagerUtil;
|
||||
import forge.gui.toolbox.itemmanager.table.ITableContainer;
|
||||
import forge.item.InventoryItem;
|
||||
|
||||
|
||||
@@ -34,7 +33,7 @@ import forge.item.InventoryItem;
|
||||
*
|
||||
* <br><br><i>(V at beginning of class name denotes a view class.)</i>
|
||||
*/
|
||||
public enum VCurrentDeck implements IVDoc<CCurrentDeck>, ITableContainer {
|
||||
public enum VCurrentDeck implements IVDoc<CCurrentDeck> {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
@@ -239,16 +238,12 @@ public enum VCurrentDeck implements IVDoc<CCurrentDeck>, ITableContainer {
|
||||
|
||||
public void setItemManager(final ItemManager<? extends InventoryItem> itemManager0) {
|
||||
this.itemManager = itemManager0;
|
||||
itemManager0.setStatLabels(this.statLabels);
|
||||
scroller.setViewportView(itemManager0.getTable());
|
||||
}
|
||||
|
||||
public JLabel getLblTitle() { return lblTitle; }
|
||||
|
||||
@Override
|
||||
public FLabel getStatLabel(SItemManagerUtil.StatTypes s) {
|
||||
return statLabels.get(s);
|
||||
}
|
||||
|
||||
//========== Retrieval
|
||||
|
||||
/** @return {@link javax.swing.JLabel} */
|
||||
|
||||
@@ -170,7 +170,7 @@ public enum VProbabilities implements IVDoc<CProbabilities> {
|
||||
final ACEditorBase<T, TModel> ed = (ACEditorBase<T, TModel>)
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
|
||||
|
||||
final List<PaperCard> cards = (List<PaperCard>) ed.getDeckManager().getItems().toFlatList();
|
||||
final List<PaperCard> cards = (List<PaperCard>) ed.getDeckManager().getPool().toFlatList();
|
||||
final String name1 = lbl.getText();
|
||||
String name2;
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.gui.toolbox.FLabel;
|
||||
import forge.gui.toolbox.itemmanager.table.ItemTable;
|
||||
import forge.gui.toolbox.itemmanager.table.ItemTableModel;
|
||||
import forge.item.InventoryItem;
|
||||
@@ -48,12 +49,13 @@ import forge.util.Aggregates;
|
||||
*/
|
||||
public final class ItemManager<T extends InventoryItem> {
|
||||
private ItemPool<T> pool;
|
||||
private ItemManagerModel<T> model;
|
||||
private final ItemManagerModel<T> model;
|
||||
private final ItemTable<T> table;
|
||||
private Predicate<T> filter = null;
|
||||
private boolean wantUnique = false;
|
||||
private boolean alwaysNonUnique = false;
|
||||
private final Class<T> genericType;
|
||||
private Map<SItemManagerUtil.StatTypes, FLabel> statLabels;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -94,7 +96,17 @@ public final class ItemManager<T extends InventoryItem> {
|
||||
this.genericType = genericType0;
|
||||
this.wantUnique = wantUnique0;
|
||||
this.model = new ItemManagerModel<T>(this, genericType0);
|
||||
this.table = new ItemTable<T>(this.model);
|
||||
this.table = new ItemTable<T>(this, this.model);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Gets the item pool.
|
||||
*
|
||||
* @return ItemPoolView
|
||||
*/
|
||||
public ItemPoolView<T> getPool() {
|
||||
return this.pool;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,23 +186,6 @@ public final class ItemManager<T extends InventoryItem> {
|
||||
return this.table.getSelectedItems();
|
||||
}
|
||||
|
||||
private boolean isUnfiltered() {
|
||||
return this.filter == null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* setFilter.
|
||||
*
|
||||
* @param filterToSet
|
||||
*/
|
||||
public void setFilter(final Predicate<T> filterToSet) {
|
||||
this.filter = filterToSet;
|
||||
if (null != pool) {
|
||||
this.updateView(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* addItem.
|
||||
@@ -203,11 +198,17 @@ public final class ItemManager<T extends InventoryItem> {
|
||||
this.pool.add(item, qty);
|
||||
if (this.isUnfiltered()) {
|
||||
this.model.addItem(item, qty);
|
||||
}
|
||||
}
|
||||
this.updateView(false);
|
||||
this.table.fixSelection(n);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* addItems.
|
||||
*
|
||||
* @param itemsToAdd
|
||||
*/
|
||||
public void addItems(Iterable<Map.Entry<T, Integer>> itemsToAdd) {
|
||||
final int n = this.table.getSelectedRow();
|
||||
for (Map.Entry<T, Integer> item : itemsToAdd) {
|
||||
@@ -220,6 +221,12 @@ public final class ItemManager<T extends InventoryItem> {
|
||||
this.table.fixSelection(n);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* addItems.
|
||||
*
|
||||
* @param itemsToAdd
|
||||
*/
|
||||
public void addItems(Collection<T> itemsToAdd) {
|
||||
final int n = this.table.getSelectedRow();
|
||||
for (T item : itemsToAdd) {
|
||||
@@ -237,7 +244,7 @@ public final class ItemManager<T extends InventoryItem> {
|
||||
* removeItem.
|
||||
*
|
||||
* @param item
|
||||
* an InventoryItem
|
||||
* @param qty
|
||||
*/
|
||||
public void removeItem(final T item, int qty) {
|
||||
final int n = this.table.getSelectedRow();
|
||||
@@ -249,6 +256,12 @@ public final class ItemManager<T extends InventoryItem> {
|
||||
this.table.fixSelection(n);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* removeItems.
|
||||
*
|
||||
* @param itemsToRemove
|
||||
*/
|
||||
public void removeItems(List<Map.Entry<T, Integer>> itemsToRemove) {
|
||||
final int n = this.table.getSelectedRow();
|
||||
for (Map.Entry<T, Integer> item : itemsToRemove) {
|
||||
@@ -261,12 +274,86 @@ public final class ItemManager<T extends InventoryItem> {
|
||||
this.table.fixSelection(n);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* getItemCount.
|
||||
*
|
||||
* @param item
|
||||
*/
|
||||
public int getItemCount(final T item) {
|
||||
return model.isInfinite() ? Integer.MAX_VALUE : this.pool.count(item);
|
||||
return this.model.isInfinite() ? Integer.MAX_VALUE : this.pool.count(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all filtered items in the model.
|
||||
*
|
||||
* @return ItemPoolView<T>
|
||||
*/
|
||||
public ItemPoolView<T> getFilteredItems() {
|
||||
return this.model.getItems();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* getStatLabels.
|
||||
*
|
||||
*/
|
||||
public Map<SItemManagerUtil.StatTypes, FLabel> getStatLabels() {
|
||||
return this.statLabels;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* getStatLabel.
|
||||
*
|
||||
* @param s
|
||||
*/
|
||||
public void setStatLabels(Map<SItemManagerUtil.StatTypes, FLabel> statLabels0) {
|
||||
this.statLabels = statLabels0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* getStatLabel.
|
||||
*
|
||||
* @param s
|
||||
*/
|
||||
public FLabel getStatLabel(SItemManagerUtil.StatTypes s) {
|
||||
if (this.statLabels != null) {
|
||||
return this.statLabels.get(s);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* getFilter.
|
||||
*
|
||||
*/
|
||||
public Predicate<T> getFilter() {
|
||||
return filter;
|
||||
return this.filter;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* isUnfiltered.
|
||||
*
|
||||
*/
|
||||
private boolean isUnfiltered() {
|
||||
return this.filter == null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* setFilter.
|
||||
*
|
||||
* @param filterToSet
|
||||
*/
|
||||
public void setFilter(final Predicate<T> filterToSet) {
|
||||
this.filter = filterToSet;
|
||||
if (this.pool != null) {
|
||||
this.updateView(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,7 +361,6 @@ public final class ItemManager<T extends InventoryItem> {
|
||||
* updateView.
|
||||
*
|
||||
* @param bForceFilter
|
||||
* a boolean
|
||||
*/
|
||||
public void updateView(final boolean bForceFilter) {
|
||||
final boolean useFilter = (bForceFilter && (this.filter != null)) || !isUnfiltered();
|
||||
@@ -300,16 +386,6 @@ public final class ItemManager<T extends InventoryItem> {
|
||||
this.table.getTableModel().refreshSort();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* getItems.
|
||||
*
|
||||
* @return ItemPoolView
|
||||
*/
|
||||
public ItemPoolView<T> getItems() {
|
||||
return this.pool;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* getWantUnique.
|
||||
@@ -350,18 +426,30 @@ public final class ItemManager<T extends InventoryItem> {
|
||||
this.alwaysNonUnique = nonUniqueOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* setWantElasticColumns.
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public void setWantElasticColumns(boolean value) {
|
||||
table.setAutoResizeMode(value ? JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS : JTable.AUTO_RESIZE_NEXT_COLUMN);
|
||||
this.table.setAutoResizeMode(value ? JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS : JTable.AUTO_RESIZE_NEXT_COLUMN);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* selectAndScrollTo.
|
||||
*
|
||||
* @param rowIdx
|
||||
*/
|
||||
public void selectAndScrollTo(int rowIdx) {
|
||||
if (!(table.getParent() instanceof JViewport)) {
|
||||
if (!(this.table.getParent() instanceof JViewport)) {
|
||||
return;
|
||||
}
|
||||
JViewport viewport = (JViewport)table.getParent();
|
||||
JViewport viewport = (JViewport)this.table.getParent();
|
||||
|
||||
// compute where we're going and where we are
|
||||
Rectangle targetRect = table.getCellRect(rowIdx, 0, true);
|
||||
Rectangle targetRect = this.table.getCellRect(rowIdx, 0, true);
|
||||
Rectangle curViewRect = viewport.getViewRect();
|
||||
|
||||
// if the target cell is not visible, attempt to jump to a location where it is
|
||||
@@ -374,15 +462,20 @@ public final class ItemManager<T extends InventoryItem> {
|
||||
targetRect.setLocation(targetRect.x, targetRect.y - (targetRect.height * 3));
|
||||
}
|
||||
|
||||
table.scrollRectToVisible(targetRect);
|
||||
table.setRowSelectionInterval(rowIdx, rowIdx);
|
||||
this.table.scrollRectToVisible(targetRect);
|
||||
this.table.setRowSelectionInterval(rowIdx, rowIdx);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* focus.
|
||||
*
|
||||
*/
|
||||
public void focus() {
|
||||
table.requestFocusInWindow();
|
||||
this.table.requestFocusInWindow();
|
||||
|
||||
if (table.getRowCount() > 0) {
|
||||
table.changeSelection(0, 0, false, false);
|
||||
if (this.table.getRowCount() > 0) {
|
||||
this.table.changeSelection(0, 0, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import forge.item.ItemPoolView;
|
||||
* @version $Id: ItemManagerModel.java 19857 2013-02-24 08:49:52Z Max mtg $
|
||||
*/
|
||||
public final class ItemManagerModel<T extends InventoryItem> {
|
||||
private final ItemManager<T> ItemManager;
|
||||
private final ItemManager<T> itemManager;
|
||||
private final ItemPool<T> data;
|
||||
private boolean infiniteSupply;
|
||||
|
||||
@@ -45,8 +45,8 @@ public final class ItemManagerModel<T extends InventoryItem> {
|
||||
* @param ItemManager0
|
||||
* @param genericType0
|
||||
*/
|
||||
public ItemManagerModel(final ItemManager<T> ItemManager0, final Class<T> genericType0) {
|
||||
this.ItemManager = ItemManager0;
|
||||
public ItemManagerModel(final ItemManager<T> itemManager0, final Class<T> genericType0) {
|
||||
this.itemManager = itemManager0;
|
||||
this.data = new ItemPool<T>(genericType0);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public final class ItemManagerModel<T extends InventoryItem> {
|
||||
final boolean wasThere = this.data.count(item0) > 0;
|
||||
if (wasThere) {
|
||||
this.data.remove(item0, qty);
|
||||
this.ItemManager.getTableModel().fireTableDataChanged();
|
||||
this.itemManager.getTableModel().fireTableDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public final class ItemManagerModel<T extends InventoryItem> {
|
||||
*/
|
||||
public void addItem(final T item0, int qty) {
|
||||
this.data.add(item0, qty);
|
||||
this.ItemManager.getTableModel().fireTableDataChanged();
|
||||
this.itemManager.getTableModel().fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +119,7 @@ public final class ItemManagerModel<T extends InventoryItem> {
|
||||
*/
|
||||
public void addItems(final Iterable<Entry<T, Integer>> items0) {
|
||||
this.data.addAll(items0);
|
||||
this.ItemManager.getTableModel().fireTableDataChanged();
|
||||
this.itemManager.getTableModel().fireTableDataChanged();
|
||||
}
|
||||
/**
|
||||
* Sets whether this table's pool of items is in infinite supply. If false, items in the
|
||||
|
||||
@@ -11,7 +11,6 @@ import forge.card.CardRulesPredicates;
|
||||
import forge.gui.deckeditor.views.VCardCatalog;
|
||||
import forge.gui.deckeditor.views.VCurrentDeck;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.itemmanager.table.ITableContainer;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPoolView;
|
||||
@@ -85,22 +84,22 @@ public final class SItemManagerUtil {
|
||||
* setStats.
|
||||
*
|
||||
* @param <T>   the generic type
|
||||
* @param items   ItemPoolView<InventoryITem>
|
||||
* @param view   {@link forge.gui.toolbox.itemmanager.table.ITableContainer}
|
||||
* @param itemManager   {@link forge.gui.toolbox.itemmanager.ItemManager<T>}
|
||||
*/
|
||||
public static <T extends InventoryItem> void setStats(final ItemPoolView<T> items, final ITableContainer view) {
|
||||
public static <T extends InventoryItem> void setStats(final ItemManager<T> itemManager) {
|
||||
final ItemPoolView<T> items = itemManager.getFilteredItems();
|
||||
for (StatTypes s : StatTypes.values()) {
|
||||
switch (s) {
|
||||
case TOTAL:
|
||||
view.getStatLabel(s).setText(String.valueOf(
|
||||
itemManager.getStatLabel(s).setText(String.valueOf(
|
||||
Aggregates.sum(Iterables.filter(items, Predicates.compose(totalPred, items.FN_GET_KEY)), items.FN_GET_COUNT)));
|
||||
break;
|
||||
case PACK:
|
||||
view.getStatLabel(s).setText(String.valueOf(
|
||||
itemManager.getStatLabel(s).setText(String.valueOf(
|
||||
Aggregates.sum(Iterables.filter(items, Predicates.compose(packPred, items.FN_GET_KEY)), items.FN_GET_COUNT)));
|
||||
break;
|
||||
default:
|
||||
view.getStatLabel(s).setText(String.valueOf(items.countAll(Predicates.compose(s.predicate, PaperCard.FN_GET_RULES), PaperCard.class)));
|
||||
itemManager.getStatLabel(s).setText(String.valueOf(items.countAll(Predicates.compose(s.predicate, PaperCard.FN_GET_RULES), PaperCard.class)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package forge.gui.toolbox.itemmanager.table;
|
||||
|
||||
import forge.gui.toolbox.FLabel;
|
||||
import forge.gui.toolbox.itemmanager.SItemManagerUtil;
|
||||
|
||||
/**
|
||||
* Dictates methods needed for a class to act as a container for
|
||||
* a EditorTableView deck editing component.
|
||||
*
|
||||
* <br><br><i>(I at beginning of class name denotes an interface.)</i>
|
||||
*
|
||||
*/
|
||||
public interface ITableContainer {
|
||||
/**
|
||||
* Sets the table used for displaying cards in this
|
||||
* deck editor container.
|
||||
*
|
||||
* @param tbl0   {@link forge.gui.toolbox.itemmanager.ItemManager}
|
||||
*/
|
||||
|
||||
FLabel getStatLabel(SItemManagerUtil.StatTypes s);
|
||||
}
|
||||
@@ -39,6 +39,7 @@ import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.itemmanager.ItemManager;
|
||||
import forge.gui.toolbox.itemmanager.ItemManagerModel;
|
||||
import forge.gui.toolbox.itemmanager.SItemManagerUtil;
|
||||
import forge.item.InventoryItem;
|
||||
@@ -52,7 +53,8 @@ import forge.item.InventoryItem;
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class ItemTable<T extends InventoryItem> extends JTable {
|
||||
private ItemTableModel<T> tableModel;
|
||||
private final ItemManager<T> itemManager;
|
||||
private final ItemTableModel<T> tableModel;
|
||||
|
||||
public ItemTableModel<T> getTableModel() {
|
||||
return this.tableModel;
|
||||
@@ -61,11 +63,12 @@ public final class ItemTable<T extends InventoryItem> extends JTable {
|
||||
/**
|
||||
* ItemTable Constructor.
|
||||
*
|
||||
* @param forceUnique whether this table should display only one item with the same name
|
||||
* @param type0 the class of item that this table will contain
|
||||
* @param itemManager0
|
||||
* @param model0
|
||||
*/
|
||||
public ItemTable(ItemManagerModel<T> model) {
|
||||
this.tableModel = new ItemTableModel<T>(this, model);
|
||||
public ItemTable(ItemManager<T> itemManager0, ItemManagerModel<T> model0) {
|
||||
this.itemManager = itemManager0;
|
||||
this.tableModel = new ItemTableModel<T>(this, model0);
|
||||
|
||||
// use different selection highlight colors for focused vs. unfocused tables
|
||||
setSelectionBackground(FSkin.getColor(FSkin.Colors.CLR_INACTIVE));
|
||||
@@ -102,13 +105,12 @@ public final class ItemTable<T extends InventoryItem> extends JTable {
|
||||
/**
|
||||
* Applies a EditorTableModel and a model listener to this instance's JTable.
|
||||
*
|
||||
* @param view0   the {@link forge.gui.itemItemManager.ITableCOntainer}
|
||||
* @param cols0   List<TableColumnInfo<InventoryItem>> of additional columns for this
|
||||
* @param cols   List<TableColumnInfo<InventoryItem>> of additional columns for this
|
||||
*/
|
||||
public void setup(final ITableContainer view0, final List<TableColumnInfo<InventoryItem>> cols0) {
|
||||
public void setup(final List<TableColumnInfo<InventoryItem>> cols) {
|
||||
final DefaultTableColumnModel colmodel = new DefaultTableColumnModel();
|
||||
|
||||
for (TableColumnInfo<InventoryItem> item : cols0) {
|
||||
for (TableColumnInfo<InventoryItem> item : cols) {
|
||||
item.setModelIndex(colmodel.getColumnCount());
|
||||
if (item.isShowing()) { colmodel.addColumn(item); }
|
||||
}
|
||||
@@ -126,7 +128,7 @@ public final class ItemTable<T extends InventoryItem> extends JTable {
|
||||
this.tableModel.addTableModelListener(new TableModelListener() {
|
||||
@Override
|
||||
public void tableChanged(final TableModelEvent ev) {
|
||||
SItemManagerUtil.setStats(ItemTable.this.tableModel.getItems(), view0);
|
||||
SItemManagerUtil.setStats(ItemTable.this.itemManager);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ import forge.gui.toolbox.itemmanager.SItemManagerIO;
|
||||
import forge.gui.toolbox.itemmanager.table.SColumnUtil.ColumnName;
|
||||
import forge.gui.toolbox.itemmanager.table.SColumnUtil.SortState;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPoolView;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -112,15 +111,6 @@ public final class ItemTableModel<T extends InventoryItem> extends AbstractTable
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all items in the model.
|
||||
*
|
||||
* @return ItemPoolView<T>
|
||||
*/
|
||||
public ItemPoolView<T> getItems() {
|
||||
return this.model.getItems();
|
||||
}
|
||||
|
||||
/**
|
||||
* Row to card.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user