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:
Maxmtg
2013-04-05 04:07:03 +00:00
parent 018729fbcd
commit 092154b0f0
10 changed files with 19 additions and 15 deletions

View File

@@ -43,9 +43,10 @@ public class FThreads {
* @param methodName   String, part of the custom exception message. * @param methodName   String, part of the custom exception message.
* @param mustBeEDT   boolean: true = exception if not EDT, false = exception if EDT * @param mustBeEDT   boolean: true = exception if not EDT, false = exception if EDT
*/ */
public static void checkEDT(final String methodName, final boolean mustBeEDT) { public static void assertExecutedByEdt(final boolean mustBeEDT) {
boolean isEDT = SwingUtilities.isEventDispatchThread(); if (isEDT() != 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"; String modalOperator = mustBeEDT ? " must be" : " may not be";
throw new IllegalStateException( methodName + modalOperator + " accessed from the event dispatch thread."); throw new IllegalStateException( methodName + modalOperator + " accessed from the event dispatch thread.");
} }

View File

@@ -17,7 +17,7 @@ public abstract class InputSyncronizedBase extends InputBase implements InputSyn
} }
public void awaitLatchRelease() { public void awaitLatchRelease() {
FThreads.checkEDT("InputSyncronizedBase.awaitLatchRelease", false); FThreads.assertExecutedByEdt(false);
try{ try{
cdlDone.await(); cdlDone.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {

View File

@@ -709,7 +709,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
* </p> * </p>
*/ */
public final void passPriority() { public final void passPriority() {
FThreads.checkEDT("PhaseHandler.passPriority", false); FThreads.assertExecutedByEdt(false);
// stop game if it's outcome is clear // stop game if it's outcome is clear
if (game.isGameOver()) { if (game.isGameOver()) {
return; return;

View File

@@ -102,7 +102,7 @@ public class HumanPlayer extends Player {
* a {@link forge.card.spellability.SpellAbility} object. * a {@link forge.card.spellability.SpellAbility} object.
*/ */
public final void playSpellAbility(SpellAbility sa) { public final void playSpellAbility(SpellAbility sa) {
FThreads.checkEDT("Player.playSpellAbility", false); FThreads.assertExecutedByEdt(false);
sa.setActivatingPlayer(this); sa.setActivatingPlayer(this);
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
@@ -253,7 +253,7 @@ public class HumanPlayer extends Player {
* a {@link forge.card.spellability.SpellAbility} object. * a {@link forge.card.spellability.SpellAbility} object.
*/ */
public final void playSpellAbilityWithoutPayingManaCost(final SpellAbility sa) { public final void playSpellAbilityWithoutPayingManaCost(final SpellAbility sa) {
FThreads.checkEDT("GameActionPlay.playSpellAbilityWithoutPayingManaCost", false); FThreads.assertExecutedByEdt(false);
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
source.setSplitStateToPlayAbility(sa); source.setSplitStateToPlayAbility(sa);

View File

@@ -1580,7 +1580,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public final boolean discard(final Card c, final SpellAbility sa) { 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 // TODO: This line should be moved inside CostPayment somehow
/*if (sa != null) { /*if (sa != null) {
sa.addCostToHashList(c, "Discarded"); sa.addCostToHashList(c, "Discarded");
@@ -1746,7 +1746,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
* a {@link forge.Card} object. * a {@link forge.Card} object.
*/ */
public final void playLand(final Card land) { public final void playLand(final Card land) {
FThreads.checkEDT("Player.playSpellAbility", false); FThreads.assertExecutedByEdt(false);
if (this.canPlayLand(land)) { if (this.canPlayLand(land)) {
land.setController(this, 0); land.setController(this, 0);
game.getAction().moveTo(this.getZone(ZoneType.Battlefield), land); game.getAction().moveTo(this.getZone(ZoneType.Battlefield), land);

View File

@@ -301,7 +301,7 @@ public class MagicStack extends MyObservable {
* a {@link forge.card.spellability.SpellAbility} object. * a {@link forge.card.spellability.SpellAbility} object.
*/ */
public final void add(final SpellAbility sp) { public final void add(final SpellAbility sp) {
FThreads.checkEDT("MagicStack.add", false); FThreads.assertExecutedByEdt(false);
final ArrayList<TargetChoices> chosenTargets = sp.getAllTargetChoices(); final ArrayList<TargetChoices> chosenTargets = sp.getAllTargetChoices();
if (sp.isManaAbility()) { // Mana Abilities go straight through if (sp.isManaAbility()) { // Mana Abilities go straight through

View File

@@ -42,6 +42,8 @@ import javax.swing.event.ListSelectionListener;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import forge.FThreads;
/** /**
* A simple class that shows a list of choices in a dialog. Two properties * A simple class that shows a list of choices in a dialog. Two properties
* influence the behavior of a list chooser: minSelection and maxSelection. * influence the behavior of a list chooser: minSelection and maxSelection.
@@ -84,6 +86,7 @@ public class ListChooser<T> {
private Action ok, cancel; private Action ok, cancel;
public ListChooser(final String title, final int minChoices, final int maxChoices, final Collection<T> list) { public ListChooser(final String title, final int minChoices, final int maxChoices, final Collection<T> list) {
FThreads.assertExecutedByEdt(true);
this.title = title; this.title = title;
this.minChoices = minChoices; this.minChoices = minChoices;
this.maxChoices = maxChoices; this.maxChoices = maxChoices;

View File

@@ -37,7 +37,7 @@ public class FProgressBar extends JProgressBar {
* @param s0 &emsp; A description to prepend before statistics. * @param s0 &emsp; A description to prepend before statistics.
*/ */
public void setDescription(final String s0) { public void setDescription(final String s0) {
FThreads.checkEDT("FProgressBar$setDescription", true); FThreads.assertExecutedByEdt(true);
this.desc = s0; this.desc = s0;
this.setString(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. */ /** Resets the various values required for this class. Must be called from EDT. */
public void reset() { public void reset() {
FThreads.checkEDT("FProgressBar$reset", true); FThreads.assertExecutedByEdt(true);
this.setIndeterminate(true); this.setIndeterminate(true);
this.setValue(0); this.setValue(0);
this.tempVal = 0; this.tempVal = 0;

View File

@@ -420,7 +420,7 @@ public enum FSkin {
*/ */
public static void loadLight(final String skinName) { public static void loadLight(final String skinName) {
// No need for this method to be loaded while on the EDT. // 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. // Non-default (preferred) skin name and dir.
FSkin.preferredName = skinName.toLowerCase().replace(' ', '_'); FSkin.preferredName = skinName.toLowerCase().replace(' ', '_');
@@ -500,7 +500,7 @@ public enum FSkin {
*/ */
public static void loadFull() { public static void loadFull() {
// No need for this method to be loaded while on the EDT. // 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, // Preferred skin name must be called via loadLight() method,
// which does some cleanup and init work. // which does some cleanup and init work.

View File

@@ -162,7 +162,7 @@ public enum FModel {
this.loadDynamicGamedata(); this.loadDynamicGamedata();
// Loads all cards (using progress bar). // Loads all cards (using progress bar).
FThreads.checkEDT("CardFactory$constructor", false); FThreads.assertExecutedByEdt(false);
final CardStorageReader reader = new CardStorageReader(NewConstants.CARD_DATA_DIR, true); final CardStorageReader reader = new CardStorageReader(NewConstants.CARD_DATA_DIR, true);
try { try {
// this fills in our map of card names to Card instances. // this fills in our map of card names to Card instances.