+
+ /*
+ * Draw the selection group as a separate image and overlay
+ */
+ private BufferedImage drawSelectionGroup(int startRes, int endRes,
+ int startSeq, int endSeq)
+ {
+ // get a new image of the correct size
+ BufferedImage selectionImage = setupImage();
+
+ if (selectionImage == null)
+ {
+ return null;
+ }
+
+ SequenceGroup group = av.getSelectionGroup();
+ if (group == null)
+ {
+ // nothing to draw
+ return null;
+ }
+
+ // set up drawing colour
+ Graphics2D g = (Graphics2D) selectionImage.getGraphics();
+ g.translate(LABEL_WEST, 0);
+ // set background to transparent
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
+ g.fillRect(0, 0, selectionImage.getWidth(), selectionImage.getHeight());
+
+ 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);
+
+ if (!av.hasHiddenColumns())
+ {
+ drawSelectionGroupPart(g, group, startRes, endRes, startSeq, endSeq);
+ }
+ else
+ {
+ // package into blocks of visible columns
+ // Graphics2D g = (Graphics2D) selectionImage.getGraphics();
+ // Graphics g1 = selectionImage.getGraphics();
+
+ 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);
+
+ drawSelectionGroupPart(g, group,
+ blockStart, blockEnd, startSeq, endSeq);
+
+ 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);
+ drawSelectionGroupPart(g, group,
+ blockStart, blockEnd, startSeq, endSeq);
+
+ g.translate(-screenY * charWidth, 0);
+ }
+ }
+ g.translate(-LABEL_WEST, 0);
+ return selectionImage;
+ }
+
+ /*
+ * Draw the selection group as a separate image and overlay
+ */
+ private void drawSelectionGroupPart(Graphics2D g, SequenceGroup group,
+ int startRes, int endRes, int startSeq, int endSeq)
+ {
+ // set up values in case the alignment is wrapped
+ int verticalOffset = 0;
+ int horizontalOffset = 0;
+ if (av.getWrapAlignment())
+ {
+ int hgap = charHeight;
+ if (av.getScaleAboveWrapped())
+ {
+ hgap += charHeight;
+ }
+
+ // get the start res of the group and work out the offsets for it in the wrapped alignment
+ int groupstart = group.getStartRes();
+ int cWidth = (getWidth() - LABEL_EAST - LABEL_WEST) / charWidth;
+
+ // group is in which slice of alignment? res position / width in residues
+ int slice = groupstart / cWidth;
+ // vertical offset is increased by slice number * number of sequences * height of each sequence
+ verticalOffset = slice * (av.getAlignment().getHeight() * charHeight
+ + getAnnotationHeight() + hgap) + hgap;
+
+ // horizontal offset is number of residues to subtract from group residue
+ // position
+ horizontalOffset = (slice * cWidth);
+ }
+
+ int visWidth = av.getRanges().getViewportWidth() * charWidth;
+
+ // set x start and end positions of group
+ int startx = (group.getStartRes() - startRes - horizontalOffset)
+ * charWidth;
+ int endx = (group.getEndRes() - startRes + 1 - horizontalOffset)
+ * charWidth;
+
+ int oldY = -1;
+ int i = 0;
+ boolean inGroup = false;
+ int top = -1;
+ int bottom = -1;
+
+ // get sequences to determine y positions of group
+ for (i = startSeq; i <= endSeq; ++i)
+ {
+ int sy = verticalOffset + (i - startSeq) * charHeight;
+
+ if (group.getSequences(null)
+ .contains(av.getAlignment().getSequenceAt(i)))
+ {
+ if ((bottom == -1) && !group.getSequences(null)
+ .contains(av.getAlignment().getSequenceAt(i + 1)))
+ {
+ bottom = sy + charHeight;
+ }
+
+ if (!inGroup)
+ {
+ if (((top == -1) && (i == 0)) || !group.getSequences(null)
+ .contains(av.getAlignment().getSequenceAt(i - 1)))
+ {
+ top = sy;
+ }
+
+ oldY = sy;
+ inGroup = true;
+ }
+ }
+ else
+ {
+ if (inGroup)
+ {
+ // if start position is visible, draw vertical line to left of
+ // group
+ if (startx >= 0 && startx < visWidth * charWidth)
+ {
+ g.drawLine(startx, oldY, startx, sy);
+ }
+
+ // if end position is visible, draw vertical line to right of
+ // group
+ if (endx <= visWidth * charWidth)
+ {
+ g.drawLine(endx, oldY, endx, sy);
+ }
+
+ if (endx > visWidth * charWidth)
+ {
+ endx = visWidth * charWidth;
+ }
+
+ // draw horizontal line at top of group
+ if (top != -1)
+ {
+ g.drawLine(startx, top, endx, top);
+ top = -1;
+ }
+
+ // draw horizontal line at bottom of group
+ if (bottom != -1)
+ {
+ g.drawLine(startx, bottom, endx, bottom);
+ bottom = -1;
+ }
+
+ inGroup = false;
+ }
+ }
+ }
+ if (inGroup)
+ {
+ int sy = verticalOffset + (i - startSeq) * charHeight;
+ if (startx >= 0 && startx < visWidth)
+ {
+ g.drawLine(startx, oldY, startx, sy);
+ }
+
+ if (endx < visWidth)
+ {
+ g.drawLine(endx, oldY, endx, sy);
+ }
+
+ if (endx > visWidth)
+ {
+ endx = visWidth;
+ }
+
+ if (top != -1)
+ {
+ g.drawLine(startx, top, endx, top);
+ top = -1;
+ }
+
+ if (bottom != -1)
+ {
+ g.drawLine(startx, bottom - 1, endx, bottom - 1);
+ bottom = -1;
+ }
+
+ inGroup = false;
+ }
+ }
+