Check endRes
[jalview.git] / src / jalview / gui / SequenceRenderer.java
index 81daef7..0c41152 100755 (executable)
@@ -24,7 +24,6 @@ import jalview.schemes.*;
 \r
 import java.awt.*;\r
 \r
-\r
 /**\r
  * DOCUMENT ME!\r
  *\r
@@ -40,6 +39,7 @@ public class SequenceRenderer
     SequenceGroup[] allGroups = null;\r
     Color resBoxColour;\r
     Graphics graphics;\r
+    boolean monospacedFont;\r
 \r
     /**\r
      * Creates a new SequenceRenderer object.\r
@@ -61,22 +61,27 @@ public class SequenceRenderer
         renderGaps = b;\r
     }\r
 \r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param cs DOCUMENT ME!\r
-     * @param seq DOCUMENT ME!\r
-     * @param i DOCUMENT ME!\r
-     *\r
-     * @return DOCUMENT ME!\r
-     */\r
-    public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i)\r
+\r
+    public Color getResidueBoxColour(SequenceI seq, int i)\r
     {\r
-        getBoxColour(cs, seq, i);\r
+      allGroups = av.alignment.findAllGroups(seq);\r
 \r
-        return resBoxColour;\r
+      if (inCurrentSequenceGroup(i))\r
+      {\r
+        if (currentSequenceGroup.getDisplayBoxes())\r
+        {\r
+          getBoxColour(currentSequenceGroup.cs, seq, i);\r
+        }\r
+      }\r
+      else if (av.getShowBoxes())\r
+      {\r
+          getBoxColour(av.globalColourScheme, seq, i);\r
+      }\r
+\r
+      return resBoxColour;\r
     }\r
 \r
+\r
     /**\r
      * DOCUMENT ME!\r
      *\r
@@ -119,6 +124,9 @@ public class SequenceRenderer
         drawBoxes(seq, start, end, x1, y1, (int) width, height);\r
 \r
         fm = g.getFontMetrics();\r
+\r
+        monospacedFont = fm.getStringBounds("M",g).getWidth()==fm.getStringBounds("|",g).getWidth();\r
+\r
         drawText(seq, start, end, x1, y1, (int) width, height);\r
     }\r
 \r
@@ -133,61 +141,62 @@ public class SequenceRenderer
      * @param width DOCUMENT ME!\r
      * @param height DOCUMENT ME!\r
      */\r
