New function to highlight text search results
[jalview.git] / src / jalview / gui / SequenceRenderer.java
index 7df9149..192e252 100755 (executable)
@@ -9,30 +9,34 @@ import java.util.*;
 public class SequenceRenderer implements RendererI\r
 {\r
   FontMetrics fm;\r
-  AlignViewport av;\r
+  boolean renderGaps = true;\r
 \r
-  public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i) {\r
-    Color c = Color.WHITE;\r
+  public void renderGaps(boolean b)\r
+  {\r
+    renderGaps = b;\r
+  }\r
 \r
+  public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i)\r
+  {\r
+   Color c = Color.white;\r
     try{\r
-      if (cs != null)\r
-        c = cs.findColour(seq, seq.getSequence(i, i + 1), i, null);\r
-    }catch(Exception ex)\r
-    {    }\r
+       c = cs.findColour(seq, seq.getSequence(i, i + 1), i, null);\r
+    }catch(Exception ex){}\r
 \r
     return c;\r
   }\r
 \r
-  public void drawSequence(Graphics g,ColourSchemeI cs,SequenceI seq,int start, int end, int x1, int y1, double width, int height,boolean showScores, boolean displayBoxes, boolean displayText,Vector freq, int seqnum,AlignViewport av) {\r
 \r
-    this.av = av;\r
+  public void drawSequence(Graphics g,ColourSchemeI cs,SequenceI seq,int start, int end, int x1, int y1, double width, int height,boolean showScores, boolean displayBoxes, boolean displayText, boolean colourText,Vector freq, int seqnum) {\r
+\r
 \r
-    if (displayBoxes == true) {\r
+    if (displayBoxes)\r
         drawBoxes(g,cs,seq,start,end,x1,y1,(int)width, height,freq);\r
-    }\r
-    if (displayText == true) {\r
+\r
+    if (displayText)\r
+    {\r
         fm = g.getFontMetrics();\r
-        drawText(g,cs,seq,start,end,x1,y1,(int)width,height);\r
+        drawText(g,cs,colourText,seq,start,end,x1,y1,(int)width,height);\r
     }\r
   }\r
 \r
@@ -96,27 +100,27 @@ public class SequenceRenderer implements RendererI
     g.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
   }\r
 \r
-  public void drawText(Graphics g, ColourSchemeI cs, SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
+  public void drawText(Graphics g, ColourSchemeI cs, boolean colText, SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
   {\r
     int pady = height/5;\r
     int charOffset=0;\r
     g.setColor(Color.black);\r
-    boolean colourText = av.getColourText();\r
-    Color c;\r
+\r
     char s;\r
     // Need to find the sequence position here.\r
     for (int i = start; i <= end; i++)\r
     {\r
-        if (i < end && i < seq.getLength())\r
-          s = seq.getSequence().charAt(i);\r
-        else if(i<seq.getLength())\r
+        if(i<seq.getLength())\r
           s = seq.getSequence().charAt(i);\r
         else\r
           s = ' ';\r
 \r
-        if (colourText)\r
+        if(!renderGaps && (s=='-' || s=='.' || s==' '))\r
+          continue;\r
+\r
+        if (colText)\r
         {\r
-            c = getResidueBoxColour(cs, seq, i);\r
+            Color c = getResidueBoxColour(cs, seq, i);\r
             g.setColor(c.darker());\r
         }\r
 \r
@@ -127,4 +131,25 @@ public class SequenceRenderer implements RendererI
     }\r
   }\r
 \r
+  public void drawHighlightedText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
+  {\r
+    int pady = height/5;\r
+    int charOffset=0;\r
+    g.setColor(Color.BLACK);\r
+    g.fillRect(x1,y1,width*(end-start+1),height);\r
+    g.setColor(Color.white);\r
+\r
+    char s='~';\r
+    // Need to find the sequence position here.\r
+    for (int i = start; i <= end; i++)\r
+    {\r
+       if(i<seq.getLength())\r
+          s = seq.getSequence().charAt(i);\r
+\r
+      charOffset =  (width - fm.charWidth(s))/2;\r
+      g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);\r
+    }\r
+  }\r
+\r
+\r
 }\r