X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FSeqCanvas.java;h=fd8330977705d18b7b81a13e6639bdb5c23941c2;hb=8878681ec11f85c050248236a96ffbcaf2f0497b;hp=5aa5d663d84574664fbce7267aa40320dee8bebf;hpb=6e71f42b0a3713ddbc3054e7ea9d8f5088130ec9;p=jalview.git diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 5aa5d66..fd83309 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -21,7 +21,6 @@ package jalview.appletgui; import java.awt.*; -import jalview.analysis.*; import jalview.datamodel.*; public class SeqCanvas @@ -36,7 +35,6 @@ public class SeqCanvas AlignViewport av; - boolean showScores = false; boolean displaySearch = false; int[] searchResults = null; @@ -45,6 +43,8 @@ public class SeqCanvas boolean fastPaint = false; + boolean isOverview = false; + public SeqCanvas(AlignViewport av) { this.av = av; @@ -97,7 +97,7 @@ public class SeqCanvas } if (value != -1) { - int x = LABEL_WEST - fm.stringWidth(value + ""); + int x = LABEL_WEST - fm.stringWidth(String.valueOf(value))-av.charWidth/2; g.drawString(value + "", x, ypos + i * av.charHeight - av.charHeight / 5); } @@ -126,7 +126,7 @@ public class SeqCanvas } if (value != -1) { - g.drawString(value + "", 0, + g.drawString(value + "", av.charWidth/2, ypos + i * av.charHeight - av.charHeight / 5); } } @@ -135,7 +135,7 @@ public class SeqCanvas public void fastPaint(int horizontal, int vertical) { - if (horizontal == 0 && vertical == 0 || gg == null) + if (gg == null) { return; } @@ -205,6 +205,8 @@ public class SeqCanvas public void paint(Graphics g) { + sr.renderGaps(av.renderGaps); + if (fastPaint) { g.drawImage(img, 0, 0, this); @@ -243,7 +245,7 @@ public class SeqCanvas if (av.getWrapAlignment()) { - drawWrappedPanel(gg, getSize().width, getSize().height, av.startRes); + drawWrappedPanel(gg, imgWidth, imgHeight, av.startRes); } else { @@ -258,24 +260,39 @@ public class SeqCanvas int LABEL_WEST, LABEL_EAST; public int getWrappedCanvasWidth(int cwidth) { - FontMetrics fm = getFontMetrics(av.getFont()); + FontMetrics fm = getFontMetrics(av.getFont()); - LABEL_EAST = 0; - LABEL_WEST = 0; + LABEL_EAST = 0; + LABEL_WEST = 0; - if (av.scaleRightWrapped) - { - LABEL_EAST = fm.stringWidth(av.alignment.getWidth() + "000"); - } + if (av.scaleRightWrapped) + { + LABEL_EAST = fm.stringWidth(getMask()+"0"); + } - if (av.scaleLeftWrapped) - { - LABEL_WEST = fm.stringWidth(av.alignment.getWidth() + ""); - } + if (av.scaleLeftWrapped) + { + LABEL_WEST = fm.stringWidth(getMask()); + } - return (cwidth - LABEL_EAST - LABEL_WEST) / av.charWidth; + return (cwidth - LABEL_EAST - LABEL_WEST) / av.charWidth; } + + /** + * Generates a string of zeroes. + * @return String + */ + String getMask() + { + String mask = "0"; + for (int i = av.alignment.getWidth(); i > 0; i /= 10) + { + mask += "0"; + } + return mask; + } + public void drawWrappedPanel(Graphics g, int canvasWidth, int canvasHeight, int startRes) { @@ -283,15 +300,16 @@ public class SeqCanvas FontMetrics fm = getFontMetrics(av.getFont()); - int LABEL_EAST = 0; if (av.scaleRightWrapped) { - LABEL_EAST = fm.stringWidth(al.getWidth() + "000"); + LABEL_EAST = fm.stringWidth(getMask()+"0"); } + int LABEL_WEST = 0; + if (av.scaleLeftWrapped) { - LABEL_WEST = fm.stringWidth(al.getWidth() + "0"); + LABEL_WEST = fm.stringWidth(getMask()); } int cWidth = (canvasWidth - LABEL_EAST - LABEL_WEST) / av.charWidth; @@ -313,9 +331,9 @@ public class SeqCanvas if (av.scaleRightWrapped) { - g.translate(canvasWidth - LABEL_EAST + av.charWidth, 0); + g.translate(canvasWidth - LABEL_EAST, 0); drawEastScale(g, startRes, endx, ypos); - g.translate( - (canvasWidth - LABEL_EAST + av.charWidth), 0); + g.translate( - (canvasWidth - LABEL_EAST), 0); } g.translate(LABEL_WEST, 0); @@ -324,24 +342,16 @@ public class SeqCanvas drawNorthScale(g, startRes, endx, ypos); } - // When printing we have an extra clipped region, - // the Printable page which we need to account for here - Shape clip = g.getClip(); - if (clip == null) - { - g.setClip(0, 0, cWidth * av.charWidth, canvasHeight); - } - else - { - g.setClip(0, - (int) clip.getBounds().y, - cWidth * av.charWidth, - (int) clip.getBounds().height - ); - } - drawPanel(g, startRes, endx, 0, al.getHeight(), startRes, 0, ypos); - g.setClip(clip); + if(g.getClip()==null) + g.setClip(0, 0, cWidth * av.charWidth, canvasHeight); + + if (av.alignment.getWidth() >= av.vconsensus.size()) + { + endx = av.vconsensus.size() - 2; + } + drawPanel(g, startRes, endx, 0, al.getHeight(), startRes, 0, ypos); + g.setClip(null); g.translate( -LABEL_WEST, 0); ypos += cHeight; @@ -374,7 +384,7 @@ public class SeqCanvas sr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq), x1, x2, (x1 - startx) * av.charWidth, offset + - AlignmentUtil.getPixelHeight(starty, i, av.charHeight), + (i-starty)*av.charHeight, av.charWidth, av.charHeight); if (av.showSequenceFeatures) @@ -382,7 +392,7 @@ public class SeqCanvas fr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq), x1, x2, (x1 - startx) * av.charWidth, offset + - AlignmentUtil.getPixelHeight(starty, i, av.charHeight), + (i-starty)*av.charHeight, av.charWidth, av.charHeight); } } @@ -402,101 +412,143 @@ public class SeqCanvas groupIndex = 0; } - if (group != null) + if (group != null && !isOverview) { do { - int oldY = -1; - int i = 0; - boolean inGroup = false; - int top = -1, bottom = -1; - for (i = y1; i < y2; i++) - { - sx = (group.getStartRes() - startx) * av.charWidth; - sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight); - ex = (group.getEndRes() + 1 - group.getStartRes()) * av.charWidth - 1; + int oldY = -1; + int i = 0; + boolean inGroup = false; + int top = -1; + int bottom = -1; - if (sx < getSize().width - && ex > 0 - && group.sequences.contains(av.alignment.getSequenceAt(i))) + for (i = y1; i < y2; i++) { - if (bottom == -1 && (i == av.alignment.getHeight() - 1 || - !group.sequences.contains(av.alignment. - getSequenceAt(i + 1)))) - { - bottom = sy + av.charHeight; - } + sx = (group.getStartRes() - startx) * av.charWidth; + sy = offset + ((i - starty) * av.charHeight); + ex = (((group.getEndRes() + 1) - group.getStartRes()) * av.charWidth) - + 1; - if (!inGroup) - { - if (top == -1 && i == 0 || - !group.sequences.contains(av.alignment.getSequenceAt(i - 1))) + if(sx+ex<0 || sx>imgWidth) { - top = sy; + continue; } - oldY = sy; - inGroup = true; - if (group == av.getSelectionGroup()) + if ( (sx <= (x2-x1)*av.charWidth) && + group.sequences.contains(av.alignment.getSequenceAt( + i))) { - g.setColor(new Color(255, 0, 0)); + if ((bottom == -1) && + !group.sequences.contains( + av.alignment.getSequenceAt(i + 1))) + { + bottom = sy + av.charHeight; + } + + if (!inGroup) + { + if (((top == -1) && (i == 0)) || + !group.sequences.contains( + av.alignment.getSequenceAt(i - 1))) + { + top = sy; + } + + oldY = sy; + inGroup = true; + + if (group == av.getSelectionGroup()) + { + g.setColor(Color.red); + } + else + { + g.setColor(group.getOutlineColour()); + } + } } else { - g.setColor(group.getOutlineColour()); + if (inGroup) + { + if (sx >= 0 && sx < imgWidth) + g.drawLine(sx, oldY, sx, sy); + + if (sx + ex < imgWidth) + g.drawLine(sx + ex, oldY, sx + ex, sy); + + if (sx < 0) + { + ex += sx; + sx = 0; + } + + if (sx + ex > imgWidth) + ex = imgWidth; + + else if (sx + ex >= (x2 - x1 + 1) * av.charWidth) + ex = (x2 - x1 + 1) * av.charWidth; + + if (top != -1) + { + g.drawLine(sx, top, sx + ex, top); + top = -1; + } + + if (bottom != -1) + { + g.drawLine(sx, bottom, sx + ex, bottom); + bottom = -1; + } + + inGroup = false; + } } - } } - else + + if (inGroup) { - if (inGroup) - { + sy = offset + ( (i - starty) * av.charHeight); + if (sx >= 0 && sx < imgWidth) g.drawLine(sx, oldY, sx, sy); + + if (sx + ex < imgWidth) g.drawLine(sx + ex, oldY, sx + ex, sy); - if (top != -1) - { - g.drawLine(sx, top, sx + ex, top); - top = -1; - } - if (bottom != -1) - { - g.drawLine(sx, bottom, sx + ex, bottom); - bottom = -1; - } + if (sx < 0) + { + ex += sx; + sx = 0; + } - inGroup = false; + if (sx + ex > imgWidth) + ex = imgWidth; + else if (sx + ex >= (x2 - x1 + 1) * av.charWidth) + ex = (x2 - x1 + 1) * av.charWidth; + + if (top != -1) + { + g.drawLine(sx, top, sx + ex, top); + top = -1; } - } - } - if (inGroup) - { + if (bottom != -1) + { + g.drawLine(sx, bottom - 1, sx + ex, bottom - 1); + bottom = -1; + } - if (top != -1) - { - g.drawLine(sx, top, sx + ex, top); - top = -1; + inGroup = false; } - if (bottom != -1) - { - g.drawLine(sx, bottom - 1, sx + ex, bottom - 1); - bottom = -1; - } - sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight); - g.drawLine(sx, oldY, sx, sy); - g.drawLine(sx + ex, oldY, sx + ex, sy); - inGroup = false; - } - groupIndex++; - if (groupIndex >= groups.size()) - { - break; - } + groupIndex++; - group = (SequenceGroup) groups.elementAt(groupIndex); + if (groupIndex >= groups.size()) + { + break; + } + group = (SequenceGroup) groups.elementAt(groupIndex); } while (groupIndex < groups.size()); } @@ -531,9 +583,7 @@ public class SeqCanvas searchEnd, (searchStart - startx) * av.charWidth, offset + - AlignmentUtil.getPixelHeight(starty, - searchSeq, - av.charHeight), + (searchSeq-starty)*av.charHeight, av.charWidth, av.charHeight); }