JAL-1152 prototype of new Annotations menu with sort options
[jalview.git] / src / jalview / jbgui / GAlignFrame.java
index 0fad6cf..5e60a85 100755 (executable)
@@ -20,6 +20,8 @@
  */
 package jalview.jbgui;
 
+import jalview.bin.Cache;
+import jalview.gui.JvSwingUtils;
 import jalview.schemes.ColourSchemeProperty;
 import jalview.util.MessageManager;
 
@@ -63,6 +65,8 @@ public class GAlignFrame extends JInternalFrame
 
   protected JMenu viewMenu = new JMenu();
 
+  protected JMenu annotationsMenu = new JMenu();
+
   protected JMenu colourMenu = new JMenu();
 
   protected JMenu calculateMenu = new JMenu();
@@ -186,8 +190,6 @@ public class GAlignFrame extends JInternalFrame
 
   public JCheckBoxMenuItem showSeqFeaturesHeight = new JCheckBoxMenuItem();
 
-  JMenuItem chooseAnnotations = new JMenuItem();
-
   JMenuItem deleteGroups = new JMenuItem();
 
   JMenuItem createGroup = new JMenuItem();
@@ -304,9 +306,13 @@ public class GAlignFrame extends JInternalFrame
 
   JMenuItem showAllhidden = new JMenuItem();
 
-  protected JMenu showAnnotations = new JMenu();
+  protected JMenuItem showAllAnnotations = new JMenuItem();
+
+  protected JMenuItem hideAllAnnotations = new JMenuItem();
 
-  protected JMenu hideAnnotations = new JMenu();
+  protected JMenuItem sortAnnBySequence = new JMenuItem();
+
+  protected JMenuItem sortAnnByType = new JMenuItem();
 
   protected JCheckBoxMenuItem hiddenMarkers = new JCheckBoxMenuItem();
 
@@ -611,6 +617,7 @@ public class GAlignFrame extends JInternalFrame
     });
     editMenu.setText(MessageManager.getString("action.edit"));
     viewMenu.setText(MessageManager.getString("action.view"));
+    annotationsMenu.setText(MessageManager.getString("action.annotations"));
     colourMenu.setText(MessageManager.getString("action.colour"));
     calculateMenu.setText(MessageManager.getString("action.calculate"));
     webService.setText(MessageManager.getString("action.web_service"));
@@ -829,7 +836,7 @@ public class GAlignFrame extends JInternalFrame
       }
     });
     removeRedundancyMenuItem.setText(MessageManager
-            .getString("action.remove_redundancy"));
+            .getString("action.remove_redundancy").concat("..."));
     removeRedundancyMenuItem.setAccelerator(javax.swing.KeyStroke
             .getKeyStroke(java.awt.event.KeyEvent.VK_D, Toolkit
                     .getDefaultToolkit().getMenuShortcutKeyMask(), false));
@@ -1063,17 +1070,61 @@ public class GAlignFrame extends JInternalFrame
     annotationPanelMenuItem.setActionCommand("");
     annotationPanelMenuItem.setText(MessageManager
             .getString("label.show_annotations"));
-    annotationPanelMenuItem.setState(jalview.bin.Cache.getDefault(
-            "SHOW_ANNOTATIONS", true));
-    annotationPanelMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                annotationPanelMenuItem_actionPerformed(e);
-              }
-            });
+    annotationPanelMenuItem.setState(Cache.getDefault("SHOW_ANNOTATIONS",
+            true));
+    annotationPanelMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        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()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        showAllAnnotations_actionPerformed();
+      }
+    });
+    hideAllAnnotations.setText(MessageManager
+            .getString("label.hide_all_annotations"));
+    hideAllAnnotations.setEnabled(annotationPanelMenuItem.getState());
+    hideAllAnnotations.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        hideAllAnnotations_actionPerformed();
+      }
+    });
+    sortAnnBySequence.setText(MessageManager
+            .getString("label.sort_annotations_by_sequence"));
+    sortAnnBySequence.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        sortAnnotationsBySequence_actionPerformed();
+      }
+    });
+    sortAnnByType.setText(MessageManager
+            .getString("label.sort_annotations_by_type"));
+    sortAnnByType.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        sortAnnotationsByType_actionPerformed();
+      }
+    });
     colourTextMenuItem.setText(MessageManager
             .getString("label.colour_text"));
     colourTextMenuItem
@@ -1187,6 +1238,8 @@ public class GAlignFrame extends JInternalFrame
     findMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_F, Toolkit.getDefaultToolkit()
                     .getMenuShortcutKeyMask(), false));
+    findMenuItem.setToolTipText(JvSwingUtils.wrapTooltip(true,
+            MessageManager.getString("label.find_tip")));
     findMenuItem.addActionListener(new java.awt.event.ActionListener()
     {
       @Override
@@ -1215,16 +1268,6 @@ public class GAlignFrame extends JInternalFrame
         showSeqFeatures_actionPerformed(actionEvent);
       }
     });
