JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / MCview / PDBCanvas.java
index 6f76a25..fdd673b 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
+ * Copyright (C) 2015 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -123,7 +123,7 @@ public class PDBCanvas extends JPanel implements MouseListener,
 
   PDBChain mainchain;
 
-  Vector highlightRes;
+  Vector<String> highlightRes;
 
   boolean pdbAction = false;
 
@@ -188,11 +188,9 @@ public class PDBCanvas extends JPanel implements MouseListener,
     {
 
       mappingDetails.append("\n\nPDB Sequence is :\nSequence = "
-              + pdb.chains.elementAt(i).sequence
-                      .getSequenceAsString());
+              + pdb.chains.elementAt(i).sequence.getSequenceAsString());
       mappingDetails.append("\nNo of residues = "
-              + pdb.chains.elementAt(i).residues.size()
-              + "\n\n");
+              + pdb.chains.elementAt(i).residues.size() + "\n\n");
 
       // Now lets compare the sequences to get
       // the start and end points.
@@ -265,23 +263,21 @@ public class PDBCanvas extends JPanel implements MouseListener,
     ToolTipManager.sharedInstance().setDismissDelay(10000);
   }
 
-  Vector visiblebonds;
+  Vector<Bond> visiblebonds;
 
   void setupBonds()
   {
     seqColoursReady = false;
     // Sort the bonds by z coord
-    visiblebonds = new Vector();
+    visiblebonds = new Vector<Bond>();
 
-    for (int ii = 0; ii < pdb.chains.size(); ii++)
+    for (PDBChain chain : pdb.chains)
     {
-      if (pdb.chains.elementAt(ii).isVisible)
+      if (chain.isVisible)
       {
-        Vector tmp = pdb.chains.elementAt(ii).bonds;
-
-        for (int i = 0; i < tmp.size(); i++)
+        for (Bond bond : chain.bonds)
         {
-          visiblebonds.addElement(tmp.elementAt(i));
+          visiblebonds.addElement(bond);
         }
       }
     }
@@ -305,16 +301,12 @@ public class PDBCanvas extends JPanel implements MouseListener,
     min[1] = (float) 1e30;
     min[2] = (float) 1e30;
 
-    for (int ii = 0; ii < pdb.chains.size(); ii++)
+    for (PDBChain chain : pdb.chains)
     {
-      if (pdb.chains.elementAt(ii).isVisible)
+      if (chain.isVisible)
       {
-        Vector bonds = pdb.chains.elementAt(ii).bonds;
-
-        for (int i = 0; i < bonds.size(); i++)
+        for (Bond tmp : chain.bonds)
         {
-          Bond tmp = (Bond) bonds.elementAt(i);
-
           if (tmp.start[0] >= max[0])
           {
             max[0] = tmp.start[0];
@@ -440,24 +432,17 @@ public class PDBCanvas extends JPanel implements MouseListener,
     int bsize = 0;
 
     // Find centre coordinate
-    for (int ii = 0; ii < pdb.chains.size(); ii++)
+    for (PDBChain chain : pdb.chains)
     {
-      if (pdb.chains.elementAt(ii).isVisible)
+      if (chain.isVisible)
       {
-        Vector bonds = pdb.chains.elementAt(ii).bonds;
-
-        bsize += bonds.size();
+        bsize += chain.bonds.size();
 
-        for (int i = 0; i < bonds.size(); i++)
+        for (Bond bond : chain.bonds)
         {
-          xtot = xtot + ((Bond) bonds.elementAt(i)).start[0]
-                  + ((Bond) bonds.elementAt(i)).end[0];
-
-          ytot = ytot + ((Bond) bonds.elementAt(i)).start[1]
-                  + ((Bond) bonds.elementAt(i)).end[1];
-
-          ztot = ztot + ((Bond) bonds.elementAt(i)).start[2]
-                  + ((Bond) bonds.elementAt(i)).end[2];
+          xtot = xtot + bond.start[0] + bond.end[0];
+          ytot = ytot + bond.start[1] + bond.end[1];
+          ztot = ztot + bond.start[2] + bond.end[2];
         }
       }
     }
@@ -562,7 +547,7 @@ public class PDBCanvas extends JPanel implements MouseListener,
 
         for (int i = 0; i < chain.bonds.size(); i++)
         {
-          Bond tmp = (Bond) chain.bonds.elementAt(i);
+          Bond tmp = chain.bonds.elementAt(i);
           tmp.startCol = Color.lightGray;
           tmp.endCol = Color.lightGray;
           if (chain != mainchain)
@@ -618,13 +603,13 @@ public class PDBCanvas extends JPanel implements MouseListener,
         zsort = new Zsort();
       }
 
-      zsort.Zsort(visiblebonds);
+      zsort.sort(visiblebonds);
     }
 
     Bond tmpBond = null;
     for (int i = 0; i < visiblebonds.size(); i++)
     {
-      tmpBond = (Bond) visiblebonds.elementAt(i);
+      tmpBond = visiblebonds.elementAt(i);
 
       xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getWidth() / 2));
       ystart = (int) (((centre[1] - tmpBond.start[1]) * scale) + (getHeight() / 2));
@@ -779,16 +764,18 @@ public class PDBCanvas extends JPanel implements MouseListener,
           {
             if (highlightRes == null)
             {
-              highlightRes = new Vector();
+              highlightRes = new Vector<String>();
             }
 
-            if (highlightRes.contains(fatom.alignmentMapping + ""))
+            final String atomString = Integer
+                    .toString(fatom.alignmentMapping);
+            if (highlightRes.contains(atomString))
             {
-              highlightRes.remove(fatom.alignmentMapping + "");
+              highlightRes.remove(atomString);
             }
             else
             {
-              highlightRes.add(fatom.alignmentMapping + "");
+              highlightRes.add(atomString);
             }
           }
         }
@@ -870,14 +857,10 @@ public class PDBCanvas extends JPanel implements MouseListener,
     }
 
     // Alter the bonds
-    for (int ii = 0; ii < pdb.chains.size(); ii++)
+    for (PDBChain chain : pdb.chains)
     {
-      Vector bonds = pdb.chains.elementAt(ii).bonds;
-
-      for (int i = 0; i < bonds.size(); i++)
+      for (Bond tmpBond : chain.bonds)
       {
-        Bond tmpBond = (Bond) bonds.elementAt(i);
-
         // Translate the bond so the centre is 0,0,0
         tmpBond.translate(-centre[0], -centre[1], -centre[2]);
 
@@ -911,18 +894,12 @@ public class PDBCanvas extends JPanel implements MouseListener,
   void drawLabels(Graphics g)
   {
 
-    for (int ii = 0; ii < pdb.chains.size(); ii++)
+    for (PDBChain chain : pdb.chains)
     {
-      PDBChain chain = pdb.chains.elementAt(ii);
-
       if (chain.isVisible)
       {
-        Vector bonds = pdb.chains.elementAt(ii).bonds;
-
-        for (int i = 0; i < bonds.size(); i++)
+        for (Bond tmpBond : chain.bonds)
         {
-          Bond tmpBond = (Bond) bonds.elementAt(i);
-
           if (tmpBond.at1.isSelected)
           {
             labelAtom(g, tmpBond, 1);
@@ -930,7 +907,6 @@ public class PDBCanvas extends JPanel implements MouseListener,
 
           if (tmpBond.at2.isSelected)
           {
-
             labelAtom(g, tmpBond, 2);
           }
         }
@@ -975,11 +951,9 @@ public class PDBCanvas extends JPanel implements MouseListener,
 
       if (chain.isVisible)
       {
-        Vector bonds = pdb.chains.elementAt(ii).bonds;
-
-        for (int i = 0; i < bonds.size(); i++)
+        for (Bond bond : chain.bonds)
         {
-          tmpBond = (Bond) bonds.elementAt(i);
+          tmpBond = bond;
 
           truex = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getWidth() / 2));
 
@@ -1015,7 +989,7 @@ public class PDBCanvas extends JPanel implements MouseListener,
       }
 
       if (fatom != null) // )&& chain.ds != null)
-      {
+      { // dead code? value of chain is either overwritten or discarded
         chain = pdb.chains.elementAt(foundchain);
       }
     }
@@ -1041,7 +1015,7 @@ public class PDBCanvas extends JPanel implements MouseListener,
     Bond tmpBond;
     for (index = 0; index < mainchain.bonds.size(); index++)
     {
-      tmpBond = (Bond) mainchain.bonds.elementAt(index);
+      tmpBond = mainchain.bonds.elementAt(index);
       if (tmpBond.at1.alignmentMapping == ii - 1)
       {
         if (highlightBond1 != null)
@@ -1059,13 +1033,13 @@ public class PDBCanvas extends JPanel implements MouseListener,
 
         if (index > 0)
         {
-          highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);
+          highlightBond1 = mainchain.bonds.elementAt(index - 1);
           highlightBond1.at2.isSelected = true;
         }
 
         if (index != mainchain.bonds.size())
         {
-          highlightBond2 = (Bond) mainchain.bonds.elementAt(index);
+          highlightBond2 = mainchain.bonds.elementAt(index);
           highlightBond2.at1.isSelected = true;
         }
 
@@ -1093,8 +1067,7 @@ public class PDBCanvas extends JPanel implements MouseListener,
   // /StructureListener
   public String[] getPdbFile()
   {
-    return new String[]
-    { pdbentry.getFile() };
+    return new String[] { pdbentry.getFile() };
   }
 
   String lastMessage;
@@ -1153,7 +1126,7 @@ public class PDBCanvas extends JPanel implements MouseListener,
     Bond tmpBond;
     for (index = 0; index < mainchain.bonds.size(); index++)
     {
-      tmpBond = (Bond) mainchain.bonds.elementAt(index);
+      tmpBond = mainchain.bonds.elementAt(index);
       if (tmpBond.at1.atomIndex == atomIndex)
       {
         if (highlightBond1 != null)
@@ -1171,13 +1144,13 @@ public class PDBCanvas extends JPanel implements MouseListener,
 
         if (index > 0)
         {
-          highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);
+          highlightBond1 = mainchain.bonds.elementAt(index - 1);
           highlightBond1.at2.isSelected = true;
         }
 
         if (index != mainchain.bonds.size())
         {
-          highlightBond2 = (Bond) mainchain.bonds.elementAt(index);
+          highlightBond2 = mainchain.bonds.elementAt(index);
           highlightBond2.at1.isSelected = true;
         }
 
@@ -1210,4 +1183,19 @@ public class PDBCanvas extends JPanel implements MouseListener,
 
   }
 
+  @Override
+  public boolean isListeningFor(SequenceI seq)
+  {
+    if (sequence != null)
+    {
+      for (SequenceI s : sequence)
+      {
+        if (s == seq)
+        {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
 }