From: amwaterhouse Date: Mon, 30 Jan 2006 14:57:43 +0000 (+0000) Subject: Faster paint X-Git-Tag: Root_VamJalview_2_07b+~197 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9c2efb07ecb9e429c4adeff76e388c12f0062a8b;p=jalview.git Faster paint --- diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 0fe3b86..7dbb8d3 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -24,7 +24,6 @@ import java.awt.*; import java.awt.image.*; import javax.swing.*; -import jalview.schemes.*; /** @@ -205,11 +204,13 @@ public class SeqCanvas extends JComponent */ public void fastPaint(int horizontal, int vertical) { - if (gg == null) + if (fastPaint || gg == null) { return; } + fastPaint = true; + gg.copyArea(horizontal * av.charWidth, vertical * av.charHeight, imgWidth, @@ -261,7 +262,6 @@ public class SeqCanvas extends JComponent drawPanel(gg, sr, er, ss, es, sr, ss, 0); gg.translate(-transX, -transY); - fastPaint = true; repaint(); } @@ -308,8 +308,10 @@ public class SeqCanvas extends JComponent 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); + + if (av.antiAlias) + gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); gg.setColor(Color.white); gg.fillRect(0, 0, imgWidth, imgHeight); @@ -539,17 +541,17 @@ public class SeqCanvas extends JComponent } - synchronized public void drawPanel(Graphics g1, int x1, int x2, int y1, - int y2, int startx, int starty, int offset) + void drawPanel(Graphics g1, int x1, int x2, int y1, int y2, int startx, int starty, int offset) { Graphics2D g = (Graphics2D) g1; g.setFont(av.getFont()); - SequenceI nextSeq, dna = null; - int aaHeight = av.charHeight, dnaHeight = av.charHeight; - Font dnafont = null, aafont = av.getFont(); + SequenceI nextSeq; + // int aaHeight = av.charHeight; + // Font aafont = av.getFont(); - /* if (av.getShowTranslation()) + /* dnafont = null, , dna = null, dnaHeight = av.charHeight + if (av.getShowTranslation()) { aaHeight = (int) (av.getCharHeight() * aaRatio); dnaHeight = (int) (av.getCharHeight() * (1 - aaRatio)); @@ -567,14 +569,13 @@ public class SeqCanvas extends JComponent } */ - ColourSchemeI cs = av.getGlobalColourScheme(); /// First draw the sequences ///////////////////////////// for (int i = y1; i < y2; i++) { nextSeq = av.alignment.getSequenceAt(i); - g.setFont(aafont); + /* if(av.getShowTranslation()) { dna = nextSeq; @@ -598,7 +599,7 @@ public class SeqCanvas extends JComponent sr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq), x1, x2, (x1 - startx) * av.charWidth, offset + ( (i - starty) * av.charHeight), av.charWidth, - aaHeight); + av.charHeight); /* if(av.getShowTranslation()) { diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 57cd0fc..0c41152 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -39,6 +39,7 @@ public class SequenceRenderer SequenceGroup[] allGroups = null; Color resBoxColour; Graphics graphics; + boolean monospacedFont; /** * Creates a new SequenceRenderer object. @@ -123,6 +124,9 @@ public class SequenceRenderer drawBoxes(seq, start, end, x1, y1, (int) width, height); fm = g.getFontMetrics(); + + monospacedFont = fm.getStringBounds("M",g).getWidth()==fm.getStringBounds("|",g).getWidth(); + drawText(seq, start, end, x1, y1, (int) width, height); } @@ -207,69 +211,73 @@ public class SequenceRenderer * @param height DOCUMENT ME! */ public void drawText(SequenceI seq, int start, int end, int x1, int y1, - int width, int height) + int width, int height) { - int pady = height / 5; - int charOffset = 0; - char s; - - - // Need to find the sequence position here. - String sequence = seq.getSequence(); + y1 += height - height / 5; // height/5 replaces pady + int charOffset = 0; + char s; if(end+1>=seq.getLength()) end = seq.getLength()-1; + graphics.setColor(Color.black); - for (int i = start; i <= end; i++) + + if(monospacedFont && av.showText && allGroups.length==0 && !av.getColourText()) { + graphics.drawString(seq.getSequence(start, end + 1), x1, y1); + } + else + { + for (int i = start; i <= end; i++) + { graphics.setColor(Color.black); - - s = sequence.charAt(i); - + s = seq.getCharAt(i); if (!renderGaps && jalview.util.Comparison.isGap(s)) { - continue; + continue; } if (inCurrentSequenceGroup(i)) { - if (!currentSequenceGroup.getDisplayText()) - { - continue; - } + if (!currentSequenceGroup.getDisplayText()) + { + continue; + } - if (currentSequenceGroup.getColourText()) - { - getBoxColour(currentSequenceGroup.cs, seq, i); - graphics.setColor(resBoxColour.darker()); - } + if (currentSequenceGroup.getColourText()) + { + getBoxColour(currentSequenceGroup.cs, seq, i); + graphics.setColor(resBoxColour.darker()); + } } else { - if (!av.getShowText()) + if (!av.getShowText()) + { + continue; + } + + if (av.getColourText()) + { + getBoxColour(av.globalColourScheme, seq, i); + + if (av.getShowBoxes()) { - continue; + graphics.setColor(resBoxColour.darker()); } - - if (av.getColourText()) + else { - getBoxColour(av.globalColourScheme, seq, i); - - if (av.getShowBoxes()) - { - graphics.setColor(resBoxColour.darker()); - } - else - { - graphics.setColor(resBoxColour); - } + graphics.setColor(resBoxColour); } + } } charOffset = (width - fm.charWidth(s)) / 2; graphics.drawString(String.valueOf(s), - charOffset + x1 + (int)(width * (i - start)), (y1 + height) - pady); + charOffset + x1 + width * (i - start), + y1); + } } }