X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSequenceRenderer.java;h=739187bcd53af277812f6ee524abb06452a3fadf;hb=2d7deb9d3e1ddc98abae846c8ffbc62606b023be;hp=0c41152638ca4da5394e697852497b66ee4a7927;hpb=9c2efb07ecb9e429c4adeff76e388c12f0062a8b;p=jalview.git diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 0c41152..739187b 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -40,6 +40,7 @@ public class SequenceRenderer Color resBoxColour; Graphics graphics; boolean monospacedFont; + boolean forOverview = false; /** * Creates a new SequenceRenderer object. @@ -56,9 +57,19 @@ public class SequenceRenderer * * @param b DOCUMENT ME! */ - public void renderGaps(boolean b) + public void prepare(Graphics g, boolean renderGaps) { - renderGaps = b; + graphics = g; + fm = g.getFontMetrics(); + + // If EPS graphics, stringWidth will be a double, not an int + double dwidth = fm.getStringBounds("M", g).getWidth(); + + monospacedFont = + (dwidth == fm.getStringBounds("|",g).getWidth() + && (float)av.charWidth == dwidth); + + this.renderGaps = renderGaps; } @@ -95,9 +106,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; } } @@ -114,20 +129,15 @@ public class SequenceRenderer * @param width DOCUMENT ME! * @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) + public void drawSequence(SequenceI seq, SequenceGroup[] sg, + int start, int end, int y1) { allGroups = sg; - graphics = g; - - drawBoxes(seq, start, end, x1, y1, (int) width, height); - - fm = g.getFontMetrics(); + drawBoxes(seq, start, end, y1); - monospacedFont = fm.getStringBounds("M",g).getWidth()==fm.getStringBounds("|",g).getWidth(); - - drawText(seq, start, end, x1, y1, (int) width, height); + if (av.validCharWidth) + drawText(seq, start, end, y1); } /** @@ -141,14 +151,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 +185,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 +219,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 +232,13 @@ public class SequenceRenderer if(monospacedFont && av.showText && allGroups.length==0 && !av.getColourText()) { - graphics.drawString(seq.getSequence(start, end + 1), x1, y1); + if(av.renderGaps) + graphics.drawString(seq.getSequence(start, end + 1), 0, y1); + else + { + char gap = av.getGapCharacter(); + graphics.drawString( seq.getSequence(start, end+1).replace(gap, ' '), 0, y1); + } } else { @@ -272,12 +286,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"); } } @@ -320,28 +337,52 @@ public class SequenceRenderer * @param width DOCUMENT ME! * @param height DOCUMENT ME! */ - public void drawHighlightedText(SequenceI seq, int start, int end, int x1, - int y1, int width, int height) + public void drawHighlightedText(SequenceI seq, int start, int end, int x1, int y1) { - int pady = height / 5; + int pady = av.charHeight / 5; int charOffset = 0; graphics.setColor(Color.BLACK); - graphics.fillRect(x1, y1, width * (end - start + 1), height); + graphics.fillRect(x1, y1, av.charWidth * (end - start + 1), av.charHeight); graphics.setColor(Color.white); char s = '~'; // Need to find the sequence position here. - for (int i = start; i <= end; i++) + if(av.validCharWidth) { + for (int i = start; i <= end; i++) + { if (i < seq.getLength()) { - s = seq.getSequence().charAt(i); + s = seq.getSequence().charAt(i); } - charOffset = (width - fm.charWidth(s)) / 2; + charOffset = (av.charWidth - fm.charWidth(s)) / 2; graphics.drawString(String.valueOf(s), - charOffset + x1 + (width * (i - start)), (y1 + height) - pady); + charOffset + x1 + (av.charWidth * (i - start)), + (y1 + av.charHeight) - pady); + } } } + + public void drawCursor(SequenceI seq, int res, int x1, int y1) + { + int pady = av.charHeight / 5; + int charOffset = 0; + graphics.setColor(Color.black); + graphics.fillRect(x1, y1, av.charWidth, av.charHeight); + + if(av.validCharWidth) + { + graphics.setColor(Color.white); + + char s = seq.getCharAt(res); + + charOffset = (av.charWidth - fm.charWidth(s)) / 2; + graphics.drawString(String.valueOf(s), + charOffset + x1, + (y1 + av.charHeight) - pady); + } + + } }