Faster paint
authoramwaterhouse <Andrew Waterhouse>
Mon, 30 Jan 2006 14:57:43 +0000 (14:57 +0000)
committeramwaterhouse <Andrew Waterhouse>
Mon, 30 Jan 2006 14:57:43 +0000 (14:57 +0000)
src/jalview/gui/SeqCanvas.java
src/jalview/gui/SequenceRenderer.java

index 0fe3b86..7dbb8d3 100755 (executable)
@@ -24,7 +24,6 @@ import java.awt.*;
 import java.awt.image.*;\r
 \r
 import javax.swing.*;\r
-import jalview.schemes.*;\r
 \r
 \r
 /**\r
@@ -205,11 +204,13 @@ public class SeqCanvas extends JComponent
      */\r
     public void fastPaint(int horizontal, int vertical)\r
     {\r
-        if (gg == null)\r
+        if (fastPaint  || gg == null)\r
         {\r
             return;\r
         }\r
 \r
+        fastPaint = true;\r
+\r
         gg.copyArea(horizontal * av.charWidth,\r
                     vertical * av.charHeight,\r
                     imgWidth,\r
@@ -261,7 +262,6 @@ public class SeqCanvas extends JComponent
         drawPanel(gg, sr, er, ss, es, sr, ss, 0);\r
         gg.translate(-transX, -transY);\r
 \r
-        fastPaint = true;\r
         repaint();\r
     }\r
 \r
@@ -308,8 +308,10 @@ public class SeqCanvas extends JComponent
         img = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_RGB);\r
         gg = (Graphics2D) img.getGraphics();\r
         gg.setFont(av.getFont());\r
-        gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
-          RenderingHints.VALUE_ANTIALIAS_ON);\r
+\r
+        if (av.antiAlias)\r
+          gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
+                              RenderingHints.VALUE_ANTIALIAS_ON);\r
 \r
         gg.setColor(Color.white);\r
         gg.fillRect(0, 0, imgWidth, imgHeight);\r
@@ -539,17 +541,17 @@ public class SeqCanvas extends JComponent
     }\r
 \r
 \r
-    synchronized public void drawPanel(Graphics g1, int x1, int x2, int y1,\r
-        int y2, int startx, int starty, int offset)\r
+    void drawPanel(Graphics g1, int x1, int x2, int y1, int y2, int startx, int starty, int offset)\r
     {\r
       Graphics2D g = (Graphics2D) g1;\r
       g.setFont(av.getFont());\r
 \r
-      SequenceI nextSeq, dna = null;\r
-      int aaHeight = av.charHeight, dnaHeight = av.charHeight;\r
-      Font dnafont = null, aafont = av.getFont();\r
+      SequenceI nextSeq;\r
+     // int aaHeight = av.charHeight;\r
+     // Font  aafont = av.getFont();\r
 \r
- /*     if (av.getShowTranslation())\r
+ /*   dnafont = null, , dna = null, dnaHeight = av.charHeight\r
+   if (av.getShowTranslation())\r
       {\r
         aaHeight = (int) (av.getCharHeight() * aaRatio);\r
         dnaHeight = (int) (av.getCharHeight() * (1 - aaRatio));\r
@@ -567,14 +569,13 @@ public class SeqCanvas extends JComponent
       }\r
 */\r
 \r
-      ColourSchemeI cs = av.getGlobalColourScheme();\r
 \r
         /// First draw the sequences\r
         /////////////////////////////\r
         for (int i = y1; i < y2; i++)\r
         {\r
             nextSeq = av.alignment.getSequenceAt(i);\r
-            g.setFont(aafont);\r
+\r
          /*   if(av.getShowTranslation())\r
             {\r
               dna = nextSeq;\r
@@ -598,7 +599,7 @@ public class SeqCanvas extends JComponent
             sr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq),\r
                             x1, x2, (x1 - startx) * av.charWidth,\r
                             offset + ( (i - starty) * av.charHeight), av.charWidth,\r
-                            aaHeight);\r
+                            av.charHeight);\r
 \r
          /*   if(av.getShowTranslation())\r
             {\r
index 57cd0fc..0c41152 100755 (executable)
@@ -39,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
@@ -123,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
@@ -207,69 +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
-\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.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
             graphics.drawString(String.valueOf(s),\r
-                charOffset + x1 + (int)(width * (i - start)), (y1 + height) - pady);\r
+                                charOffset + x1 + width * (i - start),\r
+                                y1);\r
 \r
+          }\r
         }\r
     }\r
 \r