GuiChoose invokes ListChooser from EDT thread.

This commit is contained in:
Maxmtg
2013-04-02 19:54:17 +00:00
parent 02cff88cf9
commit 81b988ae14
3 changed files with 38 additions and 20 deletions

View File

@@ -15,6 +15,14 @@ import forge.control.input.InputSynchronized;
*
*/
public class FThreads {
// This could be some bad copy of SwingWorker
public abstract static class RunnableWithResult<T> implements Runnable {
protected T result = null;
public T getResult() { return result; }
}
static {
System.out.printf("(FThreads static ctor): Running on a machine with %d cpu core(s)%n", Runtime.getRuntime().availableProcessors() );
}

View File

@@ -14,7 +14,7 @@ import forge.card.mana.ManaPool;
import forge.card.spellability.AbilityManaPart;
import forge.card.spellability.SpellAbility;
import forge.game.GameState;
import forge.game.player.Player;
import forge.game.player.HumanPlayer;
import forge.game.zone.ZoneType;
import forge.gui.GuiChoose;
import forge.gui.framework.SDisplayUtil;
@@ -291,8 +291,7 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
Runnable proc = new Runnable() {
@Override
public void run() {
final Player p = chosen.getActivatingPlayer();
p.getGame().getActionPlay().playSpellAbility(chosen, p);
player.getGame().getActionPlay().playSpellAbility(chosen, (HumanPlayer)chosen.getActivatingPlayer());
onManaAbilityPlayed(chosen);
}
};

View File

@@ -7,6 +7,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.Callable;
import javax.swing.JDialog;
import javax.swing.JFrame;
@@ -16,6 +17,7 @@ import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import forge.Card;
import forge.FThreads;
import forge.gui.match.CMatchUI;
import forge.item.InventoryItem;
@@ -102,25 +104,34 @@ public class GuiChoose {
}
}
ListChooser<T> c = new ListChooser<T>(message, min, max, choices);
final JList list = c.getJList();
list.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent ev) {
if (list.getSelectedValue() instanceof Card) {
CMatchUI.SINGLETON_INSTANCE.setCard((Card) list.getSelectedValue());
FThreads.RunnableWithResult<List<T>> showChoice = new FThreads.RunnableWithResult<List<T>>() {
GuiUtils.clearPanelSelections();
GuiUtils.setPanelSelection((Card) list.getSelectedValue());
}
if (list.getSelectedValue() instanceof InventoryItem) {
CMatchUI.SINGLETON_INSTANCE.setCard((InventoryItem) list.getSelectedValue());
}
@Override
public void run() {
ListChooser<T> c = new ListChooser<T>(message, min, max, choices);
final JList list = c.getJList();
list.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent ev) {
if (list.getSelectedValue() instanceof Card) {
CMatchUI.SINGLETON_INSTANCE.setCard((Card) list.getSelectedValue());
GuiUtils.clearPanelSelections();
GuiUtils.setPanelSelection((Card) list.getSelectedValue());
}
if (list.getSelectedValue() instanceof InventoryItem) {
CMatchUI.SINGLETON_INSTANCE.setCard((InventoryItem) list.getSelectedValue());
}
}
});
c.show();
GuiUtils.clearPanelSelections();
result = c.getSelectedValues();
}
});
c.show();
GuiUtils.clearPanelSelections();
return c.getSelectedValues();
};
FThreads.invokeInEDTAndWait(showChoice);
return showChoice.getResult();
}
// Nothing to choose here. Code uses this to just show a card.