JAL-3081 JAL-3199 no auto-sort of annotations after manual reordering
[jalview.git] / src / jalview / gui / AlignFrame.java
index 0239bb4..9ee210f 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;
@@ -145,6 +146,8 @@ import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JScrollPane;
 import javax.swing.SwingUtilities;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
 
 /**
  * DOCUMENT ME!
@@ -362,9 +365,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 +481,33 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
     });
 
+    /*
+     * ensure By Label/Sequence are not selected if annotations
+     * have been reordered manually to CUSTOM order
+     */
+    annotationsMenu.addMenuListener(new MenuListener()
+    {
+      @Override
+      public void menuSelected(MenuEvent e)
+      {
+        SequenceAnnotationOrder sortAnnotationsBy = viewport
+                .getSortAnnotationsBy();
+        sortAnnByLabel.setSelected(
+                sortAnnotationsBy == SequenceAnnotationOrder.LABEL_AND_SEQUENCE);
+        sortAnnBySequence.setSelected(
+                sortAnnotationsBy == SequenceAnnotationOrder.SEQUENCE_AND_LABEL);
+      }
+
+      @Override
+      public void menuDeselected(MenuEvent e)
+      {
+      }
+
+      @Override
+      public void menuCanceled(MenuEvent e)
+      {
+      }
+    });
   }
 
   /**
@@ -5410,14 +5437,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()
+  protected void sortAnnotations()
   {
-    this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
-    this.alignPanel.av
-            .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
+    alignPanel.sortAnnotations();
     alignPanel.paintAlignment(false, false);
   }
 
@@ -5645,6 +5670,34 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
 
   }
+
+  @Override
+  protected boolean setShowAutoCalculatedAbove(
+          boolean showAutoCalculatedAbove)
+  {
+    if (viewport.isShowAutocalculatedAbove() != showAutoCalculatedAbove)
+    {
+      viewport.setShowAutocalculatedAbove(showAutoCalculatedAbove);
+
+      /*
+       * 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