Colour text
[jalview.git] / src / jalview / gui / SequenceRenderer.java
index ab6c1ab..8d7755c 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
@@ -61,7 +61,14 @@ public class SequenceRenderer
     {\r
         graphics = g;\r
         fm = g.getFontMetrics();\r
-        monospacedFont = fm.getStringBounds("M",g).getWidth()==fm.getStringBounds("|",g).getWidth();\r
+\r
+        // If EPS graphics, stringWidth will be a double, not an int\r
+        double dwidth = fm.getStringBounds("M", g).getWidth();\r
+\r
+        monospacedFont =\r
+               (dwidth == fm.getStringBounds("|",g).getWidth()\r
+               && (float)av.charWidth == dwidth);\r
+\r
         this.renderGaps = renderGaps;\r
     }\r
 \r
@@ -129,7 +136,8 @@ public class SequenceRenderer
 \r
         drawBoxes(seq, start, end, y1);\r
 \r
-        drawText(seq, start, end, y1);\r
+        if (av.validCharWidth)\r
+          drawText(seq, start, end, y1);\r
     }\r
 \r
     /**\r
@@ -219,18 +227,30 @@ public class SequenceRenderer
 \r
         if(end+1>=seq.getLength())\r
           end = seq.getLength()-1;\r
-        graphics.setColor(Color.black);\r
+        graphics.setColor(av.textColour);\r
 \r
 \r
-        if(monospacedFont && av.showText && allGroups.length==0 && !av.getColourText())\r
+        if(monospacedFont\r
+           && av.showText\r
+           && allGroups.length==0\r
+           && !av.getColourText()\r
+           && av.thresholdTextColour==0)\r
         {\r
+          if(av.renderGaps)\r
           graphics.drawString(seq.getSequence(start, end + 1), 0, y1);\r
+         else\r
+         {\r
+           char gap = av.getGapCharacter();\r
+           graphics.drawString( seq.getSequence(start, end+1).replace(gap, ' '), 0, y1);\r
+         }\r
         }\r
         else\r
         {\r
+          boolean getboxColour = false;\r
           for (int i = start; i <= end; i++)\r
           {\r
-            graphics.setColor(Color.black);\r
+            graphics.setColor(av.textColour);\r
+            getboxColour = false;\r
             s = seq.getCharAt(i);\r
             if (!renderGaps && jalview.util.Comparison.isGap(s))\r
             {\r
@@ -244,11 +264,26 @@ public class SequenceRenderer
                 continue;\r
               }\r
 \r
-              if (currentSequenceGroup.getColourText())\r
+              if (currentSequenceGroup.thresholdTextColour > 0\r
+                  || currentSequenceGroup.getColourText())\r
               {\r
+                getboxColour = true;\r
                 getBoxColour(currentSequenceGroup.cs, seq, i);\r
-                graphics.setColor(resBoxColour.darker());\r
+\r
+                if (currentSequenceGroup.getColourText())\r
+                  graphics.setColor(resBoxColour.darker());\r
+\r
+                if (currentSequenceGroup.thresholdTextColour > 0)\r
+                {\r
+                  if (resBoxColour.getRed() +\r
+                      resBoxColour.getBlue() +\r
+                      resBoxColour.getGreen() < currentSequenceGroup.thresholdTextColour)\r
+                    graphics.setColor(currentSequenceGroup.textColour2);\r
+                }\r
               }\r
+              else\r
+                  graphics.setColor(currentSequenceGroup.textColour);\r
+\r
             }\r
             else\r
             {\r
@@ -259,6 +294,7 @@ public class SequenceRenderer
 \r
               if (av.getColourText())\r
               {\r
+                getboxColour = true;\r
                 getBoxColour(av.globalColourScheme, seq, i);\r
 \r
                 if (av.getShowBoxes())\r
@@ -270,17 +306,28 @@ public class SequenceRenderer
                   graphics.setColor(resBoxColour);\r
                 }\r
               }\r
+\r
+              if (av.thresholdTextColour > 0)\r
+              {\r
+                if (!getboxColour)\r
+                  getBoxColour(av.globalColourScheme, seq, i);\r
+\r
+                if (resBoxColour.getRed() +\r
+                    resBoxColour.getBlue() +\r
+                    resBoxColour.getGreen() < av.thresholdTextColour)\r
+                  graphics.setColor(av.textColour2);\r
+              }\r
+\r
             }\r
 \r
-            charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
 \r
-          //  System.out.print(s);\r
-            graphics.drawString(String.valueOf(s),\r
-                                charOffset + av.charWidth * (i - start),\r
-                                y1);\r
+\r
+          charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
+          graphics.drawString(String.valueOf(s),\r
+                              charOffset + av.charWidth * (i - start),\r
+                              y1);\r
 \r
           }\r
-        //  System.out.println("\n");\r
         }\r
     }\r
 \r
@@ -334,17 +381,20 @@ public class SequenceRenderer
         char s = '~';\r
 \r
         // Need to find the sequence position here.\r
-        for (int i = start; i <= end; i++)\r
+        if(av.validCharWidth)\r
         {\r
+          for (int i = start; i <= end; i++)\r
+          {\r
             if (i < seq.getLength())\r
             {\r
-                s = seq.getSequence().charAt(i);\r
+              s = seq.getSequence().charAt(i);\r
             }\r
 \r
             charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
             graphics.drawString(String.valueOf(s),\r
-                charOffset + x1 + (av.charWidth * (i - start)),\r
-                (y1 + av.charHeight) - pady);\r
+                                charOffset + x1 + (av.charWidth * (i - start)),\r
+                                (y1 + av.charHeight) - pady);\r
+          }\r
         }\r
     }\r
 \r
@@ -352,19 +402,20 @@ public class SequenceRenderer
     {\r
       int pady = av.charHeight / 5;\r
       int charOffset = 0;\r
-      graphics.setColor(Color.lightGray);\r
+      graphics.setColor(Color.black);\r
       graphics.fillRect(x1, y1, av.charWidth, av.charHeight);\r
-      graphics.setColor(Color.white);\r
-\r
-      graphics.setColor(Color.white);\r
 \r
-      char s = seq.getCharAt(res);\r
+      if(av.validCharWidth)\r
+      {\r
+        graphics.setColor(Color.white);\r
 \r
-      charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
-      graphics.drawString(String.valueOf(s),\r
-                charOffset + x1,\r
-                (y1 + av.charHeight) - pady);\r
+        char s = seq.getCharAt(res);\r
 \r
+        charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
+        graphics.drawString(String.valueOf(s),\r
+                            charOffset + x1,\r
+                            (y1 + av.charHeight) - pady);\r
+      }\r
 \r
     }\r
 }\r