X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSeqCanvas.java;h=a052ae3db1f4b968fc6eb81a97779aeaf397daf8;hb=daf64249356f9a156423bd56ab0336d9da2e5325;hp=a6219897200cb55a7b1cf036d8b93e2b8cbd4ff7;hpb=52402128d98c6744eb6348dd788fe6e8cd34575c;p=jalview.git diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index a621989..a052ae3 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -21,11 +21,14 @@ package jalview.gui; import jalview.datamodel.AlignmentI; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.renderer.ScaleRenderer; import jalview.renderer.ScaleRenderer.ScaleMark; +import jalview.viewmodel.ViewportListenerI; +import jalview.viewmodel.ViewportRanges; import java.awt.BasicStroke; import java.awt.BorderLayout; @@ -36,6 +39,7 @@ import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.Shape; import java.awt.image.BufferedImage; +import java.beans.PropertyChangeEvent; import java.util.List; import javax.swing.JComponent; @@ -46,7 +50,7 @@ import javax.swing.JComponent; * @author $author$ * @version $Revision$ */ -public class SeqCanvas extends JComponent +public class SeqCanvas extends JComponent implements ViewportListenerI { final FeatureRenderer fr; @@ -62,8 +66,6 @@ public class SeqCanvas extends JComponent AlignViewport av; - SearchResultsI searchResults = null; - boolean fastPaint = false; int LABEL_WEST; @@ -89,6 +91,8 @@ public class SeqCanvas extends JComponent setLayout(new BorderLayout()); PaintRefresher.Register(this, av.getSequenceSetId()); setBackground(Color.white); + + av.getRanges().addPropertyChangeListener(this); } public SequenceRenderer getSequenceRenderer() @@ -140,9 +144,9 @@ public class SeqCanvas extends JComponent { 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); } } } @@ -166,14 +170,17 @@ public class SeqCanvas extends JComponent if (av.hasHiddenColumns()) { - startx = av.getColumnSelection().adjustForHiddenColumns(startx); - endx = av.getColumnSelection().adjustForHiddenColumns(endx); + startx = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(startx); + endx = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(endx); } int maxwidth = av.getAlignment().getWidth(); if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } // WEST SCALE @@ -201,8 +208,8 @@ public class SeqCanvas extends JComponent { 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)); } } } @@ -225,7 +232,8 @@ public class SeqCanvas extends JComponent if (av.hasHiddenColumns()) { - endx = av.getColumnSelection().adjustForHiddenColumns(endx); + endx = av.getAlignment().getHiddenColumns() + .adjustForHiddenColumns(endx); } SequenceI seq; @@ -252,8 +260,8 @@ public class SeqCanvas extends JComponent 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)); } } } @@ -278,46 +286,47 @@ public class SeqCanvas extends JComponent fastpainting = true; fastPaint = true; updateViewport(); - gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth, - imgHeight, -horizontal * charWidth, -vertical * charHeight); - int sr = av.startRes; - int er = av.endRes; - int ss = av.startSeq; - int es = av.endSeq; + ViewportRanges ranges = av.getRanges(); + int sr = ranges.getStartRes(); + int er = ranges.getEndRes(); + int ss = ranges.getStartSeq(); + int es = ranges.getEndSeq(); int transX = 0; int transY = 0; + gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth, + imgHeight, -horizontal * charWidth, -vertical * charHeight); + if (horizontal > 0) // scrollbar pulled right, image to the left { - er++; transX = (er - sr - horizontal) * charWidth; sr = er - horizontal; } else if (horizontal < 0) { - er = sr - horizontal - 1; + er = sr - horizontal; } else if (vertical > 0) // scroll down { ss = es - vertical; - if (ss < av.startSeq) + if (ss < ranges.getStartSeq()) { // ie scrolling too fast, more than a page at a time - ss = av.startSeq; + ss = ranges.getStartSeq(); } else { - transY = imgHeight - (vertical * charHeight); + transY = imgHeight - ((vertical + 1) * charHeight); } } else if (vertical < 0) { es = ss - vertical; - if (es > av.endSeq) + if (es > ranges.getEndSeq()) { - es = av.endSeq; + es = ranges.getEndSeq(); } } @@ -347,10 +356,9 @@ public class SeqCanvas extends JComponent // 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; @@ -397,13 +405,15 @@ public class SeqCanvas extends JComponent gg.setColor(Color.white); gg.fillRect(0, 0, imgWidth, imgHeight); + ViewportRanges ranges = av.getRanges(); if (av.getWrapAlignment()) { - drawWrappedPanel(gg, getWidth(), getHeight(), av.startRes); + drawWrappedPanel(gg, getWidth(), getHeight(), ranges.getStartRes()); } else { - drawPanel(gg, av.startRes, av.endRes, av.startSeq, av.endSeq, 0); + drawPanel(gg, ranges.getStartRes(), ranges.getEndRes(), + ranges.getStartSeq(), ranges.getEndSeq(), 0); } g.drawImage(lcimg, 0, 0, this); @@ -484,6 +494,9 @@ public class SeqCanvas extends JComponent FontMetrics fm = getFontMetrics(av.getFont()); + LABEL_EAST = 0; + LABEL_WEST = 0; + if (av.getScaleRightWrapped()) { LABEL_EAST = fm.stringWidth(getMask()); @@ -505,15 +518,16 @@ public class SeqCanvas extends JComponent av.setWrappedWidth(cWidth); - av.endRes = av.startRes + cWidth; + 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.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth); } while ((ypos <= canvasHeight) && (startRes < maxwidth)) @@ -551,11 +565,11 @@ public class SeqCanvas extends JComponent { g.setColor(Color.blue); int res; - for (int i = 0; i < av.getColumnSelection().getHiddenColumns() - .size(); i++) + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); + List positions = hidden.findHiddenRegionPositions(); + for (int pos : positions) { - res = av.getColumnSelection().findHiddenRegionPosition(i) - - startRes; + res = pos - startRes; if (res < 0 || res > endx - startRes) { @@ -563,10 +577,12 @@ public class SeqCanvas extends JComponent } 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); } @@ -586,7 +602,7 @@ public class SeqCanvas extends JComponent (int) clip.getBounds().getHeight()); } - drawPanel(g, startRes, endx, 0, al.getHeight(), ypos); + drawPanel(g, startRes, endx, 0, al.getHeight() - 1, ypos); if (av.isShowAnnotation()) { @@ -596,8 +612,8 @@ public class SeqCanvas extends JComponent 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); @@ -642,8 +658,8 @@ public class SeqCanvas extends JComponent * @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()) @@ -652,13 +668,12 @@ public class SeqCanvas extends JComponent } else { - List regions = av.getColumnSelection().getHiddenColumns(); - int screenY = 0; int blockStart = startRes; int blockEnd = endRes; - for (int[] region : regions) + for (int[] region : av.getAlignment().getHiddenColumns() + .getHiddenColumnsCopy()) { int hideStart = region[0]; int hideEnd = region[1]; @@ -681,7 +696,7 @@ public class SeqCanvas extends JComponent g1.drawLine((blockEnd - blockStart + 1) * charWidth - 1, 0 + offset, (blockEnd - blockStart + 1) * charWidth - 1, - (endSeq - startSeq) * charHeight + offset); + (endSeq - startSeq + 1) * charHeight + offset); } g1.translate(-screenY * charWidth, 0); @@ -720,7 +735,7 @@ public class SeqCanvas extends JComponent // / First draw the sequences // /////////////////////////// - for (int i = startSeq; i < endSeq; i++) + for (int i = startSeq; i <= endSeq; i++) { nextSeq = av.getAlignment().getSequenceAt(i); if (nextSeq == null) @@ -734,24 +749,24 @@ public class SeqCanvas extends JComponent if (av.isShowSequenceFeatures()) { - fr.drawSequence(g, nextSeq, startRes, endRes, offset - + ((i - startSeq) * charHeight)); + fr.drawSequence(g, nextSeq, startRes, endRes, + offset + ((i - startSeq) * charHeight), false); } // / Highlight search Results once all sequences have been drawn // //////////////////////////////////////////////////////// - if (searchResults != null) + if (av.hasSearchResults()) { - int[] visibleResults = searchResults.getResults(nextSeq, startRes, - endRes); + int[] visibleResults = av.getSearchResults().getResults(nextSeq, + startRes, endRes); if (visibleResults != null) { 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)); } } } @@ -804,11 +819,12 @@ public class SeqCanvas extends JComponent int top = -1; int bottom = -1; - for (i = startSeq; i < endSeq; i++) + for (i = startSeq; i <= endSeq; i++) { 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) { @@ -816,21 +832,19 @@ public class SeqCanvas extends JComponent } 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; } @@ -841,8 +855,8 @@ public class SeqCanvas extends JComponent 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 @@ -969,8 +983,58 @@ public class SeqCanvas extends JComponent { img = null; - searchResults = results; + av.setSearchResults(results); repaint(); } + + @Override + public void propertyChange(PropertyChangeEvent evt) + { + String eventName = evt.getPropertyName(); + + if (av.getWrapAlignment()) + { + if (eventName.equals(ViewportRanges.STARTRES)) + { + repaint(); + } + } + else + { + int scrollX = 0; + if (eventName.equals(ViewportRanges.STARTRES)) + { + // Make sure we're not trying to draw a panel + // larger than the visible window + ViewportRanges vpRanges = av.getRanges(); + scrollX = (int) evt.getNewValue() - (int) evt.getOldValue(); + int range = vpRanges.getEndRes() - vpRanges.getStartRes(); + if (scrollX > range) + { + scrollX = range; + } + else if (scrollX < -range) + { + scrollX = -range; + } + } + + // 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)) + { + // scroll - startres and endres both change + fastPaint(scrollX, 0); + } + else if (eventName.equals(ViewportRanges.STARTSEQ)) + { + // scroll + fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue()); + } + } + } }