X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPopupMenu.java;h=d778125ad4c104d4950a81e4cd58b69fbed782ce;hb=7c28880430765f06ccd5ec8ad3caf17871336e97;hp=a98c1da213537b110f4117d25466a025c801704c;hpb=65b3877f9041a45bfbb7cbc1dd444a8cf87c9f3d;p=jalview.git diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java old mode 100755 new mode 100644 index a98c1da..d778125 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -1,5 +1,5 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle * * This file is part of Jalview. @@ -21,6 +21,7 @@ import java.util.*; import java.awt.*; import java.awt.event.*; + import javax.swing.*; import MCview.*; @@ -30,13 +31,14 @@ import jalview.datamodel.*; import jalview.io.*; import jalview.schemes.*; import jalview.util.GroupUrlLink; +import jalview.util.GroupUrlLink.UrlStringTooLongException; import jalview.util.UrlLink; /** * DOCUMENT ME! * * @author $author$ - * @version $Revision$ + * @version $Revision: 1.118 $ */ public class PopupMenu extends JPopupMenu { @@ -206,11 +208,11 @@ public class PopupMenu extends JPopupMenu e.printStackTrace(); } + JMenuItem menuItem; if (seq != null) { sequenceMenu.setText(sequence.getName()); - JMenuItem menuItem; if (seq.getDatasetSequence().getPDBId() != null && seq.getDatasetSequence().getPDBId().size() > 0) { @@ -227,33 +229,11 @@ public class PopupMenu extends JPopupMenu { public void actionPerformed(ActionEvent e) { - Vector seqs = new Vector(); - for (int i = 0; i < ap.av.alignment.getHeight(); i++) - { - Vector pdbs = ap.av.alignment.getSequenceAt(i) - .getDatasetSequence().getPDBId(); - if (pdbs == null) - continue; - - for (int p = 0; p < pdbs.size(); p++) - { - PDBEntry p1 = (PDBEntry) pdbs.elementAt(p); - if (p1.getId().equals(pdb.getId())) - { - if (!seqs.contains(ap.av.alignment.getSequenceAt(i))) - seqs.addElement(ap.av.alignment.getSequenceAt(i)); - - continue; - } - } - } - - SequenceI[] seqs2 = new SequenceI[seqs.size()]; - seqs.toArray(seqs2); - - new AppJmol(pdb, seqs2, null, ap); + // TODO re JAL-860: optionally open dialog or provide a menu entry allowing user to open just one structure per sequence + new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[] { pdb })[0], null, ap); // new PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE); } + }); viewStructureMenu.add(menuItem); @@ -317,7 +297,11 @@ public class PopupMenu extends JPopupMenu }); add(menuItem); } - + } + } + // for the case when no sequences are even visible + if (ap.av.hasHiddenRows) { + { menuItem = new JMenuItem("Reveal All"); menuItem.addActionListener(new ActionListener() { @@ -338,9 +322,10 @@ public class PopupMenu extends JPopupMenu SequenceGroup sg = ap.av.getSelectionGroup(); - if (sg != null) + if (sg != null&& sg.getSize()>0) { - groupName.setText(sg.getName()); + groupName.setText("Name: "+sg.getName()); + groupName.setText("Edit name and description of current group."); if (sg.cs instanceof ZappoColourScheme) { @@ -395,7 +380,7 @@ public class PopupMenu extends JPopupMenu { conservationMenuItem.setSelected(true); } - displayNonconserved.setSelected(sg.getShowunconserved()); + displayNonconserved.setSelected(sg.getShowNonconserved()); showText.setSelected(sg.getDisplayText()); showColourText.setSelected(sg.getColourText()); showBoxes.setSelected(sg.getDisplayBoxes()); @@ -404,6 +389,44 @@ public class PopupMenu extends JPopupMenu { buildGroupURLMenu(sg, groupLinks); } + // Add a 'show all structures' for the current selection + Hashtable pdbe=new Hashtable(); + SequenceI sqass=null; + for (SequenceI sq: ap.av.getSequenceSelection()) + { + Vector pes = (Vector) sq.getDatasetSequence().getPDBId(); + if (pes!=null) { + for (PDBEntry pe: pes) + { + pdbe.put(pe.getId(), pe); + if (sqass==null) + { + sqass = sq; + } + } + } + } + if (pdbe.size()>0) + { + final PDBEntry[] pe = pdbe.values().toArray(new PDBEntry[pdbe.size()]); + final JMenuItem gpdbview; + if (pdbe.size()==1) + { + structureMenu.add(gpdbview=new JMenuItem("View structure for "+sqass.getDisplayId(false))); + } else { + structureMenu.add(gpdbview=new JMenuItem("View all "+pdbe.size()+" structures.")); + } + gpdbview.setToolTipText("Open a new Jmol view with all structures associated with the current selection and superimpose them using the alignment."); + gpdbview.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + new AppJmol(ap, pe, ap.av.collateForPDB(pe)); + } + }); + } } else { @@ -422,7 +445,7 @@ public class PopupMenu extends JPopupMenu structureMenu.setVisible(false); } - if (links != null && links.size() > 0) + if (seq !=null && links != null && links.size() > 0) { JMenu linkMenu = new JMenu("Link"); @@ -451,9 +474,9 @@ public class PopupMenu extends JPopupMenu { // collect matching db-refs - DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq - .getDBRef(), new String[] - { urlLink.getTarget() }); + DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs( + seq.getDBRef(), new String[] + { urlLink.getTarget() }); // collect id string too String id = seq.getName(); String descr = seq.getDescription(); @@ -654,8 +677,14 @@ public class PopupMenu extends JPopupMenu } // and try and make the groupURL! - Object[] urlset = urlLink.makeUrlStubs(ids, seqstr, "FromJalview" - + System.currentTimeMillis(), false); + Object[] urlset = null; + try + { + urlset = urlLink.makeUrlStubs(ids, seqstr, + "FromJalview" + System.currentTimeMillis(), false); + } catch (UrlStringTooLongException e) + { + } if (urlset != null) { int type = urlLink.getGroupURLType() & 3; @@ -752,7 +781,12 @@ public class PopupMenu extends JPopupMenu public void run() { - showLink(urlgenerator.constructFrom(urlstub)); + try + { + showLink(urlgenerator.constructFrom(urlstub)); + } catch (UrlStringTooLongException e) + { + } } }).start(); @@ -1139,7 +1173,7 @@ public class PopupMenu extends JPopupMenu protected void showNonconserved_actionPerformed() { - getGroup().setShowunconserved(displayNonconserved.isSelected()); + getGroup().setShowNonconserved(displayNonconserved.isSelected()); refresh(); } @@ -1163,9 +1197,9 @@ public class PopupMenu extends JPopupMenu protected void clustalColour_actionPerformed() { SequenceGroup sg = getGroup(); - sg.cs = new ClustalxColourScheme(sg - .getSequences(ap.av.hiddenRepSequences), ap.av.alignment - .getWidth()); + sg.cs = new ClustalxColourScheme( + sg.getSequences(ap.av.hiddenRepSequences), + ap.av.alignment.getWidth()); refresh(); } @@ -1281,9 +1315,9 @@ public class PopupMenu extends JPopupMenu if (abovePIDColour.isSelected()) { - sg.cs.setConsensus(AAFrequency.calculate(sg - .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg - .getEndRes() + 1)); + sg.cs.setConsensus(AAFrequency.calculate( + sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), + sg.getEndRes() + 1)); int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup() .getName()); @@ -1335,9 +1369,9 @@ public class PopupMenu extends JPopupMenu { SequenceGroup sg = getGroup(); sg.cs = new PIDColourScheme(); - sg.cs.setConsensus(AAFrequency.calculate(sg - .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg - .getEndRes() + 1)); + sg.cs.setConsensus(AAFrequency.calculate( + sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), + sg.getEndRes() + 1)); refresh(); } @@ -1353,9 +1387,9 @@ public class PopupMenu extends JPopupMenu sg.cs = new Blosum62ColourScheme(); - sg.cs.setConsensus(AAFrequency.calculate(sg - .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg - .getEndRes() + 1)); + sg.cs.setConsensus(AAFrequency.calculate( + sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), + sg.getEndRes() + 1)); refresh(); } @@ -1389,9 +1423,9 @@ public class PopupMenu extends JPopupMenu if (conservationMenuItem.isSelected()) { Conservation c = new Conservation("Group", - ResidueProperties.propHash, 3, sg - .getSequences(ap.av.hiddenRepSequences), sg - .getStartRes(), sg.getEndRes() + 1); + ResidueProperties.propHash, 3, + sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), + sg.getEndRes() + 1); c.calculate(); c.verdict(false, ap.av.ConsPercGaps); @@ -1418,8 +1452,8 @@ public class PopupMenu extends JPopupMenu return; } - AnnotationColourGradient acg = new AnnotationColourGradient(sequence - .getAnnotation()[0], null, + AnnotationColourGradient acg = new AnnotationColourGradient( + sequence.getAnnotation()[0], null, AnnotationColourGradient.NO_THRESHOLD); acg.predefinedColours = true; @@ -1438,9 +1472,10 @@ public class PopupMenu extends JPopupMenu { SequenceGroup sg = getGroup(); - EditNameDialog dialog = new EditNameDialog(sg.getName(), sg - .getDescription(), " Group Name ", "Group Description ", - "Edit Group Name/Description"); + EditNameDialog dialog = new EditNameDialog(sg.getName(), + sg.getDescription(), " Group Name ", + "Group Description ", "Edit Group Name/Description", + ap.alignFrame); if (!dialog.accept) { @@ -1477,9 +1512,10 @@ public class PopupMenu extends JPopupMenu */ void sequenceName_actionPerformed() { - EditNameDialog dialog = new EditNameDialog(sequence.getName(), sequence - .getDescription(), " Sequence Name ", - "Sequence Description ", "Edit Sequence Name/Description"); + EditNameDialog dialog = new EditNameDialog(sequence.getName(), + sequence.getDescription(), " Sequence Name ", + "Sequence Description ", "Edit Sequence Name/Description", + ap.alignFrame); if (!dialog.accept) { @@ -1669,8 +1705,8 @@ public class PopupMenu extends JPopupMenu caseChange = ChangeCaseCommand.TO_LOWER; } - ChangeCaseCommand caseCommand = new ChangeCaseCommand(description, sg - .getSequencesAsArray(ap.av.hiddenRepSequences), startEnd, + ChangeCaseCommand caseCommand = new ChangeCaseCommand(description, + sg.getSequencesAsArray(ap.av.hiddenRepSequences), startEnd, caseChange); ap.alignFrame.addHistoryItem(caseCommand); @@ -1685,8 +1721,8 @@ public class PopupMenu extends JPopupMenu { CutAndPasteTransfer cap = new CutAndPasteTransfer(); cap.setForInput(null); - Desktop.addInternalFrame(cap, "Alignment output - " - + e.getActionCommand(), 600, 500); + Desktop.addInternalFrame(cap, + "Alignment output - " + e.getActionCommand(), 600, 500); String[] omitHidden = null; @@ -1698,7 +1734,8 @@ public class PopupMenu extends JPopupMenu omitHidden = ap.av.getViewAsString(true); Alignment oal = new Alignment(ap.av.getSequenceSelection()); AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation(); - if (nala!=null) { + if (nala != null) + { for (int i = 0; i < nala.length; i++) { AlignmentAnnotation na = nala[i]; @@ -1715,47 +1752,16 @@ public class PopupMenu extends JPopupMenu jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser( jalview.bin.Cache.getProperty("LAST_DIRECTORY")); chooser.setFileView(new jalview.io.JalviewFileView()); - chooser.setDialogTitle("Select a PDB file"); - chooser.setToolTipText("Load a PDB file"); + chooser.setDialogTitle("Select a PDB file for "+sequence.getDisplayId(false)); + chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'"); int value = chooser.showOpenDialog(null); if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION) { - PDBEntry entry = new PDBEntry(); String choice = chooser.getSelectedFile().getPath(); jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); - try - { - MCview.PDBfile pdbfile = new MCview.PDBfile(choice, - jalview.io.AppletFormatAdapter.FILE); - - if (pdbfile.id == null) - { - String reply = JOptionPane - .showInternalInputDialog( - Desktop.desktop, - "Couldn't find a PDB id in the file supplied." - + "Please enter an Id to identify this structure.", - "No PDB Id in File", JOptionPane.QUESTION_MESSAGE); - if (reply == null) - { - return; - } - - entry.setId(reply); - } - else - { - entry.setId(pdbfile.id); - } - } catch (java.io.IOException ex) - { - ex.printStackTrace(); - } - - entry.setFile(choice); - sequence.getDatasetSequence().addPDBId(entry); + new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, jalview.io.AppletFormatAdapter.FILE, sequence, true); } } @@ -1841,8 +1847,7 @@ public class PopupMenu extends JPopupMenu public void colourByStructure(String pdbid) { - Annotation[] anots = jalview.structure.StructureSelectionManager - .getStructureSelectionManager().colourSequenceFromStructure( + Annotation[] anots = ap.av.getStructureSelectionManager().colourSequenceFromStructure( sequence, pdbid); AlignmentAnnotation an = new AlignmentAnnotation("Structure", @@ -1868,17 +1873,18 @@ public class PopupMenu extends JPopupMenu if (sequence == null) sequence = (Sequence) sg.getSequenceAt(0); - EditNameDialog dialog = new EditNameDialog(sequence - .getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1), - null, "Edit Sequence ", null, "Edit Sequence"); + EditNameDialog dialog = new EditNameDialog( + sequence.getSequenceAsString(sg.getStartRes(), + sg.getEndRes() + 1), null, "Edit Sequence ", null, + "Edit Sequence", ap.alignFrame); if (dialog.accept) { EditCommand editCommand = new EditCommand("Edit Sequences", EditCommand.REPLACE, dialog.getName().replace(' ', - ap.av.getGapCharacter()), sg - .getSequencesAsArray(ap.av.hiddenRepSequences), sg - .getStartRes(), sg.getEndRes() + 1, ap.av.alignment); + ap.av.getGapCharacter()), + sg.getSequencesAsArray(ap.av.hiddenRepSequences), + sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment); ap.alignFrame.addHistoryItem(editCommand);