mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
FThreads.checkEDT renamed and no longer requires a parameter with calling method name, since it can be derived from current stack trace.
This commit is contained in:
@@ -43,9 +43,10 @@ public class FThreads {
|
||||
* @param methodName   String, part of the custom exception message.
|
||||
* @param mustBeEDT   boolean: true = exception if not EDT, false = exception if EDT
|
||||
*/
|
||||
public static void checkEDT(final String methodName, final boolean mustBeEDT) {
|
||||
boolean isEDT = SwingUtilities.isEventDispatchThread();
|
||||
if ( isEDT != mustBeEDT ) {
|
||||
public static void assertExecutedByEdt(final boolean mustBeEDT) {
|
||||
if (isEDT() != mustBeEDT ) {
|
||||
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
|
||||
final String methodName = trace[2].getClassName() + "." + trace[2].getMethodName();
|
||||
String modalOperator = mustBeEDT ? " must be" : " may not be";
|
||||
throw new IllegalStateException( methodName + modalOperator + " accessed from the event dispatch thread.");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract class InputSyncronizedBase extends InputBase implements InputSyn
|
||||
}
|
||||
|
||||
public void awaitLatchRelease() {
|
||||
FThreads.checkEDT("InputSyncronizedBase.awaitLatchRelease", false);
|
||||
FThreads.assertExecutedByEdt(false);
|
||||
try{
|
||||
cdlDone.await();
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
@@ -709,7 +709,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
* </p>
|
||||
*/
|
||||
public final void passPriority() {
|
||||
FThreads.checkEDT("PhaseHandler.passPriority", false);
|
||||
FThreads.assertExecutedByEdt(false);
|
||||
// stop game if it's outcome is clear
|
||||
if (game.isGameOver()) {
|
||||
return;
|
||||
|
||||
@@ -102,7 +102,7 @@ public class HumanPlayer extends Player {
|
||||
* a {@link forge.card.spellability.SpellAbility} object.
|
||||
*/
|
||||
public final void playSpellAbility(SpellAbility sa) {
|
||||
FThreads.checkEDT("Player.playSpellAbility", false);
|
||||
FThreads.assertExecutedByEdt(false);
|
||||
sa.setActivatingPlayer(this);
|
||||
|
||||
final Card source = sa.getSourceCard();
|
||||
@@ -253,7 +253,7 @@ public class HumanPlayer extends Player {
|
||||
* a {@link forge.card.spellability.SpellAbility} object.
|
||||
*/
|
||||
public final void playSpellAbilityWithoutPayingManaCost(final SpellAbility sa) {
|
||||
FThreads.checkEDT("GameActionPlay.playSpellAbilityWithoutPayingManaCost", false);
|
||||
FThreads.assertExecutedByEdt(false);
|
||||
final Card source = sa.getSourceCard();
|
||||
|
||||
source.setSplitStateToPlayAbility(sa);
|
||||
|
||||
@@ -1580,7 +1580,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final boolean discard(final Card c, final SpellAbility sa) {
|
||||
FThreads.checkEDT("Player.doDiscard", false);
|
||||
FThreads.assertExecutedByEdt(false);
|
||||
// TODO: This line should be moved inside CostPayment somehow
|
||||
/*if (sa != null) {
|
||||
sa.addCostToHashList(c, "Discarded");
|
||||
@@ -1746,7 +1746,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
|
||||
* a {@link forge.Card} object.
|
||||
*/
|
||||
public final void playLand(final Card land) {
|
||||
FThreads.checkEDT("Player.playSpellAbility", false);
|
||||
FThreads.assertExecutedByEdt(false);
|
||||
if (this.canPlayLand(land)) {
|
||||
land.setController(this, 0);
|
||||
game.getAction().moveTo(this.getZone(ZoneType.Battlefield), land);
|
||||
|
||||
@@ -301,7 +301,7 @@ public class MagicStack extends MyObservable {
|
||||
* a {@link forge.card.spellability.SpellAbility} object.
|
||||
*/
|
||||
public final void add(final SpellAbility sp) {
|
||||
FThreads.checkEDT("MagicStack.add", false);
|
||||
FThreads.assertExecutedByEdt(false);
|
||||
final ArrayList<TargetChoices> chosenTargets = sp.getAllTargetChoices();
|
||||
|
||||
if (sp.isManaAbility()) { // Mana Abilities go straight through
|
||||
|
||||
@@ -42,6 +42,8 @@ import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.FThreads;
|
||||
|
||||
/**
|
||||
* A simple class that shows a list of choices in a dialog. Two properties
|
||||
* influence the behavior of a list chooser: minSelection and maxSelection.
|
||||
@@ -84,6 +86,7 @@ public class ListChooser<T> {
|
||||
private Action ok, cancel;
|
||||
|
||||
public ListChooser(final String title, final int minChoices, final int maxChoices, final Collection<T> list) {
|
||||
FThreads.assertExecutedByEdt(true);
|
||||
this.title = title;
|
||||
this.minChoices = minChoices;
|
||||
this.maxChoices = maxChoices;
|
||||
|
||||
@@ -37,7 +37,7 @@ public class FProgressBar extends JProgressBar {
|
||||
* @param s0   A description to prepend before statistics.
|
||||
*/
|
||||
public void setDescription(final String s0) {
|
||||
FThreads.checkEDT("FProgressBar$setDescription", true);
|
||||
FThreads.assertExecutedByEdt(true);
|
||||
this.desc = s0;
|
||||
this.setString(s0);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class FProgressBar extends JProgressBar {
|
||||
|
||||
/** Resets the various values required for this class. Must be called from EDT. */
|
||||
public void reset() {
|
||||
FThreads.checkEDT("FProgressBar$reset", true);
|
||||
FThreads.assertExecutedByEdt(true);
|
||||
this.setIndeterminate(true);
|
||||
this.setValue(0);
|
||||
this.tempVal = 0;
|
||||
|
||||
@@ -420,7 +420,7 @@ public enum FSkin {
|
||||
*/
|
||||
public static void loadLight(final String skinName) {
|
||||
// No need for this method to be loaded while on the EDT.
|
||||
FThreads.checkEDT("FSkin$constructor", false);
|
||||
FThreads.assertExecutedByEdt(false);
|
||||
|
||||
// Non-default (preferred) skin name and dir.
|
||||
FSkin.preferredName = skinName.toLowerCase().replace(' ', '_');
|
||||
@@ -500,7 +500,7 @@ public enum FSkin {
|
||||
*/
|
||||
public static void loadFull() {
|
||||
// No need for this method to be loaded while on the EDT.
|
||||
FThreads.checkEDT("FSkin$load", false);
|
||||
FThreads.assertExecutedByEdt(false);
|
||||
|
||||
// Preferred skin name must be called via loadLight() method,
|
||||
// which does some cleanup and init work.
|
||||
|
||||
@@ -162,7 +162,7 @@ public enum FModel {
|
||||
this.loadDynamicGamedata();
|
||||
|
||||
// Loads all cards (using progress bar).
|
||||
FThreads.checkEDT("CardFactory$constructor", false);
|
||||
FThreads.assertExecutedByEdt(false);
|
||||
final CardStorageReader reader = new CardStorageReader(NewConstants.CARD_DATA_DIR, true);
|
||||
try {
|
||||
// this fills in our map of card names to Card instances.
|
||||
|
||||
Reference in New Issue
Block a user