import jalview.commands.EditCommand.Action;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
-import jalview.datamodel.Annotation;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.HiddenColumns;
import jalview.datamodel.PDBEntry;
*/
public class PopupMenu extends JPopupMenu implements ColourChangeListener
{
+ /*
+ * true for ID Panel menu, false for alignment panel menu
+ */
+ private final boolean forIdPanel;
+
+ private final AlignmentPanel ap;
+
+ /*
+ * the sequence under the cursor when clicked
+ * (additional sequences may be selected)
+ */
+ private final SequenceI sequence;
+
JMenu groupMenu = new JMenu();
JMenuItem groupName = new JMenuItem();
protected JMenuItem modifyConservation = new JMenuItem();
- AlignmentPanel ap;
-
JMenu sequenceMenu = new JMenu();
- JMenuItem sequenceName = new JMenuItem();
-
- JMenuItem sequenceDetails = new JMenuItem();
-
- JMenuItem sequenceSelDetails = new JMenuItem();
-
JMenuItem makeReferenceSeq = new JMenuItem();
- JMenuItem chooseAnnotations = new JMenuItem();
-
- SequenceI sequence;
-
JMenuItem createGroupMenuItem = new JMenuItem();
JMenuItem unGroupMenuItem = new JMenuItem();
- JMenuItem outline = new JMenuItem();
-
JMenu colourMenu = new JMenu();
JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
JMenu editMenu = new JMenu();
- JMenuItem cut = new JMenuItem();
-
- JMenuItem copy = new JMenuItem();
-
JMenuItem upperCase = new JMenuItem();
JMenuItem lowerCase = new JMenuItem();
JMenuItem toggle = new JMenuItem();
- JMenu pdbMenu = new JMenu();
-
JMenu outputMenu = new JMenu();
JMenu seqShowAnnotationsMenu = new JMenu();
JMenuItem groupAddReferenceAnnotations = new JMenuItem(
MessageManager.getString("label.add_reference_annotations"));
- JMenuItem sequenceFeature = new JMenuItem();
-
JMenuItem textColour = new JMenuItem();
- JMenu jMenu1 = new JMenu();
+ JMenu editGroupMenu = new JMenu();
- JMenuItem pdbStructureDialog = new JMenuItem();
+ JMenuItem chooseStructure = new JMenuItem();
JMenu rnaStructureMenu = new JMenu();
- JMenuItem editSequence = new JMenuItem();
-
- JMenu groupLinksMenu;
-
- JMenuItem hideInsertions = new JMenuItem();
-
/**
* Constructs a menu with sub-menu items for any hyperlinks for the sequence
* and/or features provided. Hyperlinks may include a lookup by sequence id,
* @param features
* @return
*/
- static JMenu buildLinkMenu(final SequenceI seq,
+ protected static JMenu buildLinkMenu(final SequenceI seq,
List<SequenceFeature> features)
{
JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
}
/**
- * Creates a new PopupMenu object.
+ * Constructor for a PopupMenu for a click in the alignment panel (on a residue)
*
* @param ap
* @param seq
* @param features
- * non-positional features (for seq not null), or positional features
- * at residue (for seq equal to null)
+ * sequence features overlapping the clicked residue
*/
public PopupMenu(final AlignmentPanel ap, SequenceI seq,
List<SequenceFeature> features)
{
- this(ap, seq, features, null);
+ this(false, ap, seq, features, null);
}
/**
- * Constructor
+ * Constructor for a PopupMenu for a click in the sequence id panel
*
* @param alignPanel
* @param seq
- * the sequence under the cursor if in the Id panel, null if in the
- * sequence panel
* @param features
- * non-positional features if in the Id panel, features at the
- * clicked residue if in the sequence panel
+ * non-positional features for the sequence
* @param groupLinks
*/
public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
List<SequenceFeature> features, List<String> groupLinks)
{
- // /////////////////////////////////////////////////////////
- // If this is activated from the sequence panel, the user may want to
- // edit or annotate a particular residue. Therefore display the residue menu
- //
- // If from the IDPanel, we must display the sequence menu
- // ////////////////////////////////////////////////////////
+ this(true, alignPanel, seq, features, groupLinks);
+ }
+
+ /**
+ * Private constructor that constructs a popup menu for either sequence ID
+ * Panel, or alignment context
+ *
+ * @param fromIdPanel
+ * @param alignPanel
+ * @param seq
+ * @param features
+ * @param groupLinks
+ */
+ private PopupMenu(boolean fromIdPanel,
+ final AlignmentPanel alignPanel,
+ final SequenceI seq, List<SequenceFeature> features,
+ List<String> groupLinks)
+ {
+ this.forIdPanel = fromIdPanel;
this.ap = alignPanel;
sequence = seq;
* 'reference annotations' that may be added to the alignment. First for the
* currently selected sequence (if there is one):
*/
- final List<SequenceI> selectedSequence = (seq == null
- ? Collections.<SequenceI> emptyList()
- : Arrays.asList(seq));
+ final List<SequenceI> selectedSequence = (forIdPanel
+ ? Arrays.asList(seq)
+ : Collections.<SequenceI> emptyList());
buildAnnotationTypesMenus(seqShowAnnotationsMenu,
seqHideAnnotationsMenu, selectedSequence);
configureReferenceAnnotationsMenu(seqAddReferenceAnnotations,
e.printStackTrace();
}
- JMenuItem menuItem;
- if (seq != null)
+ if (forIdPanel)
{
+ JMenuItem menuItem;
sequenceMenu.setText(sequence.getName());
if (seq == alignPanel.av.getAlignment().getSeqrep())
{
}
if (addOption)
{
- menuItem = new JMenuItem(
+ JMenuItem menuItem = new JMenuItem(
MessageManager.getString("action.reveal_all"));
menuItem.addActionListener(new ActionListener()
{
{
createGroupMenuItem.setVisible(true);
unGroupMenuItem.setVisible(false);
- jMenu1.setText(MessageManager.getString("action.edit_new_group"));
+ editGroupMenu.setText(MessageManager.getString("action.edit_new_group"));
}
else
{
createGroupMenuItem.setVisible(false);
unGroupMenuItem.setVisible(true);
- jMenu1.setText(MessageManager.getString("action.edit_group"));
+ editGroupMenu.setText(MessageManager.getString("action.edit_group"));
}
- if (seq == null)
+ if (!forIdPanel)
{
sequenceMenu.setVisible(false);
- pdbStructureDialog.setVisible(false);
+ chooseStructure.setVisible(false);
rnaStructureMenu.setVisible(false);
}
addLinks(seq, features);
- if (seq == null)
+ if (!forIdPanel)
{
addFeatureDetails(features);
}
protected void showFeatureDetails(SequenceFeature sf)
{
CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
- // it appears Java's CSS does not support border-collaps :-(
+ // it appears Java's CSS does not support border-collapse :-(
cap.addStylesheetRule("table { border-collapse: collapse;}");
cap.addStylesheetRule("table, td, th {border: 1px solid black;}");
- cap.setText(sf.getDetailsReport());
+ cap.setText(sf.getDetailsReport(sequence));
Desktop.addInternalFrame(cap,
MessageManager.getString("label.feature_details"), 500, 500);
*/
void addLinks(final SequenceI seq, List<SequenceFeature> features)
{
- JMenu linkMenu = buildLinkMenu(seq, features);
+ JMenu linkMenu = buildLinkMenu(forIdPanel ? seq : null, features);
// only add link menu if it has entries
if (linkMenu.getItemCount() > 0)
{
- if (sequence != null)
+ if (forIdPanel)
{
sequenceMenu.add(linkMenu);
}
// menu appears asap
// sequence only URLs
// ID/regex match URLs
- groupLinksMenu = new JMenu(
+ JMenu groupLinksMenu = new JMenu(
MessageManager.getString("action.group_link"));
// three types of url that might be created.
JMenu[] linkMenus = new JMenu[] { null,
}
});
sequenceMenu.setText(MessageManager.getString("label.sequence"));
- sequenceName.setText(
+
+ JMenuItem sequenceName = new JMenuItem(
MessageManager.getString("label.edit_name_description"));
sequenceName.addActionListener(new ActionListener()
{
sequenceName_actionPerformed();
}
});
- chooseAnnotations
- .setText(MessageManager.getString("action.choose_annotations"));
+ JMenuItem chooseAnnotations = new JMenuItem(
+ MessageManager.getString("action.choose_annotations"));
chooseAnnotations.addActionListener(new ActionListener()
{
@Override
chooseAnnotations_actionPerformed(e);
}
});
- sequenceDetails
- .setText(MessageManager.getString("label.sequence_details"));
+ JMenuItem sequenceDetails = new JMenuItem(
+ MessageManager.getString("label.sequence_details"));
sequenceDetails.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- sequenceDetails_actionPerformed();
+ createSequenceDetailsReport(new SequenceI[] { sequence });
}
});
- sequenceSelDetails
- .setText(MessageManager.getString("label.sequence_details"));
+ JMenuItem sequenceSelDetails = new JMenuItem(
+ MessageManager.getString("label.sequence_details"));
sequenceSelDetails.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- sequenceSelectionDetails_actionPerformed();
+ createSequenceDetailsReport(ap.av.getSequenceSelection());
}
});
}
});
- outline.setText(MessageManager.getString("action.border_colour"));
+ JMenuItem outline = new JMenuItem(
+ MessageManager.getString("action.border_colour"));
outline.addActionListener(new ActionListener()
{
@Override
}
});
editMenu.setText(MessageManager.getString("action.edit"));
- cut.setText(MessageManager.getString("action.cut"));
+ JMenuItem cut = new JMenuItem(MessageManager.getString("action.cut"));
cut.addActionListener(new ActionListener()
{
@Override
changeCase(e);
}
});
- copy.setText(MessageManager.getString("action.copy"));
+ JMenuItem copy = new JMenuItem(MessageManager.getString("action.copy"));
copy.addActionListener(new ActionListener()
{
@Override
.setText(MessageManager.getString("label.show_annotations"));
groupHideAnnotationsMenu
.setText(MessageManager.getString("label.hide_annotations"));
- sequenceFeature.setText(
+ JMenuItem sequenceFeature = new JMenuItem(
MessageManager.getString("label.create_sequence_feature"));
sequenceFeature.addActionListener(new ActionListener()
{
sequenceFeature_actionPerformed();
}
});
- jMenu1.setText(MessageManager.getString("label.group"));
- pdbStructureDialog.setText(
+ editGroupMenu.setText(MessageManager.getString("label.group"));
+ chooseStructure.setText(
MessageManager.getString("label.show_pdbstruct_dialog"));
- pdbStructureDialog.addActionListener(new ActionListener()
+ chooseStructure.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent actionEvent)
.setText(MessageManager.getString("label.view_rna_structure"));
// colStructureMenu.setText("Colour By Structure");
- editSequence.setText(
+ JMenuItem editSequence = new JMenuItem(
MessageManager.getString("label.edit_sequence") + "...");
editSequence.addActionListener(new ActionListener()
{
}
});
- hideInsertions
- .setText(MessageManager.getString("label.hide_insertions"));
- hideInsertions.addActionListener(new ActionListener()
- {
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- hideInsertions_actionPerformed(e);
- }
- });
groupMenu.add(sequenceSelDetails);
add(groupMenu);
add(sequenceMenu);
add(rnaStructureMenu);
- add(pdbStructureDialog);
- if (sequence != null)
+ add(chooseStructure);
+ if (forIdPanel)
{
+ JMenuItem hideInsertions = new JMenuItem(
+ MessageManager.getString("label.hide_insertions"));
+ hideInsertions.addActionListener(new ActionListener()
+ {
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ hideInsertions_actionPerformed(e);
+ }
+ });
add(hideInsertions);
}
// annotations configuration panel suppressed for now
groupMenu.add(sequenceFeature);
groupMenu.add(createGroupMenuItem);
groupMenu.add(unGroupMenuItem);
- groupMenu.add(jMenu1);
+ groupMenu.add(editGroupMenu);
sequenceMenu.add(sequenceName);
sequenceMenu.add(sequenceDetails);
sequenceMenu.add(makeReferenceSeq);
editMenu.add(upperCase);
editMenu.add(lowerCase);
editMenu.add(toggle);
- // JBPNote: These shouldn't be added here - should appear in a generic
- // 'apply web service to this sequence menu'
- // pdbMenu.add(RNAFold);
- // pdbMenu.add(ContraFold);
- jMenu1.add(groupName);
- jMenu1.add(colourMenu);
- jMenu1.add(showBoxes);
- jMenu1.add(showText);
- jMenu1.add(showColourText);
- jMenu1.add(outline);
- jMenu1.add(displayNonconserved);
+ editGroupMenu.add(groupName);
+ editGroupMenu.add(colourMenu);
+ editGroupMenu.add(showBoxes);
+ editGroupMenu.add(showText);
+ editGroupMenu.add(showColourText);
+ editGroupMenu.add(outline);
+ editGroupMenu.add(displayNonconserved);
}
/**
createSequenceDetailsReport(ap.av.getSequenceSelection());
}
- protected void sequenceDetails_actionPerformed()
- {
- createSequenceDetailsReport(new SequenceI[] { sequence });
- }
-
public void createSequenceDetailsReport(SequenceI[] sequences)
{
CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
}
/**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
+ * Shows a dialog where the sequence name and description may be edited. If a
+ * name containing spaces is entered, these are converted to underscores, with a
+ * warning message.
*/
void sequenceName_actionPerformed()
{
return;
}
- if (dialog.getName() != null)
+ String name = dialog.getName();
+ if (name != null)
{
- if (dialog.getName().indexOf(" ") > -1)
+ if (name.indexOf(" ") > -1)
{
JvOptionPane.showMessageDialog(ap,
MessageManager
MessageManager
.getString("label.no_spaces_allowed_sequence_name"),
JvOptionPane.WARNING_MESSAGE);
+ name = name.replace(' ', '_');
}
- sequence.setName(dialog.getName().replace(' ', '_'));
+ sequence.setName(name);
ap.paintAlignment(false, false);
}
}
}
- public void colourByStructure(String pdbid)
- {
- Annotation[] anots = ap.av.getStructureSelectionManager()
- .colourSequenceFromStructure(sequence, pdbid);
-
- AlignmentAnnotation an = new AlignmentAnnotation("Structure",
- "Coloured by " + pdbid, anots);
-
- ap.av.getAlignment().addAnnotation(an);
- an.createSequenceMapping(sequence, 0, true);
- // an.adjustForAlignment();
- ap.av.getAlignment().setAnnotationIndex(an, 0);
-
- ap.adjustAnnotationHeight();
-
- sequence.addAlignmentAnnotation(an);
-
- }
-
public void editSequence_actionPerformed(ActionEvent actionEvent)
{
SequenceGroup sg = ap.av.getSelectionGroup();
+ SequenceI seq = sequence;
if (sg != null)
{
- if (sequence == null)
+ if (seq == null)
{
- sequence = sg.getSequenceAt(0);
+ seq = sg.getSequenceAt(0);
}
EditNameDialog dialog = new EditNameDialog(
- sequence.getSequenceAsString(sg.getStartRes(),
+ seq.getSequenceAsString(sg.getStartRes(),
sg.getEndRes() + 1),
null, MessageManager.getString("label.edit_sequence"), null,
MessageManager.getString("label.edit_sequence"),
@Test(groups = { "Functional" })
public void testGetDetailsReport()
{
+ SequenceI seq = new Sequence("TestSeq", "PLRFQMD");
+
// single locus, no group, no score
SequenceFeature sf = new SequenceFeature("variant", "G,C", 22, 22, null);
- String expected = "<br><table><tr><td>Type</td><td>variant</td><td></td></tr>"
- + "<tr><td>Start/end</td><td>22</td><td></td></tr>"
+ String expected = "<br><table><tr><td>Location</td><td>TestSeq</td><td>22</td></tr>"
+ + "<tr><td>Type</td><td>variant</td><td></td></tr>"
+ "<tr><td>Description</td><td>G,C</td><td></td></tr></table>";
- assertEquals(expected, sf.getDetailsReport());
+ assertEquals(expected, sf.getDetailsReport(seq));
// contact feature
sf = new SequenceFeature("Disulphide Bond", "a description", 28, 31,
null);
- expected = "<br><table><tr><td>Type</td><td>Disulphide Bond</td><td></td></tr>"
- + "<tr><td>Start/end</td><td>28:31</td><td></td></tr>"
+ expected = "<br><table><tr><td>Location</td><td>TestSeq</td><td>28:31</td></tr>"
+ + "<tr><td>Type</td><td>Disulphide Bond</td><td></td></tr>"
+ "<tr><td>Description</td><td>a description</td><td></td></tr></table>";
- assertEquals(expected, sf.getDetailsReport());
+ assertEquals(expected, sf.getDetailsReport(seq));
sf = new SequenceFeature("variant", "G,C", 22, 33,
12.5f, "group");
sf.setValue("Parent", "ENSG001");
sf.setValue("Child", "ENSP002");
- expected = "<br><table><tr><td>Type</td><td>variant</td><td></td></tr>"
- + "<tr><td>Start/end</td><td>22-33</td><td></td></tr>"
+ expected = "<br><table><tr><td>Location</td><td>TestSeq</td><td>22-33</td></tr>"
+ + "<tr><td>Type</td><td>variant</td><td></td></tr>"
+ "<tr><td>Description</td><td>G,C</td><td></td></tr>"
+ "<tr><td>Score</td><td>12.5</td><td></td></tr>"
+ "<tr><td>Group</td><td>group</td><td></td></tr>"
+ "<tr><td>Child</td><td></td><td>ENSP002</td></tr>"
+ "<tr><td>Parent</td><td></td><td>ENSG001</td></tr></table>";
- assertEquals(expected, sf.getDetailsReport());
+ assertEquals(expected, sf.getDetailsReport(seq));
/*
* feature with embedded html link in description
*/
String desc = "<html>Fer2 Status: True Positive <a href=\"http://pfam.xfam.org/family/PF00111\">Pfam 8_8</a></html>";
sf = new SequenceFeature("Pfam", desc, 8, 83, "Uniprot");
- expected = "<br><table><tr><td>Type</td><td>Pfam</td><td></td></tr>"
- + "<tr><td>Start/end</td><td>8-83</td><td></td></tr>"
+ expected = "<br><table><tr><td>Location</td><td>TestSeq</td><td>8-83</td></tr>"
+ + "<tr><td>Type</td><td>Pfam</td><td></td></tr>"
+ "<tr><td>Description</td><td>Fer2 Status: True Positive <a href=\"http://pfam.xfam.org/family/PF00111\">Pfam 8_8</a></td><td></td></tr>"
+ "<tr><td>Group</td><td>Uniprot</td><td></td></tr></table>";
- assertEquals(expected, sf.getDetailsReport());
+ assertEquals(expected, sf.getDetailsReport(seq));
}
}