+ g.dispose();
+ return selectionImage;
+ }
+
+ /*
+ * Set up graphics for selection group
+ */
+ private void setupSelectionGroup(Graphics2D g,
+ BufferedImage selectionImage)
+ {
+ // set background to transparent
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
+ g.fillRect(0, 0, selectionImage.getWidth(), selectionImage.getHeight());
+
+ // set up foreground to draw red dashed line
+ g.setComposite(AlphaComposite.Src);
+ g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
+ BasicStroke.JOIN_ROUND, 3f, new float[]
+ { 5f, 3f }, 0f));
+ g.setColor(Color.RED);
+ }
+
+ /*
+ * Draw a selection group over an unwrapped alignment
+ * @param g graphics object to draw with
+ * @param group selection group
+ * @param startRes start residue of area to draw
+ * @param endRes end residue of area to draw
+ * @param startSeq start sequence of area to draw
+ * @param endSeq end sequence of area to draw
+ * @param offset vertical offset (used when called from wrapped alignment code)
+ */
+ private void drawUnwrappedSelection(Graphics2D g, SequenceGroup group,
+ int startRes, int endRes, int startSeq, int endSeq, int offset)
+ {
+ if (!av.hasHiddenColumns())
+ {
+ drawPartialGroupOutline(g, group, startRes, endRes, startSeq, endSeq,
+ offset);
+ }
+ else
+ {
+ // package into blocks of visible columns
+ int screenY = 0;
+ int blockStart = startRes;
+ int blockEnd = endRes;
+
+ for (int[] region : av.getAlignment().getHiddenColumns()
+ .getHiddenColumnsCopy())
+ {
+ int hideStart = region[0];
+ int hideEnd = region[1];
+
+ if (hideStart <= blockStart)
+ {
+ blockStart += (hideEnd - hideStart) + 1;
+ continue;
+ }
+
+ blockEnd = hideStart - 1;
+
+ g.translate(screenY * charWidth, 0);
+ drawPartialGroupOutline(g, group,
+ blockStart, blockEnd, startSeq, endSeq, offset);
+
+ 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);
+ }
+ }
+ }
+
+ /*
+ * Draw the selection group as a separate image and overlay
+ */
+ private void drawPartialGroupOutline(Graphics2D g, SequenceGroup group,
+ int startRes, int endRes, int startSeq, int endSeq,
+ int verticalOffset)
+ {
+ int visWidth = (endRes - startRes + 1) * charWidth;
+
+ int oldY = -1;
+ int i = 0;
+ boolean inGroup = false;
+ int top = -1;
+ int bottom = -1;
+
+ int sx = -1;
+ int sy = -1;
+ int xwidth = -1;
+
+ for (i = startSeq; i <= endSeq; i++)
+ {
+ // position of start residue of group relative to startRes, in pixels
+ sx = (group.getStartRes() - startRes) * charWidth;
+
+ // width of group in pixels
+ xwidth = (((group.getEndRes() + 1) - group.getStartRes()) * charWidth)
+ - 1;
+
+ sy = verticalOffset + (i - startSeq) * charHeight;
+
+ if (sx + xwidth < 0 || sx > visWidth)
+ {
+ continue;
+ }
+
+ if ((sx <= (endRes - startRes) * charWidth)
+ && group.getSequences(null)
+ .contains(av.getAlignment().getSequenceAt(i)))
+ {
+ if ((bottom == -1) && !group.getSequences(null)
+ .contains(av.getAlignment().getSequenceAt(i + 1)))
+ {
+ bottom = sy + charHeight;