import jalview.datamodel.SearchResultsI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.VisibleContigsIterator;
import jalview.renderer.ScaleRenderer;
import jalview.renderer.ScaleRenderer.ScaleMark;
import jalview.util.Comparison;
import java.awt.Shape;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
+import java.util.Iterator;
import java.util.List;
-import javax.swing.JComponent;
+import javax.swing.JPanel;
/**
* The Swing component on which the alignment sequences, and annotations (if
* Wrapped mode, but not the scale above in Unwrapped mode.
*
*/
-public class SeqCanvas extends JComponent implements ViewportListenerI
+public class SeqCanvas extends JPanel implements ViewportListenerI
{
private static final String ZEROS = "0000000000";
private int wrappedVisibleWidths; // number of wrapped widths displayed
- private Graphics2D gg;
+ // Don't do this! Graphics handles are supposed to be transient
+ //private Graphics2D gg;
/**
* Creates a new SeqCanvas object.
for (ScaleMark mark : marks)
{
int mpos = mark.column; // (i - startx - 1)
+// System.out.println("n " + mpos + " " + ypos);
if (mpos < 0)
{
continue;
int yPos = ypos + charHeight;
int startX = startx;
int endX = endx;
+
+ //System.out.println("v " + startx + " " + endx + " " + ypos);
+
if (av.hasHiddenColumns())
{
HiddenColumns hiddenColumns = av.getAlignment().getHiddenColumns();
- startX = hiddenColumns.adjustForHiddenColumns(startx);
- endX = hiddenColumns.adjustForHiddenColumns(endx);
+ startX = hiddenColumns.visibleToAbsoluteColumn(startx);
+ endX = hiddenColumns.visibleToAbsoluteColumn(endx);
}
FontMetrics fm = getFontMetrics(av.getFont());
// fillRect origin is top left of rectangle
g.fillRect(0, y - charHeight, left ? labelWidthWest : labelWidthEast,
charHeight + 1);
-
+
if (value != -1)
{
/*
int xOffset = labelSpace - labelLength;
g.setColor(Color.black);
g.drawString(valueAsString, xOffset, y);
+
+ //System.out.println("v " + valueAsString + " " + xOffset + " " + y);
+
}
}
}
*/
public void fastPaint(int horizontal, int vertical)
{
- if (fastpainting || gg == null || img == null)
+ if (fastpainting || img == null)
{
return;
}
int endSeq = ranges.getEndSeq();
int transX = 0;
int transY = 0;
-
+
+ Graphics gg = img.getGraphics();
gg.copyArea(horizontal * charWidth, vertical * charHeight,
img.getWidth(), img.getHeight(), -horizontal * charWidth,
-vertical * charHeight);
gg.translate(transX, transY);
drawPanel(gg, startRes, endRes, startSeq, endSeq, 0);
gg.translate(-transX, -transY);
-
- repaint();
+ gg.dispose();
+
+ // Call repaint on alignment panel so that repaints from other alignment
+ // panel components can be aggregated. Otherwise performance of the
+ // overview window and others may be adversely affected.
+ av.getAlignPanel().repaint();
} finally
{
fastpainting = false;
@Override
public void paintComponent(Graphics g)
{
- super.paintComponent(g);
-
+ super.paintComponent(g);
+
int charHeight = av.getCharHeight();
int charWidth = av.getCharWidth();
height -= (height % charHeight);
// selectImage is the selection group outline image
- BufferedImage selectImage = drawSelectionGroup(
- ranges.getStartRes(), ranges.getEndRes(),
- ranges.getStartSeq(), ranges.getEndSeq());
+ BufferedImage selectImage = drawSelectionGroup(ranges.getStartRes(),
+ ranges.getEndRes(), ranges.getStartSeq(), ranges.getEndSeq());
if ((img != null) && (fastPaint
|| (getVisibleRect().width != g.getClipBounds().width)
{
return;
}
- gg = (Graphics2D) img.getGraphics();
- gg.setFont(av.getFont());
}
+
+ Graphics2D gg = (Graphics2D) img.getGraphics();
+ gg.setFont(av.getFont());
+
if (av.antiAlias)
{
gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
drawPanel(gg, ranges.getStartRes(), ranges.getEndRes(),
ranges.getStartSeq(), ranges.getEndSeq(), 0);
}
+
+
+ gg.dispose();
// lcimg is a local *copy* of img which we'll draw selectImage on top of
BufferedImage lcimg = buildLocalImage(selectImage);
private BufferedImage buildLocalImage(BufferedImage selectImage)
{
// clone the cached image
- BufferedImage lcimg = new BufferedImage(img.getWidth(), img.getHeight(),
- img.getType());
+ BufferedImage lcimg = new BufferedImage(img.getWidth(), img.getHeight(),
+ img.getType());
+
+ // BufferedImage lcimg = new BufferedImage(img.getWidth(), img.getHeight(),
+ // img.getType());
Graphics2D g2d = lcimg.createGraphics();
g2d.drawImage(img, 0, 0, null);
try
{
- lcimg = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB); // ARGB so alpha compositing works
+ lcimg = new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_ARGB); // ARGB so alpha compositing works
} catch (OutOfMemoryError er)
{
System.gc();
ViewportRanges ranges = av.getRanges();
ranges.setViewportStartAndWidth(startColumn, wrappedWidthInResidues);
+ // we need to call this again to make sure the startColumn +
+ // wrappedWidthInResidues values are used to calculate wrappedVisibleWidths
+ // correctly.
+ calculateWrappedGeometry(canvasWidth, canvasHeight);
+
/*
* draw one width at a time (including any scales or annotation shown),
* until we have run out of either alignment or vertical space available
if (av.getScaleRightWrapped())
{
int x = labelWidthWest + viewportWidth * charWidth;
+
+ //System.out.println("shifting " + x);
g.translate(x, 0);
drawVerticalScale(g, startCol, endColumn, ypos, false);
g.translate(-x, 0);
int charWidth = av.getCharWidth();
g.setColor(Color.blue);
+ int res;
HiddenColumns hidden = av.getAlignment().getHiddenColumns();
- List<Integer> positions = hidden.findHiddenRegionPositions();
- for (int pos : positions)
+
+ Iterator<Integer> it = hidden.getStartRegionIterator(startColumn,
+ endColumn);
+ while (it.hasNext())
{
- int res = pos - startColumn;
+ res = it.next() - startColumn;
if (res < 0 || res > endColumn - startColumn + 1)
{
if (av.hasHiddenColumns())
{
maxwidth = av.getAlignment().getHiddenColumns()
- .findColumnPosition(maxwidth);
+ .absoluteToVisibleColumn(maxwidth);
}
// chop the wrapped alignment extent up into panel-sized blocks and treat
else
{
int screenY = 0;
- final int screenYMax = endRes - startRes;
- int blockStart = startRes;
- int blockEnd = endRes;
+ int blockStart;
+ int blockEnd;
- for (int[] region : av.getAlignment().getHiddenColumns()
- .getHiddenColumnsCopy())
- {
- int hideStart = region[0];
- int hideEnd = region[1];
+ HiddenColumns hidden = av.getAlignment().getHiddenColumns();
+ VisibleContigsIterator regions = hidden
+ .getVisContigsIterator(startRes, endRes + 1, true);
- if (hideStart <= blockStart)
- {
- blockStart += (hideEnd - hideStart) + 1;
- continue;
- }
+ while (regions.hasNext())
+ {
+ int[] region = regions.next();
+ blockEnd = region[1];
+ blockStart = region[0];
/*
* draw up to just before the next hidden region, or the end of
* the visible region, whichever comes first
*/
- blockEnd = Math.min(hideStart - 1, blockStart + screenYMax
- - screenY);
-
g1.translate(screenY * charWidth, 0);
draw(g1, blockStart, blockEnd, startSeq, endSeq, yOffset);
* draw the downline of the hidden column marker (ScalePanel draws the
* triangle on top) if we reached it
*/
- if (av.getShowHiddenMarkers() && blockEnd == hideStart - 1)
+ if (av.getShowHiddenMarkers()
+ && (regions.hasNext() || regions.endsAtHidden()))
{
g1.setColor(Color.blue);
g1.translate(-screenY * charWidth, 0);
screenY += blockEnd - blockStart + 1;
- blockStart = hideEnd + 1;
-
- if (screenY > screenYMax)
- {
- // already rendered last block
- return;
- }
- }
-
- if (screenY <= screenYMax)
- {
- // remaining visible region to render
- blockEnd = blockStart + screenYMax - screenY;
- g1.translate(screenY * charWidth, 0);
- draw(g1, blockStart, blockEnd, startSeq, endSeq, yOffset);
-
- g1.translate(-screenY * charWidth, 0);
}
}
if (av.hasSearchResults())
{
SearchResultsI searchResults = av.getSearchResults();
- int[] visibleResults = searchResults.getResults(nextSeq,
- startRes, endRes);
+ int[] visibleResults = searchResults.getResults(nextSeq, startRes,
+ endRes);
if (visibleResults != null)
{
for (int r = 0; r < visibleResults.length; r += 2)
{
seqRdr.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));
}
}
}
if (group != null)
{
g.setStroke(new BasicStroke());
- g.setColor(group.getOutlineColour());
do
{
+ g.setColor(group.getOutlineColour());
drawPartialGroupOutline(g, group, startRes, endRes, startSeq,
endSeq, offset);
// convert the cursorX into a position on the visible alignment
int cursor_xpos = av.getAlignment().getHiddenColumns()
- .findColumnPosition(cursorX);
+ .absoluteToVisibleColumn(cursorX);
if (av.getAlignment().getHiddenColumns().isVisible(cursorX))
{
{
// package into blocks of visible columns
int screenY = 0;
- int blockStart = startRes;
- int blockEnd = endRes;
+ int blockStart;
+ int blockEnd;
- for (int[] region : av.getAlignment().getHiddenColumns()
- .getHiddenColumnsCopy())
+ HiddenColumns hidden = av.getAlignment().getHiddenColumns();
+ VisibleContigsIterator regions = hidden
+ .getVisContigsIterator(startRes, endRes + 1, true);
+ while (regions.hasNext())
{
- int hideStart = region[0];
- int hideEnd = region[1];
-
- if (hideStart <= blockStart)
- {
- blockStart += (hideEnd - hideStart) + 1;
- continue;
- }
-
- blockEnd = hideStart - 1;
+ int[] region = regions.next();
+ blockEnd = region[1];
+ blockStart = region[0];
g.translate(screenY * charWidth, 0);
drawPartialGroupOutline(g, group,
g.translate(-screenY * charWidth, 0);
screenY += blockEnd - blockStart + 1;
- blockStart = hideEnd + 1;
-
- if (screenY > (endRes - startRes))
- {
- // already rendered last block
- break;
- }
- }
-
- if (screenY <= (endRes - startRes))
- {
- // remaining visible region to render
- blockEnd = blockStart + (endRes - startRes) - screenY;
- g.translate(screenY * charWidth, 0);
- drawPartialGroupOutline(g, group,
- blockStart, blockEnd, startSeq, endSeq, offset);
-
- g.translate(-screenY * charWidth, 0);
}
}
}
* Highlights search results in the visible region by rendering as white text
* on a black background. Any previous highlighting is removed. Answers true
* if any highlight was left on the visible alignment (so status bar should be
+ * set to match), else false. This method does _not_ set the 'fastPaint' flag,
+ * so allows the next repaint to update the whole display.
+ *
+ * @param results
+ * @return
+ */
+ public boolean highlightSearchResults(SearchResultsI results)
+ {
+ return highlightSearchResults(results, false);
+
+ }
+
+ /**
+ * Highlights search results in the visible region by rendering as white text
+ * on a black background. Any previous highlighting is removed. Answers true
+ * if any highlight was left on the visible alignment (so status bar should be
* set to match), else false.
* <p>
- * Currently fastPaint is not implemented for wrapped alignments. If a wrapped
- * alignment had to be scrolled to show the highlighted region, then it should
- * be fully redrawn, otherwise a fast paint can be performed. This argument
- * could be removed if fast paint of scrolled wrapped alignment is coded in
- * future (JAL-2609).
+ * Optionally, set the 'fastPaint' flag for a faster redraw if only the
+ * highlighted regions are modified. This speeds up highlighting across linked
+ * alignments.
+ * <p>
+ * Currently fastPaint is not implemented for scrolled wrapped alignments. If
+ * a wrapped alignment had to be scrolled to show the highlighted region, then
+ * it should be fully redrawn, otherwise a fast paint can be performed. This
+ * argument could be removed if fast paint of scrolled wrapped alignment is
+ * coded in future (JAL-2609).
*
* @param results
- * @param noFastPaint
+ * @param doFastPaint
+ * if true, sets a flag so the next repaint only redraws the modified
+ * image
* @return
*/
public boolean highlightSearchResults(SearchResultsI results,
- boolean noFastPaint)
+ boolean doFastPaint)
{
if (fastpainting)
{
boolean wrapped = av.getWrapAlignment();
try
{
- fastPaint = !noFastPaint;
+ fastPaint = doFastPaint;
fastpainting = fastPaint;
/*
*/
protected boolean drawMappedPositions(SearchResultsI results)
{
- if ((results == null) || (gg == null)) // JAL-2784 check gg is not null
+ if ((results == null) || (img == null)) // JAL-2784 check gg is not null
{
return false;
}
if (av.hasHiddenColumns())
{
firstVisibleColumn = alignment.getHiddenColumns()
- .adjustForHiddenColumns(firstVisibleColumn);
+ .visibleToAbsoluteColumn(firstVisibleColumn);
lastVisibleColumn = alignment.getHiddenColumns()
- .adjustForHiddenColumns(lastVisibleColumn);
+ .visibleToAbsoluteColumn(lastVisibleColumn);
}
for (int seqNo = ranges.getStartSeq(); seqNo <= ranges
if (av.hasHiddenColumns())
{
firstCol = alignment.getHiddenColumns()
- .findColumnPosition(firstCol);
- lastCol = alignment.getHiddenColumns().findColumnPosition(lastCol);
+ .absoluteToVisibleColumn(firstCol);
+ lastCol = alignment.getHiddenColumns().absoluteToVisibleColumn(lastCol);
}
int transX = (firstCol - ranges.getStartRes()) * av.getCharWidth();
int transY = (firstSeq - ranges.getStartSeq()) * av.getCharHeight();
+ Graphics gg = img.getGraphics();
gg.translate(transX, transY);
drawPanel(gg, firstCol, lastCol, firstSeq, lastSeq, 0);
gg.translate(-transX, -transY);
+ gg.dispose();
}
return matchFound;
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))
- {
- if (av.getWrapAlignment())
+ // 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))
+ {
+ if (av.getWrapAlignment())
+ {
+ fastPaintWrapped(scrollX);
+ }
+ else
+ {
+ fastPaint(scrollX, 0);
+ }
+ }
+ else if (eventName.equals(ViewportRanges.STARTSEQ))
+ {
+ // scroll
+ fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue());
+ }
+ else if (eventName.equals(ViewportRanges.STARTRESANDSEQ))
+ {
+ if (av.getWrapAlignment())
{
fastPaintWrapped(scrollX);
}
{
fastPaintWrapped(scrollX);
}
- else
- {
- fastPaint(scrollX, 0);
- }
- // bizarrely, we only need to scroll on the x value here as fastpaint
- // copies the full height of the image anyway. Passing in the y value
- // causes nasty repaint artefacts, which only disappear on a full
- // repaint.
}
}
{
ViewportRanges ranges = av.getRanges();
- // if (Math.abs(scrollX) > ranges.getViewportWidth())
- // JAL-2836, 2836 temporarily removed wrapped fastpaint for release 2.10.3
- if (true)
+ if (Math.abs(scrollX) > ranges.getViewportWidth())
{
/*
* shift of more than one view width is
return;
}
- if (fastpainting || gg == null)
+ if (fastpainting || img == null)
{
return;
}
try
{
+
+ Graphics gg = img.getGraphics();
+
calculateWrappedGeometry(getWidth(), getHeight());
/*
*/
drawWrappedDecorators(gg, ranges.getStartRes());
+ gg.dispose();
+
repaint();
} finally
{
return;
}
+ Graphics gg = img.getGraphics();
+
ViewportRanges ranges = av.getRanges();
int viewportWidth = ranges.getViewportWidth();
int charWidth = av.getCharWidth();
/*
* white fill first to erase annotations
*/
+
+
gg.translate(xOffset, 0);
gg.setColor(Color.white);
gg.fillRect(labelWidthWest, ypos,
gg.translate(-xOffset, 0);
drawWrappedWidth(gg, ypos, startRes, endRes, canvasHeight);
+
}
/*
gg.setColor(Color.white);
gg.fillRect(0, canvasHeight - heightBelow, getWidth(), heightBelow);
}
- }
+ gg.dispose();
+ }
/**
* Shifts the visible alignment by the specified number of columns - left if
{
return;
}
+
+ Graphics gg = img.getGraphics();
+
int charWidth = av.getCharWidth();
int canvasHeight = getHeight();
* charWidth, heightToCopy, widthToCopy,
-wrappedRepeatHeightPx);
}
-
y += wrappedRepeatHeightPx;
xpos += viewportWidth;
}
}
+ gg.dispose();
}
*/
protected boolean drawMappedPositionsWrapped(SearchResultsI results)
{
- if ((results == null) || (gg == null)) // JAL-2784 check gg is not null
+ if ((results == null) || (img == null)) // JAL-2784 check gg is not null
{
return false;
}
if (av.hasHiddenColumns())
{
firstVisibleColumn = alignment.getHiddenColumns()
- .adjustForHiddenColumns(firstVisibleColumn);
+ .visibleToAbsoluteColumn(firstVisibleColumn);
lastVisibleColumn = alignment.getHiddenColumns()
- .adjustForHiddenColumns(lastVisibleColumn);
+ .visibleToAbsoluteColumn(lastVisibleColumn);
}
int gapHeight = charHeight * (av.getScaleAboveWrapped() ? 2 : 1);
+
+ Graphics gg = img.getGraphics();
+
for (int seqNo = ranges.getStartSeq(); seqNo <= ranges
.getEndSeq(); seqNo++)
{
if (av.hasHiddenColumns())
{
displayColumn = alignment.getHiddenColumns()
- .findColumnPosition(displayColumn);
+ .absoluteToVisibleColumn(displayColumn);
}
/*
}
}
+ gg.dispose();
+
return matchFound;
}