mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18: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:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -9785,6 +9785,7 @@ src/main/java/forge/gui/deckeditor/Gui_BoosterDraft.java svneol=native#text/plai
|
|||||||
src/main/java/forge/gui/deckeditor/TableColumnInfo.java -text
|
src/main/java/forge/gui/deckeditor/TableColumnInfo.java -text
|
||||||
src/main/java/forge/gui/deckeditor/TableModel.java svneol=native#text/plain
|
src/main/java/forge/gui/deckeditor/TableModel.java svneol=native#text/plain
|
||||||
src/main/java/forge/gui/deckeditor/TableSorter.java svneol=native#text/plain
|
src/main/java/forge/gui/deckeditor/TableSorter.java svneol=native#text/plain
|
||||||
|
src/main/java/forge/gui/deckeditor/TableSorterCascade.java -text
|
||||||
src/main/java/forge/gui/deckeditor/package-info.java -text
|
src/main/java/forge/gui/deckeditor/package-info.java -text
|
||||||
src/main/java/forge/gui/game/CardDetailPanel.java svneol=native#text/plain
|
src/main/java/forge/gui/game/CardDetailPanel.java svneol=native#text/plain
|
||||||
src/main/java/forge/gui/game/CardPanel.java svneol=native#text/plain
|
src/main/java/forge/gui/game/CardPanel.java svneol=native#text/plain
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ public class CardManaCostShard {
|
|||||||
if (0 != (shard & Atom.BLACK)) { cost += 0.0080f; }
|
if (0 != (shard & Atom.BLACK)) { cost += 0.0080f; }
|
||||||
if (0 != (shard & Atom.RED)) { cost += 0.0320f; }
|
if (0 != (shard & Atom.RED)) { cost += 0.0320f; }
|
||||||
if (0 != (shard & Atom.GREEN)) { cost += 0.1280f; }
|
if (0 != (shard & Atom.GREEN)) { cost += 0.1280f; }
|
||||||
|
if (0 != (shard & Atom.OR_2_LIFE)) { cost += 0.00003f; }
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,10 +63,6 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
|||||||
private static final long serialVersionUID = 130339644136746796L;
|
private static final long serialVersionUID = 130339644136746796L;
|
||||||
|
|
||||||
public DeckEditorMenu customMenu;
|
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 removeButton = new JButton();
|
||||||
private JButton addButton = new JButton();
|
private JButton addButton = new JButton();
|
||||||
@@ -88,6 +84,8 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
|||||||
private JComboBox searchSetCombo = new JComboBox();
|
private JComboBox searchSetCombo = new JComboBox();
|
||||||
private JButton clearFilterButton = new JButton();
|
private JButton clearFilterButton = new JButton();
|
||||||
|
|
||||||
|
private boolean isConstructed = false;
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public void setTitle(String message) {
|
public void setTitle(String message) {
|
||||||
@@ -97,48 +95,19 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
|||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public void setDecks(CardPoolView topPool, CardPoolView bottomPool) {
|
public void setDecks(CardPoolView topPool, CardPoolView bottomPool) {
|
||||||
top = new CardPool(topPool);
|
top = new CardPool(topPool);
|
||||||
bottom = bottomPool;
|
|
||||||
|
|
||||||
topModel.clear();
|
topModel.clear();
|
||||||
bottomModel.clear();
|
topModel.addCards(buildFilter().select(top, CardPoolView.fnToCard));
|
||||||
|
|
||||||
|
|
||||||
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.resort();
|
topModel.resort();
|
||||||
topTable.repaint();
|
topTable.repaint();
|
||||||
|
|
||||||
|
bottom = bottomPool;
|
||||||
|
bottomModel.clear();
|
||||||
|
bottomModel.addCards(bottom);
|
||||||
bottomModel.resort();
|
bottomModel.resort();
|
||||||
bottomTable.repaint();
|
bottomTable.repaint();
|
||||||
}// updateDisplay
|
}// updateDisplay
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* updateDisplay.
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* show.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param exitCommand
|
|
||||||
* a {@link forge.Command} object.
|
|
||||||
*/
|
|
||||||
public void show(final Command exitCommand) {
|
public void show(final Command exitCommand) {
|
||||||
final Command exit = new Command() {
|
final Command exit = new Command() {
|
||||||
private static final long serialVersionUID = 5210924838133689758L;
|
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);
|
customMenu = new DeckEditorMenu(this, exit);
|
||||||
this.setJMenuBar(customMenu);
|
this.setJMenuBar(customMenu);
|
||||||
|
|
||||||
@@ -166,14 +131,16 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
|||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
|
isConstructed = Constant.Runtime.GameType[0].equals(Constant.GameType.Constructed);
|
||||||
|
|
||||||
// show cards, makes this user friendly
|
// show cards, makes this user friendly
|
||||||
if (Constant.Runtime.GameType[0].equals(Constant.GameType.Constructed))
|
if (isConstructed) {
|
||||||
customMenu.newConstructed();
|
customMenu.newConstructed();
|
||||||
|
}
|
||||||
|
|
||||||
topModel.sort(1, true);
|
topModel.sort(1, true);
|
||||||
bottomModel.sort(1, true);
|
bottomModel.sort(1, true);
|
||||||
|
|
||||||
gPBW.dispose();
|
|
||||||
}// show(Command)
|
}// show(Command)
|
||||||
|
|
||||||
|
|
||||||
@@ -464,6 +431,7 @@ public class DeckEditor extends DeckEditorBase implements NewConstants {
|
|||||||
if (!customMenu.getGameType().equals(Constant.GameType.Constructed)) {
|
if (!customMenu.getGameType().equals(Constant.GameType.Constructed)) {
|
||||||
top.remove(c);
|
top.remove(c);
|
||||||
topModel.removeCard(c);
|
topModel.removeCard(c);
|
||||||
|
topModel.resort();
|
||||||
}
|
}
|
||||||
fixSelection(topModel, topTable, n);
|
fixSelection(topModel, topTable, n);
|
||||||
}// if(valid row)
|
}// 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
|
//Use both so that when "un"maximizing, the frame isn't tiny
|
||||||
setSize(1024, 740);
|
setSize(1024, 740);
|
||||||
setExtendedState(Frame.MAXIMIZED_BOTH);
|
//setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||||
}//setupAndDisplay()
|
}//setupAndDisplay()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.awt.event.*;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
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
|
@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 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;
|
||||||
|
}
|
||||||
|
|
||||||
private int sortColumn;
|
// index of column to sort by, desired direction
|
||||||
private boolean isSortAsc = true;
|
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 CardPool data = new CardPool();
|
||||||
private final CardDisplay cardDisplay;
|
private final CardDisplay cardDisplay;
|
||||||
private final List<TableColumnInfo<CardPrinted>> columns;
|
private final List<TableColumnInfo<CardPrinted>> columns;
|
||||||
|
private final SortOrders sortOrders = new SortOrders();
|
||||||
|
|
||||||
public TableModel(final CardDisplay cd, List<TableColumnInfo<CardPrinted>> columnsToShow ) {
|
public TableModel(final CardDisplay cd, List<TableColumnInfo<CardPrinted>> columnsToShow ) {
|
||||||
cardDisplay = cd;
|
cardDisplay = cd;
|
||||||
@@ -156,13 +217,9 @@ public class TableModel extends AbstractTableModel {
|
|||||||
int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
|
int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
|
||||||
|
|
||||||
if (modelIndex < 0) { return; }
|
if (modelIndex < 0) { return; }
|
||||||
if (sortColumn == modelIndex) {
|
|
||||||
isSortAsc = !isSortAsc;
|
// This will invert if needed
|
||||||
}
|
sortOrders.add(modelIndex);
|
||||||
else {
|
|
||||||
isSortAsc = true;
|
|
||||||
sortColumn = modelIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < columns.size(); i++) {
|
for (int i = 0; i < columns.size(); i++) {
|
||||||
TableColumn column = colModel.getColumn(i);
|
TableColumn column = colModel.getColumn(i);
|
||||||
@@ -216,14 +273,11 @@ public class TableModel extends AbstractTableModel {
|
|||||||
|
|
||||||
|
|
||||||
public void resort() {
|
public void resort() {
|
||||||
TableSorter sorter = new TableSorter(columns.get(sortColumn).fnSort, isSortAsc);
|
Collections.sort(data.getOrderedList(), sortOrders.getSorter());
|
||||||
Collections.sort(data.getOrderedList(), sorter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sort( int iCol, boolean isAsc )
|
public void sort( int iCol, boolean isAsc ) {
|
||||||
{
|
sortOrders.add(iCol, isAsc);
|
||||||
sortColumn = iCol;
|
|
||||||
isSortAsc = isAsc;
|
|
||||||
resort();
|
resort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,15 +38,12 @@ public class TableSorter implements Comparator<Entry<CardPrinted, Integer>> {
|
|||||||
@Override public Comparable apply(final Entry<CardPrinted, Integer> from) { return from.getKey(); }
|
@Override public Comparable apply(final Entry<CardPrinted, Integer> from) { return from.getKey(); }
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public int compare(Entry<CardPrinted, Integer> arg0, Entry<CardPrinted, Integer> arg1) {
|
public int compare(Entry<CardPrinted, Integer> arg0, Entry<CardPrinted, Integer> arg1) {
|
||||||
Comparable obj1 = field.apply(arg0);
|
Comparable obj1 = field.apply(arg0);
|
||||||
Comparable obj2 = field.apply(arg1);
|
Comparable obj2 = field.apply(arg1);
|
||||||
//System.out.println(String.format("%s vs %s _______ %s vs %s", arg0, arg1, obj1, obj2));
|
//System.out.println(String.format("%s vs %s _______ %s vs %s", arg0, arg1, obj1, obj2));
|
||||||
if (ascending) { return obj1.compareTo(obj2); }
|
return ascending ? obj1.compareTo(obj2) : obj2.compareTo(obj1);
|
||||||
else { return 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