Merge develop to Release_2_8_3_Branch
[jalview.git] / src / MCview / AppletPDBCanvas.java
old mode 100755 (executable)
new mode 100644 (file)
index 39d0926..211cff0
@@ -1,34 +1,53 @@
 /*
- * 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-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * 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.
- * 
+ * 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 
  * PURPOSE.  See the GNU General Public License for more details.
  * 
- * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package MCview;
 
-import java.io.*;
-import java.util.*;
-
+import jalview.analysis.AlignSeq;
+import jalview.appletgui.AlignmentPanel;
+import jalview.appletgui.FeatureRenderer;
+import jalview.appletgui.SequenceRenderer;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceI;
+import jalview.structure.AtomSpec;
+import jalview.structure.StructureListener;
+import jalview.structure.StructureMapping;
+import jalview.structure.StructureSelectionManager;
+import jalview.util.MessageManager;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Event;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.Image;
 // JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.analysis.*;
-import jalview.datamodel.*;
-
-import jalview.appletgui.*;
-import jalview.structure.*;
+import java.awt.Panel;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.io.PrintStream;
+import java.util.List;
+import java.util.Vector;
 
 public class AppletPDBCanvas extends Panel implements MouseListener,
         MouseMotionListener, StructureListener
@@ -132,14 +151,17 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
     this.pdbentry = pdbentry;
     this.sequence = seq;
 
-    ssm = StructureSelectionManager.getStructureSelectionManager();
+    ssm = StructureSelectionManager
+            .getStructureSelectionManager(ap.av.applet);
 
     try
     {
       pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol);
 
       if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE))
+      {
         pdbentry.setFile("INLINE" + pdb.id);
+      }
 
     } catch (Exception ex)
     {
@@ -167,10 +189,10 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
     {
 
       mappingDetails.append("\n\nPDB Sequence is :\nSequence = "
-              + ((PDBChain) pdb.chains.elementAt(i)).sequence
+              + pdb.chains.elementAt(i).sequence
                       .getSequenceAsString());
       mappingDetails.append("\nNo of residues = "
-              + ((PDBChain) pdb.chains.elementAt(i)).residues.size()
+              + pdb.chains.elementAt(i).residues.size()
               + "\n\n");
 
       // Now lets compare the sequences to get
@@ -178,8 +200,8 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
       // Align the sequence to the pdb
       // TODO: DNa/Pep switch
       AlignSeq as = new AlignSeq(sequence,
-              ((PDBChain) pdb.chains.elementAt(i)).sequence,
-              ((PDBChain) pdb.chains.elementAt(i)).isNa ? AlignSeq.DNA
+              pdb.chains.elementAt(i).sequence,
+              pdb.chains.elementAt(i).isNa ? AlignSeq.DNA
                       : AlignSeq.PEP);
       as.calcScoreMatrix();
       as.traceAlignment();
@@ -213,7 +235,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
       mappingDetails.append("\nSEQ start/end " + seqstart + " " + seqend);
     }
 
-    mainchain = (PDBChain) pdb.chains.elementAt(maxchain);
+    mainchain = pdb.chains.elementAt(maxchain);
 
     mainchain.pdbstart = pdbstart;
     mainchain.pdbend = pdbend;
@@ -272,9 +294,9 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
 
     for (int ii = 0; ii < pdb.chains.size(); ii++)
     {
-      if (((PDBChain) pdb.chains.elementAt(ii)).isVisible)
+      if (pdb.chains.elementAt(ii).isVisible)
       {
-        Vector tmp = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+        Vector tmp = pdb.chains.elementAt(ii).bonds;
 
         for (int i = 0; i < tmp.size(); i++)
         {
@@ -303,9 +325,9 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
 
     for (int ii = 0; ii < pdb.chains.size(); ii++)
     {
-      if (((PDBChain) pdb.chains.elementAt(ii)).isVisible)
+      if (pdb.chains.elementAt(ii).isVisible)
       {
-        Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+        Vector bonds = pdb.chains.elementAt(ii).bonds;
 
         for (int i = 0; i < bonds.size(); i++)
         {
@@ -374,9 +396,9 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
       }
     }
 
-    width[0] = (float) Math.abs(max[0] - min[0]);
-    width[1] = (float) Math.abs(max[1] - min[1]);
-    width[2] = (float) Math.abs(max[2] - min[2]);
+    width[0] = Math.abs(max[0] - min[0]);
+    width[1] = Math.abs(max[1] - min[1]);
+    width[2] = Math.abs(max[2] - min[2]);
 
     maxwidth = width[0];
 
@@ -433,9 +455,9 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
     // Find centre coordinate
     for (int ii = 0; ii < pdb.chains.size(); ii++)
     {
-      if (((PDBChain) pdb.chains.elementAt(ii)).isVisible)
+      if (pdb.chains.elementAt(ii).isVisible)
       {
-        Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+        Vector bonds = pdb.chains.elementAt(ii).bonds;
 
         bsize += bonds.size();
 
@@ -467,7 +489,9 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
       g.fillRect(0, 0, getSize().width, getSize().height);
       g.setColor(Color.black);
       g.setFont(new Font("Verdana", Font.BOLD, 14));
-      g.drawString("Error loading PDB data!!", 50, getSize().height / 2);
+      g.drawString(
+              MessageManager.getString("label.error_loading_pdb_data"), 50,
+              getSize().height / 2);
       return;
     }
 
@@ -475,7 +499,8 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
     {
       g.setColor(Color.black);
       g.setFont(new Font("Verdana", Font.BOLD, 14));
-      g.drawString("Fetching PDB data...", 50, getSize().height / 2);
+      g.drawString(MessageManager.getString("label.fetching_pdb_data"), 50,
+              getSize().height / 2);
       return;
     }
 
@@ -542,7 +567,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
     StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile());
 
     boolean showFeatures = false;
-    if (ap.av.getShowSequenceFeatures())
+    if (ap.av.isShowSequenceFeatures())
     {
       if (fr == null)
       {
@@ -559,7 +584,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
     {
       for (int ii = 0; ii < pdb.chains.size(); ii++)
       {
-        chain = (PDBChain) pdb.chains.elementAt(ii);
+        chain = pdb.chains.elementAt(ii);
 
         for (int i = 0; i < chain.bonds.size(); i++)
         {
@@ -771,7 +796,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
       repaint();
       if (foundchain != -1)
       {
-        PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain);
+        PDBChain chain = pdb.chains.elementAt(foundchain);
         if (chain == mainchain)
         {
           if (fatom.alignmentMapping != -1)
@@ -817,7 +842,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
     PDBChain chain = null;
     if (foundchain != -1)
     {
-      chain = (PDBChain) pdb.chains.elementAt(foundchain);
+      chain = pdb.chains.elementAt(foundchain);
       if (chain == mainchain)
       {
         mouseOverStructure(fatom.resNumber, chain.id);
@@ -867,18 +892,18 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
 
     if ((evt.getModifiers() & Event.META_MASK) != 0)
     {
-      objmat.rotatez((float) ((mx - omx)));
+      objmat.rotatez(((mx - omx)));
     }
     else
     {
-      objmat.rotatex((float) ((omy - my)));
-      objmat.rotatey((float) ((omx - mx)));
+      objmat.rotatex(((omy - my)));
+      objmat.rotatey(((omx - mx)));
     }
 
     // Alter the bonds
     for (int ii = 0; ii < pdb.chains.size(); ii++)
     {
-      Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+      Vector bonds = pdb.chains.elementAt(ii).bonds;
 
       for (int i = 0; i < bonds.size(); i++)
       {
@@ -919,11 +944,11 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
 
     for (int ii = 0; ii < pdb.chains.size(); ii++)
     {
-      PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+      PDBChain chain = pdb.chains.elementAt(ii);
 
       if (chain.isVisible)
       {
-        Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+        Vector bonds = pdb.chains.elementAt(ii).bonds;
 
         for (int i = 0; i < bonds.size(); i++)
         {
@@ -977,13 +1002,13 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
 
     for (int ii = 0; ii < pdb.chains.size(); ii++)
     {
-      PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+      PDBChain chain = pdb.chains.elementAt(ii);
       int truex;
       Bond tmpBond = null;
 
       if (chain.isVisible)
       {
-        Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+        Vector bonds = pdb.chains.elementAt(ii).bonds;
 
         for (int i = 0; i < bonds.size(); i++)
         {
@@ -1024,7 +1049,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
 
       if (fatom != null) // )&& chain.ds != null)
       {
-        chain = (PDBChain) pdb.chains.elementAt(foundchain);
+        chain = pdb.chains.elementAt(foundchain);
       }
     }
 
@@ -1092,7 +1117,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
   {
     for (int ii = 0; ii < pdb.chains.size(); ii++)
     {
-      PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+      PDBChain chain = pdb.chains.elementAt(ii);
       chain.isVisible = b;
     }
     mainchain.isVisible = true;
@@ -1113,7 +1138,9 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
   public void mouseOverStructure(int pdbResNum, String chain)
   {
     if (lastMessage == null || !lastMessage.equals(pdbResNum + chain))
+    {
       ssm.mouseOverStructure(pdbResNum, chain, pdbentry.getFile());
+    }
 
     lastMessage = pdbResNum + chain;
   }
@@ -1122,19 +1149,40 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
 
   StringBuffer eval = new StringBuffer();
 
-  public void highlightAtom(int atomIndex, int pdbResNum, String chain,
-          String pdbfile)
+  /**
+   * Highlight the specified atoms in the structure.
+   * 
+   * @param atoms
+   */
+  @Override
+  public void highlightAtoms(List<AtomSpec> atoms)
   {
     if (!seqColoursReady)
     {
       return;
     }
-
-    if (highlightRes != null && highlightRes.contains((atomIndex - 1) + ""))
+    for (AtomSpec atom : atoms)
     {
-      return;
+      int atomIndex = atom.getAtomIndex();
+
+      if (highlightRes != null
+              && highlightRes.contains((atomIndex - 1) + ""))
+      {
+        continue;
+      }
+
+      highlightAtom(atomIndex);
     }
 
+    redrawneeded = true;
+    repaint();
+  }
+
+  /**
+   * @param atomIndex
+   */
+  protected void highlightAtom(int atomIndex)
+  {
     int index = -1;
     Bond tmpBond;
     for (index = 0; index < mainchain.bonds.size(); index++)
@@ -1170,9 +1218,6 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
         break;
       }
     }
-
-    redrawneeded = true;
-    repaint();
   }
 
   public Color getColour(int atomIndex, int pdbResNum, String chain,
@@ -1196,7 +1241,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
   public void releaseReferences(Object svl)
   {
     // TODO Auto-generated method stub
-    
+
   }
 
 }