JAL-4186 attempts to work in jalviewjs, still not working
[jalview.git] / src / jalview / gui / JvOptionPane.java
index 99ab26f..9b0d098 100644 (file)
@@ -73,6 +73,10 @@ public class JvOptionPane extends JOptionPane
 
   private static boolean interactiveMode = true;
 
+  public static final Callable<Void> NULLCALLABLE = () -> {
+    return null;
+  };
+
   private Component parentComponent;
 
   private ExecutorService executor = Executors.newCachedThreadPool();
@@ -1048,7 +1052,7 @@ public class JvOptionPane extends JOptionPane
     }
   }
 
-  public void showInternalDialog(JPanel mainPanel, String title,
+  public void showInternalDialog(Object mainPanel, String title,
           int yesNoCancelOption, int questionMessage, Icon icon,
           Object[] options, String initresponse)
   {
@@ -1066,7 +1070,6 @@ public class JvOptionPane extends JOptionPane
     this.setMessage(mainPanel);
 
     ourOptions = Arrays.asList(options);
-    int response;
     if (parentComponent != this
             && !(parentComponent == null && Desktop.instance == null))
     {
@@ -1153,6 +1156,10 @@ public class JvOptionPane extends JOptionPane
   public JvOptionPane setResponseHandler(Object response,
           Callable<Void> action)
   {
+    if (action == null)
+    {
+      action = NULLCALLABLE;
+    }
     callbacks.put(response, action);
     return this;
   }
@@ -1160,7 +1167,7 @@ public class JvOptionPane extends JOptionPane
   public ExecutorService getExecutor()
   {
     if (executor == null)
-      executor = Executors.newSingleThreadExecutor();
+      executor = Executors.newCachedThreadPool();
     return executor;
   }
 
@@ -1553,9 +1560,9 @@ public class JvOptionPane extends JOptionPane
     }
   }
 
-  public static JvOptionPane frameDialog(String message, String title,
+  public static JvOptionPane frameDialog(Object message, String title,
           int messageType, String[] buttonsTextS, String defaultButtonS,
-          Callable<Void>[] handlers, boolean modal)
+          List<Callable<Void>> handlers, boolean modal)
   {
     JFrame parent = new JFrame();
     JvOptionPane jvop = JvOptionPane.newOptionDialog();
@@ -1595,24 +1602,21 @@ public class JvOptionPane extends JOptionPane
     {
       dialogType = JOptionPane.YES_NO_CANCEL_OPTION;
     }
-    Callable<Void> nullCallable = () -> {
-      return null;
-    };
     jvop.setResponseHandler(JOptionPane.YES_OPTION,
-            (handlers != null && handlers.length > 0) ? handlers[0]
-                    : nullCallable);
+            (handlers != null && handlers.size() > 0) ? handlers.get(0)
+                    : NULLCALLABLE);
     if (dialogType == JOptionPane.YES_NO_OPTION
             || dialogType == JOptionPane.YES_NO_CANCEL_OPTION)
     {
       jvop.setResponseHandler(JOptionPane.NO_OPTION,
-              (handlers != null && handlers.length > 1) ? handlers[1]
-                      : nullCallable);
+              (handlers != null && handlers.size() > 1) ? handlers.get(1)
+                      : NULLCALLABLE);
     }
     if (dialogType == JOptionPane.YES_NO_CANCEL_OPTION)
     {
       jvop.setResponseHandler(JOptionPane.CANCEL_OPTION,
-              (handlers != null && handlers.length > 2) ? handlers[2]
-                      : nullCallable);
+              (handlers != null && handlers.size() > 2) ? handlers.get(2)
+                      : NULLCALLABLE);
     }
 
     final int dt = dialogType;