X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSequenceRenderer.java;h=fb967edde92f0503a01c399fb8e8ec8a8b93341a;hb=23acdc937f2eb189a4736f8a4c3dba924e1ebbce;hp=5bb0de7bf706b90d809a073c7a6c7ab6c550ead0;hpb=fb548a8458941602b0b8b45da5aaf60206e10ec2;p=jalview.git diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 5bb0de7..fb967ed 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -30,6 +30,9 @@ import java.awt.Color; import java.awt.FontMetrics; import java.awt.Graphics; +import org.jfree.graphics2d.svg.SVGGraphics2D; +import org.jibble.epsgraphics.EpsGraphics2D; + public class SequenceRenderer implements jalview.api.SequenceRenderer { final static int CHAR_TO_UPPER = 'A' - 'a'; @@ -75,8 +78,8 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer // If EPS graphics, stringWidth will be a double, not an int double dwidth = fm.getStringBounds("M", g).getWidth(); - monospacedFont = (dwidth == fm.getStringBounds("|", g).getWidth() && av - .getCharWidth() == dwidth); + monospacedFont = (dwidth == fm.getStringBounds("|", g).getWidth() + && av.getCharWidth() == dwidth); this.renderGaps = renderGaps; } @@ -95,13 +98,13 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer public Color getResidueColour(final SequenceI seq, int position, FeatureColourFinder finder) { - return resColourFinder.getResidueColour(av.getResidueShading(), + allGroups = av.getAlignment().findAllGroups(seq); + return resColourFinder.getResidueColour(av.getShowBoxes(), + av.getResidueShading(), allGroups, seq, position, finder); } - - /** * DOCUMENT ME! * @@ -168,8 +171,8 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer int length = seq.getLength(); int curStart = -1; - int curWidth = av.getCharWidth(), avWidth = av.getCharWidth(), avHeight = av - .getCharHeight(); + int curWidth = av.getCharWidth(), avWidth = av.getCharWidth(), + avHeight = av.getCharHeight(); Color tempColour = null; @@ -254,8 +257,19 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer } graphics.setColor(av.getTextColour()); - if (monospacedFont && av.getShowText() && allGroups.length == 0 - && !av.getColourText() && av.getThresholdTextColour() == 0) + boolean drawAllText = monospacedFont && av.getShowText() && allGroups.length == 0 + && !av.getColourText() && av.getThresholdTextColour() == 0; + + /* + * EPS or SVG misaligns monospaced strings (JAL-3239) + * so always draw these one character at a time + */ + if (graphics instanceof EpsGraphics2D + || graphics instanceof SVGGraphics2D) + { + drawAllText = false; + } + if (drawAllText) { if (av.isRenderGaps()) { @@ -264,8 +278,9 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer else { char gap = av.getGapCharacter(); - graphics.drawString(seq.getSequenceAsString(start, end + 1) - .replace(gap, ' '), 0, y1); + graphics.drawString( + seq.getSequenceAsString(start, end + 1).replace(gap, ' '), + 0, y1); } } else @@ -313,7 +328,8 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer if (currentSequenceGroup.thresholdTextColour > 0) { if (resBoxColour.getRed() + resBoxColour.getBlue() - + resBoxColour.getGreen() < currentSequenceGroup.thresholdTextColour) + + resBoxColour + .getGreen() < currentSequenceGroup.thresholdTextColour) { graphics.setColor(currentSequenceGroup.textColour2); } @@ -406,21 +422,25 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer // currentSequenceGroup.getConsensus() char conschar = (usesrep) ? (currentGroup == null || position < currentGroup.getStartRes() - || position > currentGroup.getEndRes() ? av.getAlignment() - .getSeqrep().getCharAt(position) - : (currentGroup.getSeqrep() != null ? currentGroup.getSeqrep() - .getCharAt(position) : av.getAlignment().getSeqrep() - .getCharAt(position))) + || position > currentGroup.getEndRes() + ? av.getAlignment().getSeqrep().getCharAt(position) + : (currentGroup.getSeqrep() != null + ? currentGroup.getSeqrep().getCharAt(position) + : av.getAlignment().getSeqrep() + .getCharAt(position))) : (currentGroup != null && currentGroup.getConsensus() != null && position >= currentGroup.getStartRes() - && position <= currentGroup.getEndRes() && currentGroup - .getConsensus().annotations.length > position) ? currentGroup - .getConsensus().annotations[position].displayCharacter - .charAt(0) - : av.getAlignmentConsensusAnnotation().annotations[position].displayCharacter - .charAt(0); + && position <= currentGroup.getEndRes() + && currentGroup + .getConsensus().annotations.length > position) + ? currentGroup + .getConsensus().annotations[position].displayCharacter + .charAt(0) + : av.getAlignmentConsensusAnnotation().annotations[position].displayCharacter + .charAt(0); if (!jalview.util.Comparison.isGap(conschar) - && (sequenceChar == conschar || sequenceChar + CHAR_TO_UPPER == conschar)) + && (sequenceChar == conschar + || sequenceChar + CHAR_TO_UPPER == conschar)) { sequenceChar = conservedChar; } @@ -445,8 +465,8 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer * @param height * DOCUMENT ME! */ - public void drawHighlightedText(SequenceI seq, int start, int end, - int x1, int y1) + public void drawHighlightedText(SequenceI seq, int start, int end, int x1, + int y1) { int pady = av.getCharHeight() / 5; int charOffset = 0; @@ -475,21 +495,30 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer } } - public void drawCursor(SequenceI seq, int res, int x1, int y1) + /** + * Draw a sequence canvas cursor + * + * @param g + * graphics context to draw on + * @param s + * character to draw at cursor + * @param x1 + * x position of cursor in graphics context + * @param y1 + * y position of cursor in graphics context + */ + public void drawCursor(Graphics g, char s, int x1, int y1) { int pady = av.getCharHeight() / 5; int charOffset = 0; - graphics.setColor(Color.black); - graphics.fillRect(x1, y1, av.getCharWidth(), av.getCharHeight()); + g.setColor(Color.black); + g.fillRect(x1, y1, av.getCharWidth(), av.getCharHeight()); if (av.isValidCharWidth()) { - graphics.setColor(Color.white); - - char s = seq.getCharAt(res); - + g.setColor(Color.white); charOffset = (av.getCharWidth() - fm.charWidth(s)) / 2; - graphics.drawString(String.valueOf(s), charOffset + x1, + g.drawString(String.valueOf(s), charOffset + x1, (y1 + av.getCharHeight()) - pady); }