JAL-3081 autocalculated annotation first/last leaves others unchanged
[jalview.git] / src / jalview / gui / AlignFrame.java
index 0239bb4..8994743 100644 (file)
@@ -22,6 +22,7 @@ package jalview.gui;
 
 import jalview.analysis.AlignmentSorter;
 import jalview.analysis.AlignmentUtils;
+import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.analysis.CrossRef;
 import jalview.analysis.Dna;
 import jalview.analysis.GeneticCodeI;
@@ -362,9 +363,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       sortPairwiseMenuItem_actionPerformed(null);
     }
 
-    this.alignPanel.av
-            .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
-
     setMenusFromViewport(viewport);
     buildSortByAnnotationScoresMenu();
     calculateTree.addActionListener(new ActionListener()
@@ -481,6 +479,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
     });
 
+    alignPanel.sortAnnotations(false);
   }
 
   /**
@@ -4692,7 +4691,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
       if (isAnnotation)
       {
-
+        alignPanel.sortAnnotations(false);
         alignPanel.adjustAnnotationHeight();
         viewport.updateSequenceIdColours();
         buildSortByAnnotationScoresMenu();
@@ -5410,14 +5409,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   /**
-   * Store selected annotation sort order for the view and repaint.
+   * Sorts annotations and repaints the alignment
    */
   @Override
-  protected void sortAnnotations_actionPerformed()
+  public void sortAnnotations(boolean autoCalcOnly)
   {
-    this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
-    this.alignPanel.av
-            .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
+    alignPanel.sortAnnotations(autoCalcOnly);
     alignPanel.paintAlignment(false, false);
   }
 
@@ -5645,6 +5642,40 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
 
   }
+
+  /**
+   * Sets the flag for whether auto-calculated annotations should be shown above
+   * other annotations. If the given value is the same as the current setting,
+   * simply returns false. Otherwise updates the setting, and returns true. If
+   * annotation sort order is currently set to 'Custom', this is changed to
+   * 'None', because 'Custom' ordering ignores all sort options.
+   */
+  @Override
+  public boolean setShowAutoCalculatedAbove(boolean b)
+  {
+    if (viewport.isShowAutocalculatedAbove() != b)
+    {
+      viewport.setShowAutocalculatedAbove(b);
+
+      /*
+       * change CUSTOM annotation ordering to NONE 
+       * so that sorting actually does something
+       */
+      if (viewport.getSortAnnotationsBy() == SequenceAnnotationOrder.CUSTOM)
+      {
+        viewport.setSortAnnotationsBy(SequenceAnnotationOrder.NONE);
+      }
+      return true;
+    }
+    return false;
+  }
+
+  @Override
+  public void setAnnotationSortOrder(
+          SequenceAnnotationOrder annotationSortOrder)
+  {
+    viewport.setSortAnnotationsBy(annotationSortOrder);
+  }
 }
 
 class PrintThread extends Thread