From abdc3a7c9a4b7dbf7a3bb6dd26ba9d76881933d6 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 25 Sep 2014 10:26:51 +0100 Subject: [PATCH] JAL-1264 alternative (popup menu) way to show/hide annotations by type --- resources/lang/Messages.properties | 1 + src/jalview/gui/PopupMenu.java | 84 ++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 22754f8..8c9967c 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -199,6 +199,7 @@ label.tcoffee_scores = T-Coffee Scores label.average_distance_bloslum62 = Average Distance Using BLOSUM62 label.neighbour_blosum62 = Neighbour Joining Using BLOSUM62 label.show_annotations = Show annotations +label.hide_annotations = Hide annotations label.colour_text = Colour Text label.show_non_conversed = Show nonconserved label.overview_window = Overview Window diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 4ff525e..cd60e47 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -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 found = new ArrayList(); + 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); -- 1.7.10.2