+ sx = (group.getStartRes() - startx) * av.charWidth;\r
+ sy = offset + ((i - starty) * av.charHeight);\r
+ ex = (((group.getEndRes() + 1) - group.getStartRes()) * av.charWidth) -\r
+ 1;\r
+\r
+ if(sx+ex<0 || sx>imgWidth)\r
+ {\r
+ continue;\r
+ }\r
+\r
+ if ( (sx <= (x2-x1)*av.charWidth) &&\r
+ group.sequences.contains(av.alignment.getSequenceAt(\r
+ i)))\r
+ {\r
+\r
+ if (bottom == -1)\r
+ {\r
+ if(i == y2-1 || // Dont check for i+1 if on the bottom row\r
+ !group.sequences.contains(av.alignment.getSequenceAt(i+1 )))\r
+\r
+ bottom = sy + av.charHeight;\r
+ }\r
+\r
+ if (!inGroup)\r
+ {\r
+ if (((top == -1) && (i == 0)) ||\r
+ !group.sequences.contains(\r
+ av.alignment.getSequenceAt(i - 1)))\r
+ {\r
+ top = sy;\r
+ }\r
+\r
+ oldY = sy;\r
+ inGroup = true;\r
+\r
+ if (group == av.getSelectionGroup())\r
+ {\r
+\r
+ g.setColor(Color.red);\r
+ }\r
+ else\r
+ {\r
+ g.setColor(group.getOutlineColour());\r
+ }\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if (inGroup)\r
+ {\r
+ if (sx >= 0 && sx < imgWidth)\r
+ g.drawLine(sx, oldY, sx, sy);\r
+\r
+ if (sx + ex < imgWidth)\r
+ g.drawLine(sx + ex, oldY, sx + ex, sy);\r
+\r
+ if (sx < 0)\r
+ {\r
+ ex += sx;\r
+ sx = 0;\r
+ }\r
+\r
+ if (sx + ex > imgWidth)\r
+ ex = imgWidth;\r
+\r
+ else if (sx + ex >= (x2 - x1 + 1) * av.charWidth)\r
+ ex = (x2 - x1 + 1) * av.charWidth;\r
+\r
+ if (top != -1)\r
+ {\r
+ g.drawLine(sx, top, sx + ex, top);\r
+ top = -1;\r
+ }\r
+\r
+ if (bottom != -1)\r
+ {\r
+ g.drawLine(sx, bottom, sx + ex, bottom);\r
+ bottom = -1;\r
+ }\r
+\r
+ inGroup = false;\r
+ }\r
+ }\r