X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FSeqCanvas.java;h=02c99902e6ff1204b65d14c2b4b96bdfeac49992;hb=bceadbb394604c88ac18e2dcf4b33e735377d7ac;hp=ac5ff899b871c443fe80a41691f4cbb77fe86b50;hpb=42ae188a9819c341cd345baeab442cd0606ff157;p=jalview.git diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index ac5ff89..02c9990 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -37,12 +37,13 @@ public class SeqCanvas SearchResults searchResults = null; - int chunkHeight; - int chunkWidth; - boolean fastPaint = false; + int cursorX = 0; + int cursorY = 0; + + public SeqCanvas(AlignViewport av) { this.av = av; @@ -140,7 +141,7 @@ public class SeqCanvas continue; } - value = av.alignment.getSequenceAt(i).findPosition(index); + value = seq.findPosition(index); break; } if (value != -1) @@ -152,21 +153,34 @@ public class SeqCanvas } - public void fastPaint(int horizontal, int vertical) + int lastsr=0; + void fastPaint(int horizontal, int vertical) { - if (fastPaint || gg == null) + if ( fastPaint || gg == null) { - repaint(); return; } + + // Its possible on certain browsers that the call to fastpaint + // is faster than it can paint, so this check here catches + // this possibility + if(lastsr + horizontal != av.startRes) + { + horizontal = av.startRes - lastsr; + } + + lastsr = av.startRes; + fastPaint = true; gg.copyArea(horizontal * av.charWidth, vertical * av.charHeight, - imgWidth, - imgHeight, + imgWidth - horizontal * av.charWidth, + imgHeight - vertical * av.charHeight, -horizontal * av.charWidth, - -vertical * av.charHeight); + -vertical * av.charHeight); + + int sr = av.startRes, er = av.endRes, ss = av.startSeq, es = av.endSeq, transX = 0, transY = 0; @@ -280,6 +294,8 @@ public class SeqCanvas int LABEL_WEST, LABEL_EAST; public int getWrappedCanvasWidth(int cwidth) { + cwidth -= cwidth % av.charWidth; + FontMetrics fm = getFontMetrics(av.getFont()); LABEL_EAST = 0; @@ -320,15 +336,12 @@ public class SeqCanvas FontMetrics fm = getFontMetrics(av.getFont()); - int LABEL_EAST = 0; if (av.scaleRightWrapped) { LABEL_EAST = fm.stringWidth(getMask()); } - int LABEL_WEST = 0; - if (av.scaleLeftWrapped) { LABEL_WEST = fm.stringWidth(getMask()); @@ -346,12 +359,19 @@ public class SeqCanvas av.endRes = av.startRes + cWidth; - int endx = (startRes + cWidth) - 1; + int endx; int ypos = hgap; while ((ypos <= canvasHeight) && (startRes < av.alignment.getWidth())) { + endx = startRes + cWidth -1; + + if (endx > al.getWidth()) + { + endx = al.getWidth(); + } + g.setColor(Color.black); if (av.scaleLeftWrapped) @@ -373,13 +393,6 @@ public class SeqCanvas drawNorthScale(g, startRes, endx, ypos); } - - if (av.vconsensus!=null && av.alignment.getWidth() >= av.vconsensus.size()) - { - endx = av.vconsensus.size() - 2; - } - - if(g.getClip()==null) g.setClip(0, 0, cWidth * av.charWidth, canvasHeight); @@ -393,7 +406,7 @@ public class SeqCanvas if(annotations==null) annotations = new AnnotationPanel(av); - annotations.drawComponent( g, startRes, endx + 1); + annotations.drawComponent( g, startRes, endx+1 ); g.translate(0, -cHeight - ypos-4); } g.translate(-LABEL_WEST, 0); @@ -402,12 +415,6 @@ public class SeqCanvas startRes += cWidth; - endx = (startRes + cWidth) - 1; - - if (endx > al.getWidth()) - { - endx = al.getWidth(); - } } } @@ -424,7 +431,7 @@ public class SeqCanvas return annotations.adjustPanelHeight(); } - synchronized public void drawPanel(Graphics g, int startRes, int endRes, int startSeq, int endSeq, int offset) + void drawPanel(Graphics g, int startRes, int endRes, int startSeq, int endSeq, int offset) { g.setFont(av.getFont()); @@ -438,15 +445,12 @@ public class SeqCanvas nextSeq = av.alignment.getSequenceAt(i); sr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq), startRes, endRes, - (startRes - startRes) * av.charWidth, - offset + - (i - startSeq) * av.charHeight, - av.charWidth, av.charHeight); + offset + ( (i - startSeq) * av.charHeight)); if (av.showSequenceFeatures) { fr.drawSequence(g, nextSeq, startRes, endRes, - offset +(i - startSeq) * av.charHeight, + offset + ((i - startSeq) * av.charHeight), av.charWidth, av.charHeight); } /// Highlight search Results once all sequences have been drawn @@ -464,164 +468,174 @@ public class SeqCanvas av.charWidth, av.charHeight); } } + + if (av.cursorMode && cursorY == i + && cursorX >= startRes && cursorX <= endRes) + { + sr.drawCursor(nextSeq, cursorX, (cursorX - startRes) * av.charWidth, + offset + ( (i - startSeq) * av.charHeight)); + } + } - ///////////////////////////////////// + // + ///////////////////////////////////// + // Now outline any areas if necessary + ///////////////////////////////////// + SequenceGroup group = av.getSelectionGroup(); - // Now outline any areas if necessary - ///////////////////////////////////// - SequenceGroup group = av.getSelectionGroup(); - java.util.Vector groups = av.alignment.getGroups(); + int sx = -1; + int sy = -1; + int ex = -1; + int groupIndex = -1; - int sx = -1, sy = -1, ex = -1; - int groupIndex = -1; - if (group == null && groups.size() > 0) - { - group = (SequenceGroup) groups.elementAt(0); + if ((group == null) && (av.alignment.getGroups().size() > 0)) + { + group = (SequenceGroup) av.alignment.getGroups().elementAt(0); groupIndex = 0; - } - if (group != null) - { - do - { - int oldY = -1; - int i = 0; - boolean inGroup = false; - int top = -1; - int bottom = -1; + } - for (i = startSeq; i < endSeq; i++) - { - sx = (group.getStartRes() - startRes) * av.charWidth; - sy = offset + ((i - startSeq) * av.charHeight); - ex = (((group.getEndRes() + 1) - group.getStartRes()) * av.charWidth) - - 1; + if ( group != null ) + { + do + { + int oldY = -1; + int i = 0; + boolean inGroup = false; + int top = -1; + int bottom = -1; + int alHeight = av.alignment.getHeight()-1; + + for (i = startSeq; i < endSeq; i++) + { + sx = (group.getStartRes() - startRes) * av.charWidth; + sy = offset + ((i - startSeq) * av.charHeight); + ex = (((group.getEndRes() + 1) - group.getStartRes()) * av.charWidth) - + 1; + + if(sx+ex<0 || sx>imgWidth) + { + continue; + } - if(sx+ex<0 || sx>imgWidth) + if ( (sx <= (endRes-startRes)*av.charWidth) && + group.sequences.contains(av.alignment.getSequenceAt( + i))) + { + if ( (bottom == -1) && + (i >= alHeight || + !group.sequences.contains( + av.alignment.getSequenceAt(i + 1)))) { - continue; + bottom = sy + av.charHeight; } - if ( (sx <= (endRes-startRes)*av.charWidth) && - group.sequences.contains(av.alignment.getSequenceAt( - i))) + 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 + { + if (inGroup) { + if (sx >= 0 && sx < imgWidth) + g.drawLine(sx, oldY, sx, sy); - if (bottom == -1) - { - if(i == endSeq-1 || // Dont check for i+1 if on the bottom row - !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 - { - if (inGroup) + if (sx + ex < imgWidth) + g.drawLine(sx + ex, oldY, sx + ex, sy); + + if (sx < 0) { - 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 >= (endRes - startRes + 1) * av.charWidth) - ex = (endRes - startRes + 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; - } - } - } + ex += sx; + sx = 0; + } - if (inGroup) - { - sy = offset + ( (i - startSeq) * av.charHeight); - if (sx >= 0 && sx < imgWidth) - g.drawLine(sx, oldY, sx, sy); + if (sx + ex > imgWidth) + ex = imgWidth; - if (sx + ex < imgWidth) - g.drawLine(sx + ex, oldY, sx + ex, sy); + else if (sx + ex >= (endRes - startRes + 1) * av.charWidth) + ex = (endRes - startRes + 1) * av.charWidth; - if (sx < 0) - { - ex += sx; - sx = 0; - } + if (top != -1) + { + g.drawLine(sx, top, sx + ex, top); + top = -1; + } - if (sx + ex > imgWidth) - ex = imgWidth; - else if (sx + ex >= (endRes - startRes + 1) * av.charWidth) - ex = (endRes - startRes + 1) * av.charWidth; + if (bottom != -1) + { + g.drawLine(sx, bottom, sx + ex, bottom); + 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; - } + if (inGroup) + { + sy = offset + ( (i - startSeq) * av.charHeight); + if (sx >= 0 && sx < imgWidth) + g.drawLine(sx, oldY, sx, sy); - inGroup = false; + if (sx + ex < imgWidth) + g.drawLine(sx + ex, oldY, sx + ex, sy); + + if (sx < 0) + { + ex += sx; + sx = 0; } - groupIndex++; + if (sx + ex > imgWidth) + ex = imgWidth; + else if (sx + ex >= (endRes - startRes + 1) * av.charWidth) + ex = (endRes - startRes + 1) * av.charWidth; - if (groupIndex >= groups.size()) + if (top != -1) { - break; + g.drawLine(sx, top, sx + ex, top); + top = -1; } - group = (SequenceGroup) groups.elementAt(groupIndex); - } - while (groupIndex < groups.size()); + if (bottom != -1) + { + g.drawLine(sx, bottom - 1, sx + ex, bottom - 1); + bottom = -1; + } + + inGroup = false; + } + + groupIndex++; + + if (groupIndex >= av.alignment.getGroups().size()) + { + break; + } + + group = (SequenceGroup) av.alignment.getGroups().elementAt(groupIndex); + } + while (groupIndex < av.alignment.getGroups().size()); } }