mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
* GuiChoose.getOrderChoice is properly parameterized now
This commit is contained in:
@@ -767,7 +767,7 @@ public final class AbilityFactoryClash {
|
||||
|
||||
// first, separate the cards into piles
|
||||
if (separator.isHuman()) {
|
||||
final List<Object> firstPile = GuiChoose.getOrderChoices("Place into two piles", "Pile 1", -1, pool.toArray(), null, card);
|
||||
final List<Card> firstPile = GuiChoose.getOrderChoices("Place into two piles", "Pile 1", -1, pool, null, card);
|
||||
for (final Object o : firstPile) {
|
||||
pile1.add((Card)o);
|
||||
}
|
||||
|
||||
@@ -2050,7 +2050,7 @@ public final class AbilityFactoryReveal {
|
||||
topCards.add(lib.get(j));
|
||||
}
|
||||
|
||||
List<Object> orderedCards = GuiChoose.getOrderChoices("Select order to Rearrange", "Top of Library", 0, topCards.toArray(), null, src);
|
||||
List<Card> orderedCards = GuiChoose.getOrderChoices("Select order to Rearrange", "Top of Library", 0, topCards, null, src);
|
||||
for (int i = maxCards - 1; i >= 0; i--) {
|
||||
Card next = (Card) orderedCards.get(i);
|
||||
Singletons.getModel().getGameAction().moveToLibrary(next, 0);
|
||||
@@ -2414,7 +2414,7 @@ public final class AbilityFactoryReveal {
|
||||
final int validamount = Math.min(valid.size(), max);
|
||||
|
||||
if (anyNumber && player.isHuman() && validamount > 0) {
|
||||
final List<Object> selection = GuiChoose.getOrderChoices("Choose Which Cards to Reveal", "Revealed", -1, valid.toArray(), null, null);
|
||||
final List<Card> selection = GuiChoose.getOrderChoices("Choose Which Cards to Reveal", "Revealed", -1, valid, null, null);
|
||||
for (final Object o : selection) {
|
||||
if (o != null && o instanceof Card) {
|
||||
chosen.add((Card) o);
|
||||
|
||||
@@ -4847,7 +4847,7 @@ public class CardFactoryUtil {
|
||||
card.clearDevoured();
|
||||
if (card.getController().isHuman()) {
|
||||
if (creats.size() > 0) {
|
||||
final List<Object> selection = GuiChoose.getOrderChoices("Devour", "Devouring", -1, creats.toArray(), null, card);
|
||||
final List<Card> selection = GuiChoose.getOrderChoices("Devour", "Devouring", -1, creats, null, card);
|
||||
numCreatures[0] = selection.size();
|
||||
|
||||
for (Object o : selection) {
|
||||
|
||||
@@ -440,7 +440,7 @@ public class CombatUtil {
|
||||
|
||||
List<Card> orderedBlockers = null;
|
||||
if (player.isHuman()) {
|
||||
List<Object> ordered = GuiChoose.getOrderChoices("Choose Blocking Order", "Damaged First", 0, blockers.toArray(), null, attacker);
|
||||
List<Card> ordered = GuiChoose.getOrderChoices("Choose Blocking Order", "Damaged First", 0, blockers, null, attacker);
|
||||
|
||||
orderedBlockers = new ArrayList<Card>();
|
||||
for(Object o : ordered) {
|
||||
@@ -468,7 +468,7 @@ public class CombatUtil {
|
||||
|
||||
List<Card> orderedAttacker = null;
|
||||
if (player.isHuman()) {
|
||||
List<Object> ordered = GuiChoose.getOrderChoices("Choose Blocking Order", "Damaged First", 0, attackers.toArray(), null, blocker);
|
||||
List<Card> ordered = GuiChoose.getOrderChoices("Choose Blocking Order", "Damaged First", 0, attackers, null, blocker);
|
||||
|
||||
orderedAttacker = new ArrayList<Card>();
|
||||
for(Object o : ordered) {
|
||||
|
||||
@@ -1355,7 +1355,7 @@ public class MagicStack extends MyObservable {
|
||||
}
|
||||
else{
|
||||
// Otherwise, gave a dual list form to create instead of needing to do it one at a time
|
||||
List<Object> orderedSAs = GuiChoose.getOrderChoices("Select order for Simultaneous Spell Abilities", "Resolve first", 0, activePlayerSAs.toArray(), null, null);
|
||||
List<SpellAbility> orderedSAs = GuiChoose.getOrderChoices("Select order for Simultaneous Spell Abilities", "Resolve first", 0, activePlayerSAs, null, null);
|
||||
int size = orderedSAs.size();
|
||||
for(int i = size-1; i >= 0; i--){
|
||||
SpellAbility next = (SpellAbility)orderedSAs.get(i);
|
||||
|
||||
@@ -6,8 +6,7 @@ import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
@@ -35,14 +34,14 @@ import forge.gui.match.CMatchUI;
|
||||
// Single ok button, disabled until left box is empty
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class DualListBox extends JPanel {
|
||||
public class DualListBox<T> extends JPanel {
|
||||
private JList sourceList;
|
||||
|
||||
private UnsortedListModel sourceListModel;
|
||||
private UnsortedListModel<T> sourceListModel;
|
||||
|
||||
private JList destList;
|
||||
|
||||
private UnsortedListModel destListModel;
|
||||
private UnsortedListModel<T> destListModel;
|
||||
|
||||
private JButton addButton;
|
||||
private JButton addAllButton;
|
||||
@@ -59,7 +58,7 @@ public class DualListBox extends JPanel {
|
||||
|
||||
private Card refCard = null;
|
||||
|
||||
public DualListBox(int remainingObjects, String label, Object[] sourceElements, Object[] destElements,
|
||||
public DualListBox(int remainingObjects, String label, List<T> sourceElements, List<T> destElements,
|
||||
Card referenceCard) {
|
||||
this.remainingObjects = remainingObjects;
|
||||
this.refCard = referenceCard;
|
||||
@@ -91,31 +90,32 @@ public class DualListBox extends JPanel {
|
||||
addSourceElements(newValue);
|
||||
}
|
||||
|
||||
public void addDestinationElements(List<T> newValue) {
|
||||
fillListModel(destListModel, newValue);
|
||||
}
|
||||
|
||||
public void addDestinationElements(ListModel newValue) {
|
||||
fillListModel(destListModel, newValue);
|
||||
}
|
||||
|
||||
private void fillListModel(UnsortedListModel model, ListModel newValues) {
|
||||
@SuppressWarnings("unchecked") // Java 7 has type parameterized ListModel
|
||||
private void fillListModel(UnsortedListModel<T> model, ListModel newValues) {
|
||||
int size = newValues.getSize();
|
||||
for (int i = 0; i < size; i++) {
|
||||
model.add(newValues.getElementAt(i));
|
||||
model.add((T)newValues.getElementAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void addSourceElements(Object[] newValue) {
|
||||
public void addSourceElements(List<T> newValue) {
|
||||
fillListModel(sourceListModel, newValue);
|
||||
}
|
||||
|
||||
public void setSourceElements(Object[] newValue) {
|
||||
public void setSourceElements(List<T> newValue) {
|
||||
clearSourceListModel();
|
||||
addSourceElements(newValue);
|
||||
}
|
||||
|
||||
public void addDestinationElements(Object[] newValue) {
|
||||
fillListModel(destListModel, newValue);
|
||||
}
|
||||
|
||||
private void fillListModel(UnsortedListModel model, Object[] newValues) {
|
||||
private void fillListModel(UnsortedListModel<T> model, List<T> newValues) {
|
||||
model.addAll(newValues);
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public class DualListBox extends JPanel {
|
||||
destList.getSelectionModel().clearSelection();
|
||||
}
|
||||
|
||||
public List<Object> getOrderedList() {
|
||||
public List<T> getOrderedList() {
|
||||
this.setVisible(false);
|
||||
return destListModel.model;
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public class DualListBox extends JPanel {
|
||||
private void initScreen() {
|
||||
setPreferredSize(new Dimension(650, 300));
|
||||
setLayout(new GridLayout(0, 3));
|
||||
sourceListModel = new UnsortedListModel();
|
||||
sourceListModel = new UnsortedListModel<T>();
|
||||
sourceList = new JList(sourceListModel);
|
||||
|
||||
// Dual List control buttons
|
||||
@@ -182,7 +182,7 @@ public class DualListBox extends JPanel {
|
||||
autoButton = new JButton("Auto");
|
||||
autoButton.addActionListener(new AutoListener());
|
||||
|
||||
destListModel = new UnsortedListModel();
|
||||
destListModel = new UnsortedListModel<T>();
|
||||
destList = new JList(destListModel);
|
||||
|
||||
JPanel leftPanel = new JPanel(new BorderLayout());
|
||||
@@ -217,7 +217,8 @@ public class DualListBox extends JPanel {
|
||||
private class AddListener implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Object[] selected = sourceList.getSelectedValues();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<T> selected = (List<T>) Arrays.asList(sourceList.getSelectedValues());
|
||||
addDestinationElements(selected);
|
||||
clearSourceSelected();
|
||||
sourceList.validate();
|
||||
@@ -226,16 +227,7 @@ public class DualListBox extends JPanel {
|
||||
}
|
||||
|
||||
private void addAll() {
|
||||
Iterator<Object> itr = sourceListModel.iterator();
|
||||
|
||||
ArrayList<Object> objects = new ArrayList<Object>();
|
||||
|
||||
while (itr.hasNext()) {
|
||||
Object obj = itr.next();
|
||||
objects.add(obj);
|
||||
}
|
||||
|
||||
addDestinationElements(objects.toArray());
|
||||
addDestinationElements(sourceListModel);
|
||||
clearSourceListModel();
|
||||
setButtonState();
|
||||
}
|
||||
@@ -251,7 +243,8 @@ public class DualListBox extends JPanel {
|
||||
private class RemoveListener implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Object[] selected = destList.getSelectedValues();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<T> selected = (List<T>) Arrays.asList(destList.getSelectedValues());
|
||||
addSourceElements(selected);
|
||||
clearDestinationSelected();
|
||||
setButtonState();
|
||||
@@ -261,16 +254,7 @@ public class DualListBox extends JPanel {
|
||||
private class RemoveAllListener implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Iterator<Object> itr = destListModel.iterator();
|
||||
|
||||
ArrayList<Object> objects = new ArrayList<Object>();
|
||||
|
||||
while (itr.hasNext()) {
|
||||
Object obj = itr.next();
|
||||
objects.add(obj);
|
||||
}
|
||||
|
||||
addSourceElements(objects.toArray());
|
||||
addSourceElements(destListModel);
|
||||
clearDestinationListModel();
|
||||
setButtonState();
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class GuiAssignDamageFrame extends JFrame {
|
||||
private final JPanel buttonPanel = new JPanel();
|
||||
private final BoxLayout buttonLayout = new BoxLayout(buttonPanel, BoxLayout.X_AXIS);
|
||||
|
||||
private UnsortedListModel recipientsListModel = new UnsortedListModel();
|
||||
private UnsortedListModel<GameEntity> recipientsListModel = new UnsortedListModel<GameEntity>();
|
||||
private final JList recipientsList = new JList(recipientsListModel);
|
||||
|
||||
private final JButton oneDamageButton = new JButton("Assign 1");
|
||||
|
||||
@@ -194,11 +194,11 @@ public class GuiChoose {
|
||||
return c.getSelectedValues();
|
||||
} // getChoice()
|
||||
|
||||
public static List<Object> getOrderChoices(final String title, final String top, int remainingObjects,
|
||||
final Object[] sourceChoices, Object[] destChoices, Card referenceCard) {
|
||||
public static <T> List<T> getOrderChoices(final String title, final String top, int remainingObjects,
|
||||
final List<T> sourceChoices, List<T> destChoices, Card referenceCard) {
|
||||
// An input box for handling the order of choices.
|
||||
final JFrame frame = new JFrame();
|
||||
DualListBox dual = new DualListBox(remainingObjects, top, sourceChoices, destChoices, referenceCard);
|
||||
DualListBox<T> dual = new DualListBox<T>(remainingObjects, top, sourceChoices, destChoices, referenceCard);
|
||||
|
||||
frame.setLayout(new BorderLayout());
|
||||
frame.setSize(dual.getPreferredSize());
|
||||
@@ -218,7 +218,7 @@ public class GuiChoose {
|
||||
}
|
||||
dialog.setVisible(true);
|
||||
|
||||
List<Object> objects = dual.getOrderedList();
|
||||
List<T> objects = dual.getOrderedList();
|
||||
dialog.dispose();
|
||||
return objects;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package forge.gui;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
@@ -8,12 +7,13 @@ import java.util.List;
|
||||
|
||||
import javax.swing.AbstractListModel;
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class UnsortedListModel extends AbstractListModel {
|
||||
List<Object> model;
|
||||
class UnsortedListModel<T> extends AbstractListModel { // Java 7 has a generic version. In 6 we have to cast types
|
||||
List<T> model;
|
||||
|
||||
public UnsortedListModel() {
|
||||
model = new LinkedList<Object>();
|
||||
model = new LinkedList<T>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,18 +26,24 @@ class UnsortedListModel extends AbstractListModel {
|
||||
return model.get(index);
|
||||
}
|
||||
|
||||
public void add(Object element) {
|
||||
public void add(T element) {
|
||||
if (model.add(element)) {
|
||||
fireContentsChanged(this, 0, getSize());
|
||||
}
|
||||
}
|
||||
|
||||
public void addAll(Object elements[]) {
|
||||
Collection<Object> c = Arrays.asList(elements);
|
||||
model.addAll(c);
|
||||
public void addAll(T[] elements) {
|
||||
for(T e : elements)
|
||||
model.add(e);
|
||||
fireContentsChanged(this, 0, getSize());
|
||||
}
|
||||
|
||||
public void addAll(Collection<T> elements) {
|
||||
model.addAll(elements);
|
||||
fireContentsChanged(this, 0, getSize());
|
||||
}
|
||||
|
||||
|
||||
public void clear() {
|
||||
model.clear();
|
||||
fireContentsChanged(this, 0, getSize());
|
||||
@@ -47,7 +53,7 @@ class UnsortedListModel extends AbstractListModel {
|
||||
return model.contains(element);
|
||||
}
|
||||
|
||||
public Iterator<Object> iterator() {
|
||||
public Iterator<T> iterator() {
|
||||
return model.iterator();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ public enum CPicture implements ICDoc {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private InventoryItem item = null;
|
||||
private Card currentCard = null;
|
||||
private boolean flipped = false;
|
||||
|
||||
@@ -46,14 +45,12 @@ public enum CPicture implements ICDoc {
|
||||
*   Card object
|
||||
*/
|
||||
public void showCard(final Card c) {
|
||||
this.item = null;
|
||||
this.currentCard = c;
|
||||
VPicture.SINGLETON_INSTANCE.getLblFlipcard().setVisible(c != null && c.isDoubleFaced() ? true : false);
|
||||
VPicture.SINGLETON_INSTANCE.getPnlPicture().setCard(c);
|
||||
}
|
||||
|
||||
public void showCard(final InventoryItem item) {
|
||||
this.item = item;
|
||||
this.currentCard = null;
|
||||
VPicture.SINGLETON_INSTANCE.getLblFlipcard().setVisible(false);
|
||||
VPicture.SINGLETON_INSTANCE.getPnlPicture().setCard(item);
|
||||
|
||||
Reference in New Issue
Block a user