From: amwaterhouse Date: Fri, 24 Feb 2006 11:44:20 +0000 (+0000) Subject: Less args, faster rendering X-Git-Tag: Root_VamJalview_2_07b+~95 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3d1120fca6dd9dc2865ee6cde98760f65c2701da;p=jalview.git Less args, faster rendering --- diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index a9f2329..f542b17 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -100,7 +100,7 @@ public class SeqCanvas extends JComponent // NORTH SCALE for (int i = scalestartx; i < endx; i += 10) { - String string = String.valueOf(i); + String string = String.valueOf(av.getColumnSelection().adjustForHiddenColumns(i)); g.drawString(string, (i - startx - 1) * av.charWidth, ypos - (av.charHeight / 2)); @@ -203,7 +203,7 @@ public class SeqCanvas extends JComponent */ public void fastPaint(int horizontal, int vertical) { - if (fastPaint || gg == null) + if (gg == null) { return; } @@ -258,7 +258,7 @@ public class SeqCanvas extends JComponent } gg.translate(transX, transY); - drawPanel(gg, sr, er, ss, es, sr, ss, 0); + drawPanel(gg, sr, er, ss, es, 0); gg.translate(-transX, -transY); repaint(); @@ -322,8 +322,7 @@ public class SeqCanvas extends JComponent } else { - drawPanel(gg, av.startRes, av.endRes, av.startSeq, av.endSeq, - av.startRes, av.startSeq, 0); + drawPanel(gg, av.startRes, av.endRes, av.startSeq, av.endSeq, 0); } g.drawImage(img, 0, 0, this); @@ -467,7 +466,7 @@ public class SeqCanvas extends JComponent } - drawPanel(g, startRes, endx, 0, al.getHeight(), startRes, 0, ypos); + drawPanel(g, startRes, endx, 0, al.getHeight(), ypos); if(av.showAnnotation) { @@ -540,83 +539,94 @@ public class SeqCanvas extends JComponent } - void drawPanel(Graphics g1, int x1, int x2, int y1, int y2, int startx, int starty, int offset) + void drawPanel(Graphics g1, int startRes, int endRes, + int startSeq, int endSeq, int offset) { - Graphics2D g = (Graphics2D) g1; - g.setFont(av.getFont()); + if(!av.hasHiddenColumns) + { + draw(g1, startRes, endRes, startSeq, endSeq, offset); + } + else + { + java.util.Vector regions = av.getColumnSelection().getHiddenColumns(); - SequenceI nextSeq; - // int aaHeight = av.charHeight; - // Font aafont = av.getFont(); + int screenY = 0; + int blockStart = startRes; + int blockEnd = endRes; - /* dnafont = null, , dna = null, dnaHeight = av.charHeight - if (av.getShowTranslation()) - { - aaHeight = (int) (av.getCharHeight() * aaRatio); - dnaHeight = (int) (av.getCharHeight() * (1 - aaRatio)); - java.awt.geom.AffineTransform transform = new java.awt.geom.AffineTransform(); - transform.scale(1f / 3f, 1); - dnafont = new Font(av.getFont().getName(), av.getFont().getStyle(), - dnaHeight); - dnafont = dnafont.deriveFont(transform); - - aafont = new Font(av.getFont().getName(), av.getFont().getStyle(), - aaHeight); - transform = new java.awt.geom.AffineTransform(); - transform.scale(1 / aaRatio, 1); - aafont = aafont.deriveFont(transform); + for (int i = 0; i < regions.size(); i++) + { + int[] region = (int[]) regions.elementAt(i); + int hideStart = region[0]; + int hideEnd = region[1]; + + if (hideStart <= blockStart) + { + blockStart += (hideEnd - hideStart) + 1; + continue; + } + + blockEnd = hideStart - 1; + + g1.translate(screenY * av.charWidth, 0); + + draw(g1, blockStart, blockEnd, startSeq, endSeq, offset); + + g1.setColor(Color.blue); + g1.drawLine( (blockEnd - blockStart + 1) * av.charWidth - 1, + startSeq + offset, + (blockEnd - blockStart + 1) * av.charWidth - 1, + startSeq + (endSeq - startSeq) * av.charHeight + offset); + g1.drawLine( (blockEnd - blockStart + 1) * av.charWidth, + startSeq + offset, + (blockEnd - blockStart + 1) * av.charWidth, + startSeq + (endSeq - startSeq) * av.charHeight + offset); + + g1.translate( -screenY * av.charWidth, 0); + screenY += blockEnd - blockStart + 1; + blockStart = hideEnd + 1; + } + + if (screenY < (endRes - startRes)) + { + blockEnd = blockStart + (endRes - startRes) - screenY; + g1.translate(screenY * av.charWidth, 0); + draw(g1, blockStart, blockEnd, startSeq, endSeq, offset); + g1.translate( -screenY * av.charWidth, 0); + } } -*/ + } + + + + + //int startRes, int endRes, int startSeq, int endSeq, int x, int y, + // int x1, int x2, int y1, int y2, int startx, int starty, + void draw(Graphics g1, + int startRes, int endRes, + int startSeq, int endSeq, + int offset) + { + Graphics2D g = (Graphics2D) g1; + g.setFont(av.getFont()); + + SequenceI nextSeq; /// First draw the sequences ///////////////////////////// - for (int i = y1; i < y2; i++) + for (int i = startSeq; i < endSeq; i++) { nextSeq = av.alignment.getSequenceAt(i); - /* if(av.getShowTranslation()) - { - dna = nextSeq; - StringBuffer sb = new StringBuffer(); - for(int r = 0; r imgWidth) ex = imgWidth; - else if (sx + ex >= (x2 - x1 + 1) * av.charWidth) - ex = (x2 - x1 + 1) * av.charWidth; + else if (sx + ex >= (endRes - startRes + 1) * av.charWidth) + ex = (endRes - startRes + 1) * av.charWidth; if (top != -1) { @@ -755,7 +765,7 @@ public class SeqCanvas extends JComponent if (inGroup) { - sy = offset + ( (i - starty) * av.charHeight); + sy = offset + ( (i - startSeq) * av.charHeight); if (sx >= 0 && sx < imgWidth) g.drawLine(sx, oldY, sx, sy); @@ -770,8 +780,8 @@ public class SeqCanvas extends JComponent if (sx + ex > imgWidth) ex = imgWidth; - else if (sx + ex >= (x2 - x1 + 1) * av.charWidth) - ex = (x2 - x1 + 1) * av.charWidth; + else if (sx + ex >= (endRes - startRes + 1) * av.charWidth) + ex = (endRes - startRes + 1) * av.charWidth; if (top != -1) { diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 0c41152..0e4312a 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -40,6 +40,7 @@ public class SequenceRenderer Color resBoxColour; Graphics graphics; boolean monospacedFont; + boolean forOverview = false; /** * Creates a new SequenceRenderer object. @@ -95,9 +96,13 @@ public class SequenceRenderer { resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i); } + else if(forOverview && !jalview.util.Comparison.isGap(seq.getCharAt(i))) + { + resBoxColour = Color.lightGray; + } else { - resBoxColour = Color.white; + resBoxColour = Color.white; } } @@ -115,19 +120,19 @@ public class SequenceRenderer * @param height DOCUMENT ME! */ public void drawSequence(Graphics g, SequenceI seq, SequenceGroup[] sg, - int start, int end, int x1, int y1, int width, int height) + int start, int end, int y1) { allGroups = sg; graphics = g; - drawBoxes(seq, start, end, x1, y1, (int) width, height); + drawBoxes(seq, start, end, y1); fm = g.getFontMetrics(); monospacedFont = fm.getStringBounds("M",g).getWidth()==fm.getStringBounds("|",g).getWidth(); - drawText(seq, start, end, x1, y1, (int) width, height); + drawText(seq, start, end, y1); } /** @@ -141,14 +146,13 @@ public class SequenceRenderer * @param width DOCUMENT ME! * @param height DOCUMENT ME! */ - public synchronized void drawBoxes(SequenceI seq, int start, int end, int x1, int y1, - int width, int height) + public synchronized void drawBoxes(SequenceI seq, int start, int end, int y1) { int i = start; int length = seq.getLength(); int curStart = -1; - int curWidth = width; + int curWidth = av.charWidth; Color tempColour = null; @@ -176,26 +180,26 @@ public class SequenceRenderer { if (tempColour != null) { - graphics.fillRect(x1 + (width * (curStart - start)), y1, - curWidth, height); + graphics.fillRect( av.charWidth * (curStart - start), y1, + curWidth, av.charHeight); } graphics.setColor(resBoxColour); curStart = i; - curWidth = width; + curWidth = av.charWidth; tempColour = resBoxColour; } else { - curWidth += width; + curWidth += av.charWidth; } i++; } - graphics.fillRect(x1 + (width * (curStart - start)), y1, curWidth, - height); + graphics.fillRect( av.charWidth * (curStart - start), y1, curWidth, + av.charHeight); } @@ -210,10 +214,9 @@ public class SequenceRenderer * @param width DOCUMENT ME! * @param height DOCUMENT ME! */ - public void drawText(SequenceI seq, int start, int end, int x1, int y1, - int width, int height) + public void drawText(SequenceI seq, int start, int end, int y1) { - y1 += height - height / 5; // height/5 replaces pady + y1 += av.charHeight - av.charHeight / 5; // height/5 replaces pady int charOffset = 0; char s; @@ -224,7 +227,7 @@ public class SequenceRenderer if(monospacedFont && av.showText && allGroups.length==0 && !av.getColourText()) { - graphics.drawString(seq.getSequence(start, end + 1), x1, y1); + graphics.drawString(seq.getSequence(start, end + 1), 0, y1); } else { @@ -272,12 +275,15 @@ public class SequenceRenderer } } - charOffset = (width - fm.charWidth(s)) / 2; + charOffset = (av.charWidth - fm.charWidth(s)) / 2; + + // System.out.print(s); graphics.drawString(String.valueOf(s), - charOffset + x1 + width * (i - start), + charOffset + av.charWidth * (i - start), y1); } + // System.out.println("\n"); } }