JAL-1152 prototype of new Annotations menu with sort options
[jalview.git] / src / jalview / gui / PopupMenu.java
index 3da4494..8e0e6e3 100644 (file)
@@ -22,6 +22,7 @@ package jalview.gui;
 
 import jalview.analysis.AAFrequency;
 import jalview.analysis.AlignmentAnnotationUtils;
+import jalview.analysis.AnnotationSorter;
 import jalview.analysis.Conservation;
 import jalview.commands.ChangeCaseCommand;
 import jalview.commands.EditCommand;
@@ -1875,7 +1876,6 @@ public class PopupMenu extends JPopupMenu
      * Add annotations at the top of the annotation, in the same order as their
      * related sequences.
      */
-    int insertPosition = 0;
     for (SequenceI seq : candidates.keySet())
     {
       for (AlignmentAnnotation ann : candidates.get(seq))
@@ -1896,10 +1896,15 @@ public class PopupMenu extends JPopupMenu
         // adjust for gaps
         copyAnn.adjustForAlignment();
         // add to the alignment and set visible
-        this.ap.getAlignment().addAnnotation(copyAnn, insertPosition++);
+        this.ap.getAlignment().addAnnotation(copyAnn);
         copyAnn.visible = true;
       }
     }
+    // TODO: save annotation sort order on AlignViewport
+    // do sorting from AlignmentPanel.updateAnnotation()
+    new AnnotationSorter(this.ap.getAlignment())
+            .sortBySequenceAndType(this.ap.getAlignment()
+                    .getAlignmentAnnotation());
     refresh();
   }