@Override
  public void invokeAndWait(@NotNull Runnable runnable, @NotNull ModalityState modalityState) {
    if (isDispatchThread()) {
      runnable.run();
    }
    else {
      try {
        SwingUtilities.invokeAndWait(runnable);
      }
      catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
  }
@Override
  public void invokeAndWait(@NotNull Runnable runnable, @NotNull ModalityState modalityState)