import jalview.datamodel.AlignmentI;
import jalview.datamodel.HiddenColumns;
-import jalview.datamodel.SearchResults;
import jalview.datamodel.SearchResultsI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
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;
}
/*
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)
{
}
}
- 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