JAL-3081 JAL-3199 no auto-sort of annotations after manual reordering
[jalview.git] / src / jalview / jbgui / GAlignFrame.java
index 9f41c92..50ee6c8 100755 (executable)
@@ -200,14 +200,16 @@ public class GAlignFrame extends JInternalFrame
 
   protected JCheckBoxMenuItem applyAutoAnnotationSettings = new JCheckBoxMenuItem();
 
-  private SequenceAnnotationOrder annotationSortOrder;
-
-  private boolean showAutoCalculatedAbove = false;
-
   private Map<KeyStroke, JMenuItem> accelerators = new HashMap<>();
 
   private SplitContainerI splitFrame;
 
+  protected JCheckBoxMenuItem sortAnnBySequence;
+
+  protected JCheckBoxMenuItem sortAnnByLabel;
+
+  protected JMenu annotationsMenu;
+
   public GAlignFrame()
   {
     try
@@ -286,7 +288,7 @@ public class GAlignFrame extends JInternalFrame
 
     JMenu editMenu = new JMenu(MessageManager.getString("action.edit"));
     JMenu viewMenu = new JMenu(MessageManager.getString("action.view"));
-    JMenu annotationsMenu = new JMenu(
+    annotationsMenu = new JMenu(
             MessageManager.getString("action.annotations"));
     JMenu showMenu = new JMenu(MessageManager.getString("action.show"));
     colourMenu.setText(MessageManager.getString("action.colour"));
@@ -602,9 +604,9 @@ public class GAlignFrame extends JInternalFrame
     SequenceAnnotationOrder sortAnnotationsBy = SequenceAnnotationOrder
             .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
                     SequenceAnnotationOrder.NONE.name()));
-    final JCheckBoxMenuItem sortAnnBySequence = new JCheckBoxMenuItem(
+    sortAnnBySequence = new JCheckBoxMenuItem(
             MessageManager.getString("label.sort_annotations_by_sequence"));
-    final JCheckBoxMenuItem sortAnnByLabel = new JCheckBoxMenuItem(
+    sortAnnByLabel = new JCheckBoxMenuItem(
             MessageManager.getString("label.sort_annotations_by_label"));
 
     sortAnnBySequence.setSelected(
@@ -619,7 +621,7 @@ public class GAlignFrame extends JInternalFrame
         setAnnotationSortOrder(
                 newState ? SequenceAnnotationOrder.SEQUENCE_AND_LABEL
                         : SequenceAnnotationOrder.NONE);
-        sortAnnotations_actionPerformed();
+        sortAnnotations();
       }
     });
     sortAnnByLabel.setSelected(
@@ -634,7 +636,7 @@ public class GAlignFrame extends JInternalFrame
         setAnnotationSortOrder(
                 newState ? SequenceAnnotationOrder.LABEL_AND_SEQUENCE
                         : SequenceAnnotationOrder.NONE);
-        sortAnnotations_actionPerformed();
+        sortAnnotations();
       }
     });
     colourTextMenuItem = new JCheckBoxMenuItem(
@@ -885,14 +887,15 @@ public class GAlignFrame extends JInternalFrame
     final boolean autoFirst = Cache
             .getDefault(Preferences.SHOW_AUTOCALC_ABOVE, false);
     showAutoFirst.setSelected(autoFirst);
-    setShowAutoCalculatedAbove(autoFirst);
     showAutoFirst.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        setShowAutoCalculatedAbove(showAutoFirst.isSelected());
-        sortAnnotations_actionPerformed();
+        if (setShowAutoCalculatedAbove(showAutoFirst.isSelected()))
+        {
+          sortAnnotations();
+        }
       }
     });
     showAutoLast.setSelected(!showAutoFirst.isSelected());
@@ -901,8 +904,10 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        setShowAutoCalculatedAbove(!showAutoLast.isSelected());
-        sortAnnotations_actionPerformed();
+        if (setShowAutoCalculatedAbove(!showAutoLast.isSelected()))
+        {
+          sortAnnotations();
+        }
       }
     });
 
@@ -2023,7 +2028,7 @@ public class GAlignFrame extends JInternalFrame
    * 
    * @param sortOrder
    */
-  protected void sortAnnotations_actionPerformed()
+  protected void sortAnnotations()
   {
   }
 
@@ -2620,25 +2625,22 @@ public class GAlignFrame extends JInternalFrame
 
   }
 
-  protected boolean isShowAutoCalculatedAbove()
-  {
-    return showAutoCalculatedAbove;
-  }
-
-  protected void setShowAutoCalculatedAbove(boolean showAutoCalculatedAbove)
-  {
-    this.showAutoCalculatedAbove = showAutoCalculatedAbove;
-  }
-
-  protected SequenceAnnotationOrder getAnnotationSortOrder()
+  /**
+   * Sets the value of the flag for 'show autocalculated annotations above other
+   * annotations'. Answers true if the value changed, else false.
+   * 
+   * @param showAutoCalculatedAbove
+   * @return
+   */
+  protected boolean setShowAutoCalculatedAbove(
+          boolean showAutoCalculatedAbove)
   {
-    return annotationSortOrder;
+    return false;
   }
 
-  protected void setAnnotationSortOrder(
+  public void setAnnotationSortOrder(
           SequenceAnnotationOrder annotationSortOrder)
   {
-    this.annotationSortOrder = annotationSortOrder;
   }
 
   public Map<KeyStroke, JMenuItem> getAccelerators()