JAL-1152 menu tweaks plus new option to put Autocalc at top or below.
[jalview.git] / src / jalview / jbgui / GAlignFrame.java
index 3591056..dba77dd 100755 (executable)
@@ -20,7 +20,7 @@
  */
 package jalview.jbgui;
 
-import jalview.analysis.AnnotationSorter.SortOrder;
+import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.bin.Cache;
 import jalview.gui.JvSwingUtils;
 import jalview.schemes.ColourSchemeProperty;
@@ -307,13 +307,17 @@ public class GAlignFrame extends JInternalFrame
 
   JMenuItem showAllhidden = new JMenuItem();
 
-  protected JMenuItem showAllAnnotations = new JMenuItem();
+  protected JMenuItem showAllSeqAnnotations = new JMenuItem();
 
-  protected JMenuItem hideAllAnnotations = new JMenuItem();
+  protected JMenuItem hideAllSeqAnnotations = new JMenuItem();
+
+  protected JMenuItem showAllAlAnnotations = new JMenuItem();
+
+  protected JMenuItem hideAllAlAnnotations = new JMenuItem();
 
   protected JCheckBoxMenuItem sortAnnBySequence = new JCheckBoxMenuItem();
 
-  protected JCheckBoxMenuItem sortAnnByType = new JCheckBoxMenuItem();
+  protected JCheckBoxMenuItem sortAnnByLabel = new JCheckBoxMenuItem();
 
   protected JCheckBoxMenuItem hiddenMarkers = new JCheckBoxMenuItem();
 
@@ -367,8 +371,16 @@ public class GAlignFrame extends JInternalFrame
 
   protected JCheckBoxMenuItem applyAutoAnnotationSettings = new JCheckBoxMenuItem();
 
+  protected JCheckBoxMenuItem showAutoFirst = new JCheckBoxMenuItem();
+
+  protected JCheckBoxMenuItem showAutoLast = new JCheckBoxMenuItem();
+
   private JMenuItem grpsFromSelection = new JMenuItem();
 
+  private SequenceAnnotationOrder annotationSortOrder;
+
+  private boolean showAutoCalculatedAbove = false;
+
   public GAlignFrame()
   {
     try
@@ -1081,29 +1093,50 @@ public class GAlignFrame extends JInternalFrame
         annotationPanelMenuItem_actionPerformed(e);
       }
     });
-    /*
-     * Show/hide all annotations only enabled if annotation panel is shown
-     */
-    showAllAnnotations.setText(MessageManager
-            .getString("label.show_all_annotations"));
-    showAllAnnotations.setEnabled(annotationPanelMenuItem.getState());
-    showAllAnnotations.addActionListener(new ActionListener()
+    showAllAlAnnotations.setText(MessageManager
+            .getString("label.show_all_al_annotations"));
+    final boolean isAnnotationPanelShown = annotationPanelMenuItem
+            .getState();
+    showAllAlAnnotations.setEnabled(isAnnotationPanelShown);
+    showAllAlAnnotations.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        showAllAnnotations_actionPerformed(false, true);
+      }
+    });
+    hideAllAlAnnotations.setText(MessageManager
+            .getString("label.hide_all_al_annotations"));
+    hideAllAlAnnotations.setEnabled(isAnnotationPanelShown);
+    hideAllAlAnnotations.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        hideAllAnnotations_actionPerformed(false, true);
+      }
+    });
+    showAllSeqAnnotations.setText(MessageManager
+            .getString("label.show_all_seq_annotations"));
+    showAllSeqAnnotations.setEnabled(isAnnotationPanelShown);
+    showAllSeqAnnotations.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        showAllAnnotations_actionPerformed();
+        showAllAnnotations_actionPerformed(true, false);
       }
     });
-    hideAllAnnotations.setText(MessageManager
-            .getString("label.hide_all_annotations"));
-    hideAllAnnotations.setEnabled(annotationPanelMenuItem.getState());
-    hideAllAnnotations.addActionListener(new ActionListener()
+    hideAllSeqAnnotations.setText(MessageManager
+            .getString("label.hide_all_seq_annotations"));
+    hideAllSeqAnnotations.setEnabled(isAnnotationPanelShown);
+    hideAllSeqAnnotations.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        hideAllAnnotations_actionPerformed();
+        hideAllAnnotations_actionPerformed(true, false);
       }
     });
     sortAnnBySequence.setText(MessageManager
@@ -1113,25 +1146,25 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        sortAnnBySequence.setEnabled(false);
-        sortAnnBySequence.setState(true);
-        sortAnnByType.setEnabled(true);
-        sortAnnByType.setState(false);
-        sortAnnotations_actionPerformed(SortOrder.SEQUENCE_AND_TYPE);
+        boolean newState = sortAnnBySequence.getState();
+        sortAnnByLabel.setState(false);
+        setAnnotationSortOrder(newState ? SequenceAnnotationOrder.SEQUENCE_AND_LABEL
+                : SequenceAnnotationOrder.NONE);
+        sortAnnotations_actionPerformed();
       }
     });
