X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FSeqCanvas.java;h=89df11f67ad932b15b70c80404e09957db6eb12b;hb=10eedfb43dacd4cf32d4b5fe27d8d5987c70eaf8;hp=7689535dcf747428206d0af5025d71fd02264abf;hpb=17e77c3f2949a0729322b4a8d907f3f34b6a9914;p=jalview.git diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 7689535..89df11f 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9) - * Copyright (C) 2015 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -21,10 +21,13 @@ package jalview.appletgui; import jalview.datamodel.AlignmentI; -import jalview.datamodel.SearchResults; +import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.renderer.ScaleRenderer; +import jalview.renderer.ScaleRenderer.ScaleMark; import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.ViewportRanges; import java.awt.Color; import java.awt.FontMetrics; @@ -48,8 +51,6 @@ public class SeqCanvas extends Panel AlignViewport av; - SearchResults searchResults = null; - boolean fastPaint = false; int cursorX = 0; @@ -90,26 +91,29 @@ public class SeqCanvas extends Panel private void drawNorthScale(Graphics g, int startx, int endx, int ypos) { - int scalestartx = startx - startx % 10 + 10; - + updateViewport(); g.setColor(Color.black); - - // NORTH SCALE - for (int i = scalestartx; i < endx; i += 10) + for (ScaleMark mark : new ScaleRenderer().calculateMarks(av, startx, + endx)) { - int value = i; - if (av.hasHiddenColumns()) + int mpos = mark.column; // (i - startx - 1) + if (mpos < 0) { - value = av.getColumnSelection().adjustForHiddenColumns(value); + continue; } + String mstring = mark.text; - g.drawString(String.valueOf(value), (i - startx - 1) * avcharWidth, - ypos - (avcharHeight / 2)); - - g.drawLine(((i - startx - 1) * avcharWidth) + (avcharWidth / 2), - (ypos + 2) - (avcharHeight / 2), - ((i - startx - 1) * avcharWidth) + (avcharWidth / 2), - ypos - 2); + if (mark.major) + { + if (mstring != null) + { + g.drawString(mstring, mpos * avcharWidth, ypos + - (avcharHeight / 2)); + } + g.drawLine((mpos * avcharWidth) + (avcharWidth / 2), (ypos + 2) + - (avcharHeight / 2), (mpos * avcharWidth) + + (avcharWidth / 2), ypos - 2); + } } } @@ -208,17 +212,19 @@ public class SeqCanvas extends Panel return; } + ViewportRanges ranges = av.getRanges(); + updateViewport(); // 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) + if (lastsr + horizontal != ranges.getStartRes()) { - horizontal = av.startRes - lastsr; + horizontal = ranges.getStartRes() - lastsr; } - lastsr = av.startRes; + lastsr = ranges.getStartRes(); fastPaint = true; gg.copyArea(horizontal * avcharWidth, vertical * avcharHeight, imgWidth @@ -226,7 +232,9 @@ public class SeqCanvas extends Panel imgHeight - vertical * avcharHeight, -horizontal * avcharWidth, -vertical * avcharHeight); - int sr = av.startRes, er = av.endRes, ss = av.startSeq, es = av.endSeq, transX = 0, transY = 0; + int sr = ranges.getStartRes(), er = ranges.getEndRes(), ss = ranges + .getStartSeq(), es = ranges + .getEndSeq(), transX = 0, transY = 0; if (horizontal > 0) // scrollbar pulled right, image to the left { @@ -241,21 +249,23 @@ public class SeqCanvas extends Panel else if (vertical > 0) // scroll down { ss = es - vertical; - if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time + 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 * avcharHeight; + transY = imgHeight - ((vertical + 1) * avcharHeight); } } else if (vertical < 0) { es = ss - vertical; - if (es > av.endSeq) + if (es > ranges.getEndSeq()) { - es = av.endSeq; + es = ranges.getEndSeq(); } } @@ -276,6 +286,7 @@ public class SeqCanvas extends Panel * at 0). NOTE 1: The av limits are set in setFont in this class and in the * adjustment listener in SeqPanel when the scrollbars move. */ + @Override public void update(Graphics g) { paint(g); @@ -325,13 +336,16 @@ public class SeqCanvas extends Panel gg.setColor(Color.white); gg.fillRect(0, 0, imgWidth, imgHeight); + ViewportRanges ranges = av.getRanges(); + if (av.getWrapAlignment()) { - drawWrappedPanel(gg, imgWidth, imgHeight, av.startRes); + drawWrappedPanel(gg, imgWidth, imgHeight, 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(img, 0, 0, this); @@ -417,7 +431,7 @@ public class SeqCanvas extends Panel av.setWrappedWidth(cWidth); - av.endRes = av.startRes + cWidth; + av.getRanges().setEndRes(av.getRanges().getStartRes() + cWidth); int endx; int ypos = hgap; @@ -487,7 +501,7 @@ public class SeqCanvas extends Panel g.setClip(0, 0, cWidth * avcharWidth, canvasHeight); } - drawPanel(g, startRes, endx, 0, al.getHeight(), ypos); + drawPanel(g, startRes, endx, 0, al.getHeight() - 1, ypos); g.setClip(null); if (av.isShowAnnotation()) @@ -566,17 +580,24 @@ public class SeqCanvas extends Panel g1.setColor(Color.blue); g1.drawLine((blockEnd - blockStart + 1) * avcharWidth - 1, 0 + offset, (blockEnd - blockStart + 1) * avcharWidth - - 1, (endSeq - startSeq) * avcharHeight + - 1, (endSeq - startSeq + 1) * avcharHeight + offset); } g1.translate(-screenY * avcharWidth, 0); screenY += blockEnd - blockStart + 1; blockStart = hideEnd + 1; + + if (screenY > (endRes - startRes)) + { + // already rendered last block + return; + } } } if (screenY <= (endRes - startRes)) { + // remaining visible region to render blockEnd = blockStart + (endRes - startRes) - screenY; g1.translate(screenY * avcharWidth, 0); draw(g1, blockStart, blockEnd, startSeq, endSeq, offset); @@ -599,7 +620,7 @@ public class SeqCanvas extends Panel // / First draw the sequences // /////////////////////////// - for (int i = startSeq; i < endSeq; i++) + for (int i = startSeq; i <= endSeq; i++) { nextSeq = av.getAlignment().getSequenceAt(i); @@ -614,14 +635,15 @@ public class SeqCanvas extends Panel if (av.isShowSequenceFeatures()) { fr.drawSequence(g, nextSeq, startRes, endRes, offset - + ((i - startSeq) * avcharHeight)); + + ((i - startSeq) * avcharHeight), false); } // / Highlight search Results once all sequences have been drawn // //////////////////////////////////////////////////////// - if (searchResults != null) + if (av.hasSearchResults()) { - int[] visibleResults = searchResults.getResults(nextSeq, startRes, + int[] visibleResults = av.getSearchResults().getResults(nextSeq, + startRes, endRes); if (visibleResults != null) { @@ -682,7 +704,7 @@ public class SeqCanvas extends Panel int bottom = -1; int alHeight = av.getAlignment().getHeight() - 1; - for (i = startSeq; i < endSeq; i++) + for (i = startSeq; i <= endSeq; i++) { sx = (group.getStartRes() - startRes) * avcharWidth; sy = offset + ((i - startSeq) * avcharHeight); @@ -830,10 +852,9 @@ public class SeqCanvas extends Panel } } - public void highlightSearchResults(SearchResults results) + public void highlightSearchResults(SearchResultsI results) { - searchResults = results; - + av.setSearchResults(results); repaint(); }