no need for right mouse click
[jalview.git] / src / jalview / gui / IdCanvas.java
index cb7fddf..882ed7a 100755 (executable)
@@ -17,6 +17,9 @@ public class IdCanvas extends JPanel
   BufferedImage image;\r
   Graphics2D gg;\r
   int imgHeight=0;\r
+  boolean fastPaint = false;\r
+\r
+  java.util.Vector searchResults;\r
 \r
   public IdCanvas(AlignViewport av)\r
   {\r
@@ -28,8 +31,13 @@ public class IdCanvas extends JPanel
   public void drawIdString(Graphics2D gg,SequenceI s,int i, int starty, int ypos) {\r
       int charHeight = av.getCharHeight();\r
 \r
-\r
-      if (av.getSelectionGroup()!=null && av.getSelectionGroup().sequences.contains(s)) {\r
+      if(searchResults!=null && searchResults.contains(s))\r
+      {\r
+        gg.setColor(Color.black);\r
+        gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);\r
+        gg.setColor(Color.white);\r
+      }\r
+      else if (av.getSelectionGroup()!=null && av.getSelectionGroup().sequences.contains(s)) {\r
          gg.setColor(Color.lightGray);\r
          gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);\r
          gg.setColor(Color.white);\r
@@ -49,25 +57,29 @@ public class IdCanvas extends JPanel
 \r
   public void fastPaint(int vertical)\r
   {\r
-    if(image==null)\r
-    {\r
-      repaint();\r
-      return;\r
-    }\r
+    if(gg==null)\r
+    {  repaint(); return;}\r
 \r
     gg.copyArea( 0,0, getWidth(), imgHeight, 0, -vertical*av.charHeight );\r
 \r
     int ss=av.startSeq, es=av.endSeq, transY = 0;\r
-     if(vertical>0)    // scroll down\r
+    if (vertical > 0) // scroll down\r
      {\r
-       transY = imgHeight - vertical*av.charHeight;\r
        ss = es - vertical;\r
+       if(ss<av.startSeq) // ie scrolling too fast, more than a page at a time\r
+         ss = av.startSeq;\r
+       else\r
+         transY = imgHeight - vertical * av.charHeight;\r
      }\r
-     else if(vertical<0)\r
+     else if (vertical < 0)\r
      {\r
-       es = ss-vertical;\r
+       es = ss - vertical;\r
+       if(es > av.endSeq)\r
+         es = av.endSeq;\r
      }\r
 \r
+\r
+\r
         gg.translate(0, transY);\r
 \r
         drawIds(ss, es);\r
@@ -75,11 +87,22 @@ public class IdCanvas extends JPanel
         gg.translate( 0, -transY );\r
 \r
 \r
-    getGraphics().drawImage(image, 0, 0, this);\r
+      fastPaint = true;\r
+      repaint();\r
   }\r
 \r
   public void paintComponent(Graphics g)\r
   {\r
+    g.setColor(Color.white);\r
+    g.fillRect(0, 0, getWidth(), getHeight());\r
+\r
+    if (fastPaint)\r
+    {\r
+      fastPaint = false;\r
+      g.drawImage(image, 0, 0, this);\r
+      return;\r
+    }\r
+\r
     imgHeight = getHeight();\r
     imgHeight -= imgHeight % av.charHeight;\r
     image = new BufferedImage(getWidth(), imgHeight, BufferedImage.TYPE_INT_RGB);\r
@@ -93,10 +116,6 @@ public class IdCanvas extends JPanel
                            av.getFont().getSize());\r
     gg.setFont(italic);\r
 \r
-\r
-    g.setColor(Color.white);\r
-    g.fillRect(0,0,getWidth(),getHeight());\r
-\r
     drawIds( av.getStartSeq(), av.endSeq);\r
 \r
     g.drawImage(image, 0, 0, this);\r
@@ -104,18 +123,18 @@ public class IdCanvas extends JPanel
 \r
   void drawIds(int starty, int endy)\r
   {\r
-\r
     Color currentColor     = Color.white;\r
     Color currentTextColor = Color.black;\r
 \r
     if (av.getWrapAlignment())\r
     {\r
+\r
+          int rowSize =  av.getEndRes() - av.getStartRes();\r
           // Draw the rest of the panels\r
-          int chunkHeight =  (av.alignment.getHeight() + 2)*av.charHeight;\r
-          int row = av.getStartRes() / av.chunkWidth ;\r
-          for(int ypos=2*av.charHeight;\r
-              ypos <= getHeight() && row*av.chunkWidth<av.alignment.getWidth();\r
-              ypos += chunkHeight, row++ )\r
+\r
+          for(int ypos=2*av.charHeight, row=av.startRes;\r
+              ypos <= getHeight() && row<av.alignment.getWidth();\r
+              ypos += av.chunkHeight, row+=rowSize )\r
           {\r
             for (int i = starty; i < av.alignment.getHeight(); i++)\r
             {\r
@@ -133,10 +152,15 @@ public class IdCanvas extends JPanel
       {\r
         // Selected sequence colours\r
 \r
-        if (av.getSelectionGroup()!= null\r
+        if(searchResults!=null && searchResults.contains(av.alignment.getSequenceAt(i)))\r
+        {\r
+          gg.setColor(Color.black);\r
+          currentColor = Color.black;\r
+          currentTextColor = Color.white;\r
+      }\r
+      else if (av.getSelectionGroup()!= null\r
             && av.getSelectionGroup().sequences.contains(av.alignment.getSequenceAt(i)))\r
         {\r
-       //   if(av.alignment.findGroup(al.getSequenceAt(i)).getEndRes()==\r
           currentColor = Color.lightGray;\r
           currentTextColor = Color.black;\r
         }\r
@@ -168,4 +192,10 @@ public class IdCanvas extends JPanel
     }\r
 \r
   }\r
+\r
+  public void setHighlighted(java.util.Vector found)\r
+  {\r
+    searchResults = found;\r
+    repaint();\r
+  }\r
 }\r