JAL-1713 update from Jalview 2.11.3 develop
[jalview.git] / src / jalview / gui / FeatureEditor.java
index d547c58..ba9da67 100644 (file)
@@ -1,16 +1,25 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.gui;
 
-import jalview.api.FeatureColourI;
-import jalview.datamodel.SearchResults;
-import jalview.datamodel.SearchResultsI;
-import jalview.datamodel.SequenceFeature;
-import jalview.datamodel.SequenceI;
-import jalview.gui.JalviewColourChooser.ColourChooserListener;
-import jalview.io.FeaturesFile;
-import jalview.schemes.FeatureColour;
-import jalview.util.ColorUtils;
-import jalview.util.MessageManager;
-
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Dimension;
@@ -24,6 +33,7 @@ import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.Callable;
 
 import javax.swing.JComboBox;
 import javax.swing.JLabel;
@@ -39,6 +49,17 @@ import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 
+import jalview.api.FeatureColourI;
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.SearchResultsI;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceI;
+import jalview.gui.JalviewColourChooser.ColourChooserListener;
+import jalview.io.FeaturesFile;
+import jalview.schemes.FeatureColour;
+import jalview.util.ColorUtils;
+import jalview.util.MessageManager;
+
 /**
  * Provides a dialog allowing the user to add new features, or amend or delete
  * existing features
@@ -170,30 +191,30 @@ public class FeatureEditor
     });
 
     description = new JTextArea(3, 25);
-    
+
     start = new JSpinner();
     end = new JSpinner();
     start.setPreferredSize(new Dimension(80, 20));
     end.setPreferredSize(new Dimension(80, 20));
-    
+
     /*
      * ensure that start can never be more than end
      */
-    start.addChangeListener(new ChangeListener() 
+    start.addChangeListener(new ChangeListener()
     {
       @Override
       public void stateChanged(ChangeEvent e)
       {
-        Integer startVal = (Integer) start.getValue(); 
+        Integer startVal = (Integer) start.getValue();
         ((SpinnerNumberModel) end.getModel()).setMinimum(startVal);
       }
     });
-    end.addChangeListener(new ChangeListener() 
+    end.addChangeListener(new ChangeListener()
     {
       @Override
       public void stateChanged(ChangeEvent e)
       {
-        Integer endVal = (Integer) end.getValue(); 
+        Integer endVal = (Integer) end.getValue();
         ((SpinnerNumberModel) start.getModel()).setMaximum(endVal);
       }
     });
@@ -381,8 +402,10 @@ public class FeatureEditor
 
     start.setValue(new Integer(firstFeature.getBegin()));
     end.setValue(new Integer(firstFeature.getEnd()));
-    ((SpinnerNumberModel) start.getModel()).setMaximum(firstFeature.getEnd());
-    ((SpinnerNumberModel) end.getModel()).setMinimum(firstFeature.getBegin());
+    ((SpinnerNumberModel) start.getModel())
+            .setMaximum(firstFeature.getEnd());
+    ((SpinnerNumberModel) end.getModel())
+            .setMinimum(firstFeature.getBegin());
 
     description.setText(firstFeature.getDescription());
     featureColour = fr.getFeatureStyle(featureType);
@@ -405,15 +428,17 @@ public class FeatureEditor
    */
   public void showDialog()
   {
-         Runnable okAction = forCreate ? getCreateAction() : getAmendAction();
-         Runnable cancelAction = getCancelAction();
+    Callable<Void> okAction = forCreate ? getCreateAction()
+            : getAmendAction();
+    Callable<Void> 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)
-            .setResponseHandler(0, okAction).setResponseHandler(2, cancelAction);
+    JvOptionPane dialog = JvOptionPane.newOptionDialog(ap.alignFrame)
+            .setResponseHandler(0, okAction)
+            .setResponseHandler(2, cancelAction);
     if (!forCreate)
     {
       dialog.setResponseHandler(1, getDeleteAction());
@@ -439,9 +464,8 @@ public class FeatureEditor
     }
 
     dialog.showInternalDialog(mainPanel, title,
-            JvOptionPane.YES_NO_CANCEL_OPTION,
-            JvOptionPane.PLAIN_MESSAGE, null, options,
-            MessageManager.getString("action.ok"));
+            JvOptionPane.YES_NO_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE,
+            null, options, MessageManager.getString("action.ok"));
   }
 
   /**
@@ -452,16 +476,12 @@ public class FeatureEditor
    * 
    * @return
    */
-  protected Runnable getCancelAction()
+  protected Callable getCancelAction()
   {
-       Runnable okAction = new Runnable()
-    {
-      @Override
-      public void run()
-      {
-        ap.highlightSearchResults(null);
-        ap.paintAlignment(false, false);
-      }
+    Callable<Void> okAction = () -> {
+      ap.highlightSearchResults(null);
+      ap.paintAlignment(false, false);
+      return null;
     };
     return okAction;
   }
@@ -476,13 +496,14 @@ public class FeatureEditor
    * 
    * @return
    */
-  protected Runnable getCreateAction()
+  protected Callable getCreateAction()
   {
-       Runnable okAction = new Runnable()
+    Callable<Void> okAction = new Callable()
     {
       boolean useLastDefaults = features.get(0).getType() == null;
 
-      public void run()
+      @Override
+      public Void call()
       {
         final String enteredType = name.getText().trim();
         final String enteredGroup = group.getText().trim();
@@ -522,6 +543,7 @@ public class FeatureEditor
 
           repaintPanel();
         }
+        return null;
       }
     };
     return okAction;
@@ -534,18 +556,15 @@ public class FeatureEditor
    * 
    * @return
    */
-  protected Runnable getDeleteAction()
+  protected Callable getDeleteAction()
   {
-         Runnable deleteAction = new Runnable()
-    {
-      public void run()
-      {
-        SequenceFeature sf = features.get(featureIndex);
-        sequences.get(0).getDatasetSequence().deleteFeature(sf);
-        fr.featuresAdded();
-        ap.getSeqPanel().seqCanvas.highlightSearchResults(null);
-        ap.paintAlignment(true, true);
-      }
+    Callable<Void> deleteAction = () -> {
+      SequenceFeature sf = features.get(featureIndex);
+      sequences.get(0).getDatasetSequence().deleteFeature(sf);
+      fr.featuresAdded();
+      ap.getSeqPanel().seqCanvas.highlightSearchResults(null);
+      ap.paintAlignment(true, true);
+      return null;
     };
     return deleteAction;
   }
@@ -636,17 +655,18 @@ public class FeatureEditor
    * 
    * @return
    */
-  protected Runnable getAmendAction()
+  protected Callable getAmendAction()
   {
-       Runnable okAction = new Runnable()
+    Callable<Void> okAction = new Callable()
     {
       boolean useLastDefaults = features.get(0).getType() == null;
-  
+
       String featureType = name.getText();
-  
+
       String featureGroup = group.getText();
-  
-      public void run()
+
+      @Override
+      public Void call()
       {
         final String enteredType = name.getText().trim();
         final String enteredGroup = group.getText().trim();
@@ -709,6 +729,7 @@ public class FeatureEditor
           fr.featuresAdded();
         }
         repaintPanel();
+        return null;
       }
     };
     return okAction;