JAL-3199 corrected sort menu items to JMenuItem
[jalview.git] / src / jalview / jbgui / GAlignFrame.java
index aac8428..9491d33 100755 (executable)
@@ -21,6 +21,8 @@
 package jalview.jbgui;
 
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
+import jalview.analysis.GeneticCodeI;
+import jalview.analysis.GeneticCodes;
 import jalview.api.SplitContainerI;
 import jalview.bin.Cache;
 import jalview.gui.JvSwingUtils;
@@ -76,7 +78,7 @@ public class GAlignFrame extends JInternalFrame
 
   protected JMenu sortByAnnotScore = new JMenu();
 
-  public JLabel statusBar = new JLabel();
+  protected JLabel statusBar = new JLabel();
 
   protected JMenu outputTextboxMenu = new JMenu();
 
@@ -138,7 +140,7 @@ public class GAlignFrame extends JInternalFrame
 
   protected JCheckBoxMenuItem showDbRefsMenuitem = new JCheckBoxMenuItem();
 
-  protected JMenuItem showTranslation = new JMenuItem();
+  protected JMenu showTranslation = new JMenu();
 
   protected JMenuItem showReverse = new JMenuItem();
 
@@ -198,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 JMenuItem sortAnnBySequence;
+
+  protected JMenuItem sortAnnByLabel;
+
+  protected JMenu annotationsMenu;
+
   public GAlignFrame()
   {
     try
@@ -284,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"));
@@ -597,42 +601,27 @@ public class GAlignFrame extends JInternalFrame
         hideAllAnnotations_actionPerformed(true, false);
       }
     });
-    SequenceAnnotationOrder sortAnnotationsBy = SequenceAnnotationOrder
-            .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
-                    SequenceAnnotationOrder.NONE.name()));
-    final JCheckBoxMenuItem sortAnnBySequence = new JCheckBoxMenuItem(
+    sortAnnBySequence = new JMenuItem(
             MessageManager.getString("label.sort_annotations_by_sequence"));
-    final JCheckBoxMenuItem sortAnnByLabel = new JCheckBoxMenuItem(
+    sortAnnByLabel = new JMenuItem(
             MessageManager.getString("label.sort_annotations_by_label"));
 
-    sortAnnBySequence.setSelected(
-            sortAnnotationsBy == SequenceAnnotationOrder.SEQUENCE_AND_LABEL);
     sortAnnBySequence.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        boolean newState = sortAnnBySequence.getState();
-        sortAnnByLabel.setSelected(false);
-        setAnnotationSortOrder(
-                newState ? SequenceAnnotationOrder.SEQUENCE_AND_LABEL
-                        : SequenceAnnotationOrder.NONE);
-        sortAnnotations_actionPerformed();
+        setAnnotationSortOrder(SequenceAnnotationOrder.SEQUENCE_AND_LABEL);
+        sortAnnotations(false);
       }
     });
-    sortAnnByLabel.setSelected(
-            sortAnnotationsBy == SequenceAnnotationOrder.LABEL_AND_SEQUENCE);
     sortAnnByLabel.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        boolean newState = sortAnnByLabel.getState();
-        sortAnnBySequence.setSelected(false);
-        setAnnotationSortOrder(
-                newState ? SequenceAnnotationOrder.LABEL_AND_SEQUENCE
-                        : SequenceAnnotationOrder.NONE);
-        sortAnnotations_actionPerformed();
+        setAnnotationSortOrder(SequenceAnnotationOrder.LABEL_AND_SEQUENCE);
+        sortAnnotations(false);
       }
     });
     colourTextMenuItem = new JCheckBoxMenuItem(
@@ -883,14 +872,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(true);
+        }
       }
     });
     showAutoLast.setSelected(!showAutoFirst.isSelected());
@@ -899,8 +889,10 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        setShowAutoCalculatedAbove(!showAutoLast.isSelected());
-        sortAnnotations_actionPerformed();
+        if (setShowAutoCalculatedAbove(!showAutoLast.isSelected()))
+        {
+          sortAnnotations(true);
+        }
       }
     });
 
@@ -1222,16 +1214,33 @@ public class GAlignFrame extends JInternalFrame
         vamsasStore_actionPerformed(e);
       }
     });
-    showTranslation
-            .setText(MessageManager.getString("label.translate_cDNA"));
-    showTranslation.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
+
+    /*
+     * Translate as cDNA with sub-menu of translation tables
+     */
+    showTranslation.setText(MessageManager
+            .getString("label.translate_cDNA"));
+    boolean first = true;
+    for (final GeneticCodeI table : GeneticCodes.getInstance()
+            .getCodeTables())
+    {
+      JMenuItem item = new JMenuItem(table.getId() + " " + table.getName());
+      showTranslation.add(item);
+      item.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          showTranslation_actionPerformed(table);
+        }
+      });
+      if (first)
       {
-        showTranslation_actionPerformed(e);
+        showTranslation.addSeparator();
       }
-    });
+      first = false;
+    }
+
     showReverse.setText(MessageManager.getString("label.reverse"));
     showReverse.addActionListener(new ActionListener()
     {
@@ -2000,11 +2009,12 @@ public class GAlignFrame extends JInternalFrame
   }
 
   /**
-   * Action on clicking sort annotations by type.
+   * Action on clicking sort annotations by type, or change position of
+   * autocalculated annotation
    * 
-   * @param sortOrder
+   * @param autoCalcOnly
    */
-  protected void sortAnnotations_actionPerformed()
+  protected void sortAnnotations(boolean autoCalcOnly)
   {
   }
 
@@ -2442,7 +2452,7 @@ public class GAlignFrame extends JInternalFrame
 
   }
 
-  public void showTranslation_actionPerformed(ActionEvent e)
+  public void showTranslation_actionPerformed(GeneticCodeI codeTable)
   {
 
   }
@@ -2601,25 +2611,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()