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 { 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 { static {
System.out.printf("(FThreads static ctor): Running on a machine with %d cpu core(s)%n", Runtime.getRuntime().availableProcessors() ); 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.AbilityManaPart;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GameState; import forge.game.GameState;
import forge.game.player.Player; import forge.game.player.HumanPlayer;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.GuiChoose; import forge.gui.GuiChoose;
import forge.gui.framework.SDisplayUtil; import forge.gui.framework.SDisplayUtil;
@@ -291,8 +291,7 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
Runnable proc = new Runnable() { Runnable proc = new Runnable() {
@Override @Override
public void run() { public void run() {
final Player p = chosen.getActivatingPlayer(); player.getGame().getActionPlay().playSpellAbility(chosen, (HumanPlayer)chosen.getActivatingPlayer());
p.getGame().getActionPlay().playSpellAbility(chosen, p);
onManaAbilityPlayed(chosen); onManaAbilityPlayed(chosen);
} }
}; };

View File

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