Move WaitCallback and WaitRunnable to forge-gui

This commit is contained in:
drdev
2014-12-06 18:16:30 +00:00
parent b9275d5678
commit 8e26dc333f
3 changed files with 4 additions and 6 deletions

View File

@@ -0,0 +1,34 @@
package forge.util;
import forge.FThreads;
public abstract class WaitCallback<T> extends Callback<T> implements Runnable {
public class Lock {
}
private final Lock lock = new Lock();
private T result;
@Override
public final void run(T result0) {
result = result0;
synchronized (lock) {
lock.notify();
}
}
public final T invokeAndWait() {
FThreads.assertExecutedByEdt(false); //not supported if on UI thread
FThreads.invokeInEdtLater(this);
try {
synchronized (lock) {
lock.wait();
}
}
catch (InterruptedException e) {
e.printStackTrace();
}
return result;
}
}

View File

@@ -0,0 +1,31 @@
package forge.util;
import forge.FThreads;
public abstract class WaitRunnable implements Runnable {
public class Lock {
}
private final Lock lock = new Lock();
public void invokeAndWait() {
FThreads.assertExecutedByEdt(false); //not supported if on UI thread
FThreads.invokeInEdtLater(new Runnable() {
@Override
public void run() {
WaitRunnable.this.run();
synchronized(lock) {
lock.notify();
}
}
});
try {
synchronized(lock) {
lock.wait();
}
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}