apply version 2.7 copyright
[jalview.git] / src / jalview / gui / PopupMenu.java
old mode 100755 (executable)
new mode 100644 (file)
index 07fdeea..da95ae0
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 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.*;
@@ -37,7 +38,7 @@ import jalview.util.UrlLink;
  * DOCUMENT ME!
  * 
  * @author $author$
- * @version $Revision$
+ * @version $Revision: 1.118 $
  */
 public class PopupMenu extends JPopupMenu
 {
@@ -207,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)
       {
@@ -228,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);
 
@@ -318,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()
         {
@@ -339,7 +322,7 @@ public class PopupMenu extends JPopupMenu
 
     SequenceGroup sg = ap.av.getSelectionGroup();
 
-    if (sg != null)
+    if (sg != null&& sg.getSize()>0)
     {
       groupName.setText("Name: "+sg.getName());
       groupName.setText("Edit name and description of current group.");
@@ -406,6 +389,44 @@ public class PopupMenu extends JPopupMenu
       {
         buildGroupURLMenu(sg, groupLinks);
       }
+      // Add a 'show all structures' for the current selection
+      Hashtable<String, PDBEntry> pdbe=new Hashtable<String,PDBEntry>();
+      SequenceI sqass=null;
+      for (SequenceI sq: ap.av.getSequenceSelection())
+      {
+        Vector<PDBEntry> pes = (Vector<PDBEntry>) 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
     {
@@ -424,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");
@@ -1826,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",