wrap alignment box paints correctly
authoramwaterhouse <Andrew Waterhouse>
Mon, 18 Apr 2005 16:04:37 +0000 (16:04 +0000)
committeramwaterhouse <Andrew Waterhouse>
Mon, 18 Apr 2005 16:04:37 +0000 (16:04 +0000)
src/jalview/gui/SeqCanvas.java

index 9b59309..83e3a6d 100755 (executable)
@@ -1,6 +1,7 @@
 package jalview.gui;\r
 \r
 import java.awt.*;\r
+import java.awt.image.*;\r
 import javax.swing.*;\r
 import jalview.datamodel.*;\r
 import jalview.analysis.*;\r
@@ -9,7 +10,7 @@ import jalview.analysis.*;
 public class SeqCanvas extends JPanel\r
 {\r
      FeatureRenderer fr;\r
-    Image             img;\r
+    BufferedImage             img;\r
     Graphics2D          gg;\r
     int               imgWidth;\r
     int               imgHeight;\r
@@ -77,7 +78,7 @@ public class SeqCanvas extends JPanel
       }\r
       if(value!=-1)\r
       {\r
-        int x = fm.stringWidth("000") - fm.stringWidth(value+"");\r
+        int x = LABEL_WEST - fm.stringWidth(value+"");\r
         g.drawString(value + "", x,  ypos +  i*av.charHeight - av.charHeight/5);\r
       }\r
     }\r
@@ -191,7 +192,7 @@ public void fastPaint(int horizontal, int vertical)
       imgWidth -= imgWidth%av.charWidth;\r
       imgHeight-= imgHeight%av.charHeight;\r
 \r
-      img = createImage(imgWidth,imgHeight);\r
+      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,RenderingHints.VALUE_ANTIALIAS_ON);\r
@@ -215,16 +216,19 @@ public void fastPaint(int horizontal, int vertical)
 \r
   }\r
 \r
+  int LABEL_WEST, LABEL_EAST;\r
   public int getWrappedCanvasWidth(int cwidth)\r
   {\r
     FontMetrics fm = getFontMetrics(av.getFont());\r
 \r
-    int LABEL_EAST = 0;\r
+    LABEL_EAST = 0;\r
+    LABEL_WEST = 0;\r
+\r
     if(av.scaleRightWrapped)\r
       LABEL_EAST = fm.stringWidth( av.alignment.getWidth()+"000" );\r
-    int LABEL_WEST = 0;\r
+\r
     if(av.scaleLeftWrapped)\r
-      LABEL_WEST = fm.stringWidth( av.alignment.getWidth()+"0" );\r
+      LABEL_WEST = fm.stringWidth( av.alignment.getWidth()+"" );\r
 \r
     return  (cwidth - LABEL_EAST -LABEL_WEST)/av.charWidth;\r
   }\r
@@ -240,7 +244,8 @@ public void fastPaint(int horizontal, int vertical)
         LABEL_EAST = fm.stringWidth( al.getWidth()+"000" );\r
       int LABEL_WEST = 0;\r
       if(av.scaleLeftWrapped)\r
-        LABEL_WEST = fm.stringWidth( al.getWidth()+"0" );\r
+        LABEL_WEST = fm.stringWidth(al.getWidth()+"0");\r
+\r
 \r
       int cWidth  =   (canvasWidth - LABEL_EAST -LABEL_WEST)/av.charWidth;\r
       int cHeight =  (av.getAlignment().getHeight() + 2)*av.charHeight;\r
@@ -249,7 +254,7 @@ public void fastPaint(int horizontal, int vertical)
       int  ypos  = 2*av.charHeight;\r
 \r
 \r
-      while (ypos <= canvasHeight)\r
+      while (ypos <= canvasHeight && startRes<av.alignment.getWidth() )\r
       {\r
         g.setColor(Color.black);\r
 \r
@@ -263,12 +268,13 @@ public void fastPaint(int horizontal, int vertical)
           g.translate( - (canvasWidth - LABEL_EAST+av.charWidth), 0);\r
         }\r
 \r
-\r
         g.translate(LABEL_WEST,0);\r
         if(av.scaleAboveWrapped)\r
           drawNorthScale(g, startRes, endx, ypos);\r
 \r
+        g.setClip(0, 0, cWidth*av.charWidth, getHeight());\r
         drawPanel(g, startRes, endx, 0, al.getHeight(), startRes, 0, ypos);\r
+        g.setClip(null);\r
         g.translate(-LABEL_WEST,0);\r
 \r
         ypos += cHeight;\r
@@ -288,32 +294,6 @@ public void fastPaint(int horizontal, int vertical)
     g.setFont(av.getFont());\r
     RendererI sr = av.getRenderer();\r
 \r
-    /*Vector    pid    = av.getConsensus(false);\r
-    Vector tmpseq = new Vector();\r
-    for (int i = 0; i < av.getAlignment().getHeight(); i++)\r
-       if (!av.getSelection().contains(av.getAlignment().getSequenceAt(i)))\r
-           tmpseq.addElement(av.getAlignment().getSequenceAt(i));\r
-\r
-    if (sr instanceof SequenceRenderer)\r
-       pid    = AAFrequency.calculate(tmpseq,x1,x2);\r
-\r
-    else if (sr instanceof GraphRenderer)\r
-       pid = AAFrequency.calculatePID(av.getAlignment().getSequenceAt(0),\r
-                                      av.getAlignment().getSequences(),\r
-                                      av.getPIDWindow(),x1,x2);\r
-\r
-*/\r
-\r
-   /* if (y2 > starty && y1 < av.getEndSeq())\r
-    {\r
-       fillBackground(g,\r
-                   Color.red,\r
-                   (x1-startx)*charWidth,\r
-                   offset + AlignmentUtil.getPixelHeight(starty,y1,av.getCharHeight()),\r
-                   (x2-x1+1)*charWidth,\r
-                   offset + AlignmentUtil.getPixelHeight(y1,y2,av.getCharHeight()));\r
-    }*/\r
-\r
     SequenceI nextSeq;\r
 \r
     /// First draw the sequences\r
@@ -365,15 +345,6 @@ public void fastPaint(int horizontal, int vertical)
           sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight);\r
           ex = (group.getEndRes() + 1 - group.getStartRes()) * av.charWidth -1;\r
 \r
-          if (av.getWrapAlignment())\r
-          {\r
-            if (sx < 0)\r
-              sx = 0;\r
-\r
-            if (ex > getWidth())\r
-                ex = getWrappedCanvasWidth(getWidth()) * av.charWidth;\r
-          }\r
-\r
           if (sx < getWidth()\r
               && ex > 0\r
               && group.sequences.contains(av.alignment.getSequenceAt(i)))\r