JAL-1264 alternative (popup menu) way to show/hide annotations by type
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 25 Sep 2014 09:26:51 +0000 (10:26 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 25 Sep 2014 09:26:51 +0000 (10:26 +0100)
resources/lang/Messages.properties
src/jalview/gui/PopupMenu.java

index 22754f8..8c9967c 100644 (file)
@@ -199,6 +199,7 @@ label.tcoffee_scores = T-Coffee Scores
 label.average_distance_bloslum62 = Average Distance Using BLOSUM62\r
 label.neighbour_blosum62 = Neighbour Joining Using BLOSUM62\r
 label.show_annotations = Show annotations\r
+label.hide_annotations = Hide annotations\r
 label.colour_text = Colour Text\r
 label.show_non_conversed = Show nonconserved\r
 label.overview_window = Overview Window\r
index 4ff525e..cd60e47 100644 (file)
@@ -57,7 +57,9 @@ import jalview.util.UrlLink;
 import java.awt.Color;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.util.ArrayList;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Vector;
 
 import javax.swing.ButtonGroup;
@@ -176,6 +178,10 @@ public class PopupMenu extends JPopupMenu
 
   JMenu outputMenu = new JMenu();
 
+  JMenu showAnnotationsMenu = new JMenu();
+
+  JMenu hideAnnotationsMenu = new JMenu();
+
   JMenuItem sequenceFeature = new JMenuItem();
 
   JMenuItem textColour = new JMenuItem();
@@ -260,6 +266,8 @@ public class PopupMenu extends JPopupMenu
       outputMenu.add(item);
     }
 
+    buildAnnotationTypesMenu();
+
     try
     {
       jbInit();
@@ -777,6 +785,76 @@ public class PopupMenu extends JPopupMenu
     }
   }
 
+  /**
+   * Find which sequence-specific annotation types are associated with the
+   * current selection, and add these as menu items (for show / hide annotation
+   * types).
+   */
+  protected void buildAnnotationTypesMenu()
+  {
+    List<String> found = new ArrayList<String>();
+    for (AlignmentAnnotation aa : ap.getAlignment()
+            .getAlignmentAnnotation())
+    {
+      if (aa.sequenceRef != null)
+      {
+        if (ap.av.getSelectionGroup().getSequences()
+                .contains(aa.sequenceRef))
+        {
+          final String label = aa.label;
+          if (!found.contains(label))
+          {
+            found.add(label);
+            final JMenuItem showitem = new JMenuItem(label);
+            showitem.addActionListener(new java.awt.event.ActionListener()
+            {
+              @Override
+              public void actionPerformed(ActionEvent e)
+              {
+                showHideAnnotation_actionPerformed(label, true);
+              }
+            });
+            showAnnotationsMenu.add(showitem);
+            final JMenuItem hideitem = new JMenuItem(label);
+            hideitem.addActionListener(new java.awt.event.ActionListener()
+            {
+              @Override
+              public void actionPerformed(ActionEvent e)
+              {
+                showHideAnnotation_actionPerformed(label, false);
+              }
+            });
+            hideAnnotationsMenu.add(hideitem);
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * Action on selecting an annotation type to show or hide for the selection.
+   * 
+   * @param type
+   * @param doShow
+   */
+  protected void showHideAnnotation_actionPerformed(String type,
+          boolean doShow)
+  {
+    for (AlignmentAnnotation aa : ap.getAlignment()
+            .getAlignmentAnnotation())
+    {
+      if (aa.sequenceRef != null && type.equals(aa.label))
+      {
+        if (ap.av.getSelectionGroup().getSequences()
+                .contains(aa.sequenceRef))
+        {
+          aa.visible = doShow;
+        }
+      }
+    }
+    refresh();
+  }
+
   private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
   {
 
@@ -1263,6 +1341,10 @@ public class PopupMenu extends JPopupMenu
     });
     outputMenu.setText(MessageManager.getString("label.out_to_textbox")
             + "...");
+    showAnnotationsMenu.setText(MessageManager
+            .getString("label.show_annotations"));
+    hideAnnotationsMenu.setText(MessageManager
+            .getString("label.hide_annotations"));
     sequenceFeature.setText(MessageManager
             .getString("label.create_sequence_feature"));
     sequenceFeature.addActionListener(new ActionListener()
@@ -1309,6 +1391,8 @@ public class PopupMenu extends JPopupMenu
     add(sequenceMenu);
     this.add(structureMenu);
     groupMenu.add(chooseAnnotations);
+    groupMenu.add(showAnnotationsMenu);
+    groupMenu.add(hideAnnotationsMenu);
     groupMenu.add(editMenu);
     groupMenu.add(outputMenu);
     groupMenu.add(sequenceFeature);