X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FAPopupMenu.java;h=a726e3ce99de2e157be881ea021e3789bf17ce7f;hb=17e77c3f2949a0729322b4a8d907f3f34b6a9914;hp=c58fc5b88149b2ae27042f0a119c95912642ae9b;hpb=b948e764c92b0954100f216927114b2c9720b76c;p=jalview.git
diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java
index c58fc5b..a726e3c 100644
--- a/src/jalview/appletgui/APopupMenu.java
+++ b/src/jalview/appletgui/APopupMenu.java
@@ -1,6 +1,6 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
+ * Copyright (C) 2015 The Jalview Authors
*
* This file is part of Jalview.
*
@@ -21,13 +21,16 @@
package jalview.appletgui;
import jalview.analysis.AAFrequency;
+import jalview.analysis.AlignmentAnnotationUtils;
+import jalview.analysis.AlignmentUtils;
import jalview.analysis.Conservation;
import jalview.commands.ChangeCaseCommand;
import jalview.commands.EditCommand;
import jalview.commands.EditCommand.Action;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.PDBEntry;
-import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
@@ -56,11 +59,19 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
import java.util.Vector;
public class APopupMenu extends java.awt.PopupMenu implements
ActionListener, ItemListener
{
+ private static final String ALL_ANNOTATIONS = "All";
+
Menu groupMenu = new Menu();
MenuItem editGroupName = new MenuItem();
@@ -111,12 +122,29 @@ public class APopupMenu extends java.awt.PopupMenu implements
CheckboxMenuItem displayNonconserved = new CheckboxMenuItem();
+ Menu seqShowAnnotationsMenu = new Menu(
+ MessageManager.getString("label.show_annotations"));
+
+ Menu seqHideAnnotationsMenu = new Menu(
+ MessageManager.getString("label.hide_annotations"));
+
+ MenuItem seqAddReferenceAnnotations = new MenuItem(
+ MessageManager.getString("label.add_reference_annotations"));
+
+ Menu groupShowAnnotationsMenu = new Menu(
+ MessageManager.getString("label.show_annotations"));
+
+ Menu groupHideAnnotationsMenu = new Menu(
+ MessageManager.getString("label.hide_annotations"));
+
+ MenuItem groupAddReferenceAnnotations = new MenuItem(
+ MessageManager.getString("label.add_reference_annotations"));
+
Menu editMenu = new Menu(MessageManager.getString("action.edit"));
- MenuItem copy = new MenuItem(
- MessageManager.getString("label.jalview_copy"));
+ MenuItem copy = new MenuItem(MessageManager.getString("action.copy"));
- MenuItem cut = new MenuItem(MessageManager.getString("label.jalview_cut"));
+ MenuItem cut = new MenuItem(MessageManager.getString("action.cut"));
MenuItem toUpper = new MenuItem(
MessageManager.getString("label.to_upper_case"));
@@ -147,14 +175,14 @@ public class APopupMenu extends java.awt.PopupMenu implements
MessageManager.getString("label.edit_sequence"));
MenuItem sequenceDetails = new MenuItem(
- MessageManager.getString("label.sequence_details") + "...");
+ MessageManager.getString("label.sequence_details"));
MenuItem selSeqDetails = new MenuItem(
- MessageManager.getString("label.sequence_details") + "...");
+ MessageManager.getString("label.sequence_details"));
MenuItem makeReferenceSeq = new MenuItem();
-
- Sequence seq;
+
+ SequenceI seq;
MenuItem revealAll = new MenuItem();
@@ -167,7 +195,8 @@ public class APopupMenu extends java.awt.PopupMenu implements
Menu menu1 = new Menu();
- public APopupMenu(AlignmentPanel apanel, final Sequence seq, Vector links)
+ public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
+ Vector links)
{
// /////////////////////////////////////////////////////////
// If this is activated from the sequence panel, the user may want to
@@ -196,13 +225,13 @@ public class APopupMenu extends java.awt.PopupMenu implements
outputmenu.add(item);
}
- SequenceGroup sg = ap.av.getSelectionGroup();
+ buildAnnotationSubmenus();
+ SequenceGroup sg = ap.av.getSelectionGroup();
if (sg != null && sg.getSize() > 0)
{
editGroupName.setLabel(MessageManager.formatMessage(
- "label.name_param", new String[]
- { sg.getName() }));
+ "label.name_param", new Object[] { sg.getName() }));
showText.setState(sg.getDisplayText());
showColourText.setState(sg.getColourText());
showBoxes.setState(sg.getDisplayBoxes());
@@ -228,10 +257,9 @@ public class APopupMenu extends java.awt.PopupMenu implements
if (links != null && links.size() > 0)
{
Menu linkMenu = new Menu(MessageManager.getString("action.link"));
- String link;
for (int i = 0; i < links.size(); i++)
{
- link = links.elementAt(i).toString();
+ String link = links.elementAt(i);
UrlLink urlLink = new UrlLink(link);
if (!urlLink.isValid())
{
@@ -246,8 +274,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
// collect matching db-refs
DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
- seq.getDBRef(), new String[]
- { target });
+ seq.getDBRef(), new String[] { target });
// collect id string too
String id = seq.getName();
String descr = seq.getDescription();
@@ -361,8 +388,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
.getString("action.set_as_reference")); // );
}
repGroup.setLabel(MessageManager.formatMessage(
- "label.represent_group_with", new String[]
- { seq.getName() }));
+ "label.represent_group_with", new Object[] { seq.getName() }));
}
else
{
@@ -391,6 +417,95 @@ public class APopupMenu extends java.awt.PopupMenu implements
}
/**
+ * Build menus for annotation types that may be shown or hidden, and for
+ * 'reference annotations' that may be added to the alignment.
+ */
+ private void buildAnnotationSubmenus()
+ {
+ /*
+ * First for the currently selected sequence (if there is one):
+ */
+ 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);
+ }
+
+ /**
+ * Determine whether or not to enable 'add reference annotations' menu item.
+ * It is enable if there are any annotations, on any of the selected
+ * sequences, which are not yet on the alignment (visible or not).
+ *
+ * @param menu
+ * @param forSequences
+ */
+ private void configureReferenceAnnotationsMenu(MenuItem menuItem,
+ List forSequences)
+ {
+ menuItem.setEnabled(false);
+
+ /*
+ * Temporary store to hold distinct calcId / type pairs for the tooltip.
+ * Using TreeMap means calcIds are shown in alphabetical order.
+ */
+ Map tipEntries = new TreeMap();
+ final Map> candidates = new LinkedHashMap>();
+ AlignmentI al = this.ap.av.getAlignment();
+ AlignmentUtils.findAddableReferenceAnnotations(forSequences,
+ tipEntries, candidates, al);
+ if (!candidates.isEmpty())
+ {
+ StringBuilder tooltip = new StringBuilder(64);
+ tooltip.append(MessageManager.getString("label.add_annotations_for"));
+
+ /*
+ * Found annotations that could be added. Enable the menu item, and
+ * configure its action.
+ */
+ menuItem.setEnabled(true);
+
+ menuItem.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ addReferenceAnnotations_actionPerformed(candidates);
+ }
+ });
+ }
+ }
+
+ /**
+ * Add annotations to the sequences and to the alignment.
+ *
+ * @param candidates
+ * a map whose keys are sequences on the alignment, and values a list
+ * of annotations to add to each sequence
+ */
+ protected void addReferenceAnnotations_actionPerformed(
+ Map> candidates)
+ {
+ final SequenceGroup selectionGroup = this.ap.av.getSelectionGroup();
+ final AlignmentI alignment = this.ap.getAlignment();
+ AlignmentUtils.addReferenceAnnotations(candidates, alignment,
+ selectionGroup);
+ refresh();
+ }
+
+ /**
* add a show URL menu item to the given linkMenu
*
* @param linkMenu
@@ -591,7 +706,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
{
if (seq == null)
{
- seq = (Sequence) sg.getSequenceAt(0);
+ seq = sg.getSequenceAt(0);
}
EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
@@ -602,7 +717,8 @@ public class APopupMenu extends java.awt.PopupMenu implements
if (dialog.accept)
{
- EditCommand editCommand = new EditCommand(MessageManager.getString("label.edit_sequences"),
+ EditCommand editCommand = new EditCommand(
+ MessageManager.getString("label.edit_sequences"),
Action.REPLACE, dialog.getName().replace(' ',
ap.av.getGapCharacter()),
sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
@@ -619,10 +735,9 @@ public class APopupMenu extends java.awt.PopupMenu implements
else if (source == toUpper || source == toLower || source == toggleCase)
{
SequenceGroup sg = ap.av.getSelectionGroup();
- Vector regions = new Vector();
if (sg != null)
{
- int[][] startEnd = ap.av.getVisibleRegionBoundaries(
+ List startEnd = ap.av.getVisibleRegionBoundaries(
sg.getStartRes(), sg.getEndRes() + 1);
String description;
@@ -690,7 +805,8 @@ public class APopupMenu extends java.awt.PopupMenu implements
features, true, ap))
{
ap.alignFrame.sequenceFeatures.setState(true);
- ap.av.setShowSequenceFeatures(true);;
+ ap.av.setShowSequenceFeatures(true);
+ ;
ap.highlightSearchResults(null);
}
}
@@ -708,15 +824,14 @@ public class APopupMenu extends java.awt.PopupMenu implements
Frame frame = new Frame();
frame.add(cap);
jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
- "label.selection_output_command", new String[]
- { e.getActionCommand() }), 600, 500);
+ "label.selection_output_command",
+ new Object[] { e.getActionCommand() }), 600, 500);
// JBPNote: getSelectionAsNewSequence behaviour has changed - this method
// now returns a full copy of sequence data
// TODO consider using getSequenceSelection instead here
cap.setText(new jalview.io.AppletFormatAdapter().formatSequences(
- e.getActionCommand(),
- ap.av.showJVSuffix, ap.av, true));
+ e.getActionCommand(), ap.av.getShowJVSuffix(), ap, true));
}
@@ -727,8 +842,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
protected void showSequenceDetails()
{
- createSequenceDetailsReport(new SequenceI[]
- { seq });
+ createSequenceDetailsReport(new SequenceI[] { seq });
}
public void createSequenceDetailsReport(SequenceI[] sequences)
@@ -740,17 +854,16 @@ public class APopupMenu extends java.awt.PopupMenu implements
for (SequenceI seq : sequences)
{
contents.append(MessageManager.formatMessage(
- "label.annotation_for_displayid", new String[]
- { seq.getDisplayId(true) }));
- new SequenceAnnotationReport(null)
- .createSequenceAnnotationReport(
- contents,
- seq,
- true,
- true,
- false,
- (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr.getMinMax()
- : null);
+ "label.annotation_for_displayid",
+ new Object[] { seq.getDisplayId(true) }));
+ new SequenceAnnotationReport(null).createSequenceAnnotationReport(
+ contents,
+ seq,
+ true,
+ true,
+ false,
+ (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr
+ .getMinMax() : null);
contents.append("
");
}
Frame frame = new Frame();
@@ -759,8 +872,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
+ (sequences.length == 1 ? sequences[0].getDisplayId(true)
: "Selection"), 600, 500);
cap.setText(MessageManager.formatMessage("label.html_content",
- new String[]
- { contents.toString() }));
+ new Object[] { contents.toString() }));
}
void editName()
@@ -780,19 +892,19 @@ public class APopupMenu extends java.awt.PopupMenu implements
void addPDB()
{
- if (seq.getPDBId() != null)
+ if (seq.getAllPDBEntries() != null)
{
- PDBEntry entry = (PDBEntry) seq.getPDBId().firstElement();
+ PDBEntry entry = seq.getAllPDBEntries().firstElement();
if (ap.av.applet.jmolAvailable)
{
- new jalview.appletgui.AppletJmol(entry, new Sequence[]
- { seq }, null, ap, AppletFormatAdapter.URL);
+ new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
+ null, ap, AppletFormatAdapter.URL);
}
else
{
- new MCview.AppletPDBViewer(entry, new Sequence[]
- { seq }, null, ap, AppletFormatAdapter.URL);
+ new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null,
+ ap, AppletFormatAdapter.URL);
}
}
@@ -804,8 +916,8 @@ public class APopupMenu extends java.awt.PopupMenu implements
Frame frame = new Frame();
frame.add(cap);
jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
- "label.paste_pdb_file_for_sequence", new String[]
- { seq.getName() }), 400, 300);
+ "label.paste_pdb_file_for_sequence",
+ new Object[] { seq.getName() }), 400, 300);
}
}
@@ -848,8 +960,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
pdb.setLabel(MessageManager.getString("label.view_pdb_structure"));
hideSeqs.setLabel(MessageManager.getString("action.hide_sequences"));
repGroup.setLabel(MessageManager.formatMessage(
- "label.represent_group_with", new String[]
- { "" }));
+ "label.represent_group_with", new Object[] { "" }));
revealAll.setLabel(MessageManager.getString("action.reveal_all"));
revealSeq.setLabel(MessageManager.getString("action.reveal_sequences"));
menu1.setLabel(MessageManager.getString("label.group") + ":");
@@ -859,6 +970,9 @@ public class APopupMenu extends java.awt.PopupMenu implements
this.add(revealSeq);
this.add(revealAll);
// groupMenu.add(selSeqDetails);
+ groupMenu.add(groupShowAnnotationsMenu);
+ groupMenu.add(groupHideAnnotationsMenu);
+ groupMenu.add(groupAddReferenceAnnotations);
groupMenu.add(editMenu);
groupMenu.add(outputmenu);
groupMenu.add(sequenceFeature);
@@ -886,31 +1000,39 @@ public class APopupMenu extends java.awt.PopupMenu implements
noColourmenuItem.setLabel(MessageManager.getString("label.none"));
noColourmenuItem.addActionListener(this);
- clustalColour.setLabel(MessageManager.getString("label.clustalx_colours"));
+ clustalColour.setLabel(MessageManager
+ .getString("label.clustalx_colours"));
clustalColour.addActionListener(this);
zappoColour.setLabel(MessageManager.getString("label.zappo"));
zappoColour.addActionListener(this);
taylorColour.setLabel(MessageManager.getString("label.taylor"));
taylorColour.addActionListener(this);
- hydrophobicityColour.setLabel(MessageManager.getString("label.hydrophobicity"));
+ hydrophobicityColour.setLabel(MessageManager
+ .getString("label.hydrophobicity"));
hydrophobicityColour.addActionListener(this);
- helixColour.setLabel(MessageManager.getString("label.helix_propensity"));
+ helixColour
+ .setLabel(MessageManager.getString("label.helix_propensity"));
helixColour.addActionListener(this);
- strandColour.setLabel(MessageManager.getString("label.strand_propensity"));
+ strandColour.setLabel(MessageManager
+ .getString("label.strand_propensity"));
strandColour.addActionListener(this);
turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
turnColour.addActionListener(this);
buriedColour.setLabel(MessageManager.getString("label.buried_index"));
buriedColour.addActionListener(this);
- abovePIDColour.setLabel(MessageManager.getString("label.above_identity_percentage"));
+ abovePIDColour.setLabel(MessageManager
+ .getString("label.above_identity_percentage"));
- userDefinedColour.setLabel(MessageManager.getString("action.user_defined"));
+ userDefinedColour.setLabel(MessageManager
+ .getString("action.user_defined"));
userDefinedColour.addActionListener(this);
- PIDColour.setLabel(MessageManager.getString("action.percentage_identity"));
+ PIDColour.setLabel(MessageManager
+ .getString("label.percentage_identity"));
PIDColour.addActionListener(this);
BLOSUM62Colour.setLabel("BLOSUM62");
BLOSUM62Colour.addActionListener(this);
- conservationMenuItem.setLabel(MessageManager.getString("label.conservation"));
+ conservationMenuItem.setLabel(MessageManager
+ .getString("label.conservation"));
editMenu.add(copy);
copy.addActionListener(this);
@@ -925,6 +1047,9 @@ public class APopupMenu extends java.awt.PopupMenu implements
editMenu.add(toLower);
toLower.addActionListener(this);
editMenu.add(toggleCase);
+ seqMenu.add(seqShowAnnotationsMenu);
+ seqMenu.add(seqHideAnnotationsMenu);
+ seqMenu.add(seqAddReferenceAnnotations);
seqMenu.add(sequenceName);
seqMenu.add(makeReferenceSeq);
// seqMenu.add(sequenceDetails);
@@ -1024,7 +1149,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
.getName());
- sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
+ sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
SliderPanel.showPIDSlider();
@@ -1032,7 +1157,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
else
// remove PIDColouring
{
- sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
+ sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
}
refresh();
@@ -1136,6 +1261,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
getGroup().setDisplayText(showText.getState());
refresh();
}
+
public void makeReferenceSeq_actionPerformed()
{
if (!ap.av.getAlignment().hasSeqrep())
@@ -1176,8 +1302,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
SequenceGroup sg = ap.av.getSelectionGroup();
if (sg == null || sg.getSize() < 1)
{
- ap.av.hideSequence(new SequenceI[]
- { seq });
+ ap.av.hideSequence(new SequenceI[] { seq });
return;
}
@@ -1205,4 +1330,107 @@ public class APopupMenu extends java.awt.PopupMenu implements
ap.av.sendSelection();
}
+ /**
+ * 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. 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
+ * as visible (to avoid duplication of the display). For such groups we add a
+ * composite type name, e.g.
+ *
+ * IUPredWS (Long), IUPredWS (Short)
+ *
+ * @param seq
+ */
+ protected void buildAnnotationTypesMenus(Menu showMenu, Menu hideMenu,
+ List forSequences)
+ {
+ showMenu.removeAll();
+ hideMenu.removeAll();
+
+ final List all = Arrays.asList(ALL_ANNOTATIONS);
+ 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. Using LinkedHashMap means we will retrieve in
+ * the insertion order, which is the order of the annotations on the
+ * alignment.
+ */
+ Map>> shownTypes = new LinkedHashMap>>();
+ Map>> hiddenTypes = new LinkedHashMap>>();
+ AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
+ AlignmentAnnotationUtils.asList(annotations), forSequences);
+
+ for (String calcId : hiddenTypes.keySet())
+ {
+ for (List type : hiddenTypes.get(calcId))
+ {
+ addAnnotationTypeToShowHide(showMenu, forSequences, calcId, type,
+ false, true);
+ }
+ }
+ // grey out 'show annotations' if none are hidden
+ showMenu.setEnabled(!hiddenTypes.isEmpty());
+
+ for (String calcId : shownTypes.keySet())
+ {
+ for (List type : shownTypes.get(calcId))
+ {
+ addAnnotationTypeToShowHide(hideMenu, forSequences, calcId, type,
+ false, false);
+ }
+ }
+ // grey out 'hide annotations' if none are shown
+ hideMenu.setEnabled(!shownTypes.isEmpty());
+ }
+
+ /**
+ * Add one annotation type to the 'Show Annotations' or 'Hide Annotations'
+ * menus.
+ *
+ * @param showOrHideMenu
+ * the menu to add to
+ * @param forSequences
+ * the sequences whose annotations may be shown or hidden
+ * @param calcId
+ * @param types
+ * the label to add
+ * @param allTypes
+ * if true this is a special label meaning 'All'
+ * @param actionIsShow
+ * if true, the select menu item action is to show the annotation
+ * type, else hide
+ */
+ protected void addAnnotationTypeToShowHide(Menu showOrHideMenu,
+ final List forSequences, String calcId,
+ final List types, final boolean allTypes,
+ final boolean actionIsShow)
+ {
+ String label = types.toString(); // [a, b, c]
+ label = label.substring(1, label.length() - 1);
+ final MenuItem item = new MenuItem(label);
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ AlignmentUtils.showOrHideSequenceAnnotations(ap.getAlignment(),
+ types, forSequences, allTypes, actionIsShow);
+ refresh();
+ }
+ });
+ showOrHideMenu.add(item);
+ }
+
}