JAL-3081 restore annotation ordering from project (work in progress)
[jalview.git] / src / jalview / gui / AlignFrame.java
index a587ac3..092cf47 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,35 @@ 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)
+      {
+      }
+    });
+
+    alignPanel.sortAnnotations();
   }
 
   /**
@@ -974,7 +1003,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void setStatus(String text)
   {
-    statusBar.setText(text);
+    statusBar.setText(text == null || text.isEmpty() ? " " : text);
   }
 
   /*
@@ -3104,7 +3133,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   protected void scaleAbove_actionPerformed(ActionEvent e)
   {
     viewport.setScaleAboveWrapped(scaleAbove.isSelected());
-    // TODO: do we actually need to update overview for scale above change ?
+    alignPanel.updateLayout();
     alignPanel.paintAlignment(true, false);
   }
 
@@ -3118,6 +3147,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   protected void scaleLeft_actionPerformed(ActionEvent e)
   {
     viewport.setScaleLeftWrapped(scaleLeft.isSelected());
+    alignPanel.updateLayout();
     alignPanel.paintAlignment(true, false);
   }
 
@@ -3131,6 +3161,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   protected void scaleRight_actionPerformed(ActionEvent e)
   {
     viewport.setScaleRightWrapped(scaleRight.isSelected());
+    alignPanel.updateLayout();
     alignPanel.paintAlignment(true, false);
   }
 
@@ -5408,14 +5439,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()
   {
-    this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
-    this.alignPanel.av
-            .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
+    alignPanel.sortAnnotations();
     alignPanel.paintAlignment(false, false);
   }
 
@@ -5643,6 +5672,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