JAL-4186 attempts to work in jalviewjs, still not working
authorBen Soares <b.soares@dundee.ac.uk>
Wed, 24 May 2023 23:41:50 +0000 (00:41 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Wed, 24 May 2023 23:41:50 +0000 (00:41 +0100)
src/jalview/gui/EditNameDialog.java
src/jalview/gui/JvOptionPane.java
src/jalview/gui/PopupMenu.java

index ff0fe3a..d61177c 100644 (file)
@@ -22,6 +22,8 @@ package jalview.gui;
 
 import java.awt.FlowLayout;
 import java.awt.Font;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.Callable;
 
 import javax.swing.BoxLayout;
@@ -87,7 +89,7 @@ public class EditNameDialog
     panel.add(descriptionPanel);
 
     JLabel nameLabel = new JLabel(label1);
-    nameLabel.setFont(COURIER_12);
+    // nameLabel.setFont(COURIER_12);
     namePanel.add(nameLabel);
 
     id = new JTextField(name, 40);
@@ -101,7 +103,7 @@ public class EditNameDialog
     if (desc != null || label2 != null)
     {
       JLabel descLabel = new JLabel(label2);
-      descLabel.setFont(COURIER_12);
+      // descLabel.setFont(COURIER_12);
       descriptionPanel.add(descLabel);
       descriptionPanel.add(description);
     }
@@ -112,14 +114,25 @@ public class EditNameDialog
    * 
    * @param action
    */
-  public void showDialog(JComponent parent, String title, Callable action)
+  public void showDialog(JComponent parent, String title,
+          Callable<Void> action)
   {
-    Object[] options = new Object[] { MessageManager.getString("action.ok"),
-        MessageManager.getString("action.cancel") };
-    JvOptionPane.newOptionDialog(parent).setResponseHandler(0, action)
-            .showInternalDialog(panel, title,
-                    JvOptionPane.YES_NO_CANCEL_OPTION,
-                    JvOptionPane.PLAIN_MESSAGE, null, options,
-                    MessageManager.getString("action.ok"));
+    String ok = MessageManager.getString("action.ok");
+    String cancel = MessageManager.getString("action.cancel");
+    String[] options = new String[] { ok, cancel };
+
+    /*
+    JvOptionPane.newOptionDialog(parent)
+            .setResponseHandler(JvOptionPane.OK_OPTION, action)
+            .showInternalDialog(panel, title, JvOptionPane.OK_CANCEL_OPTION,
+                    JvOptionPane.PLAIN_MESSAGE, null, options, ok);
+            */
+
+    List<Callable<Void>> actions = new ArrayList<>();
+    actions.add(action);
+    actions.add(JvOptionPane.NULLCALLABLE);
+
+    JvOptionPane.frameDialog(panel, title, JvOptionPane.PLAIN_MESSAGE,
+            options, ok, actions, false);
   }
 }
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;
index 9d62976..562d0f5 100644 (file)
@@ -2028,13 +2028,26 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
               {
                 if (dialog.getName().indexOf(" ") > -1)
                 {
-                  JvOptionPane.frameDialog(
-                          MessageManager.getString(
-                                  "label.spaces_converted_to_underscores"),
-                          MessageManager.getString(
-                                  "label.no_spaces_allowed_sequence_name"),
-                          JvOptionPane.WARNING_MESSAGE, null, null, null,
-                          false);
+                  if (!Platform.isJS())
+                  /**
+                   * Java only
+                   * 
+                   * @j2sIgnore
+                   */
+                  {
+                    String ok = MessageManager.getString("action.ok");
+                    String cancel = MessageManager
+                            .getString("action.cancel");
+                    String message = MessageManager.getString(
+                            "label.spaces_converted_to_underscores");
+                    String title = MessageManager.getString(
+                            "label.no_spaces_allowed_sequence_name");
+                    Object[] options = new Object[] { ok, cancel };
+
+                    JvOptionPane.frameDialog(message, title,
+                            JvOptionPane.WARNING_MESSAGE, null, null, null,
+                            false);
+                  }
                 }
                 sequence.setName(dialog.getName().replace(' ', '_'));
                 ap.paintAlignment(false, false);