X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPopupMenu.java;fp=src%2Fjalview%2Fgui%2FPopupMenu.java;h=2845122557c8ba3888faa0f8e5f0e5c94f8537db;hb=a5ae12c17739ea531cf9aacc712fff8444765cd7;hp=ad7726d1a0e8e53b64fcc472b72bd26efcde07e2;hpb=50ff87bdae1829a7a7471ec393142ae659b40a11;p=jalview.git diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index ad7726d..2845122 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -62,7 +62,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.Hashtable; import java.util.LinkedHashMap; import java.util.List; @@ -190,11 +189,17 @@ public class PopupMenu extends JPopupMenu JMenu outputMenu = new JMenu(); - JMenu showAnnotationsMenu = new JMenu(); + JMenu seqShowAnnotationsMenu = new JMenu(); - JMenu hideAnnotationsMenu = new JMenu(); + JMenu seqHideAnnotationsMenu = new JMenu(); - JMenuItem addReferenceAnnotations = new JMenuItem(); + JMenuItem seqAddReferenceAnnotations = new JMenuItem(); + + JMenu groupShowAnnotationsMenu = new JMenu(); + + JMenu groupHideAnnotationsMenu = new JMenu(); + + JMenuItem groupAddReferenceAnnotations = new JMenuItem(); JMenuItem sequenceFeature = new JMenuItem(); @@ -282,17 +287,26 @@ public class PopupMenu extends JPopupMenu /* * Build menus for annotation types that may be shown or hidden, and for - * 'reference annotations' that may be added to the alignment. The scope is - * annotations for the current selection group (if there is one), else the - * current sequence (if there is one), else not applicable (e.g. for popup - * menu within the sequence). + * 'reference annotations' that may be added to the alignment. First for the + * currently selected sequence (if there is one): */ - final List sequenceScope = getSequenceScope(seq); - if (!sequenceScope.isEmpty()) - { - buildAnnotationTypesMenus(sequenceScope); - configureReferenceAnnotationsMenu(addReferenceAnnotations, sequenceScope); - } + final List selectedSequence = (seq == null ? Collections + . emptyList() : Arrays.asList(seq)); + buildAnnotationTypesMenus(seqShowAnnotationsMenu, + seqHideAnnotationsMenu, selectedSequence); + configureReferenceAnnotationsMenu(seqAddReferenceAnnotations, + selectedSequence); + + /* + * And repeat for the current selection group (if there is one): + */ + final List selectedGroup = (ap.av.getSelectionGroup() == null ? Collections + . emptyList() : ap.av.getSelectionGroup() + .getSequences()); + buildAnnotationTypesMenus(groupShowAnnotationsMenu, + groupHideAnnotationsMenu, selectedGroup); + configureReferenceAnnotationsMenu(groupAddReferenceAnnotations, + selectedGroup); try { @@ -809,9 +823,10 @@ public class PopupMenu extends JPopupMenu } /** - * Add annotation types to a 'Show annotations' or 'Hide annotations' menu. + * Add annotation types to 'Show annotations' and/or 'Hide annotations' menus. * "All" is added first, followed by a separator. Then add any annotation - * types associated with the current selection. + * types associated with the current selection. Separate menus are built for + * the selected sequence group (if any), and the selected sequence. *

* Some annotation rows are always rendered together - these can be identified * by a common graphGroup property > -1. Only one of each group will be marked @@ -820,29 +835,32 @@ public class PopupMenu extends JPopupMenu *

* IUPredWS (Long), IUPredWS (Short) * - * @param forSequences + * @param seq */ - protected void buildAnnotationTypesMenus(List forSequences) + protected void buildAnnotationTypesMenus(JMenu showMenu, JMenu hideMenu, + List forSequences) { - showAnnotationsMenu.removeAll(); - hideAnnotationsMenu.removeAll(); + showMenu.removeAll(); + hideMenu.removeAll(); + final List all = Arrays.asList(ALL_ANNOTATIONS); - addAnnotationTypeToShowHide(showAnnotationsMenu, forSequences, "", all, - true, true); - addAnnotationTypeToShowHide(hideAnnotationsMenu, forSequences, "", all, - true, false); - showAnnotationsMenu.addSeparator(); - hideAnnotationsMenu.addSeparator(); + addAnnotationTypeToShowHide(showMenu, forSequences, "", all, true, true); + addAnnotationTypeToShowHide(hideMenu, forSequences, "", all, true, + false); + showMenu.addSeparator(); + hideMenu.addSeparator(); final AlignmentAnnotation[] annotations = ap.getAlignment() .getAlignmentAnnotation(); /* * Find shown/hidden annotations types, distinguished by source (calcId), - * and grouped by graphGroup. + * and grouped by graphGroup. Using LinkedHashMap means we will retrieve in + * the insertion order, which is the order of the annotations on the + * alignment. */ - Map>> shownTypes = new HashMap>>(); - Map>> hiddenTypes = new HashMap>>(); + Map>> shownTypes = new LinkedHashMap>>(); + Map>> hiddenTypes = new LinkedHashMap>>(); AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes, AlignmentAnnotationUtils.asList(annotations), @@ -852,23 +870,23 @@ public class PopupMenu extends JPopupMenu { for (List type : hiddenTypes.get(calcId)) { - addAnnotationTypeToShowHide(showAnnotationsMenu, forSequences, + addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type, false, true); } } // grey out 'show annotations' if none are hidden - showAnnotationsMenu.setEnabled(!hiddenTypes.isEmpty()); + showMenu.setEnabled(!hiddenTypes.isEmpty()); for (String calcId : shownTypes.keySet()) { for (List type : shownTypes.get(calcId)) { - addAnnotationTypeToShowHide(hideAnnotationsMenu, forSequences, + addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type, false, false); } } // grey out 'hide annotations' if none are shown - hideAnnotationsMenu.setEnabled(!shownTypes.isEmpty()); + hideMenu.setEnabled(!shownTypes.isEmpty()); } /** @@ -1445,9 +1463,13 @@ public class PopupMenu extends JPopupMenu }); outputMenu.setText(MessageManager.getString("label.out_to_textbox") + "..."); - showAnnotationsMenu.setText(MessageManager + seqShowAnnotationsMenu.setText(MessageManager .getString("label.show_annotations")); - hideAnnotationsMenu.setText(MessageManager + seqHideAnnotationsMenu.setText(MessageManager + .getString("label.hide_annotations")); + groupShowAnnotationsMenu.setText(MessageManager + .getString("label.show_annotations")); + groupHideAnnotationsMenu.setText(MessageManager .getString("label.hide_annotations")); sequenceFeature.setText(MessageManager .getString("label.create_sequence_feature")); @@ -1498,22 +1520,15 @@ public class PopupMenu extends JPopupMenu // groupMenu.add(chooseAnnotations); /* - * Add show/hide annotations to either Selection menu (if a selection group - * in force), else to the Sequence menu. + * Add show/hide annotations to the Sequence menu, and to the Selection menu + * (if a selection group is in force). */ - SequenceGroup sg = this.ap.av.getSelectionGroup(); - if (sg != null && sg.getSize() > 0) - { - groupMenu.add(showAnnotationsMenu); - groupMenu.add(hideAnnotationsMenu); - groupMenu.add(addReferenceAnnotations); - } - else - { - sequenceMenu.add(showAnnotationsMenu); - sequenceMenu.add(hideAnnotationsMenu); - sequenceMenu.add(addReferenceAnnotations); - } + sequenceMenu.add(seqShowAnnotationsMenu); + sequenceMenu.add(seqHideAnnotationsMenu); + sequenceMenu.add(seqAddReferenceAnnotations); + groupMenu.add(groupShowAnnotationsMenu); + groupMenu.add(groupHideAnnotationsMenu); + groupMenu.add(groupAddReferenceAnnotations); groupMenu.add(editMenu); groupMenu.add(outputMenu); groupMenu.add(sequenceFeature); @@ -2552,7 +2567,8 @@ public class PopupMenu extends JPopupMenu String choice = chooser.getSelectedFile().getPath(); jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, - jalview.io.AppletFormatAdapter.FILE, sequence, true); + jalview.io.AppletFormatAdapter.FILE, sequence, true, + Desktop.instance); } }