Remove empty() from feature ToolTip
[jalview.git] / src / MCview / PDBCanvas.java
index 6014455..9805c35 100755 (executable)
@@ -1,6 +1,6 @@
 /*\r
 * Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+* Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
 *\r
 * This program is free software; you can redistribute it and/or\r
 * modify it under the terms of the GNU General Public License\r
@@ -73,6 +73,8 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe
     Vector highlightRes;\r
     boolean pdbAction = false;\r
     boolean seqColoursReady = false;\r
+    jalview.gui.FeatureRenderer fr;\r
+    Color backgroundColour = Color.black;\r
 \r
     public PDBCanvas(jalview.gui.SeqCanvas seqcanvas, Sequence seq)\r
     {\r
@@ -416,7 +418,7 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe
 \r
     public void drawAll(Graphics g, int width, int height)\r
     {\r
-      g.setColor(Color.black);\r
+      g.setColor(backgroundColour);\r
       g.fillRect(0, 0, width, height);\r
       drawScene(g);\r
       drawLabels(g);\r
@@ -477,11 +479,20 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe
     void colourBySequence(PDBChain chain)\r
     {\r
      // System.out.println("colour by seq");\r
+     boolean showFeatures = false;\r
+     if(seqcanvas.getViewport().getShowSequenceFeatures())\r
+     {\r
+       showFeatures = true;\r
+       if (fr == null)\r
+         fr = new jalview.gui.FeatureRenderer(seqcanvas.getViewport());\r
+\r
+       fr.transferSettings( seqcanvas.getFeatureRenderer() );\r
+     }\r
+\r
+      Bond tmp;\r
       for (int i = 0; i < chain.bonds.size(); i++)\r
       {\r
-        Bond tmp = (Bond) chain.bonds.elementAt(i);\r
-        tmp.startCol = Color.lightGray;\r
-        tmp.endCol = Color.lightGray;\r
+        tmp = (Bond) chain.bonds.elementAt(i);\r
 \r
         if(chain!=mainchain)\r
           continue;\r
@@ -495,11 +506,12 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe
             {\r
               tmp.startCol = seqcanvas.getSequenceRenderer().\r
                   getResidueBoxColour( sequence, index);\r
+\r
+              if(showFeatures)\r
+                tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);\r
+\r
               if(tmp.startCol==null)\r
                 tmp.startCol = Color.white;\r
-\r
-              tmp.startCol = seqcanvas.getFeatureRenderer().\r
-                  findFeatureColour(tmp.startCol, sequence, index);\r
             }\r
         }\r
 \r
@@ -513,95 +525,118 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe
             {\r
               tmp.endCol = seqcanvas.getSequenceRenderer().\r
                   getResidueBoxColour( sequence, index);\r
+\r
+              if(showFeatures)\r
+                tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);\r
+\r
               if(tmp.endCol==null)\r
                 tmp.endCol = Color.white;\r
-              tmp.endCol = seqcanvas.getFeatureRenderer().\r
-                  findFeatureColour(tmp.endCol, sequence, index);\r
             }\r
         }\r
       }\r
     }\r
 \r
 \r
+    Zsort zsort;\r
     public void drawScene(Graphics g)\r
     {\r
-        if (zbuffer)\r
-        {\r
-            Zsort.Zsort(visiblebonds);\r
-        }\r
+      if (zbuffer)\r
+      {\r
+        if (zsort == null)\r
+          zsort = new Zsort();\r
 \r
-        Bond tmpBond=null;\r
-        for (int i = 0; i < visiblebonds.size(); i++)\r
-        {\r
-            tmpBond = (Bond) visiblebonds.elementAt(i);\r
+        zsort.Zsort(visiblebonds);\r
+      }\r
 \r
-            xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) +\r
-                (getWidth() / 2));\r
-            ystart = (int) (((tmpBond.start[1] - centre[1]) * scale) +\r
-                (getHeight() / 2));\r
+      Bond tmpBond = null;\r
+      for (int i = 0; i < visiblebonds.size(); i++)\r
+      {\r
+        tmpBond = (Bond) visiblebonds.elementAt(i);\r
 \r
-            xend = (int) (((tmpBond.end[0] - centre[0]) * scale) +\r
-                (getWidth() / 2));\r
-            yend = (int) (((tmpBond.end[1] - centre[1]) * scale) +\r
-                (getHeight() / 2));\r
+        xstart = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) +\r
+                        (getWidth() / 2));\r
+        ystart = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) +\r
+                        (getHeight() / 2));\r
 \r
-            xmid = (xend + xstart) / 2;\r
-            ymid = (yend + ystart) / 2;\r
+        xend = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +\r
+                      (getWidth() / 2));\r
+        yend = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +\r
+                      (getHeight() / 2));\r
 \r
-            if (depthcue && !bymolecule)\r
-            {\r
-                if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) {\r
-                    g.setColor(tmpBond.startCol.darker().darker());\r
-                    drawLine(g, xstart, ystart, xmid, ymid);\r
-                    g.setColor(tmpBond.endCol.darker().darker());\r
-                    drawLine(g, xmid, ymid, xend, yend);\r
-                } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {\r
-                    g.setColor(tmpBond.startCol.darker());\r
-                    drawLine(g, xstart, ystart, xmid, ymid);\r
-\r
-                    g.setColor(tmpBond.endCol.darker());\r
-                    drawLine(g, xmid, ymid, xend, yend);\r
-                } else {\r
-                    g.setColor(tmpBond.startCol);\r
-                    drawLine(g, xstart, ystart, xmid, ymid);\r
+        xmid = (xend + xstart) / 2;\r
+        ymid = (yend + ystart) / 2;\r
+        if (depthcue && !bymolecule)\r
+        {\r
+          if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))\r
+          {\r
 \r
-                    g.setColor(tmpBond.endCol);\r
-                    drawLine(g, xmid, ymid, xend, yend);\r
-                }\r
-            } else if (depthcue && bymolecule) {\r
-                if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) {\r
-                    g.setColor(Color.green.darker().darker());\r
-                    drawLine(g, xstart, ystart, xend, yend);\r
-                } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {\r
-                    g.setColor(Color.green.darker());\r
-                    drawLine(g, xstart, ystart, xend, yend);\r
-                } else {\r
-                    g.setColor(Color.green);\r
-                    drawLine(g, xstart, ystart, xend, yend);\r
-                }\r
-            } else if (!depthcue && !bymolecule) {\r
-                g.setColor(tmpBond.startCol);\r
-                drawLine(g, xstart, ystart, xmid, ymid);\r
-                g.setColor(tmpBond.endCol);\r
-                drawLine(g, xmid, ymid, xend, yend);\r
-            } else {\r
-                drawLine(g, xstart, ystart, xend, yend);\r
-            }\r
+            g.setColor(tmpBond.startCol.darker().darker());\r
+            drawLine(g, xstart, ystart, xmid, ymid);\r
+            g.setColor(tmpBond.endCol.darker().darker());\r
+            drawLine(g, xmid, ymid, xend, yend);\r
 \r
-            if(highlightBond1!=null && highlightBond1==tmpBond)\r
-            {\r
-              g.setColor(tmpBond.endCol.brighter().brighter().brighter().brighter());\r
-              drawLine(g, xmid, ymid, xend, yend);\r
-            }\r
+          }\r
+          else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))\r
+          {\r
+            g.setColor(tmpBond.startCol.darker());\r
+            drawLine(g, xstart, ystart, xmid, ymid);\r
 \r
-            if(highlightBond2!=null && highlightBond2==tmpBond)\r
-            {\r
-              g.setColor(tmpBond.startCol.brighter().brighter().brighter().brighter());\r
-              drawLine(g, xstart, ystart, xmid, ymid);\r
-            }\r
+            g.setColor(tmpBond.endCol.darker());\r
+            drawLine(g, xmid, ymid, xend, yend);\r
+          }\r
+          else\r
+          {\r
+            g.setColor(tmpBond.startCol);\r
+            drawLine(g, xstart, ystart, xmid, ymid);\r
+\r
+            g.setColor(tmpBond.endCol);\r
+            drawLine(g, xmid, ymid, xend, yend);\r
+          }\r
+        }\r
+        else if (depthcue && bymolecule)\r
+        {\r
+          if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))\r
+          {\r
+            g.setColor(Color.green.darker().darker());\r
+            drawLine(g, xstart, ystart, xend, yend);\r
+          }\r
+          else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))\r
+          {\r
+            g.setColor(Color.green.darker());\r
+            drawLine(g, xstart, ystart, xend, yend);\r
+          }\r
+          else\r
+          {\r
+            g.setColor(Color.green);\r
+            drawLine(g, xstart, ystart, xend, yend);\r
+          }\r
+        }\r
+        else if (!depthcue && !bymolecule)\r
+        {\r
+          g.setColor(tmpBond.startCol);\r
+          drawLine(g, xstart, ystart, xmid, ymid);\r
+          g.setColor(tmpBond.endCol);\r
+          drawLine(g, xmid, ymid, xend, yend);\r
+        }\r
+        else\r
+        {\r
+          drawLine(g, xstart, ystart, xend, yend);\r
+        }\r
 \r
+        if (highlightBond1 != null && highlightBond1 == tmpBond)\r
+        {\r
+          g.setColor(tmpBond.endCol.brighter().brighter().brighter().brighter());\r
+          drawLine(g, xmid, ymid, xend, yend);\r
         }\r
 \r
+        if (highlightBond2 != null && highlightBond2 == tmpBond)\r
+        {\r
+          g.setColor(tmpBond.startCol.brighter().brighter().brighter().brighter());\r
+          drawLine(g, xstart, ystart, xmid, ymid);\r
+        }\r
+\r
+      }\r
+\r
 \r
     }\r
 \r
@@ -666,7 +701,7 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe
                 if (highlightRes == null)\r
                   highlightRes = new Vector();\r
 \r
-                if (highlightRes.contains(fatom.alignmentMapping+"" + ""))\r
+                if (highlightRes.contains(fatom.alignmentMapping+""))\r
                   highlightRes.remove(fatom.alignmentMapping + "");\r
                 else\r
                   highlightRes.add(fatom.alignmentMapping + "");\r
@@ -718,35 +753,24 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe
 \r
     void highlightSeqcanvas(int pos)\r
     {\r
-      int index = seqcanvas.getViewport().getAlignment().findIndex(sequence);\r
-\r
-      int size = pos==-1?0:3;\r
-\r
-      if(highlightRes!=null)\r
-        size += highlightRes.size()*3;\r
-\r
-      int [] array = new int[size];\r
-      int i=0;\r
+      SearchResults searchResults = new SearchResults();\r
       if(highlightRes!=null)\r
       {\r
-        for (i = 0; i < highlightRes.size(); i++)\r
+        for (int i = 0; i < highlightRes.size(); i++)\r
         {\r
           int a = Integer.parseInt(highlightRes.elementAt(\r
               i).toString())+1;\r
-          array[i * 3] = index;\r
-          array[ (i * 3) + 1] = a;\r
-          array[ (i * 3) + 2] = a;\r
+\r
+          searchResults.addResult(sequence, a, a);\r
         }\r
       }\r
 \r
       if(pos!=-1)\r
       {\r
-        array[i * 3] = index;\r
-        array[i * 3 + 1] = pos+1;\r
-        array[i * 3 + 2] = pos+1;\r
+        searchResults.addResult(sequence, pos+1, pos+1);\r
       }\r
 \r
-      seqcanvas.highlightSearchResults(array);\r
+      seqcanvas.highlightSearchResults(searchResults);\r
     }\r
 \r
 \r