From 43141b2f7afda8dbb88090d0630574b1cdefb0eb Mon Sep 17 00:00:00 2001 From: gmungoc Date: Sat, 24 Jun 2017 06:48:27 +0100 Subject: [PATCH] JAL-1858 refactored method to redraw previous/new highlighted positions --- src/jalview/gui/SeqCanvas.java | 72 +++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 7035142..52e5849 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -22,7 +22,6 @@ package jalview.gui; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; -import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -1000,20 +999,43 @@ public class SeqCanvas extends JComponent implements ViewportListenerI fastpainting = true; fastPaint = true; - /* - * to avoid redrawing the whole visible region, we instead - * calculate the minimal redraw to remove previous highlights - * and add new ones; - * first make a temporary SearchResults that includes - * both the new and any existing search results - */ - SearchResultsI combined = results; - SearchResultsI previous = av.getSearchResults(); - if (previous != null) + try + { + /* + * to avoid redrawing the whole visible region, we instead + * redraw just the minimal regions to remove previous highlights + * and add new ones + */ + SearchResultsI previous = av.getSearchResults(); + av.setSearchResults(results); + boolean redrawn = drawMappedPositions(previous); + redrawn |= drawMappedPositions(results); + if (redrawn) + { + repaint(); + } + } finally + { + fastpainting = false; + } + } + + /** + * Redraws the minimal rectangle in the visible region (if any) that includes + * mapped positions of the given search results. Whether or not positions are + * highlighted depends on the SearchResults set on the Viewport. This allows + * this method to be called to either clear or set highlighting. Answers true + * if any positions were drawn (in which case a repaint is still required), + * else false. + * + * @param results + * @return + */ + protected boolean drawMappedPositions(SearchResultsI results) + { + if (results == null) { - combined = new SearchResults(); - combined.addSearchResults(results); - combined.addSearchResults(previous); + return false; } /* @@ -1029,20 +1051,21 @@ public class SeqCanvas extends JComponent implements ViewportListenerI ViewportRanges ranges = av.getRanges(); int firstVisibleColumn = ranges.getStartRes(); int lastVisibleColumn = ranges.getEndRes(); + AlignmentI alignment = av.getAlignment(); if (av.hasHiddenColumns()) { - firstVisibleColumn = av.getAlignment().getHiddenColumns() + firstVisibleColumn = alignment.getHiddenColumns() .adjustForHiddenColumns(firstVisibleColumn); - lastVisibleColumn = av.getAlignment().getHiddenColumns() + lastVisibleColumn = alignment.getHiddenColumns() .adjustForHiddenColumns(lastVisibleColumn); } for (int seqNo = ranges.getStartSeq(); seqNo <= ranges .getEndSeq(); seqNo++) { - SequenceI seq = av.getAlignment().getSequenceAt(seqNo); + SequenceI seq = alignment.getSequenceAt(seqNo); - int[] visibleResults = combined.getResults(seq, firstVisibleColumn, + int[] visibleResults = results.getResults(seq, firstVisibleColumn, lastVisibleColumn); if (visibleResults != null) { @@ -1072,27 +1095,22 @@ public class SeqCanvas extends JComponent implements ViewportListenerI } } - av.setSearchResults(results); - if (matchFound) { if (av.hasHiddenColumns()) { - firstCol = av.getAlignment().getHiddenColumns() + firstCol = alignment.getHiddenColumns() .findColumnPosition(firstCol); - lastCol = av.getAlignment().getHiddenColumns() - .findColumnPosition(lastCol); + lastCol = alignment.getHiddenColumns().findColumnPosition(lastCol); } - int transX = (firstCol - firstVisibleColumn) * av.getCharWidth(); + int transX = (firstCol - ranges.getStartRes()) * av.getCharWidth(); int transY = (firstSeq - ranges.getStartSeq()) * av.getCharHeight(); gg.translate(transX, transY); drawPanel(gg, firstCol, lastCol, firstSeq, lastSeq, 0); gg.translate(-transX, -transY); - - repaint(); } - fastpainting = false; // todo in finally block? + return matchFound; } @Override -- 1.7.10.2