+ /**
+ * Process the given action in the main Swing UI thread.
+ * <p>
+ * The code will make sure the current thread is the main UI thread and, if
+ * not, will switch to it before executing the runnable.
+ * <p>
+ * Synchronous operation.
+ *
+ * @param run
+ * the action to run
+ */
+ public void inUi(final Runnable run) {
+ if (EventQueue.isDispatchThread()) {
+ run.run();
+ } else {
+ try {
+ EventQueue.invokeAndWait(run);
+ } catch (InterruptedException e) {
+ Instance.getTraceHandler().error(e);
+ } catch (InvocationTargetException e) {
+ Instance.getTraceHandler().error(e);
+ }
+ }
+ }
+