+1 error in group edit all sequences
[jalview.git] / src / jalview / gui / SequenceRenderer.java
index 57cd0fc..ec93abf 100755 (executable)
@@ -39,6 +39,8 @@ public class SequenceRenderer
     SequenceGroup[] allGroups = null;\r
     Color resBoxColour;\r
     Graphics graphics;\r
+    boolean monospacedFont;\r
+    boolean forOverview = false;\r
 \r
     /**\r
      * Creates a new SequenceRenderer object.\r
@@ -55,9 +57,12 @@ public class SequenceRenderer
      *\r
      * @param b DOCUMENT ME!\r
      */\r
-    public void renderGaps(boolean b)\r
+    public void prepare(Graphics g, boolean renderGaps)\r
     {\r
-        renderGaps = b;\r
+        graphics = g;\r
+        fm = g.getFontMetrics();\r
+        monospacedFont = fm.getStringBounds("M",g).getWidth()==fm.getStringBounds("|",g).getWidth();\r
+        this.renderGaps = renderGaps;\r
     }\r
 \r
 \r
@@ -94,9 +99,13 @@ public class SequenceRenderer
         {\r
             resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i);\r
         }\r
+        else if(forOverview && !jalview.util.Comparison.isGap(seq.getCharAt(i)))\r
+        {\r
+            resBoxColour = Color.lightGray;\r
+        }\r
         else\r
         {\r
-            resBoxColour = Color.white;\r
+          resBoxColour = Color.white;\r
         }\r
     }\r
 \r
@@ -113,17 +122,14 @@ public class SequenceRenderer
      * @param width DOCUMENT ME!\r
      * @param height DOCUMENT ME!\r
      */\r
-    public void drawSequence(Graphics g, SequenceI seq, SequenceGroup[] sg,\r
-        int start, int end, int x1, int y1, int width, int height)\r
+    public void drawSequence(SequenceI seq, SequenceGroup[] sg,\r
+        int start, int end, int y1)\r
     {\r
         allGroups = sg;\r
 \r
-        graphics = g;\r
-\r
-        drawBoxes(seq, start, end, x1, y1, (int) width, height);\r
+        drawBoxes(seq, start, end, y1);\r
 \r
-        fm = g.getFontMetrics();\r
-        drawText(seq, start, end, x1, y1, (int) width, height);\r
+        drawText(seq, start, end, y1);\r
     }\r
 \r
     /**\r
@@ -137,14 +143,13 @@ public class SequenceRenderer
      * @param width DOCUMENT ME!\r
      * @param height DOCUMENT ME!\r
      */\r
-    public synchronized void drawBoxes(SequenceI seq, int start, int end, int x1, int y1,\r
-        int width, int height)\r
+    public synchronized void drawBoxes(SequenceI seq, int start, int end, int y1)\r
     {\r
       int i = start;\r
       int length = seq.getLength();\r
 \r
       int curStart = -1;\r
-      int curWidth = width;\r
+      int curWidth = av.charWidth;\r
 \r
       Color tempColour = null;\r
 \r
@@ -172,26 +177,26 @@ public class SequenceRenderer
           {\r
               if (tempColour != null)\r
               {\r
-                  graphics.fillRect(x1 + (width * (curStart - start)), y1,\r
-                      curWidth, height);\r
+                  graphics.fillRect( av.charWidth * (curStart - start), y1,\r
+                      curWidth, av.charHeight);\r
               }\r
 \r
               graphics.setColor(resBoxColour);\r
 \r
               curStart = i;\r
-              curWidth = width;\r
+              curWidth = av.charWidth;\r
               tempColour = resBoxColour;\r
           }\r
           else\r
           {\r
-              curWidth += width;\r
+              curWidth += av.charWidth;\r
           }\r
 \r
           i++;\r
       }\r
 \r
-      graphics.fillRect(x1 + (width * (curStart - start)), y1, curWidth,\r
-          height);\r
+      graphics.fillRect( av.charWidth * (curStart - start), y1, curWidth,\r
+          av.charHeight);\r
 \r
     }\r
 \r
@@ -206,70 +211,82 @@ public class SequenceRenderer
      * @param width DOCUMENT ME!\r
      * @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
+    public void drawText(SequenceI seq, int start, int end, int y1)\r
     {\r
-        int pady = height / 5;\r
-        int charOffset = 0;\r
-        char s;\r
-\r
-\r
-        // Need to find the sequence position here.\r
-        String sequence = seq.getSequence();\r
+      y1 += av.charHeight - av.charHeight / 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
+          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
+          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.globalColourScheme, 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
+            charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
+\r
+          //  System.out.print(s);\r
             graphics.drawString(String.valueOf(s),\r
-                charOffset + x1 + (int)(width * (i - start)), (y1 + height) - pady);\r
+                                charOffset + av.charWidth * (i - start),\r
+                                y1);\r
 \r
+          }\r
+        //  System.out.println("\n");\r
         }\r
     }\r
 \r
@@ -312,13 +329,12 @@ public class SequenceRenderer
      * @param width DOCUMENT ME!\r
      * @param height DOCUMENT ME!\r
      */\r
-    public void drawHighlightedText(SequenceI seq, int start, int end, int x1,\r
-        int y1, int width, int height)\r
+    public void drawHighlightedText(SequenceI seq, int start, int end, int x1, int y1)\r
     {\r
-        int pady = height / 5;\r
+        int pady = av.charHeight / 5;\r
         int charOffset = 0;\r
         graphics.setColor(Color.BLACK);\r
-        graphics.fillRect(x1, y1, width * (end - start + 1), height);\r
+        graphics.fillRect(x1, y1, av.charWidth * (end - start + 1), av.charHeight);\r
         graphics.setColor(Color.white);\r
 \r
         char s = '~';\r
@@ -331,9 +347,30 @@ public class SequenceRenderer
                 s = seq.getSequence().charAt(i);\r
             }\r
 \r
-            charOffset = (width - fm.charWidth(s)) / 2;\r
+            charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
             graphics.drawString(String.valueOf(s),\r
-                charOffset + x1 + (width * (i - start)), (y1 + height) - pady);\r
+                charOffset + x1 + (av.charWidth * (i - start)),\r
+                (y1 + av.charHeight) - pady);\r
         }\r
     }\r
+\r
+    public void drawCursor(SequenceI seq, int res, int x1, int y1)\r
+    {\r
+      int pady = av.charHeight / 5;\r
+      int charOffset = 0;\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
+\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