X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSeqCanvas.java;h=a052ae3db1f4b968fc6eb81a97779aeaf397daf8;hb=a990c2c6facfd04d61d316dcafba31d03747d162;hp=f1b473cff43f4106c5474ba9de11f3b9259e521e;hpb=bef980d8536bd7da240abcbf357e3ed3b064b523;p=jalview.git diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index f1b473c..a052ae3 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -144,9 +144,9 @@ public class SeqCanvas extends JComponent implements ViewportListenerI { g.drawString(mstring, mpos * charWidth, ypos - (charHeight / 2)); } - g.drawLine((mpos * charWidth) + (charWidth / 2), (ypos + 2) - - (charHeight / 2), (mpos * charWidth) + (charWidth / 2), - ypos - 2); + g.drawLine((mpos * charWidth) + (charWidth / 2), + (ypos + 2) - (charHeight / 2), + (mpos * charWidth) + (charWidth / 2), ypos - 2); } } } @@ -208,8 +208,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI { int x = LABEL_WEST - fm.stringWidth(String.valueOf(value)) - charWidth / 2; - g.drawString(value + "", x, (ypos + (i * charHeight)) - - (charHeight / 5)); + g.drawString(value + "", x, + (ypos + (i * charHeight)) - (charHeight / 5)); } } } @@ -260,8 +260,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI if (value != -1) { - g.drawString(String.valueOf(value), 0, (ypos + (i * charHeight)) - - (charHeight / 5)); + g.drawString(String.valueOf(value), 0, + (ypos + (i * charHeight)) - (charHeight / 5)); } } } @@ -277,7 +277,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI * @param vertical * shift up or down in repaint */ - public void fastPaint(int horizontal, int vertical, boolean isresize) + public void fastPaint(int horizontal, int vertical) { if (fastpainting || gg == null) { @@ -295,71 +295,38 @@ public class SeqCanvas extends JComponent implements ViewportListenerI int transX = 0; int transY = 0; - if (isresize) - { - imgWidth = getWidth(); - imgHeight = getHeight(); - - imgWidth -= (imgWidth % charWidth); - imgHeight -= (imgHeight % charHeight); - - if ((imgWidth > 0) && (imgHeight > 0)) - { - BufferedImage newimg = new BufferedImage(imgWidth, imgHeight, - BufferedImage.TYPE_INT_ARGB); - - gg = (Graphics2D) newimg.getGraphics(); - gg.setFont(av.getFont()); - gg.drawImage(img, null, 0, 0); - img = newimg; + gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth, + imgHeight, -horizontal * charWidth, -vertical * charHeight); - if (horizontal != 0) - { - transX = (er - horizontal - sr) * charWidth; - sr = er - horizontal - sr; - } - else if (vertical != 0) - { - transY = imgHeight - ((vertical + 1) * charHeight); - ss = es - vertical - ss; - } - } + if (horizontal > 0) // scrollbar pulled right, image to the left + { + transX = (er - sr - horizontal) * charWidth; + sr = er - horizontal; } - else + else if (horizontal < 0) + { + er = sr - horizontal; + } + else if (vertical > 0) // scroll down { - gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth, - imgHeight, -horizontal * charWidth, -vertical * charHeight); + ss = es - vertical; - if (horizontal > 0) // scrollbar pulled right, image to the left - { - transX = (er - sr - horizontal) * charWidth; - sr = er - horizontal; + if (ss < ranges.getStartSeq()) + { // ie scrolling too fast, more than a page at a time + ss = ranges.getStartSeq(); } - else if (horizontal < 0) + else { - er = sr - horizontal; + transY = imgHeight - ((vertical + 1) * charHeight); } - else if (vertical > 0) // scroll down - { - ss = es - vertical; + } + else if (vertical < 0) + { + es = ss - vertical; - if (ss < ranges.getStartSeq()) - { // ie scrolling too fast, more than a page at a time - ss = ranges.getStartSeq(); - } - else - { - transY = imgHeight - ((vertical + 1) * charHeight); - } - } - else if (vertical < 0) + if (es > ranges.getEndSeq()) { - es = ss - vertical; - - if (es > ranges.getEndSeq()) - { - es = ranges.getEndSeq(); - } + es = ranges.getEndSeq(); } } @@ -389,10 +356,9 @@ public class SeqCanvas extends JComponent implements ViewportListenerI // img and call later. super.paintComponent(g); - if (lcimg != null - && (fastPaint - || (getVisibleRect().width != g.getClipBounds().width) || (getVisibleRect().height != g - .getClipBounds().height))) + if (lcimg != null && (fastPaint + || (getVisibleRect().width != g.getClipBounds().width) + || (getVisibleRect().height != g.getClipBounds().height))) { g.drawImage(lcimg, 0, 0, this); fastPaint = false; @@ -528,6 +494,9 @@ public class SeqCanvas extends JComponent implements ViewportListenerI FontMetrics fm = getFontMetrics(av.getFont()); + LABEL_EAST = 0; + LABEL_WEST = 0; + if (av.getScaleRightWrapped()) { LABEL_EAST = fm.stringWidth(getMask()); @@ -549,16 +518,16 @@ public class SeqCanvas extends JComponent implements ViewportListenerI av.setWrappedWidth(cWidth); - av.getRanges().setEndRes(av.getRanges().getStartRes() + cWidth - 1); + av.getRanges().setViewportStartAndWidth(startRes, cWidth); int endx; int ypos = hgap; - int maxwidth = av.getAlignment().getWidth() - 1; + int maxwidth = av.getAlignment().getWidth(); if (av.hasHiddenColumns()) { maxwidth = av.getAlignment().getHiddenColumns() - .findColumnPosition(maxwidth) - 1; + .findColumnPosition(maxwidth); } while ((ypos <= canvasHeight) && (startRes < maxwidth)) @@ -608,10 +577,12 @@ public class SeqCanvas extends JComponent implements ViewportListenerI } gg.fillPolygon( - new int[] { res * charWidth - charHeight / 4, + new int[] + { res * charWidth - charHeight / 4, res * charWidth + charHeight / 4, res * charWidth }, - new int[] { ypos - (charHeight / 2), - ypos - (charHeight / 2), ypos - (charHeight / 2) + 8 }, + new int[] + { ypos - (charHeight / 2), ypos - (charHeight / 2), + ypos - (charHeight / 2) + 8 }, 3); } @@ -641,8 +612,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI annotations = new AnnotationPanel(av); } - annotations.renderer.drawComponent(annotations, av, g, -1, - startRes, endx + 1); + annotations.renderer.drawComponent(annotations, av, g, -1, startRes, + endx + 1); g.translate(0, -cHeight - ypos - 3); } g.setClip(clip); @@ -687,8 +658,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI * @param offset * DOCUMENT ME! */ - public void drawPanel(Graphics g1, int startRes, int endRes, - int startSeq, int endSeq, int offset) + public void drawPanel(Graphics g1, int startRes, int endRes, int startSeq, + int endSeq, int offset) { updateViewport(); if (!av.hasHiddenColumns()) @@ -778,8 +749,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI if (av.isShowSequenceFeatures()) { - fr.drawSequence(g, nextSeq, startRes, endRes, offset - + ((i - startSeq) * charHeight), false); + fr.drawSequence(g, nextSeq, startRes, endRes, + offset + ((i - startSeq) * charHeight), false); } // / Highlight search Results once all sequences have been drawn @@ -793,9 +764,9 @@ public class SeqCanvas extends JComponent implements ViewportListenerI for (int r = 0; r < visibleResults.length; r += 2) { sr.drawHighlightedText(nextSeq, visibleResults[r], - visibleResults[r + 1], (visibleResults[r] - startRes) - * charWidth, offset - + ((i - startSeq) * charHeight)); + visibleResults[r + 1], + (visibleResults[r] - startRes) * charWidth, + offset + ((i - startSeq) * charHeight)); } } } @@ -852,7 +823,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI { sx = (group.getStartRes() - startRes) * charWidth; sy = offset + ((i - startSeq) * charHeight); - ex = (((group.getEndRes() + 1) - group.getStartRes()) * charWidth) - 1; + ex = (((group.getEndRes() + 1) - group.getStartRes()) * charWidth) + - 1; if (sx + ex < 0 || sx > visWidth) { @@ -860,21 +832,19 @@ public class SeqCanvas extends JComponent implements ViewportListenerI } if ((sx <= (endRes - startRes) * charWidth) - && group.getSequences(null).contains( - av.getAlignment().getSequenceAt(i))) + && group.getSequences(null) + .contains(av.getAlignment().getSequenceAt(i))) { - if ((bottom == -1) - && !group.getSequences(null).contains( - av.getAlignment().getSequenceAt(i + 1))) + if ((bottom == -1) && !group.getSequences(null) + .contains(av.getAlignment().getSequenceAt(i + 1))) { bottom = sy + charHeight; } if (!inGroup) { - if (((top == -1) && (i == 0)) - || !group.getSequences(null).contains( - av.getAlignment().getSequenceAt(i - 1))) + if (((top == -1) && (i == 0)) || !group.getSequences(null) + .contains(av.getAlignment().getSequenceAt(i - 1))) { top = sy; } @@ -885,8 +855,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI if (group == av.getSelectionGroup()) { g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, - BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, - 0f)); + BasicStroke.JOIN_ROUND, 3f, new float[] + { 5f, 3f }, 0f)); g.setColor(Color.RED); } else @@ -1021,42 +991,49 @@ public class SeqCanvas extends JComponent implements ViewportListenerI @Override public void propertyChange(PropertyChangeEvent evt) { - if (!av.getWrapAlignment()) + String eventName = evt.getPropertyName(); + + if (av.getWrapAlignment()) { - if (evt.getPropertyName().equals("startres")) + if (eventName.equals(ViewportRanges.STARTRES)) + { + repaint(); + } + } + else + { + int scrollX = 0; + if (eventName.equals(ViewportRanges.STARTRES)) { - // scroll - startres and endres both change - // Make sure we're not trying to draw a panel // larger than the visible window ViewportRanges vpRanges = av.getRanges(); - int scrollX = (int) evt.getNewValue() - (int) evt.getOldValue(); - if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes()) + scrollX = (int) evt.getNewValue() - (int) evt.getOldValue(); + int range = vpRanges.getEndRes() - vpRanges.getStartRes(); + if (scrollX > range) { - scrollX = vpRanges.getEndRes() - vpRanges.getStartRes(); + scrollX = range; } - else if (scrollX < vpRanges.getStartRes() - vpRanges.getEndRes()) + else if (scrollX < -range) { - scrollX = vpRanges.getStartRes() - vpRanges.getEndRes(); + scrollX = -range; } - fastPaint(scrollX, 0, false); } - else if (evt.getPropertyName().equals("endres")) + + // Both scrolling and resizing change viewport ranges: scrolling changes + // both start and end points, but resize only changes end values. + // Here we only want to fastpaint on a scroll, with resize using a normal + // paint, so scroll events are identified as changes to the horizontal or + // vertical start value. + if (eventName.equals(ViewportRanges.STARTRES)) { - // resize - only endres changes - int scrollX = (int) evt.getNewValue() - (int) evt.getOldValue(); - fastPaint(scrollX, 0, true); + // scroll - startres and endres both change + fastPaint(scrollX, 0); } - else if (evt.getPropertyName().equals("startseq")) + else if (eventName.equals(ViewportRanges.STARTSEQ)) { // scroll - fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue(), false); - } - else if (evt.getPropertyName().equals("endseq")) - { - // resize - fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue(), - true); + fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue()); } } }