Merge branch 'develop' into menard
[jalview.git] / src / jalview / gui / PopupMenu.java
index c354964..3b43e6b 100644 (file)
@@ -1,13 +1,13 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
- * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
+ * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
  * 
  * Jalview is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License 
  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- * 
+ *  
  * Jalview is distributed in the hope that it will be useful, but 
  * WITHOUT ANY WARRANTY; without even the implied warranty 
  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
@@ -32,7 +32,6 @@ import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
 
-import MCview.*;
 import jalview.analysis.*;
 import jalview.commands.*;
 import jalview.datamodel.*;
@@ -93,8 +92,9 @@ public class PopupMenu extends JPopupMenu
   JMenu sequenceMenu = new JMenu();
 
   JMenuItem sequenceName = new JMenuItem();
-  
+
   JMenuItem sequenceDetails = new JMenuItem();
+
   JMenuItem sequenceSelDetails = new JMenuItem();
 
   SequenceI sequence;
@@ -174,8 +174,8 @@ public class PopupMenu extends JPopupMenu
    * @param links
    * @param groupLinks
    */
-  public PopupMenu(final AlignmentPanel ap, final SequenceI seq, Vector links,
-          Vector groupLinks)
+  public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
+          Vector links, Vector groupLinks)
   {
     // /////////////////////////////////////////////////////////
     // If this is activated from the sequence panel, the user may want to
@@ -249,8 +249,10 @@ public class PopupMenu extends JPopupMenu
           {
             public void actionPerformed(ActionEvent e)
             {
-               // 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);
+              // 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);
             }
 
@@ -270,22 +272,23 @@ public class PopupMenu extends JPopupMenu
       {
         if (ap.av.getAlignment().isNucleotide() == false)
         {
-        structureMenu.remove(viewStructureMenu);
+          structureMenu.remove(viewStructureMenu);
         }
         // structureMenu.remove(colStructureMenu);
       }
 
       if (ap.av.getAlignment().isNucleotide() == true)
       {
-        AlignmentAnnotation[] aa = ap.av.getAlignment().getAlignmentAnnotation();
+        AlignmentAnnotation[] aa = ap.av.getAlignment()
+                .getAlignmentAnnotation();
         for (int i = 0; i < aa.length; i++)
         {
           if (aa[i].getRNAStruc() != null)
           {
             final String rnastruc = aa[i].getRNAStruc();
-            final String structureLine=aa[i].label;
+            final String structureLine = aa[i].label;
             menuItem = new JMenuItem();
-            menuItem.setText("2D RNA "+structureLine);
+            menuItem.setText("2D RNA " + structureLine);
             menuItem.addActionListener(new java.awt.event.ActionListener()
             
             {
@@ -320,19 +323,19 @@ public class PopupMenu extends JPopupMenu
             if (seqAnno[i].getRNAStruc() != null)
             {
               final String rnastruc = seqAnno[i].getRNAStruc();
-              
-           // TODO: make rnastrucF a bit more nice
+
+              // TODO: make rnastrucF a bit more nice
               menuItem = new JMenuItem();
-              menuItem.setText("2D RNA - "+seq.getName());
+              menuItem.setText("2D RNA - " + seq.getName());
               menuItem.addActionListener(new java.awt.event.ActionListener()
               {
                 public void actionPerformed(ActionEvent e)
                 {
                   // TODO: VARNA does'nt print gaps in the sequence
                 
-                  //new AppVarna(seq.getName()+" structure",seq,rnastruc,seq.getRNA(), seq.getName(), ap);
-                  new AppVarna(seq.getName()+" structure",seq,seq.getSequenceAsString(), rnastruc, seq
-                          .getName(), ap);
+                  new AppVarna(seq.getName() + " structure", seq, seq
+                          .getSequenceAsString(), rnastruc, seq.getName(),
+                          ap);
                 }
               });
               viewStructureMenu.add(menuItem);
@@ -340,7 +343,6 @@ public class PopupMenu extends JPopupMenu
           }
         }
 
-        
       }
 
       menuItem = new JMenuItem("Hide Sequences");
@@ -391,7 +393,8 @@ public class PopupMenu extends JPopupMenu
       }
     }
     // for the case when no sequences are even visible
-    if (ap.av.hasHiddenRows()) {
+    if (ap.av.hasHiddenRows())
+    {
       {
         menuItem = new JMenuItem("Reveal All");
         menuItem.addActionListener(new ActionListener()
@@ -413,9 +416,9 @@ public class PopupMenu extends JPopupMenu
 
     SequenceGroup sg = ap.av.getSelectionGroup();
 
-    if (sg != null&& sg.getSize()>0)
+    if (sg != null && sg.getSize() > 0)
     {
-      groupName.setText("Name: "+sg.getName());
+      groupName.setText("Name: " + sg.getName());
       groupName.setText("Edit name and description of current group.");
 
       if (sg.cs instanceof ZappoColourScheme)
@@ -494,36 +497,43 @@ 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())
+      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)
+        Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence()
+                .getPDBId();
+        if (pes != null)
+        {
+          for (PDBEntry pe : pes)
           {
-            pdbe.put(pe.getId(),  pe);
-            if (sqass==null)
+            pdbe.put(pe.getId(), pe);
+            if (sqass == null)
             {
               sqass = sq;
             }
           }
         }
       }
-      if (pdbe.size()>0)
+      if (pdbe.size() > 0)
       {
-        final PDBEntry[] pe = pdbe.values().toArray(new PDBEntry[pdbe.size()]);
+        final PDBEntry[] pe = pdbe.values().toArray(
+                new PDBEntry[pdbe.size()]);
         final JMenuItem gpdbview;
-        if (pdbe.size()==1)
+        if (pdbe.size() == 1)
+        {
+          structureMenu.add(gpdbview = new JMenuItem("View structure for "
+                  + sqass.getDisplayId(false)));
+        }
+        else
         {
-          structureMenu.add(gpdbview=new JMenuItem("View structure for "+sqass.getDisplayId(false)));
-        } else {
-          structureMenu.add(gpdbview=new JMenuItem("View all "+pdbe.size()+" structures."));
+          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)
           {
@@ -574,7 +584,7 @@ public class PopupMenu extends JPopupMenu
           continue;
         }
         final String label = urlLink.getLabel();
-        if (seq!=null && urlLink.isDynamic())
+        if (seq != null && urlLink.isDynamic())
         {
 
           // collect matching db-refs
@@ -933,14 +943,17 @@ public class PopupMenu extends JPopupMenu
       public void actionPerformed(ActionEvent e)
       {
         sequenceDetails_actionPerformed();
-     }});
+      }
+    });
     sequenceSelDetails.setText("Sequence Details ...");
-    sequenceSelDetails.addActionListener(new java.awt.event.ActionListener()
-    {
-      public void actionPerformed(ActionEvent e)
-      {
-        sequenceSelectionDetails_actionPerformed();
-     }});    
+    sequenceSelDetails
+            .addActionListener(new java.awt.event.ActionListener()
+            {
+              public void actionPerformed(ActionEvent e)
+              {
+                sequenceSelectionDetails_actionPerformed();
+              }
+            });
     PIDColour.setFocusPainted(false);
     unGroupMenuItem.setText("Remove Group");
     unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
@@ -1121,7 +1134,7 @@ public class PopupMenu extends JPopupMenu
         editSequence_actionPerformed(actionEvent);
       }
     });