-    public void drawBoxes(SequenceI seq, int start, int end, int x1, int y1,\r
+    public synchronized void drawBoxes(SequenceI seq, int start, int end, int x1, int y1,\r
         int width, int height)\r
     {\r
-        int i = start;\r
-        int length = seq.getLength();\r
+      int i = start;\r
+      int length = seq.getLength();\r
 \r
-        int curStart = -1;\r
-        int curWidth = width;\r
+      int curStart = -1;\r
+      int curWidth = width;\r
 \r
-        Color tempColour = null;\r
+      Color tempColour = null;\r
 \r
-        while (i <= end)\r
-        {\r
-          resBoxColour = Color.white;\r
+      while (i <= end)\r
+      {\r
+        resBoxColour = Color.white;\r
 \r
-          if (i < length)\r
+        if (i < length)\r
+        {\r
+          if (inCurrentSequenceGroup(i))\r
           {\r
-            if (inCurrentSequenceGroup(i))\r
+            if (currentSequenceGroup.getDisplayBoxes())\r
             {\r
-              if (currentSequenceGroup.getDisplayBoxes())\r
-              {\r
-                getBoxColour(currentSequenceGroup.cs, seq, i);\r
-              }\r
-            }\r
-            else if (av.getShowBoxes())\r
-            {\r
-              getBoxColour(av.getGlobalColourScheme(), seq, i);\r
+              getBoxColour(currentSequenceGroup.cs, seq, i);\r
             }\r
-\r
+          }\r
+          else if (av.getShowBoxes())\r
+          {\r
+            getBoxColour(av.globalColourScheme, seq, i);\r
           }\r
 \r
-            if (resBoxColour != tempColour)\r
-            {\r
-                if (tempColour != null)\r
-                {\r
-                    graphics.fillRect(x1 + (width * (curStart - start)), y1,\r
-                        curWidth, height);\r
-                }\r
+        }\r
 \r
-                graphics.setColor(resBoxColour);\r
+          if (resBoxColour != tempColour)\r
+          {\r
+              if (tempColour != null)\r
+              {\r
+                  graphics.fillRect(x1 + (width * (curStart - start)), y1,\r
+                      curWidth, height);\r
+              }\r
 \r
-                curStart = i;\r
-                curWidth = width;\r
-                tempColour = resBoxColour;\r
-            }\r
-            else\r
-            {\r
-                curWidth += width;\r
-            }\r
+              graphics.setColor(resBoxColour);\r
 \r
-            i++;\r
-        }\r
+              curStart = i;\r
+              curWidth = width;\r
+              tempColour = resBoxColour;\r
+          }\r
+          else\r
+          {\r
+              curWidth += width;\r
+          }\r
+\r
+          i++;\r
+      }\r
+\r
+      graphics.fillRect(x1 + (width * (curStart - start)), y1, curWidth,\r
+          height);\r
 \r
-        graphics.fillRect(x1 + (width * (curStart - start)), y1, curWidth,\r
-            height);\r
     }\r
 \r
     /**\r
@@ -202,67 +211,73 @@ public class SequenceRenderer
      * @param height DOCUMENT ME!\r
      */\r
     public void drawText(SequenceI seq, int start, int end, int x1, int y1,\r
-        int width, int height)\r
+                         int width, int height)\r
     {\r
-        int pady = height / 5;\r
-        int charOffset = 0;\r
-        char s;\r
-\r
-        // Need to find the sequence position here.\r
-        String sequence = seq.getSequence();\r
+      y1 += height - height / 5; // height/5 replaces pady\r
+      int charOffset = 0;\r
+      char s;\r
 \r
         if(end+1>=seq.getLength())\r
           end = seq.getLength()-1;\r
+        graphics.setColor(Color.black);\r
 \r
-        for (int i = start; i <= end; i++)\r
+\r
+        if(monospacedFont && av.showText && allGroups.length==0 && !av.getColourText())\r
+        {\r
+          graphics.drawString(seq.getSequence(start, end + 1), x1, y1);\r
+        }\r
+        else\r
         {\r
+          for (int i = start; i <= end; i++)\r
+          {\r
             graphics.setColor(Color.black);\r
-\r
-            s = sequence.charAt(i);\r
-\r
+            s = seq.getCharAt(i);\r
             if (!renderGaps && jalview.util.Comparison.isGap(s))\r
             {\r
-                continue;\r
+              continue;\r
             }\r
 \r
             if (inCurrentSequenceGroup(i))\r
             {\r
-                if (!currentSequenceGroup.getDisplayText())\r
-                {\r
-                    continue;\r
-                }\r
+              if (!currentSequenceGroup.getDisplayText())\r
+              {\r
+                continue;\r
+              }\r
 \r
-                if (currentSequenceGroup.getColourText())\r
-                {\r
-                    getBoxColour(currentSequenceGroup.cs, seq, i);\r
-                    graphics.setColor(resBoxColour.darker());\r
-                }\r
+              if (currentSequenceGroup.getColourText())\r
+              {\r
+                getBoxColour(currentSequenceGroup.cs, seq, i);\r
+                graphics.setColor(resBoxColour.darker());\r
+              }\r
             }\r
             else\r
             {\r
-                if (!av.getShowText())\r
+              if (!av.getShowText())\r
+              {\r
+                continue;\r
+              }\r
+\r
+              if (av.getColourText())\r
+              {\r
+                getBoxColour(av.globalColourScheme, seq, i);\r
+\r
+                if (av.getShowBoxes())\r
                 {\r
-                    continue;\r
+                  graphics.setColor(resBoxColour.darker());\r
                 }\r
-\r
-                if (av.getColourText())\r
+                else\r
                 {\r
-                    getBoxColour(av.getGlobalColourScheme(), seq, i);\r
-\r
-                    if (av.getShowBoxes())\r
-                    {\r
-                        graphics.setColor(resBoxColour.darker());\r
-                    }\r
-                    else\r
-                    {\r
-                        graphics.setColor(resBoxColour);\r
-                    }\r
+                  graphics.setColor(resBoxColour);\r
                 }\r
+              }\r
             }\r
 \r
             charOffset = (width - fm.charWidth(s)) / 2;\r
             graphics.drawString(String.valueOf(s),\r
-                charOffset + x1 + (width * (i - start)), (y1 + height) - pady);\r
+                                charOffset + x1 + width * (i - start),\r
+                                y1);\r
+\r
+          }\r
         }\r
     }\r
 \r