mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
GuiChoose invokes ListChooser from EDT thread.
This commit is contained in:
@@ -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() );
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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,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);
|
||||
final JList list = c.getJList();
|
||||
list.addListSelectionListener(new ListSelectionListener() {
|
||||
@@ -120,7 +126,12 @@ public class GuiChoose {
|
||||
});
|
||||
c.show();
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user