-    sortAnnByType.setText(MessageManager
-            .getString("label.sort_annotations_by_type"));
-    sortAnnByType.addActionListener(new ActionListener()
+    sortAnnByLabel.setText(MessageManager
+            .getString("label.sort_annotations_by_label"));
+    sortAnnByLabel.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        sortAnnByType.setEnabled(false);
-        sortAnnByType.setState(true);
-        sortAnnBySequence.setEnabled(true);
+        boolean newState = sortAnnByLabel.getState();
         sortAnnBySequence.setState(false);
-        sortAnnotations_actionPerformed(SortOrder.TYPE_AND_SEQUENCE);
+        setAnnotationSortOrder(newState ? SequenceAnnotationOrder.LABEL_AND_SEQUENCE
+                : SequenceAnnotationOrder.NONE);
+        sortAnnotations_actionPerformed();
       }
     });
     colourTextMenuItem.setText(MessageManager
@@ -1374,13 +1407,38 @@ public class GAlignFrame extends JInternalFrame
     applyAutoAnnotationSettings.setVisible(true);
     applyAutoAnnotationSettings.addActionListener(new ActionListener()
     {
-
       @Override
       public void actionPerformed(ActionEvent e)
       {
         applyAutoAnnotationSettings_actionPerformed(e);
       }
+    });
 
+    showAutoFirst.setText(MessageManager.getString("label.show_first"));
+    showAutoFirst.setState(Cache.getDefault("SHOW_AUTOCALC_ABOVE", false));
+    showAutoFirst.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        boolean sortFirst = showAutoFirst.getState();
+        setShowAutoCalculatedAbove(sortFirst);
+        showAutoLast.setState(!sortFirst);
+        sortAnnotations_actionPerformed();
+      }
+    });
+    showAutoLast.setText(MessageManager.getString("label.show_last"));
+    showAutoLast.setState(!showAutoFirst.getState());
+    showAutoLast.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        boolean sortLast = showAutoLast.getState();
+        setShowAutoCalculatedAbove(!sortLast);
+        showAutoFirst.setState(!sortLast);
+        sortAnnotations_actionPerformed();
+      }
     });
 
     nucleotideColour.setText(MessageManager.getString("label.nucleotide"));
@@ -2188,10 +2246,18 @@ public class GAlignFrame extends JInternalFrame
     viewMenu.addSeparator();
     viewMenu.add(followHighlightMenuItem);
     annotationsMenu.add(annotationPanelMenuItem);
-    annotationsMenu.add(showAllAnnotations);
-    annotationsMenu.add(hideAllAnnotations);
+    annotationsMenu.addSeparator();
+    annotationsMenu.add(showAllAlAnnotations);
+    annotationsMenu.add(hideAllAlAnnotations);
+    annotationsMenu.addSeparator();
+    annotationsMenu.add(showAllSeqAnnotations);
+    annotationsMenu.add(hideAllSeqAnnotations);
     annotationsMenu.add(sortAnnBySequence);
-    annotationsMenu.add(sortAnnByType);
+    annotationsMenu.add(sortAnnByLabel);
+    annotationsMenu.addSeparator();
+    autoAnnMenu.add(showAutoFirst);
+    autoAnnMenu.add(showAutoLast);
+    autoAnnMenu.addSeparator();
     autoAnnMenu.add(applyAutoAnnotationSettings);
     autoAnnMenu.add(showConsensusHistogram);
     autoAnnMenu.add(showSequenceLogo);
@@ -2315,32 +2381,50 @@ public class GAlignFrame extends JInternalFrame
    * 
    * @param sortOrder
    */
-  protected void sortAnnotations_actionPerformed(SortOrder sortOrder)
+  protected void sortAnnotations_actionPerformed()
   {
   }
 
   /**
    * Action on clicking Show all annotations.
+   * 
+   * @param forSequences
+   *          update sequence-related annotations
+   * @param forAlignment
+   *          update non-sequence-related annotations
    */
-  protected void showAllAnnotations_actionPerformed()
+  protected void showAllAnnotations_actionPerformed(boolean forSequences,
+          boolean forAlignment)
   {
-    setAllAnnotationsVisibility(true);
+    setAnnotationsVisibility(true, forSequences, forAlignment);
   }
 
   /**
    * Action on clicking Hide all annotations.
+   * 
+   * @param forSequences
+   *          update sequence-related annotations
+   * @param forAlignment
+   *          update non-sequence-related annotations
    */
-  protected void hideAllAnnotations_actionPerformed()
+  protected void hideAllAnnotations_actionPerformed(boolean forSequences,
+          boolean forAlignment)
   {
-    setAllAnnotationsVisibility(false);
+    setAnnotationsVisibility(false, forSequences, forAlignment);
   }
 
   /**
-   * Set the visibility of all annotations to true or false.
+   * Set the visibility of annotations to true or false. Can act on
+   * sequence-related annotations, or alignment-related, or both.
    * 
    * @param visible
+   * @param forSequences
+   *          update sequence-related annotations
+   * @param forAlignment
+   *          update non-sequence-related annotations
    */
-  protected void setAllAnnotationsVisibility(boolean visible)
+  protected void setAnnotationsVisibility(boolean visible,
+          boolean forSequences, boolean forAlignment)
   {
 
   }
@@ -2989,4 +3073,24 @@ public class GAlignFrame extends JInternalFrame
     // TODO Auto-generated method stub
 
   }
+
+  protected boolean isShowAutoCalculatedAbove()
+  {
+    return showAutoCalculatedAbove;
+  }
+
+  protected void setShowAutoCalculatedAbove(boolean showAutoCalculatedAbove)
+  {
+    this.showAutoCalculatedAbove = showAutoCalculatedAbove;
+  }
+
+  protected SequenceAnnotationOrder getAnnotationSortOrder()
+  {
+    return annotationSortOrder;
+  }
+
+  protected void setAnnotationSortOrder(SequenceAnnotationOrder annotationSortOrder)
+  {
+    this.annotationSortOrder = annotationSortOrder;
+  }
 }