-    chooseAnnotations.setText(MessageManager
-            .getString("label.choose_annotations") + "...");
-    chooseAnnotations.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent actionEvent)
-      {
-        chooseAnnotations_actionPerformed();
-      }
-    });
     /*
      * showSeqFeaturesHeight.setText("Vary Sequence Feature Height");
      * showSeqFeaturesHeight.addActionListener(new ActionListener() { public
@@ -1417,8 +1460,6 @@ public class GAlignFrame extends JInternalFrame
       }
     });
     delete.setText(MessageManager.getString("action.delete"));
-    delete.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_BACK_SPACE, 0, false));
     delete.addActionListener(new java.awt.event.ActionListener()
     {
       @Override
@@ -1926,25 +1967,6 @@ public class GAlignFrame extends JInternalFrame
         showAllhidden_actionPerformed(e);
       }
     });
-    showAnnotations.setText(MessageManager.getString("label.annotations"));
-    showAnnotations.addMouseListener(new MouseAdapter()
-    {
-      @Override
-      public void mouseEntered(MouseEvent e)
-      {
-        buildShowHideAnnotationMenus();
-      }
-    });
-    hideAnnotations.setText(MessageManager.getString("label.annotations"));
-    hideAnnotations.addMouseListener(new MouseAdapter()
-    {
-      @Override
-      public void mouseEntered(MouseEvent e)
-      {
-        buildShowHideAnnotationMenus();
-      }
-    });
-
     hiddenMarkers.setText(MessageManager
             .getString("action.show_hidden_markers"));
     hiddenMarkers.addActionListener(new ActionListener()
@@ -2106,6 +2128,7 @@ public class GAlignFrame extends JInternalFrame
     alignFrameMenuBar.add(editMenu);
     alignFrameMenuBar.add(selectMenu);
     alignFrameMenuBar.add(viewMenu);
+    alignFrameMenuBar.add(annotationsMenu);
     alignFrameMenuBar.add(formatMenu);
     alignFrameMenuBar.add(colourMenu);
     alignFrameMenuBar.add(calculateMenu);
@@ -2155,7 +2178,11 @@ public class GAlignFrame extends JInternalFrame
     viewMenu.add(hideMenu);
     viewMenu.addSeparator();
     viewMenu.add(followHighlightMenuItem);
-    viewMenu.add(annotationPanelMenuItem);
+    annotationsMenu.add(annotationPanelMenuItem);
+    annotationsMenu.add(showAllAnnotations);
+    annotationsMenu.add(hideAllAnnotations);
+    annotationsMenu.add(sortAnnBySequence);
+    annotationsMenu.add(sortAnnByType);
     autoAnnMenu.add(applyAutoAnnotationSettings);
     autoAnnMenu.add(showConsensusHistogram);
     autoAnnMenu.add(showSequenceLogo);
@@ -2163,10 +2190,9 @@ public class GAlignFrame extends JInternalFrame
     autoAnnMenu.addSeparator();
     autoAnnMenu.add(showGroupConservation);
     autoAnnMenu.add(showGroupConsensus);
-    viewMenu.add(autoAnnMenu);
+    annotationsMenu.add(autoAnnMenu);
     viewMenu.addSeparator();
     viewMenu.add(showSeqFeatures);
-    viewMenu.add(chooseAnnotations);
     // viewMenu.add(showSeqFeaturesHeight);
 
     viewMenu.add(openFeatureSettings);
@@ -2238,12 +2264,10 @@ public class GAlignFrame extends JInternalFrame
     jMenu3.add(showAllColumns);
     jMenu3.add(showAllSeqs);
     jMenu3.add(showAllhidden);
-    jMenu3.add(showAnnotations);
     hideMenu.add(hideSelColumns);
     hideMenu.add(hideSelSequences);
     hideMenu.add(hideAllSelection);
     hideMenu.add(hideAllButSelection);
-    hideMenu.add(hideAnnotations);
 
     formatMenu.add(font);
     formatMenu.addSeparator();
@@ -2278,20 +2302,41 @@ public class GAlignFrame extends JInternalFrame
   }
 
   /**
-   * Dynamically build list of annotation types to show or hide.
+   * Action on clicking sort annotations by type.
+   */
+  protected void sortAnnotationsByType_actionPerformed()
+  {
+  }
+
+  /**
+   * Action on clicking sort annotations by sequence
    */
-  protected void buildShowHideAnnotationMenus()
+  protected void sortAnnotationsBySequence_actionPerformed()
   {
   }
 
-  protected void showHideAnnotation_actionPerformed(String type, boolean b)
+  /**
+   * Action on clicking Show all annotations.
+   */
+  protected void showAllAnnotations_actionPerformed()
   {
+    setAllAnnotationsVisibility(true);
   }
 
   /**
-   * Action on menu item "Show/hide sequence annotations..."
+   * Action on clicking Hide all annotations.
+   */
+  protected void hideAllAnnotations_actionPerformed()
+  {
+    setAllAnnotationsVisibility(false);
+  }
+
+  /**
+   * Set the visibility of all annotations to true or false.
+   * 
+   * @param visible
    */
-  protected void chooseAnnotations_actionPerformed()
+  protected void setAllAnnotationsVisibility(boolean visible)
   {
 
   }