Created
July 14, 2011 21:06
-
-
Save grignaak/1083442 to your computer and use it in GitHub Desktop.
Swing EDT utilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.Callable; | |
import java.util.concurrent.atomic.AtomicReference; | |
import javax.swing.SwingUtilities; | |
public class EventQueue { | |
private EventQueue() {} | |
public static void invokeAndWait(Runnable doRun) { | |
try { | |
SwingUtilities.invokeAndWait(doRun); | |
} catch (Exception e) { | |
throw Exceptions.rethrow(e); | |
} | |
} | |
public static void invokeLater(Runnable doRun) { | |
SwingUtilities.invokeLater(doRun); | |
} | |
public static boolean isEventDispatchThread() { | |
return SwingUtilities.isEventDispatchThread(); | |
} | |
public static <T> T invokeAndGet(final Callable<T> doRun) { | |
final AtomicReference<T> result = new AtomicReference<T>(); | |
invokeAndWait(new Runnable() { | |
public void run() { | |
try { | |
result.set(doRun.call()); | |
} catch (Exception e) { | |
Exceptions.rethrow(e); | |
} | |
} | |
}); | |
return result.get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This uses my Exceptions utility class