X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FSeqCanvas.java;h=7f9ee97a26ba931d54d1423123fadfd53ef463a3;hb=d1a7bcdb924eaa9403d2ad10b26f0afa93c9828a;hp=841f929a1a1766e87d5a305beae34c2f572869a3;hpb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;p=jalview.git diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 841f929..7f9ee97 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -41,15 +41,14 @@ public class SeqCanvas extends JComponent int imgWidth; int imgHeight; AlignViewport av; - boolean showScores = false; boolean displaySearch = false; int[] searchResults = null; - int chunkHeight; - int chunkWidth; boolean fastPaint = false; int LABEL_WEST; int LABEL_EAST; + boolean isOverview = false; + /** * Creates a new SeqCanvas object. * @@ -129,7 +128,7 @@ public class SeqCanvas extends JComponent 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)); } @@ -171,7 +170,7 @@ public class SeqCanvas extends JComponent if (value != -1) { - g.drawString(value + "", 0, + g.drawString(String.valueOf(value), av.charWidth/2, (ypos + (i * av.charHeight)) - (av.charHeight / 5)); } } @@ -185,13 +184,17 @@ public class SeqCanvas extends JComponent */ public void fastPaint(int horizontal, int vertical) { - if (((horizontal == 0) && (vertical == 0)) || (gg == null)) + if (gg == null) { return; } - gg.copyArea(0, 0, imgWidth, imgHeight, -horizontal * av.charWidth, - -vertical * av.charHeight); + gg.copyArea(horizontal * av.charWidth, + vertical * av.charHeight, + imgWidth, + imgHeight, + -horizontal * av.charWidth, + -vertical * av.charHeight); int sr = av.startRes; int er = av.endRes; @@ -202,12 +205,13 @@ public class SeqCanvas extends JComponent if (horizontal > 0) // scrollbar pulled right, image to the left { + er ++; transX = (er - sr - horizontal) * av.charWidth; sr = er - horizontal; } else if (horizontal < 0) { - er = sr - horizontal; + er = sr - horizontal-1; } else if (vertical > 0) // scroll down { @@ -233,10 +237,6 @@ public class SeqCanvas extends JComponent } gg.translate(transX, transY); - - gg.setColor(Color.white); - gg.fillRect(0, 0, (er - sr + 1) * av.charWidth, - (es - ss) * av.charHeight); drawPanel(gg, sr, er, ss, es, sr, ss, 0); gg.translate(-transX, -transY); @@ -258,6 +258,8 @@ public class SeqCanvas extends JComponent // Set this to false to force a full panel paint public void paintComponent(Graphics g) { + sr.renderGaps(av.renderGaps); + if ((img != null) && (fastPaint || (getWidth() != g.getClipBounds().width) || (getHeight() != g.getClipBounds().height))) @@ -280,20 +282,16 @@ public class SeqCanvas extends JComponent return; } + 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); + RenderingHints.VALUE_ANTIALIAS_ON); gg.setColor(Color.white); gg.fillRect(0, 0, imgWidth, imgHeight); - chunkWidth = getWrappedCanvasWidth(getWidth()); - chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; - - av.setChunkHeight(chunkHeight); - av.setChunkWidth(chunkWidth); if (av.getWrapAlignment()) { @@ -324,17 +322,32 @@ public class SeqCanvas extends JComponent if (av.scaleRightWrapped) { - LABEL_EAST = fm.stringWidth(av.alignment.getWidth() + "000"); + LABEL_EAST = fm.stringWidth(getMask()+"0"); } if (av.scaleLeftWrapped) { - LABEL_WEST = fm.stringWidth(av.alignment.getWidth() + ""); + LABEL_WEST = fm.stringWidth(getMask()); } 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; + } + /** * DOCUMENT ME! * @@ -346,6 +359,7 @@ public class SeqCanvas extends JComponent public void drawWrappedPanel(Graphics g, int canvasWidth, int canvasHeight, int startRes) { + AlignmentI al = av.getAlignment(); FontMetrics fm = getFontMetrics(av.getFont()); @@ -354,26 +368,35 @@ public class SeqCanvas extends JComponent 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 hgap = av.charHeight; + if(av.scaleAboveWrapped) + hgap += av.charHeight; + int cWidth = (canvasWidth - LABEL_EAST - LABEL_WEST) / av.charWidth; - int cHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; + int cHeight = av.getAlignment().getHeight() * av.charHeight; + + av.setWrappedWidth(cWidth); av.endRes = av.startRes + cWidth; + int endx = (startRes + cWidth) - 1; - int ypos = 2 * av.charHeight; + int ypos = hgap; + while ((ypos <= canvasHeight) && (startRes < av.alignment.getWidth())) { + g.setFont(av.getFont()); g.setColor(Color.black); if (av.scaleLeftWrapped) @@ -383,9 +406,9 @@ public class SeqCanvas extends JComponent 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); @@ -409,11 +432,30 @@ public class SeqCanvas extends JComponent cWidth * av.charWidth, (int) clip.getBounds().getHeight()); } + if (av.vconsensus!=null && av.alignment.getWidth() >= av.vconsensus.size()) + { + endx = av.vconsensus.size() - 2; + } + + drawPanel(g, startRes, endx, 0, al.getHeight(), startRes, 0, ypos); + + if(av.showAnnotation) + { + g.translate(0, cHeight + ypos + 3); + if(annotations==null) + annotations = new AnnotationPanel(av); + + annotations.drawComponent( (Graphics2D) g, startRes, endx + 1); + g.translate(0, -cHeight - ypos); + } g.setClip(clip); g.translate(-LABEL_WEST, 0); - ypos += cHeight; + ypos += cHeight+getAnnotationHeight()+hgap; + if(av.showAnnotation) + ypos -= 3; + startRes += cWidth; endx = (startRes + cWidth) - 1; @@ -424,6 +466,18 @@ public class SeqCanvas extends JComponent } } + AnnotationPanel annotations; + int getAnnotationHeight() + { + if(!av.showAnnotation) + return 0; + + if(annotations==null) + annotations = new AnnotationPanel(av); + + return annotations.adjustPanelHeight(); + } + /** * DOCUMENT ME! * @@ -436,25 +490,51 @@ public class SeqCanvas extends JComponent * @param starty DOCUMENT ME! * @param offset DOCUMENT ME! */ + + float aaRatio = 2f/3f; + public void increaseAARatio() + { + aaRatio += .025; + if(aaRatio>1) + aaRatio = 1; + + repaint(); + } + + public void decreaseAARation() + { + aaRatio -= .025; + if(aaRatio<0) + aaRatio = 0; + + repaint(); + } + synchronized public 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()); - sr.renderGaps(av.renderGaps); - SequenceI nextSeq; + + SequenceI nextSeq; + /// First draw the sequences ///////////////////////////// for (int i = y1; i < y2; i++) { nextSeq = av.alignment.getSequenceAt(i); + g.setFont(av.getFont()); + sr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq), - x1, x2, (x1 - startx) * av.charWidth, - offset + ((i - starty) * av.charHeight), av.charWidth, - av.charHeight); + x1, x2, (x1 - startx) * av.charWidth, + offset + ( (i - starty) * av.charHeight), av.charWidth, + av.charHeight); + + + if (av.showSequenceFeatures) { @@ -485,7 +565,7 @@ public class SeqCanvas extends JComponent } - if (group != null) + if (group != null && !isOverview) { do { @@ -502,8 +582,12 @@ public class SeqCanvas extends JComponent ex = (((group.getEndRes() + 1) - group.getStartRes()) * av.charWidth) - 1; + if(sx+ex<0 || sx>imgWidth) + { + continue; + } - if ((sx < (x2-x1)*av.charWidth) && + if ( (sx <= (x2-x1)*av.charWidth) && group.sequences.contains(av.alignment.getSequenceAt( i))) { @@ -543,46 +627,75 @@ public class SeqCanvas extends JComponent } else { - if (inGroup) + 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) { - g.drawLine(sx, oldY, sx, sy); - g.drawLine(sx + ex, oldY, sx + ex, sy); + ex += sx; + sx = 0; + } - if (top != -1) - { - g.drawLine(sx, top, sx + ex, top); - top = -1; - } + if (sx + ex > imgWidth) + ex = imgWidth; - if (bottom != -1) - { - g.drawLine(sx, bottom, sx + ex, bottom); - bottom = -1; - } + else if (sx + ex >= (x2 - x1 + 1) * av.charWidth) + ex = (x2 - x1 + 1) * av.charWidth; - inGroup = false; + 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; } } } - if (inGroup) { - if (top != -1) - { - g.drawLine(sx, top, sx + ex, top); - top = -1; - } - - if (bottom != -1) - { - g.drawLine(sx, bottom - 1, sx + ex, bottom - 1); - bottom = -1; - } - - sy = offset + ((i - starty) * av.charHeight); + 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 (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 - 1, sx + ex, bottom - 1); + bottom = -1; + } + inGroup = false; }