JAL-3081 autocalculated annotation first/last leaves others unchanged
[jalview.git] / src / jalview / analysis / AnnotationSorter.java
index e5e9de4..f16d9ea 100644 (file)
@@ -38,7 +38,6 @@ import java.util.Map;
  */
 public class AnnotationSorter
 {
-
   /**
    * enum for annotation sort options. The text description is used in the
    * Preferences drop-down options. The enum name is saved in the preferences
@@ -93,18 +92,24 @@ public class AnnotationSorter
   // working map of sequence index in alignment
   private final Map<SequenceI, Integer> sequenceIndices = new HashMap<>();
 
+  // if true, sort only repositions auto-calculated annotation (to top or
+  // bottom)
+  private final boolean autocalcOnly;
+
   /**
    * Constructor given an alignment and the location (top or bottom) of
    * Consensus and similar.
    * 
    * @param alignmentI
    * @param showAutocalculatedAbove
+   * @param autoCalcOnly
    */
   public AnnotationSorter(AlignmentI alignmentI,
-          boolean showAutocalculatedAbove)
+          boolean showAutocalculatedAbove, boolean autoCalcOnly)
   {
     this.alignment = alignmentI;
     this.showAutocalcAbove = showAutocalculatedAbove;
+    this.autocalcOnly = autoCalcOnly;
   }
 
   /**
@@ -159,6 +164,10 @@ public class AnnotationSorter
       {
         return showAutocalcAbove ? 1 : -1;
       }
+      if (autocalcOnly)
+      {
+        return 0; // don't reorder other annotations
+      }
       int sequenceOrder = compareSequences(o1, o2);
       return sequenceOrder == 0 ? compareLabels(o1, o2) : sequenceOrder;
     }
@@ -221,6 +230,10 @@ public class AnnotationSorter
       {
         return showAutocalcAbove ? 1 : -1;
       }
+      if (autocalcOnly)
+      {
+        return 0; // don't reorder other annotations
+      }
       int labelOrder = compareLabels(o1, o2);
       return labelOrder == 0 ? compareSequences(o1, o2) : labelOrder;
     }