-    
+
     /*
      * annotationMenuItem.setText("By Annotation");
      * annotationMenuItem.addActionListener(new ActionListener() { public void
@@ -1151,8 +1164,8 @@ public class PopupMenu extends JPopupMenu
     colourMenu.add(turnColour);
     colourMenu.add(buriedColour);
     colourMenu.add(nucleotideMenuItem);
-    colourMenu.add(RNAInteractionColour);
     if (ap.getAlignment().isNucleotide()) {
+      colourMenu.add(RNAInteractionColour);
        colourMenu.add(purinePyrimidineColour);
     }
     // colourMenu.add(covariationColour);
@@ -1350,31 +1363,35 @@ public class PopupMenu extends JPopupMenu
 
   protected void sequenceDetails_actionPerformed()
   {
-    createSequenceDetailsReport(new SequenceI[]{sequence});
+    createSequenceDetailsReport(new SequenceI[]
+    { sequence });
   }
+
   public void createSequenceDetailsReport(SequenceI[] sequences)
   {
     CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer();
     StringBuffer contents = new StringBuffer();
-    for (SequenceI seq:sequences)
-    {
-    contents.append("<p><h2>Annotation for "+seq.getDisplayId(true)+"</h2></p><p>");
-    new SequenceAnnotationReport(null)
-            .createSequenceAnnotationReport(
-                    contents,
-                    seq,
-                    true,
-                    true,false, 
-                    (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr.minmax
-                            : null);
-    contents.append("</p>");
+    for (SequenceI seq : sequences)
+    {
+      contents.append("<p><h2>Annotation for " + seq.getDisplayId(true)
+              + "</h2></p><p>");
+      new SequenceAnnotationReport(null)
+              .createSequenceAnnotationReport(
+                      contents,
+                      seq,
+                      true,
+                      true,
+                      false,
+                      (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr.minmax
+                              : null);
+      contents.append("</p>");
     }
     cap.setText("<html>" + contents.toString() + "</html>");
-    
-    Desktop.instance.addInternalFrame(cap, 
-            "Sequence Details for " + (sequences.length==1 ? sequences[0].getDisplayId(true) : "Selection") 
-, 500, 400);
-    
+
+    Desktop.instance.addInternalFrame(cap, "Sequence Details for "
+            + (sequences.length == 1 ? sequences[0].getDisplayId(true)
+                    : "Selection"), 500, 400);
+
   }
 
   protected void showNonconserved_actionPerformed()
@@ -1403,8 +1420,7 @@ public class PopupMenu extends JPopupMenu
   protected void clustalColour_actionPerformed()
   {
     SequenceGroup sg = getGroup();
-    sg.cs = new ClustalxColourScheme(
-            sg,ap.av.getHiddenRepSequences());
+    sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
     refresh();
   }
 
@@ -1536,8 +1552,8 @@ public class PopupMenu extends JPopupMenu
     if (abovePIDColour.isSelected())
     {
       sg.cs.setConsensus(AAFrequency.calculate(
-              sg.getSequences(ap.av.getHiddenRepSequences()), sg.getStartRes(),
-              sg.getEndRes() + 1));
+              sg.getSequences(ap.av.getHiddenRepSequences()),
+              sg.getStartRes(), sg.getEndRes() + 1));
 
       int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
               .getName());
@@ -1590,8 +1606,8 @@ public class PopupMenu extends JPopupMenu
     SequenceGroup sg = getGroup();
     sg.cs = new PIDColourScheme();
     sg.cs.setConsensus(AAFrequency.calculate(
-            sg.getSequences(ap.av.getHiddenRepSequences()), sg.getStartRes(),
-            sg.getEndRes() + 1));
+            sg.getSequences(ap.av.getHiddenRepSequences()),
+            sg.getStartRes(), sg.getEndRes() + 1));
     refresh();
   }
 
@@ -1608,8 +1624,8 @@ public class PopupMenu extends JPopupMenu
     sg.cs = new Blosum62ColourScheme();
 
     sg.cs.setConsensus(AAFrequency.calculate(
-            sg.getSequences(ap.av.getHiddenRepSequences()), sg.getStartRes(),
-            sg.getEndRes() + 1));
+            sg.getSequences(ap.av.getHiddenRepSequences()),
+            sg.getStartRes(), sg.getEndRes() + 1));
 
     refresh();
   }
@@ -1643,8 +1659,8 @@ public class PopupMenu extends JPopupMenu
     if (conservationMenuItem.isSelected())
     {
       Conservation c = new Conservation("Group",
-              ResidueProperties.propHash, 3,
-              sg.getSequences(ap.av.getHiddenRepSequences()), sg.getStartRes(),
+              ResidueProperties.propHash, 3, sg.getSequences(ap.av
+                      .getHiddenRepSequences()), sg.getStartRes(),
               sg.getEndRes() + 1);
 
       c.calculate();
@@ -1926,8 +1942,8 @@ public class PopupMenu extends JPopupMenu
       }
 
       ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
-              sg.getSequencesAsArray(ap.av.getHiddenRepSequences()), startEnd,
-              caseChange);
+              sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
+              startEnd, caseChange);
 
       ap.alignFrame.addHistoryItem(caseCommand);
 
@@ -1953,7 +1969,8 @@ public class PopupMenu extends JPopupMenu
     ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
     omitHidden = ap.av.getViewAsString(true);
     Alignment oal = new Alignment(ap.av.getSequenceSelection());
-    AlignmentAnnotation[] nala = ap.av.getAlignment().getAlignmentAnnotation();
+    AlignmentAnnotation[] nala = ap.av.getAlignment()
+            .getAlignmentAnnotation();
     if (nala != null)
     {
       for (int i = 0; i < nala.length; i++)
@@ -1972,8 +1989,10 @@ 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 for "+sequence.getDisplayId(false));
-    chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'");
+    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);
 
@@ -1981,7 +2000,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);
+      new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
+              jalview.io.AppletFormatAdapter.FILE, sequence, true);
     }
 
   }
@@ -2067,8 +2087,8 @@ public class PopupMenu extends JPopupMenu
 
   public void colourByStructure(String pdbid)
   {
-    Annotation[] anots = ap.av.getStructureSelectionManager().colourSequenceFromStructure(
-                    sequence, pdbid);
+    Annotation[] anots = ap.av.getStructureSelectionManager()
+            .colourSequenceFromStructure(sequence, pdbid);
 
     AlignmentAnnotation an = new AlignmentAnnotation("Structure",
             "Coloured by " + pdbid, anots);