- AF_TwoPiles will now use DualListBox

- DualListBox now will display Source Cards when selected
This commit is contained in:
Sol
2012-09-02 18:48:17 +00:00
parent da9ba6e45e
commit 5dff8256fd
4 changed files with 36 additions and 7 deletions

View File

@@ -766,9 +766,9 @@ public final class AbilityFactoryClash {
// first, separate the cards into piles // first, separate the cards into piles
if (separator.isHuman()) { if (separator.isHuman()) {
final List<Card> l = GuiUtils.chooseNoneOrMany("Put into pile 1 (multi-select)", pool.toArray()); final List<Object> firstPile = GuiUtils.getOrderChoices("Place into two piles", "Pile 1", false, (Object[])pool.toArray());
for (final Card c : l) { for (final Object o : firstPile) {
pile1.add(c); pile1.add((Card)o);
} }
for (final Card c : pool) { for (final Card c : pool) {

View File

@@ -1449,7 +1449,7 @@ public class MagicStack extends MyObservable {
} }
else{ else{
// Otherwise, gave a dual list form to create instead of needing to do it one at a time // Otherwise, gave a dual list form to create instead of needing to do it one at a time
List<Object> orderedSAs = GuiUtils.getOrderChoices("Select order for Simultaneous Spell Abilities", "Resolve first", activePlayerSAs.toArray()); List<Object> orderedSAs = GuiUtils.getOrderChoices("Select order for Simultaneous Spell Abilities", "Resolve first", true, activePlayerSAs.toArray());
int size = orderedSAs.size(); int size = orderedSAs.size();
for(int i = size-1; i >= 0; i--){ for(int i = size-1; i >= 0; i--){
SpellAbility next = (SpellAbility)orderedSAs.get(i); SpellAbility next = (SpellAbility)orderedSAs.get(i);

View File

@@ -22,6 +22,12 @@ import javax.swing.JList;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.ListModel; import javax.swing.ListModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import forge.Card;
import forge.card.spellability.SpellAbility;
import forge.gui.match.CMatchUI;
@SuppressWarnings("serial") @SuppressWarnings("serial")
class UnsortedListModel extends AbstractListModel { class UnsortedListModel extends AbstractListModel {
@@ -109,9 +115,9 @@ public class DualListBox extends JPanel {
private boolean selectAll = true; private boolean selectAll = true;
public DualListBox(boolean selectAll, String label) { public DualListBox(boolean selectAll, String label) {
this.selectAll = selectAll;
initScreen(); initScreen();
orderedLabel.setText(label); orderedLabel.setText(label);
this.selectAll = selectAll;
} }
public void clearSourceListModel() { public void clearSourceListModel() {
@@ -180,6 +186,26 @@ public class DualListBox extends JPanel {
return destListModel.model; return destListModel.model;
} }
private static void addCardViewListener(final JList list) {
list.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent ev) {
Card card = null;
Object obj = list.getSelectedValue();
if (obj instanceof Card) {
card = (Card) obj;
}
else if (obj instanceof SpellAbility) {
card = ((SpellAbility)obj).getSourceCard();
}
if (card != null) {
CMatchUI.SINGLETON_INSTANCE.setCard(card);
}
}
});
}
private void initScreen() { private void initScreen() {
setPreferredSize(new Dimension(650, 300)); setPreferredSize(new Dimension(650, 300));
setLayout(new GridLayout(0, 3)); setLayout(new GridLayout(0, 3));
@@ -230,6 +256,9 @@ public class DualListBox extends JPanel {
add(leftPanel); add(leftPanel);
add(centerPanel); add(centerPanel);
add(rightPanel); add(rightPanel);
addCardViewListener(sourceList);
addCardViewListener(destList);
} }
private class AddListener implements ActionListener { private class AddListener implements ActionListener {

View File

@@ -357,10 +357,10 @@ public final class GuiUtils {
return c.getSelectedValues(); return c.getSelectedValues();
} // getChoice() } // getChoice()
public static List<Object> getOrderChoices(final String title, final String top, final Object... choices) { public static List<Object> getOrderChoices(final String title, final String top, boolean selectAll, final Object... choices) {
// An input box for handling the order of choices. // An input box for handling the order of choices.
final JFrame frame = new JFrame(); final JFrame frame = new JFrame();
DualListBox dual = new DualListBox(true, top); DualListBox dual = new DualListBox(selectAll, top);
dual.addSourceElements(choices); dual.addSourceElements(choices);
frame.setLayout(new BorderLayout()); frame.setLayout(new BorderLayout());