JAL-1925 update source version in license
[jalview.git] / src / MCview / AppletPDBCanvas.java
index 211cff0..a75df88 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.0b2)
+ * Copyright (C) 2015 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -127,7 +127,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
 
   PDBChain mainchain;
 
-  Vector highlightRes;
+  Vector<String> highlightRes;
 
   boolean pdbAction = false;
 
@@ -189,11 +189,9 @@ public class AppletPDBCanvas extends Panel 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.
@@ -201,8 +199,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
       // TODO: DNa/Pep switch
       AlignSeq as = new AlignSeq(sequence,
               pdb.chains.elementAt(i).sequence,
-              pdb.chains.elementAt(i).isNa ? AlignSeq.DNA
-                      : AlignSeq.PEP);
+              pdb.chains.elementAt(i).isNa ? AlignSeq.DNA : AlignSeq.PEP);
       as.calcScoreMatrix();
       as.traceAlignment();
       PrintStream ps = new PrintStream(System.out)
@@ -284,19 +281,19 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
     scale = findScale();
   }
 
-  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++)
     {
       if (pdb.chains.elementAt(ii).isVisible)
       {
-        Vector tmp = pdb.chains.elementAt(ii).bonds;
+        Vector<Bond> tmp = pdb.chains.elementAt(ii).bonds;
 
         for (int i = 0; i < tmp.size(); i++)
         {
@@ -327,12 +324,10 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
     {
       if (pdb.chains.elementAt(ii).isVisible)
       {
-        Vector bonds = pdb.chains.elementAt(ii).bonds;
+        Vector<Bond> bonds = pdb.chains.elementAt(ii).bonds;
 
-        for (int i = 0; i < bonds.size(); i++)
+        for (Bond tmp : bonds)
         {
-          Bond tmp = (Bond) bonds.elementAt(i);
-
           if (tmp.start[0] >= max[0])
           {
             max[0] = tmp.start[0];
@@ -457,20 +452,15 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
     {
       if (pdb.chains.elementAt(ii).isVisible)
       {
-        Vector bonds = pdb.chains.elementAt(ii).bonds;
+        Vector<Bond> bonds = pdb.chains.elementAt(ii).bonds;
 
         bsize += bonds.size();
 
-        for (int i = 0; i < bonds.size(); i++)
+        for (Bond b : 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 + b.start[0] + b.end[0];
+          ytot = ytot + b.start[1] + b.end[1];
+          ztot = ztot + b.start[2] + b.end[2];
         }
       }
     }
@@ -588,7 +578,7 @@ public class AppletPDBCanvas extends Panel 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)
@@ -644,13 +634,13 @@ public class AppletPDBCanvas extends Panel 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) + (getSize().width / 2));
       ystart = (int) (((centre[1] - tmpBond.start[1]) * scale) + (getSize().height / 2));
@@ -803,16 +793,18 @@ public class AppletPDBCanvas extends Panel 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.removeElement(fatom.alignmentMapping + "");
+              highlightRes.removeElement(atomString);
             }
             else
             {
-              highlightRes.addElement(fatom.alignmentMapping + "");
+              highlightRes.addElement(atomString);
             }
           }
         }
@@ -901,14 +893,10 @@ public class AppletPDBCanvas extends Panel 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]);
 
@@ -942,18 +930,12 @@ public class AppletPDBCanvas extends Panel 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);
@@ -961,7 +943,6 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
 
           if (tmpBond.at2.isSelected)
           {
-
             labelAtom(g, tmpBond, 2);
           }
         }
@@ -1008,11 +989,11 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
 
       if (chain.isVisible)
       {
-        Vector bonds = pdb.chains.elementAt(ii).bonds;
+        Vector<Bond> bonds = pdb.chains.elementAt(ii).bonds;
 
         for (int i = 0; i < bonds.size(); i++)
         {
-          tmpBond = (Bond) bonds.elementAt(i);
+          tmpBond = bonds.elementAt(i);
 
           truex = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getSize().width / 2));
 
@@ -1077,7 +1058,7 @@ public class AppletPDBCanvas extends Panel 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)
@@ -1095,13 +1076,13 @@ public class AppletPDBCanvas extends Panel 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;
         }
 
@@ -1129,8 +1110,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
   // /StructureListener
   public String[] getPdbFile()
   {
-    return new String[]
-    { pdbentry.getFile() };
+    return new String[] { pdbentry.getFile() };
   }
 
   String lastMessage;
@@ -1187,7 +1167,7 @@ public class AppletPDBCanvas extends Panel 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)
@@ -1205,13 +1185,13 @@ public class AppletPDBCanvas extends Panel 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;
         }
 
@@ -1244,4 +1224,19 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
 
   }
 
+  @Override
+  public boolean isListeningFor(SequenceI seq)
+  {
+    if (sequence != null)
+    {
+      for (SequenceI s : sequence)
+      {
+        if (s == seq)
+        {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
 }