mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Code cleanup
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -1082,6 +1082,7 @@ forge-gui-mobile/src/forge/error/BugReporter.java -text
|
|||||||
forge-gui-mobile/src/forge/itemmanager/CardManager.java -text
|
forge-gui-mobile/src/forge/itemmanager/CardManager.java -text
|
||||||
forge-gui-mobile/src/forge/itemmanager/DeckManager.java -text
|
forge-gui-mobile/src/forge/itemmanager/DeckManager.java -text
|
||||||
forge-gui-mobile/src/forge/itemmanager/ItemManager.java -text
|
forge-gui-mobile/src/forge/itemmanager/ItemManager.java -text
|
||||||
|
forge-gui-mobile/src/forge/itemmanager/SpellShopManager.java -text
|
||||||
forge-gui-mobile/src/forge/itemmanager/filters/CardCMCFilter.java -text
|
forge-gui-mobile/src/forge/itemmanager/filters/CardCMCFilter.java -text
|
||||||
forge-gui-mobile/src/forge/itemmanager/filters/CardCMCRangeFilter.java -text
|
forge-gui-mobile/src/forge/itemmanager/filters/CardCMCRangeFilter.java -text
|
||||||
forge-gui-mobile/src/forge/itemmanager/filters/CardColorFilter.java -text
|
forge-gui-mobile/src/forge/itemmanager/filters/CardColorFilter.java -text
|
||||||
|
|||||||
27
forge-gui-mobile/src/forge/itemmanager/SpellShopManager.java
Normal file
27
forge-gui-mobile/src/forge/itemmanager/SpellShopManager.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package forge.itemmanager;
|
||||||
|
|
||||||
|
import forge.item.InventoryItem;
|
||||||
|
import forge.itemmanager.filters.ItemFilter;
|
||||||
|
import forge.menu.FPopupMenu;
|
||||||
|
|
||||||
|
|
||||||
|
public final class SpellShopManager extends ItemManager<InventoryItem> {
|
||||||
|
public SpellShopManager(boolean wantUnique0) {
|
||||||
|
super(InventoryItem.class, wantUnique0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addDefaultFilters() {
|
||||||
|
CardManager.addDefaultFilters(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ItemFilter<? extends InventoryItem> createSearchFilter() {
|
||||||
|
return CardManager.createSearchFilter(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void buildAddFilterMenu(FPopupMenu menu) {
|
||||||
|
CardManager.buildAddFilterMenu(menu, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,6 @@ import forge.item.InventoryItem;
|
|||||||
import forge.itemmanager.ItemManager;
|
import forge.itemmanager.ItemManager;
|
||||||
import forge.menu.FTooltip;
|
import forge.menu.FTooltip;
|
||||||
import forge.toolbox.FLabel;
|
import forge.toolbox.FLabel;
|
||||||
import forge.toolbox.FTextField;
|
|
||||||
import forge.util.LayoutHelper;
|
import forge.util.LayoutHelper;
|
||||||
import forge.util.TextUtil;
|
import forge.util.TextUtil;
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import forge.toolbox.FDisplayObject;
|
|||||||
import forge.toolbox.FEvent;
|
import forge.toolbox.FEvent;
|
||||||
import forge.toolbox.FEvent.FEventHandler;
|
import forge.toolbox.FEvent.FEventHandler;
|
||||||
import forge.toolbox.FList;
|
import forge.toolbox.FList;
|
||||||
|
import forge.util.Utils;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@@ -46,19 +47,16 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
private static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
|
private static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
|
||||||
private static final FSkinColor SEL_ACTIVE_COLOR = FSkinColor.get(Colors.CLR_ACTIVE);
|
private static final FSkinColor SEL_ACTIVE_COLOR = FSkinColor.get(Colors.CLR_ACTIVE);
|
||||||
private static final FSkinColor SEL_INACTIVE_COLOR = FSkinColor.get(Colors.CLR_INACTIVE);
|
private static final FSkinColor SEL_INACTIVE_COLOR = FSkinColor.get(Colors.CLR_INACTIVE);
|
||||||
private static final FSkinColor HEADER_BACK_COLOR = BACK_COLOR.getContrastColor(-10);
|
|
||||||
static final FSkinColor ALT_ROW_COLOR = BACK_COLOR.getContrastColor(-20);
|
|
||||||
private static final FSkinColor GRID_COLOR = BACK_COLOR.getContrastColor(20);
|
|
||||||
private static final FSkinFont ROW_FONT = FSkinFont.get(12);
|
private static final FSkinFont ROW_FONT = FSkinFont.get(12);
|
||||||
private static final int ROW_HEIGHT = 19;
|
private static final float ROW_HEIGHT = Utils.AVG_FINGER_HEIGHT + 12;
|
||||||
|
|
||||||
private final ItemTable table = new ItemTable();
|
private final ItemList list = new ItemList();
|
||||||
private final ItemTableModel tableModel;
|
private final ItemListModel listModel;
|
||||||
private boolean allowMultipleSelections;
|
private boolean allowMultipleSelections;
|
||||||
private List<Integer> selectedIndices = new ArrayList<Integer>();
|
private List<Integer> selectedIndices = new ArrayList<Integer>();
|
||||||
|
|
||||||
public ItemTableModel getTableModel() {
|
public ItemListModel getTableModel() {
|
||||||
return tableModel;
|
return listModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,7 +67,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
*/
|
*/
|
||||||
public ItemListView(ItemManager<T> itemManager0, ItemManagerModel<T> model0) {
|
public ItemListView(ItemManager<T> itemManager0, ItemManagerModel<T> model0) {
|
||||||
super(itemManager0, model0);
|
super(itemManager0, model0);
|
||||||
tableModel = new ItemTableModel(model0);
|
listModel = new ItemListModel(model0);
|
||||||
setAllowMultipleSelections(false);
|
setAllowMultipleSelections(false);
|
||||||
getPnlOptions().setVisible(false); //hide options panel by default
|
getPnlOptions().setVisible(false); //hide options panel by default
|
||||||
}
|
}
|
||||||
@@ -78,26 +76,23 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
public void setup(ItemManagerConfig config, Map<ColumnDef, ItemColumn> colOverrides) {
|
public void setup(ItemManagerConfig config, Map<ColumnDef, ItemColumn> colOverrides) {
|
||||||
final Iterable<T> selectedItemsBefore = getSelectedItems();
|
final Iterable<T> selectedItemsBefore = getSelectedItems();
|
||||||
|
|
||||||
//ensure columns ordered properly
|
//ensure cells ordered properly
|
||||||
final List<ItemColumn> columns = new LinkedList<ItemColumn>();
|
final List<ItemColumn> cols = new LinkedList<ItemColumn>();
|
||||||
for (ItemColumnConfig colConfig : config.getCols().values()) {
|
for (ItemColumnConfig colConfig : config.getCols().values()) {
|
||||||
if (colOverrides == null || !colOverrides.containsKey(colConfig.getDef())) {
|
if (colOverrides == null || !colOverrides.containsKey(colConfig.getDef())) {
|
||||||
columns.add(new ItemColumn(colConfig));
|
cols.add(new ItemColumn(colConfig));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
columns.add(colOverrides.get(colConfig.getDef()));
|
cols.add(colOverrides.get(colConfig.getDef()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(columns, new Comparator<ItemColumn>() {
|
Collections.sort(cols, new Comparator<ItemColumn>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(ItemColumn arg0, ItemColumn arg1) {
|
public int compare(ItemColumn arg0, ItemColumn arg1) {
|
||||||
return Integer.compare(arg0.getConfig().getIndex(), arg1.getConfig().getIndex());
|
return Integer.compare(arg0.getConfig().getIndex(), arg1.getConfig().getIndex());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//hide table header if only showing single string column
|
|
||||||
boolean hideHeader = (config.getCols().size() == 1 && config.getCols().containsKey(ColumnDef.STRING));
|
|
||||||
|
|
||||||
getPnlOptions().clear();
|
getPnlOptions().clear();
|
||||||
|
|
||||||
if (config.getShowUniqueCardsOption()) {
|
if (config.getShowUniqueCardsOption()) {
|
||||||
@@ -112,7 +107,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
itemManager.refresh();
|
itemManager.refresh();
|
||||||
|
|
||||||
if (itemManager.getConfig() != null) {
|
if (itemManager.getConfig() != null) {
|
||||||
itemManager.getConfig().setUniqueCardsOnly(wantUnique);
|
itemManager.setWantUnique(wantUnique);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -120,58 +115,53 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int modelIndex = 0;
|
int modelIndex = 0;
|
||||||
for (final ItemColumn col : columns) {
|
for (final ItemColumn col : cols) {
|
||||||
col.getConfig().setIndex(modelIndex++);
|
final ItemCell cell = new ItemCell(col);
|
||||||
if (col.getConfig().isVisible()) { table.columns.add(col); }
|
col.setIndex(modelIndex++);
|
||||||
|
if (col.isVisible()) { list.cells.add(cell); }
|
||||||
|
|
||||||
if (!hideHeader) {
|
final FCheckBox chkBox = new FCheckBox(StringUtils.isEmpty(col.getShortName()) ?
|
||||||
final FCheckBox chkBox = new FCheckBox(StringUtils.isEmpty(col.getConfig().getShortName()) ?
|
col.getLongName() : col.getShortName(), col.isVisible());
|
||||||
col.getConfig().getLongName() : col.getConfig().getShortName(), col.getConfig().isVisible());
|
chkBox.setFontSize(ROW_FONT.getSize());
|
||||||
chkBox.setFontSize(ROW_FONT.getSize());
|
chkBox.setCommand(new FEventHandler() {
|
||||||
chkBox.setCommand(new FEventHandler() {
|
@Override
|
||||||
@Override
|
public void handleEvent(FEvent e) {
|
||||||
public void handleEvent(FEvent e) {
|
boolean visible = chkBox.isSelected();
|
||||||
boolean visible = chkBox.isSelected();
|
if (col.isVisible() == visible) { return; }
|
||||||
if (col.getConfig().isVisible() == visible) { return; }
|
col.setVisible(visible);
|
||||||
col.getConfig().setVisible(visible);
|
|
||||||
|
|
||||||
if (col.getConfig().isVisible()) {
|
if (col.isVisible()) {
|
||||||
table.columns.add(col);
|
list.cells.add(cell);
|
||||||
|
|
||||||
//move column into proper position
|
//move cell into proper position
|
||||||
int oldIndex = table.getColumnCount() - 1;
|
int oldIndex = list.getCellCount() - 1;
|
||||||
int newIndex = col.getConfig().getIndex();
|
int newIndex = col.getIndex();
|
||||||
for (int i = 0; i < col.getConfig().getIndex(); i++) {
|
for (int i = 0; i < col.getIndex(); i++) {
|
||||||
if (!columns.get(i).getConfig().isVisible()) {
|
if (!cols.get(i).isVisible()) {
|
||||||
newIndex--;
|
newIndex--;
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newIndex < oldIndex) {
|
|
||||||
table.columns.remove(oldIndex);
|
|
||||||
table.columns.add(newIndex, col);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
if (newIndex < oldIndex) {
|
||||||
table.columns.remove(col);
|
list.cells.remove(oldIndex);
|
||||||
|
list.cells.add(newIndex, cell);
|
||||||
}
|
}
|
||||||
ItemManagerConfig.save();
|
|
||||||
}
|
}
|
||||||
});
|
else {
|
||||||
getPnlOptions().add(chkBox);
|
list.cells.remove(cell);
|
||||||
}
|
}
|
||||||
|
ItemManagerConfig.save();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
getPnlOptions().add(chkBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
tableModel.setup();
|
listModel.setup();
|
||||||
refresh(selectedItemsBefore, 0, 0);
|
refresh(selectedItemsBefore, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemTable getTable() {
|
|
||||||
return table;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FDisplayObject getComponent() {
|
public FDisplayObject getComponent() {
|
||||||
return table;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -218,7 +208,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void scrollSelectionIntoView() {
|
public void scrollSelectionIntoView() {
|
||||||
//table.scrollIntoView(table.getItemAt(getSelectedIndex()));
|
//list.scrollIntoView(list.getItemAt(getSelectedIndex()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -227,18 +217,18 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getIndexOfItem(T item) {
|
public int getIndexOfItem(T item) {
|
||||||
return tableModel.itemToRow(item);
|
return listModel.itemToRow(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T getItemAtIndex(int index) {
|
public T getItemAtIndex(int index) {
|
||||||
Entry<T, Integer> itemEntry = tableModel.rowToItem(index);
|
Entry<T, Integer> itemEntry = listModel.rowToItem(index);
|
||||||
return itemEntry != null ? itemEntry.getKey() : null;
|
return itemEntry != null ? itemEntry.getKey() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return table.getCount();
|
return list.getCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -259,50 +249,49 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
protected void onRefresh() {
|
protected void onRefresh() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class ItemTable extends FList<T> {
|
public final class ItemList extends FList<T> {
|
||||||
private List<ItemColumn> columns = new ArrayList<ItemColumn>();
|
private List<ItemCell> cells = new ArrayList<ItemCell>();
|
||||||
|
|
||||||
private ItemTable() {
|
private ItemList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<ItemColumn> getColumns() {
|
public Iterable<ItemCell> getCells() {
|
||||||
return columns;
|
return cells;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColumnCount() {
|
public int getCellCount() {
|
||||||
return columns.size();
|
return cells.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class ItemTableModel {
|
public final class ItemListModel {
|
||||||
private final ItemManagerModel<T> model;
|
private final ItemManagerModel<T> model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new table model.
|
* Instantiates a new list model.
|
||||||
*
|
*
|
||||||
* @param table0   {@link forge.gui.ItemManager.ItemTable<T>}
|
|
||||||
* @param model0   {@link forge.gui.ItemManager.ItemManagerModel<T>}
|
* @param model0   {@link forge.gui.ItemManager.ItemManagerModel<T>}
|
||||||
*/
|
*/
|
||||||
public ItemTableModel(final ItemManagerModel<T> model0) {
|
public ItemListModel(final ItemManagerModel<T> model0) {
|
||||||
model = model0;
|
model = model0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setup() {
|
public void setup() {
|
||||||
final ItemColumn[] sortcols = new ItemColumn[table.getColumnCount()];
|
final ItemCell[] sortcells = new ItemCell[list.getCellCount()];
|
||||||
|
|
||||||
// Assemble priority sort.
|
// Assemble priority sort.
|
||||||
for (ItemColumn col : table.getColumns()) {
|
for (ItemCell cell : list.getCells()) {
|
||||||
if (col.getConfig().getSortPriority() > 0 && col.getConfig().getSortPriority() <= sortcols.length) {
|
if (cell.getSortPriority() > 0 && cell.getSortPriority() <= sortcells.length) {
|
||||||
sortcols[col.getConfig().getSortPriority() - 1] = col;
|
sortcells[cell.getSortPriority() - 1] = cell;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
model.getCascadeManager().reset();
|
model.getCascadeManager().reset();
|
||||||
|
|
||||||
for (int i = sortcols.length - 1; i >= 0; i--) {
|
for (int i = sortcells.length - 1; i >= 0; i--) {
|
||||||
ItemColumn col = sortcols[i];
|
ItemCell cell = sortcells[i];
|
||||||
if (col != null) {
|
if (cell != null) {
|
||||||
model.getCascadeManager().add(col, true);
|
model.getCascadeManager().add(cell.getItemColumn(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ package forge.itemmanager;
|
|||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
|
import forge.itemmanager.ItemColumnConfig.SortState;
|
||||||
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
|
||||||
@@ -50,6 +52,50 @@ public class ItemColumn {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getShortName() {
|
||||||
|
return config.getShortName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLongName() {
|
||||||
|
return config.getLongName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndex() {
|
||||||
|
return config.getIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndex(final int index0) {
|
||||||
|
config.setIndex(index0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSortPriority() {
|
||||||
|
return config.getSortPriority();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortPriority(final int sortPriority0) {
|
||||||
|
config.setSortPriority(sortPriority0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortState getSortState() {
|
||||||
|
return config.getSortState();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortState(final SortState state0) {
|
||||||
|
config.setSortState(state0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortState getDefaultSortState() {
|
||||||
|
return config.getDefaultSortState();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVisible() {
|
||||||
|
return config.isVisible();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVisible(boolean visible0) {
|
||||||
|
config.setVisible(visible0);
|
||||||
|
}
|
||||||
|
|
||||||
public Function<Entry<InventoryItem, Integer>, Comparable<?>> getFnSort() {
|
public Function<Entry<InventoryItem, Integer>, Comparable<?>> getFnSort() {
|
||||||
return fnSort;
|
return fnSort;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user