From: amwaterhouse Date: Wed, 6 Apr 2005 11:38:59 +0000 (+0000) Subject: Fast paint method implemented X-Git-Tag: Release_2_0~492 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4532dfefeac026198bfea1b9dbe84186e870bfc8;p=jalview.git Fast paint method implemented --- diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 248fb3d..04b596a 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -280,7 +280,6 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene return false; vscroll.setValue(vscroll.getValue() + 1); } - return true; } @@ -333,6 +332,8 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene public void adjustmentValueChanged(AdjustmentEvent evt) { + int oldX = av.getStartRes(); + int oldY = av.getStartSeq(); if (evt.getSource() == hscroll) { @@ -359,7 +360,10 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene if(overviewPanel!=null) overviewPanel.setBoxPosition(); - repaint(); + seqPanel.seqCanvas.fastPaint(av.getStartRes()-oldX, av.getStartSeq()-oldY); + idPanel.idCanvas.fastPaint( av.getStartSeq()-oldY ); + scalePanel.repaint(); + annotationPanel.fastPaint(av.getStartRes()-oldX); } diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 2874494..c94a5a8 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -23,7 +23,12 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio static Color HELIX_COLOUR = Color.red.darker(); static Color SHEET_COLOUR = Color.green.darker().darker(); - BufferedImage bi; + + BufferedImage image; + Graphics2D gg; + FontMetrics fm; + int imgWidth=0; + @@ -312,27 +317,63 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio public void paintComponent(Graphics g) { - if(bi==null - || bi.getWidth()!=ap.annotationPanel.getWidth() - || bi.getHeight()!=ap.annotationPanel.getHeight()) - { - bi = new BufferedImage(ap.annotationPanel.getWidth(), - ap.annotationPanel.getHeight(), - BufferedImage.TYPE_INT_RGB); - } + g.setColor(Color.white); + g.fillRect(0,0,getWidth(), getHeight()); + + imgWidth = (av.endRes-av.startRes+1) *av.charWidth; + + image = new BufferedImage(imgWidth, + ap.annotationPanel.getHeight(), + BufferedImage.TYPE_INT_RGB); + gg = (Graphics2D) image.getGraphics(); + gg.setColor(Color.white); + gg.fillRect(0, 0, imgWidth, getHeight()); + gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + fm = gg.getFontMetrics(); + gg.setFont(av.getFont()); - drawComponent( (Graphics2D)bi.getGraphics() ); - g.drawImage( bi, 0, 0, this); + + drawComponent( gg, av.startRes, av.endRes+1); + g.drawImage( image, 0, 0, this); } - public void drawComponent(Graphics2D g) + public void fastPaint(int horizontal) +{ + if(image==null || horizontal ==0) { - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); - FontMetrics fm = g.getFontMetrics(); - g.setFont(av.getFont()); - g.setColor(Color.white); - g.fillRect(0,0,getWidth(),getHeight()); + repaint(); + return; + } + + gg.copyArea( 0,0, imgWidth, getHeight(), -horizontal*av.charWidth, 0 ); + int sr=av.startRes, er=av.endRes+1, transX=0; + if(horizontal>0) // scrollbar pulled right, image to the left + { + transX = (er-sr-horizontal)*av.charWidth; + sr = er - horizontal ; + } + else if(horizontal<0) + { + er = sr-horizontal; + } + + + gg.translate(transX, 0); + + drawComponent(gg, sr, er); + + gg.translate( -transX, 0 ); + + getGraphics().drawImage(image, 0, 0, this); +} + + + public void drawComponent(Graphics2D g, int startRes, int endRes) + { + g.setColor(Color.white); + g.fillRect(0,0,(endRes-startRes) *av.charWidth, getHeight()); if(av.alignment.getAlignmentAnnotation()==null || av.alignment.getAlignmentAnnotation().length<1) { g.setColor(Color.black); @@ -366,11 +407,11 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio else iconOffset = 0; - for(j=av.startRes; j0) // scroll down + { + transY = imgHeight - vertical*av.charHeight; + ss = es - vertical; + } + else if(vertical<0) + { + es = ss-vertical; + } + gg.translate(0, transY); + + drawIds(ss, es); + + gg.translate( 0, -transY ); + + + getGraphics().drawImage(image, 0, 0, this); + } + public void paintComponent(Graphics g) + { + imgHeight = getHeight(); + imgHeight -= imgHeight % av.charHeight; + image = new BufferedImage(getWidth(), imgHeight, BufferedImage.TYPE_INT_RGB); + gg = (Graphics2D) image.getGraphics(); //Fill in the background gg.setColor(Color.white); - gg.fillRect(0,0,getWidth(),getHeight()); + gg.fillRect(0, 0, getWidth(), imgHeight); + gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + Font italic = new Font(av.getFont().getName(), Font.ITALIC, + av.getFont().getSize()); + gg.setFont(italic); + + + g.setColor(Color.white); + g.fillRect(0,0,getWidth(),getHeight()); + + drawIds( av.getStartSeq(), av.endSeq); + + g.drawImage(image, 0, 0, this); + } + + void drawIds(int starty, int endy) + { Color currentColor = Color.white; Color currentTextColor = Color.black; - //Which ids are we printing - int starty = av.getStartSeq(); - int endy = av.endSeq; - if (av.getWrapAlignment()) { // Draw the rest of the panels - int chunkHeight = (al.getHeight() + 2)*av.charHeight; + int chunkHeight = (av.alignment.getHeight() + 2)*av.charHeight; int row = av.getStartRes() / av.chunkWidth ; for(int ypos=2*av.charHeight; - ypos <= getHeight() && row*av.chunkWidth0) // scrollbar pulled right, image to the left + { + transX = (er-sr-horizontal)*av.charWidth; + sr = er - horizontal ; + } + else if(horizontal<0) + { + er = sr-horizontal; + } + + + + + if(vertical>0) // scroll down + { + transY = imgHeight - vertical*av.charHeight; + ss = es - vertical; + } + else if(vertical<0) + { + + es = ss-vertical; + + } + + gg.translate(transX, transY); + + drawPanel(gg, sr,er,ss,es,sr,ss,0); + + gg.translate( -transX, -transY ); + getGraphics().drawImage(img,0,0,this); + +} + /** * Definitions of startx and endx (hopefully): * SMJS This is what I'm working towards! @@ -66,17 +117,20 @@ public class SeqCanvas extends JPanel public void paintComponent(Graphics g) { + // this draws the whole of the alignment - if (img==null || imgWidth!=getWidth() || imgHeight!=getHeight() || paintFlag) - { imgWidth = getWidth(); imgHeight = getHeight(); + + imgWidth -= imgWidth%av.charWidth; + imgHeight-= imgHeight%av.charHeight; + img = createImage(imgWidth,imgHeight); gg = (Graphics2D)img.getGraphics(); gg.setFont(av.getFont()); gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); + gg.setClip(0,0,imgWidth, imgHeight); paintFlag = false; - } chunkWidth = getWidth()/av.charWidth; @@ -85,8 +139,8 @@ public class SeqCanvas extends JPanel av.setChunkHeight(chunkHeight); av.setChunkWidth(chunkWidth); - gg.setColor(Color.WHITE); - gg.fillRect(0,0,imgWidth,imgHeight); + g.setColor(Color.WHITE); + g.fillRect(0,0,getWidth(), getHeight()); if (av.getWrapAlignment()) drawWrappedPanel(gg, getWidth(), getHeight(), av.startRes); @@ -217,7 +271,7 @@ public class SeqCanvas extends JPanel inGroup = true; if (group == av.getSelectionGroup()) { - g.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 3f, new float[]{5f,2f,2f}, 0f )); + // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 3f, new float[]{5f,2f,2f}, 0f )); g.setColor(Color.RED); } else