new method for outlining groups
authoramwaterhouse <Andrew Waterhouse>
Mon, 21 Mar 2005 18:47:17 +0000 (18:47 +0000)
committeramwaterhouse <Andrew Waterhouse>
Mon, 21 Mar 2005 18:47:17 +0000 (18:47 +0000)
src/jalview/gui/SeqCanvas.java

index 96dea90..f9ab015 100755 (executable)
@@ -2,9 +2,7 @@ package jalview.gui;
 \r
 import java.awt.*;\r
 import javax.swing.*;\r
-import java.awt.event.*;\r
 import jalview.datamodel.*;\r
-import jalview.schemes.*;\r
 import jalview.analysis.*;\r
 \r
 \r
@@ -157,111 +155,97 @@ public class SeqCanvas extends JPanel
     }*/\r
 \r
     SequenceI nextSeq;\r
-    SequenceGroup group=null;\r
-    SequenceGroup [] groups=null;\r
-    boolean inGroup=false; // are we in a defined group?\r
-    boolean inRB=false; //Are we in a rubberband group?\r
-    int sx=-1, sy=-1, ex=-1, ey=-1;\r
-    int oldStartX=0,oldEndX=0,oldY=0;\r
-    int oldRStartX=0,oldREndX=0,oldRY=0;\r
+\r
+    /// First draw the sequences\r
+    /////////////////////////////\r
     for (int i = y1 ; i < y2 ;i++)\r
     {\r
      nextSeq = av.getAlignment().getSequenceAt(i);\r
 \r
-     group = av.alignment.findGroup( nextSeq );\r
-     groups = av.alignment.findAllGroups( nextSeq );\r
-\r
-     sr.drawSequence(g, nextSeq, groups,x1,x2,\r
+     sr.drawSequence(g, nextSeq, av.alignment.findAllGroups( nextSeq ),x1,x2,\r
                  (x1 - startx) * av.charWidth,\r
                  offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight),\r
                  av.charWidth,av.charHeight,null, i);\r
 \r
      if(av.showSequenceFeatures)\r
      {\r
-       fr.drawSequence(g, nextSeq, groups, x1, x2,\r
+       fr.drawSequence(g, nextSeq, av.alignment.findAllGroups( nextSeq ), x1, x2,\r
                        (x1 - startx) * av.charWidth,\r
                        offset +\r
                        AlignmentUtil.getPixelHeight(starty, i, av.charHeight),\r
                        av.charWidth, av.charHeight, null, i);\r
      }\r
+    }\r
+    //\r
+    /////////////////////////////////////\r
 \r
+    // Now outline any areas if necessary\r
+    /////////////////////////////////////\r
+    SequenceGroup group = av.getSelectionGroup();\r
+    java.util.Vector groups = av.alignment.getGroups();\r
 \r
+    int sx = -1, sy = -1, ex = -1;\r
+    int groupIndex = -1;\r
+    if (group == null && groups.size() > 0)\r
+    {\r
+      group = (SequenceGroup) groups.elementAt(0);\r
+      groupIndex = 0;\r
+    }\r
 \r
-\r
-     if( group!=null )\r
-     {\r
-\r
-        g.setColor(Color.lightGray);\r
-\r
-        sx = (group.getStartRes()-startx)*av.charWidth;\r
-        sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight);\r
-        ex = (group.getEndRes()+1-startx)*av.charWidth;\r
-        ey = offset + AlignmentUtil.getPixelHeight(starty, i+1, av.charHeight);\r
-\r
-\r
-        if (!inGroup)\r
+    if (group != null)\r
+      do\r
+      {\r
+        int oldY = -1;\r
+        int i = 0;\r
+        boolean inGroup = false;\r
+        for (i = y1; i < y2; i++)\r
         {\r
-          g.drawLine(sx, sy, ex, sy); // Horizontal, top of new box\r
-          inGroup=true;\r
+          sx = (group.getStartRes() - startx) * av.charWidth;\r
+          sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight);\r
+          ex = (group.getEndRes() + 1 - group.getStartRes()) * av.charWidth;\r
+\r
+          if (group.sequences.contains(av.alignment.getSequenceAt(i))\r
+              && sx < getWidth()\r
+              && ex > 0)\r
+          {\r
+            if (!inGroup)\r
+            {\r
+              oldY = sy;\r
+              inGroup = true;\r
+              if (group == av.getSelectionGroup())\r
+                g.setColor(Color.RED.brighter());\r
+              else\r
+                g.setColor(group.getOutlineColour());\r
+            }\r
+          }\r
+          else\r
+          {\r
+            if (inGroup)\r
+            {\r
+              g.drawRect(sx, oldY, ex, (sy - oldY));\r
+              inGroup = false;\r
+            }\r
+          }\r
+        }\r
+        if (inGroup)\r
+        {\r
+          sy = offset + AlignmentUtil.getPixelHeight(starty, i, av.charHeight);\r
+          g.drawRect(sx, oldY, ex, (sy - oldY));\r
+          inGroup = false;\r
         }\r
 \r
-        g.drawLine(sx, sy, sx, ey ); // vertical line, left hand side\r
-        g.drawLine( ex,sy,ex,ey);    // vertical line, right hand side\r
-        if (i == y2 - 1)// last line of alignment, seal the box\r
-          g.drawLine(sx, ey, ex, ey); // Horizontal, bottom of old box\r
-\r
-        oldStartX = sx;\r
-        oldEndX = ex;\r
-        oldY = ey;\r
+        groupIndex++;\r
+        if (groupIndex >= groups.size())\r
+          break;\r
 \r
-     }\r
-     else if(inGroup)\r
-     {\r
-       g.setColor(Color.lightGray);\r
-       g.drawLine(oldStartX, oldY, oldEndX, oldY); // Horizontal, bottom of old box\r
-     }\r
-     else\r
-       inGroup = false;\r
+        group = (SequenceGroup) groups.elementAt(groupIndex);\r
 \r
