X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSeqCanvas.java;h=b2e9d3ead108b105ba18a00fa8bde011e2ec21e6;hb=c521a798765bb3672e89ea8cda3241a97d6c6e73;hp=c243a2e02fbf34f52a0fa167ec6ee29190189a93;hpb=79f4b175e12f4c16d598b4cb56ffe62532b592a1;p=jalview.git diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index c243a2e..b2e9d3e 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -1,15 +1,17 @@ package jalview.gui; import java.awt.*; +import java.awt.image.*; import javax.swing.*; import jalview.datamodel.*; import jalview.analysis.*; -public class SeqCanvas extends JPanel +public class SeqCanvas extends JComponent { FeatureRenderer fr; - Image img; + SequenceRenderer sr; + BufferedImage img; Graphics2D gg; int imgWidth; int imgHeight; @@ -30,6 +32,7 @@ public class SeqCanvas extends JPanel { this.av = av; fr = new FeatureRenderer(av); + sr = new SequenceRenderer(av); setLayout(new BorderLayout()); PaintRefresher.Register(this); @@ -77,7 +80,7 @@ public class SeqCanvas extends JPanel } if(value!=-1) { - int x = fm.stringWidth("000") - fm.stringWidth(value+""); + int x = LABEL_WEST - fm.stringWidth(value+""); g.drawString(value + "", x, ypos + i*av.charHeight - av.charHeight/5); } } @@ -121,7 +124,7 @@ public void fastPaint(int horizontal, int vertical) gg.copyArea(0, 0, imgWidth, imgHeight, -horizontal * av.charWidth, -vertical * av.charHeight); - int sr = av.startRes, er = av.endRes + 1, ss = av.startSeq, es = av.endSeq, + int sr = av.startRes, er = av.endRes, ss = av.startSeq, es = av.endSeq, transX = 0, transY = 0; if (horizontal > 0) // scrollbar pulled right, image to the left { @@ -150,7 +153,7 @@ public void fastPaint(int horizontal, int vertical) gg.translate(transX, transY); gg.setColor(Color.white); - gg.fillRect(0,0, (er-sr)*av.charWidth, (es-ss)*av.charHeight); + gg.fillRect(0,0, (er-sr+1)*av.charWidth, (es-ss)*av.charHeight); drawPanel(gg, sr, er, ss, es, sr, ss, 0); gg.translate( -transX, -transY); @@ -185,13 +188,14 @@ public void fastPaint(int horizontal, int vertical) // this draws the whole of the alignment imgWidth = getWidth(); imgHeight = getHeight(); - if(imgWidth==0 || imgHeight==0) - return; imgWidth -= imgWidth%av.charWidth; imgHeight-= imgHeight%av.charHeight; - img = createImage(imgWidth,imgHeight); + if(imgWidth<1 || imgHeight<1) + return; + + img = new BufferedImage(imgWidth,imgHeight,BufferedImage.TYPE_INT_RGB); gg = (Graphics2D)img.getGraphics(); gg.setFont(av.getFont()); gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); @@ -215,16 +219,19 @@ public void fastPaint(int horizontal, int vertical) } + int LABEL_WEST, LABEL_EAST; public int getWrappedCanvasWidth(int cwidth) { FontMetrics fm = getFontMetrics(av.getFont()); - int LABEL_EAST = 0; + LABEL_EAST = 0; + LABEL_WEST = 0; + if(av.scaleRightWrapped) LABEL_EAST = fm.stringWidth( av.alignment.getWidth()+"000" ); - int LABEL_WEST = 0; + if(av.scaleLeftWrapped) - LABEL_WEST = fm.stringWidth( av.alignment.getWidth()+"0" ); + LABEL_WEST = fm.stringWidth( av.alignment.getWidth()+"" ); return (cwidth - LABEL_EAST -LABEL_WEST)/av.charWidth; } @@ -240,16 +247,18 @@ public void fastPaint(int horizontal, int vertical) LABEL_EAST = fm.stringWidth( al.getWidth()+"000" ); int LABEL_WEST = 0; if(av.scaleLeftWrapped) - LABEL_WEST = fm.stringWidth( al.getWidth()+"0" ); + LABEL_WEST = fm.stringWidth(al.getWidth()+"0"); + int cWidth = (canvasWidth - LABEL_EAST -LABEL_WEST)/av.charWidth; int cHeight = (av.getAlignment().getHeight() + 2)*av.charHeight; + av.endRes = av.startRes + cWidth; + int endx = startRes+cWidth-1; int ypos = 2*av.charHeight; - - while (ypos <= canvasHeight && endx starty && y1 < av.getEndSeq()) - { - fillBackground(g, - Color.red, - (x1-startx)*charWidth, - offset + AlignmentUtil.getPixelHeight(starty,y1,av.getCharHeight()), - (x2-x1+1)*charWidth, - offset + AlignmentUtil.getPixelHeight(y1,y2,av.getCharHeight())); - }*/ SequenceI nextSeq; @@ -325,7 +322,7 @@ public void fastPaint(int horizontal, int vertical) sr.drawSequence(g, nextSeq, av.alignment.findAllGroups( nextSeq ),x1,x2, (x1 - startx) * av.charWidth, offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight), - av.charWidth,av.charHeight,null, i); + av.charWidth,av.charHeight); if(av.showSequenceFeatures) { @@ -333,7 +330,7 @@ public void fastPaint(int horizontal, int vertical) (x1 - startx) * av.charWidth, offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight), - av.charWidth, av.charHeight, null, i); + av.charWidth, av.charHeight); } } // @@ -363,23 +360,7 @@ public void fastPaint(int horizontal, int vertical) { sx = (group.getStartRes() - startx) * av.charWidth; sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight); - ex = (group.getEndRes() + 1 - group.getStartRes()) * av.charWidth; - - if (av.getWrapAlignment()) - { - if (sx < 0) - sx = 0; - - if (ex > getWidth()) - { - if (av.getWrapAlignment()) - ex = getWrappedCanvasWidth(getWidth()) * av.charWidth; - - } - } - else if(ex>getWidth()) - ex -= av.charWidth; - + ex = (group.getEndRes() + 1 - group.getStartRes()) * av.charWidth -1; if (sx < getWidth() && ex > 0 @@ -470,17 +451,21 @@ public void fastPaint(int horizontal, int vertical) for(int r=0; r= y1 && searchSeq < y2) { + SequenceI seq = av.getAlignment().getSequenceAt(searchSeq); + + int searchStart = seq.findIndex( searchResults[r+1] )-1; + int searchEnd = seq.findIndex( searchResults[r+2] )-1; + SequenceRenderer ssr = (SequenceRenderer) sr; if(searchStart x2) searchEnd = x2; - ssr.drawHighlightedText(av.getAlignment().getSequenceAt(searchSeq), + + ssr.drawHighlightedText(seq, searchStart, searchEnd, (searchStart - startx) * av.charWidth,