JAL-3060 tidy Cancel dialog action handler code
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 16 Jul 2018 14:55:06 +0000 (15:55 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 16 Jul 2018 14:55:06 +0000 (15:55 +0100)
src/jalview/gui/FeatureEditor.java

index 00ea668..60f26e6 100644 (file)
@@ -80,8 +80,6 @@ public class FeatureEditor
 
   AlignmentPanel ap;
 
-  Object[] options;
-
   JTextField name;
 
   JTextField group;
@@ -359,25 +357,15 @@ public class FeatureEditor
     featureColour = fr.getFeatureStyle(featureType);
     oldColour = featureColour;
     updateColourButton(mainPanel, colour, oldColour);
-    if (forCreate)
-    {
-      options = new Object[] { MessageManager.getString("action.ok"),
-          MessageManager.getString("action.cancel") };
-    }
-    else
-    {
-      options = new Object[] { MessageManager.getString("label.amend"),
-          MessageManager.getString("action.delete"),
-          MessageManager.getString("action.cancel") };
-    }
   }
 
   /**
    * Presents a dialog allowing the user to add new features, or amend or delete
    * an existing feature. Currently this can be on
    * <ul>
-   * <li>double-click on a sequence - Amend/Delete features at position</li>
-   * <li>Create sequence feature from pop-up menu on selected region</li>
+   * <li>double-click on a sequence - Amend/Delete a selected feature at the
+   * position</li>
+   * <li>Create sequence feature(s) from pop-up menu on selected region</li>
    * <li>Create features for pattern matches from Find</li>
    * </ul>
    * If the supplied feature type is null, show (and update on confirm) the type
@@ -387,21 +375,42 @@ public class FeatureEditor
   public void showDialog()
   {
     RunResponse okAction = forCreate ? getCreateAction() : getAmendAction();
-    RunResponse deleteAction = getDeleteAction();
-    Runnable cancelAction = getCancelAction();
-
-    String title = forCreate
-            ? MessageManager.getString("label.create_new_sequence_features")
-            : MessageManager.formatMessage("label.amend_delete_features",
-                    new String[]
-                    { sequences.get(0).getName() });
-
-    JvOptionPane.newOptionDialog(Desktop.desktop).response(okAction)
-            .response(deleteAction).defaultResponse(cancelAction)
-            .showInternalDialog(mainPanel, title,
-                    JvOptionPane.YES_NO_CANCEL_OPTION,
-                    JvOptionPane.QUESTION_MESSAGE, null, options,
-                    MessageManager.getString("action.ok"));
+    RunResponse cancelAction = getCancelAction();
+
+    /*
+     * set dialog action handlers for OK (create/Amend) and Cancel options
+     * also for Delete if applicable (when amending features)
+     */
+    JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop)
+            .response(okAction).response(cancelAction);
+    if (!forCreate)
+    {
+      dialog.response(getDeleteAction());
+    }
+
+    String title = null;
+    Object[] options = null;
+    if (forCreate)
+    {
+      title = MessageManager
+              .getString("label.create_new_sequence_features");
+      options = new Object[] { MessageManager.getString("action.ok"),
+          MessageManager.getString("action.cancel") };
+    }
+    else
+    {
+      title = MessageManager.formatMessage("label.amend_delete_features",
+              new String[]
+              { sequences.get(0).getName() });
+      options = new Object[] { MessageManager.getString("label.amend"),
+          MessageManager.getString("action.delete"),
+          MessageManager.getString("action.cancel") };
+    }
+
+    dialog.showInternalDialog(mainPanel, title,
+            JvOptionPane.YES_NO_CANCEL_OPTION,
+            JvOptionPane.QUESTION_MESSAGE, null, options,
+            MessageManager.getString("action.ok"));
   }
 
   /**
@@ -412,17 +421,18 @@ public class FeatureEditor
    * 
    * @return
    */
-  protected Runnable getCancelAction()
+  protected RunResponse getCancelAction()
   {
-    Runnable defaultResponse = new Runnable()
+    RunResponse okAction = new RunResponse(JvOptionPane.CANCEL_OPTION)
     {
+      @Override
       public void run()
       {
         ap.highlightSearchResults(null);
         ap.paintAlignment(false, false);
       }
     };
-    return defaultResponse;
+    return okAction;
   }
 
   /**