-     group = av.getSelectionGroup();\r
-     if( group != null && group.sequences.contains(nextSeq) )\r
-     {\r
-         g.setColor(Color.RED.brighter());\r
-         sx = (group.getStartRes() - startx) * av.charWidth;\r
-         sy = offset +\r
-             AlignmentUtil.getPixelHeight(starty, i, av.charHeight);\r
-         ex = (group.getEndRes() + 1 - startx) * av.charWidth;\r
-         ey = offset +\r
-             AlignmentUtil.getPixelHeight(starty, i + 1, av.charHeight);\r
-\r
-         if (!inRB)\r
-         {\r
-\r
-           g.drawLine(sx, sy, ex, sy); // Horizontal, top of new box\r
-           inRB = true;\r
-         }\r
-\r
-         g.drawLine(sx, sy, sx, ey); // vertical line, left hand side\r
-         g.drawLine(ex, sy, ex, ey); // vertical line, right hand side\r
-         if (i == y2 - 1) // last line of alignment, seal the box\r
-           g.drawLine(sx, ey, ex, ey); // Horizontal, bottom of old box\r
-\r
-          oldRStartX = sx;\r
-          oldREndX = ex;\r
-          oldRY = ey;\r
-     }\r
-     else if(inRB)\r
-     {\r
-       g.setColor(Color.RED.brighter());\r
-       g.drawLine(oldRStartX, oldRY, oldREndX, oldRY); // Horizontal, bottom of old box\r
-       inRB = false;\r
-     }\r
-     else\r
-       inRB = false;\r
+      }\r
+      while (groupIndex < groups.size());\r
 \r
-    }\r
 \r
     /// Highlight search Results once all sequences have been drawn\r
+    //////////////////////////////////////////////////////////\r
     if(displaySearch)\r
     {\r
       for(int r=0; r<searchResults.length; r+=3)\r