+ showAnnotationsMenu.removeAll();
+ hideAnnotationsMenu.removeAll();
+ final List<String> all = Arrays.asList(ALL_ANNOTATIONS);
+ addAnnotationTypeToShowHide(showAnnotationsMenu,
+ all, true,
+ true);
+ addAnnotationTypeToShowHide(hideAnnotationsMenu, all, true,
+ false);
+ showAnnotationsMenu.addSeparator();
+ hideAnnotationsMenu.addSeparator();
+
+ final AlignmentAnnotation[] annotations = ap.getAlignment()
+ .getAlignmentAnnotation();
+ BitSet visibleGraphGroups = PopupMenu
+ .getVisibleLineGraphGroups(annotations);
+
+ List<List<String>> shownTypes = new ArrayList<List<String>>();
+ List<List<String>> hiddenTypes = new ArrayList<List<String>>();
+ PopupMenu.getAnnotationTypesForShowHide(shownTypes, hiddenTypes,
+ visibleGraphGroups, annotations, ap.av.getSelectionGroup());
+
+ for (List<String> types : hiddenTypes)
+ {
+ addAnnotationTypeToShowHide(showAnnotationsMenu, types, false, true);
+ }
+
+ for (List<String> types : shownTypes)
+ {
+ addAnnotationTypeToShowHide(hideAnnotationsMenu, types, false, false);
+ }
+ }
+
+ /**
+ * Helper method to populate lists of annotation types for the Show/Hide
+ * Annotations menus. If sequenceGroup is not null, this is restricted to
+ * annotations which are associated with sequences in the selection group.
+ * <p/>
+ * If an annotation row is currently visible, its type (label) is added (once
+ * only per type), to the shownTypes list. If it is currently hidden, it is
+ * added to the hiddenTypesList.
+ * <p/>
+ * For rows that belong to a line graph group, so are always rendered
+ * together:
+ * <ul>
+ * <li>Treat all rows in the group as visible, if at least one of them is</li>
+ * <li>Build a comma-separated label with all the types that belong to the
+ * group</li>
+ * </ul>
+ *
+ * @param shownTypes
+ * @param hiddenTypes
+ * @param visibleGraphGroups
+ * @param annotations
+ * @param sequenceGroup
+ */
+ public static void getAnnotationTypesForShowHide(
+ List<List<String>> shownTypes, List<List<String>> hiddenTypes,
+ BitSet visibleGraphGroups,
+ AlignmentAnnotation[] annotations, SequenceGroup sequenceGroup)
+ {
+ // lookup table, key = graph group, value = list of types in the group
+ Map<Integer, List<String>> groupLabels = new LinkedHashMap<Integer, List<String>>();
+
+ List<String> addedToShown = new ArrayList<String>();
+ List<String> addedToHidden = new ArrayList<String>();
+
+ for (AlignmentAnnotation aa : annotations)