mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
tableModel now remembers up to 3 sortings. (like by name, set and then color) and remembers them
boosterDraft window should not be maximized on start totally removed progressbar from deckeditor mana comparison: R/P is now a bit greater than R
This commit is contained in:
@@ -97,6 +97,7 @@ public class CardManaCostShard {
|
||||
if (0 != (shard & Atom.BLACK)) { cost += 0.0080f; }
|
||||
if (0 != (shard & Atom.RED)) { cost += 0.0320f; }
|
||||
if (0 != (shard & Atom.GREEN)) { cost += 0.1280f; }
|
||||
if (0 != (shard & Atom.OR_2_LIFE)) { cost += 0.00003f; }
|
||||
return cost;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,10 +63,6 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
private static final long serialVersionUID = 130339644136746796L;
|
||||
|
||||
public DeckEditorMenu customMenu;
|
||||
public Gui_ProgressBarWindow gPBW = new Gui_ProgressBarWindow();
|
||||
|
||||
// private ImageIcon upIcon = Constant.IO.upIcon;
|
||||
// private ImageIcon downIcon = Constant.IO.downIcon;
|
||||
|
||||
private JButton removeButton = new JButton();
|
||||
private JButton addButton = new JButton();
|
||||
@@ -87,6 +83,8 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
private JTextField txtCardRules = new JTextField();
|
||||
private JComboBox searchSetCombo = new JComboBox();
|
||||
private JButton clearFilterButton = new JButton();
|
||||
|
||||
private boolean isConstructed = false;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
@@ -97,48 +95,19 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
/** {@inheritDoc} */
|
||||
public void setDecks(CardPoolView topPool, CardPoolView bottomPool) {
|
||||
top = new CardPool(topPool);
|
||||
bottom = bottomPool;
|
||||
|
||||
topModel.clear();
|
||||
bottomModel.clear();
|
||||
|
||||
|
||||
if (gPBW.isVisible())
|
||||
gPBW.setProgressRange(0, top.countDistinct() + bottom.countDistinct());
|
||||
|
||||
// this should have been called each step :)
|
||||
if (gPBW.isVisible()) { gPBW.increment(); }
|
||||
|
||||
Predicate<CardRules> filter = buildFilter();
|
||||
topModel.addCards(filter.select(top, CardPoolView.fnToCard));
|
||||
|
||||
// update bottom
|
||||
bottomModel.addCards(bottom);
|
||||
|
||||
if (gPBW.isVisible())
|
||||
gPBW.setTitle("Sorting Deck Editor");
|
||||
|
||||
topModel.addCards(buildFilter().select(top, CardPoolView.fnToCard));
|
||||
topModel.resort();
|
||||
topTable.repaint();
|
||||
|
||||
bottom = bottomPool;
|
||||
bottomModel.clear();
|
||||
bottomModel.addCards(bottom);
|
||||
bottomModel.resort();
|
||||
bottomTable.repaint();
|
||||
}// updateDisplay
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* updateDisplay.
|
||||
* </p>
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* show.
|
||||
* </p>
|
||||
*
|
||||
* @param exitCommand
|
||||
* a {@link forge.Command} object.
|
||||
*/
|
||||
public void show(final Command exitCommand) {
|
||||
final Command exit = new Command() {
|
||||
private static final long serialVersionUID = 5210924838133689758L;
|
||||
@@ -149,10 +118,6 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
}
|
||||
};
|
||||
|
||||
// pm = new ProgressMonitor(this, "Loading Deck Editor", "", 0, 20000);
|
||||
gPBW.setTitle("Loading Deck Editor");
|
||||
gPBW.setVisible(true);
|
||||
|
||||
customMenu = new DeckEditorMenu(this, exit);
|
||||
this.setJMenuBar(customMenu);
|
||||
|
||||
@@ -166,14 +131,16 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
|
||||
setup();
|
||||
|
||||
isConstructed = Constant.Runtime.GameType[0].equals(Constant.GameType.Constructed);
|
||||
|
||||
// show cards, makes this user friendly
|
||||
if (Constant.Runtime.GameType[0].equals(Constant.GameType.Constructed))
|
||||
if (isConstructed) {
|
||||
customMenu.newConstructed();
|
||||
}
|
||||
|
||||
topModel.sort(1, true);
|
||||
bottomModel.sort(1, true);
|
||||
|
||||
gPBW.dispose();
|
||||
}// show(Command)
|
||||
|
||||
|
||||
@@ -464,6 +431,7 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
||||
if (!customMenu.getGameType().equals(Constant.GameType.Constructed)) {
|
||||
top.remove(c);
|
||||
topModel.removeCard(c);
|
||||
topModel.resort();
|
||||
}
|
||||
fixSelection(topModel, topTable, n);
|
||||
}// if(valid row)
|
||||
|
||||
@@ -163,7 +163,7 @@ public class Gui_BoosterDraft extends JFrame implements NewConstants, NewConstan
|
||||
|
||||
//Use both so that when "un"maximizing, the frame isn't tiny
|
||||
setSize(1024, 740);
|
||||
setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
//setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
}//setupAndDisplay()
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.awt.event.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Stack;
|
||||
|
||||
|
||||
/**
|
||||
@@ -37,14 +38,74 @@ public class TableModel extends AbstractTableModel {
|
||||
|
||||
@SuppressWarnings("rawtypes") // We use raw comparables to provide fields for sorting
|
||||
|
||||
private final class SortOrders {
|
||||
private class Order {
|
||||
public final int sortColumn;
|
||||
public boolean isSortAsc = true;
|
||||
public Order(int col) { sortColumn = col; }
|
||||
};
|
||||
|
||||
|
||||
private int sortColumn;
|
||||
private boolean isSortAsc = true;
|
||||
private final int MAX_DEPTH = 3;
|
||||
Order[] orders = new Order[] {null, null, null};
|
||||
private TableSorterCascade sorter = null;
|
||||
private boolean isSorterReady = false;
|
||||
private int indexOfColumn(final int column) {
|
||||
int posColumn = orders.length - 1;
|
||||
for (; posColumn >= 0; posColumn--) {
|
||||
if (orders[posColumn] != null && orders[posColumn].sortColumn == column) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return posColumn;
|
||||
}
|
||||
|
||||
// index of column to sort by, desired direction
|
||||
public void add(final int column, boolean wantAsc) {
|
||||
add(column);
|
||||
orders[0].isSortAsc = wantAsc;
|
||||
isSorterReady = false;
|
||||
}
|
||||
|
||||
// puts desired direction on top, set "asc"; if already was on top, inverts direction;
|
||||
public void add(final int column) {
|
||||
int posColumn = indexOfColumn(column);
|
||||
switch (posColumn) {
|
||||
case -1: // no such column here - let's add then
|
||||
System.arraycopy(orders, 0, orders, 1, MAX_DEPTH - 1);
|
||||
orders[0] = new Order(column);
|
||||
break;
|
||||
case 0: // found at top-level, should invert
|
||||
orders[0].isSortAsc ^= true; // invert
|
||||
break;
|
||||
default: // found somewhere, move down others, set this one onto top;
|
||||
System.arraycopy(orders, 0, orders, 1, posColumn);
|
||||
orders[0] = new Order(column);
|
||||
break;
|
||||
}
|
||||
isSorterReady = false;
|
||||
}
|
||||
|
||||
public TableSorterCascade getSorter() {
|
||||
if (!isSorterReady) {
|
||||
TableSorter[] oneColSorters = new TableSorter[MAX_DEPTH];
|
||||
for (int i = 0; i < orders.length; i++) {
|
||||
Order order = orders[i];
|
||||
if (order == null) {
|
||||
oneColSorters[i] = null;
|
||||
} else {
|
||||
oneColSorters[i] = new TableSorter(columns.get(order.sortColumn).fnSort, order.isSortAsc);
|
||||
}
|
||||
}
|
||||
sorter = new TableSorterCascade(oneColSorters);
|
||||
}
|
||||
return sorter;
|
||||
}
|
||||
}
|
||||
|
||||
private CardPool data = new CardPool();
|
||||
private final CardDisplay cardDisplay;
|
||||
private final List<TableColumnInfo<CardPrinted>> columns;
|
||||
private final SortOrders sortOrders = new SortOrders();
|
||||
|
||||
public TableModel(final CardDisplay cd, List<TableColumnInfo<CardPrinted>> columnsToShow ) {
|
||||
cardDisplay = cd;
|
||||
@@ -156,13 +217,9 @@ public class TableModel extends AbstractTableModel {
|
||||
int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
|
||||
|
||||
if (modelIndex < 0) { return; }
|
||||
if (sortColumn == modelIndex) {
|
||||
isSortAsc = !isSortAsc;
|
||||
}
|
||||
else {
|
||||
isSortAsc = true;
|
||||
sortColumn = modelIndex;
|
||||
}
|
||||
|
||||
// This will invert if needed
|
||||
sortOrders.add(modelIndex);
|
||||
|
||||
for (int i = 0; i < columns.size(); i++) {
|
||||
TableColumn column = colModel.getColumn(i);
|
||||
@@ -215,16 +272,13 @@ public class TableModel extends AbstractTableModel {
|
||||
}//addCardListener()
|
||||
|
||||
|
||||
public void resort() {
|
||||
TableSorter sorter = new TableSorter(columns.get(sortColumn).fnSort, isSortAsc);
|
||||
Collections.sort(data.getOrderedList(), sorter);
|
||||
public void resort() {
|
||||
Collections.sort(data.getOrderedList(), sortOrders.getSorter());
|
||||
}
|
||||
|
||||
public void sort( int iCol, boolean isAsc )
|
||||
{
|
||||
sortColumn = iCol;
|
||||
isSortAsc = isAsc;
|
||||
resort();
|
||||
|
||||
public void sort( int iCol, boolean isAsc ) {
|
||||
sortOrders.add(iCol, isAsc);
|
||||
resort();
|
||||
}
|
||||
|
||||
}//CardTableModel
|
||||
|
||||
@@ -31,22 +31,19 @@ public class TableSorter implements Comparator<Entry<CardPrinted, Integer>> {
|
||||
this.field = field;
|
||||
ascending = in_ascending;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final TableSorter byNameThenSet = new TableSorter(
|
||||
new Lambda1<Comparable, Entry<CardPrinted, Integer>>() {
|
||||
@Override public Comparable apply(final Entry<CardPrinted, Integer> from) { return from.getKey(); }
|
||||
}, true);
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public int compare(Entry<CardPrinted, Integer> arg0, Entry<CardPrinted, Integer> arg1) {
|
||||
Comparable obj1 = field.apply(arg0);
|
||||
Comparable obj2 = field.apply(arg1);
|
||||
//System.out.println(String.format("%s vs %s _______ %s vs %s", arg0, arg1, obj1, obj2));
|
||||
if (ascending) { return obj1.compareTo(obj2); }
|
||||
else { return obj2.compareTo(obj1); }
|
||||
return ascending ? obj1.compareTo(obj2) : obj2.compareTo(obj1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
39
src/main/java/forge/gui/deckeditor/TableSorterCascade.java
Normal file
39
src/main/java/forge/gui/deckeditor/TableSorterCascade.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import forge.card.CardPrinted;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* <p>TableSorter class.</p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: TableSorter.java 10146 2011-09-01 18:11:00Z Max mtg $
|
||||
*/
|
||||
public class TableSorterCascade implements Comparator<Entry<CardPrinted, Integer>> {
|
||||
private TableSorter[] sorters;
|
||||
private final int cntFields;
|
||||
private static final TableSorter[] EMPTY_SORTER_ARRAY = new TableSorter[0];
|
||||
|
||||
public TableSorterCascade(final List<TableSorter> sortersCascade) {
|
||||
this(sortersCascade.toArray(EMPTY_SORTER_ARRAY));
|
||||
}
|
||||
|
||||
public TableSorterCascade(final TableSorter[] sortersCascade) {
|
||||
this.sorters = sortersCascade;
|
||||
cntFields = sortersCascade.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int compare(final Entry<CardPrinted, Integer> arg0, final Entry<CardPrinted, Integer> arg1) {
|
||||
int lastCompare = 0;
|
||||
int iField = -1;
|
||||
while (++iField < cntFields && lastCompare == 0) {
|
||||
TableSorter sorter = sorters[iField];
|
||||
if (sorter == null) { break; }
|
||||
lastCompare = sorter.compare(arg0, arg1);
|
||||
}
|
||||
return lastCompare;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user