Addition of rubberband
authoramwaterhouse <Andrew Waterhouse>
Fri, 10 Dec 2004 14:37:09 +0000 (14:37 +0000)
committeramwaterhouse <Andrew Waterhouse>
Fri, 10 Dec 2004 14:37:09 +0000 (14:37 +0000)
src/jalview/gui/SeqPanel.java

index ebcbc76..3680503 100755 (executable)
@@ -328,142 +328,78 @@ public class SeqPanel extends JPanel
   }\r
 \r
 \r
-  public void setColourScheme(ColourSchemeI cs, boolean showConservation)\r
+  public void doMousePressedDefineMode(MouseEvent evt)\r
   {\r
-    seqCanvas.paintFlag = true;\r
-    if (av.getSelection().size() == 0)\r
-    {\r
-      seqCanvas.globalColorScheme = cs;\r
-      for (int i = 0; i < av.alignment.getGroups().size();i++)\r
-      {\r
-        SequenceGroup sg = (SequenceGroup)av.alignment.getGroups().elementAt(i);\r
-        sg.cs = cs;\r
-        if(!showConservation\r
-            && !(sg.cs instanceof Blosum62ColourScheme)\r
-            && sg.cs instanceof ConservationColourScheme)\r
-         {\r
-           // remove ConservationColouring from existing Conservation group\r
-           ConservationColourScheme ccs = (ConservationColourScheme)sg.cs;\r
-           sg.cs = ccs.cs;\r
-         }\r
-         else if(showConservation && !(sg.cs instanceof ConservationColourScheme))\r
-         {\r
-           // add ConservationColouring to new group\r
-           Conservation c = sg.getConservation();\r
-           Alignment al = (Alignment) av.getAlignment();\r
-           c = new Conservation("All", al.cons,\r
-                                ResidueProperties.propHash, 3, sg.sequences, 0,\r
-                                al.getWidth() );\r
-           c.calculate();\r
-           c.verdict(false, 100);\r
-           sg.setConservation(c);\r
-           sg.cs = new ConservationColourScheme(sg);\r
-         }\r
-      }\r
-    }\r
-    else\r
-    {\r
-      SequenceGroup sg = av.alignment.findGroup((Sequence)av.sel.sequenceAt(0));\r
+    int res = evt.getX()/av.getCharWidth() + av.getStartRes();\r
+    int seq = evt.getY()/av.getCharHeight() + av.getStartSeq();\r
 \r
-      if( isNewSelection(sg) )\r
-      {\r
-        sg = av.getAlignment().addGroup();\r
-        for (int i=0; i < av.getSelection().size(); i++)\r
-        {\r
-          av.alignment.removeFromGroup(av.alignment.findGroup( (Sequence) av.\r
-              sel.sequenceAt(i)),\r
-                                       (Sequence) av.sel.sequenceAt(i));\r
-          av.alignment.addToGroup(sg, (Sequence) av.sel.sequenceAt(i));\r
-        }\r
-      }\r
+    stretchGroup = av.getRubberbandGroup();\r
+    if(stretchGroup == null)\r
+        stretchGroup = av.alignment.findGroup((Sequence)av.getAlignment().getSequenceAt(seq));\r
+      else if(!stretchGroup.sequences.contains((Sequence)av.getAlignment().getSequenceAt(seq))\r
+            || stretchGroup.getStartRes()<res\r
+            || stretchGroup.getEndRes()>res)\r
+     {\r
+       System.out.println(stretchGroup.getStartRes()+" "+stretchGroup.getEndRes()+" "+res);\r
+       stretchGroup = null;\r
+     }\r
 \r
 \r
-      sg.cs = cs;\r
 \r
-      // Selection is made, we only want to change the conservationColour for selected group\r
-      if(  showConservation\r
-           && !(sg.cs instanceof ConservationColourScheme)\r
-           && !(sg.cs instanceof Blosum62ColourScheme))\r
-      {\r
-        Conservation c = sg.getConservation();\r
-        Alignment al = (Alignment) av.getAlignment();\r
-\r
-        c = new Conservation("All", al.cons,\r
-                             ResidueProperties.propHash, 3, sg.sequences, 0,\r
-                             al.getWidth() );\r
-        c.calculate();\r
-        c.verdict(false, 100);\r
-        sg.setConservation(c);\r
-        sg.cs = new ConservationColourScheme(sg);\r
+    if(stretchGroup==null)\r
+    {\r
+      // define a new group here\r
+      SequenceGroup sg = new SequenceGroup();\r
+      sg.setStartRes(res);\r
+      sg.setEndRes(res);\r
+      sg.addSequence( (Sequence)av.getAlignment().getSequenceAt(seq) );\r
+      av.setRubberbandGroup( sg );\r
+      stretchGroup = sg;\r
+      System.out.println("new rubberband group");\r
     }\r
-    else  if( !showConservation && sg.cs instanceof ConservationColourScheme)\r
+    else if( javax.swing.SwingUtilities.isRightMouseButton(evt))\r
     {\r
-      ConservationColourScheme ccs = (ConservationColourScheme)sg.cs;\r
-      sg.cs = ccs.cs;\r
+        // edit the properties of existing group\r
     }\r
-   }\r
-   repaint();\r
-  }\r
-\r
-  boolean isNewSelection(SequenceGroup sg)\r
-  {\r
-    if(sg==null)\r
-      return true;\r
-\r
-    if(sg.getSize()!=av.getSelection().size())\r
-      return true;\r
-\r
-    for(int i=0; i<sg.getSize(); i++)\r
-     if( !av.getSelection().contains( sg.getSequenceAt(i) ))\r
-       return true;\r
-\r
-    return false;\r
-  }\r
 \r
-\r
-  public ColourSchemeI getColourScheme()\r
-  {\r
-    if(av.getSelection().size()>0)\r
-       return av.alignment.findGroup((Sequence)av.sel.sequenceAt(0)).cs;\r
-    else\r
-      return seqCanvas.globalColorScheme;\r
-  }\r
-\r
-  public void doMousePressedDefineMode(MouseEvent evt)\r
-  {\r
-    int res = evt.getX()/av.getCharWidth() + av.getStartRes();\r
-    int seq = evt.getY()/av.getCharHeight() + av.getStartSeq();\r
-\r
-    stretchGroup = av.alignment.findGroup((Sequence)av.getAlignment().getSequenceAt(seq));\r
-\r
-    if(stretchGroup!=null  && stretchGroup.getEndRes()==res)\r
+    if(stretchGroup!=null && stretchGroup.getEndRes()==res)\r
     {\r
       // Edit end res position of selected group\r
       changeEndRes = true;\r
     }\r
-    else if(stretchGroup!=null  && stretchGroup.getStartRes()==res)\r
+    if(stretchGroup!=null && stretchGroup.getStartRes()==res)\r
     {\r
       // Edit end res position of selected group\r
       changeStartRes = true;\r
     }\r
 \r
+    seqCanvas.paintFlag = true;\r
+    repaint();\r
+\r
 \r
   }\r
 \r
+  boolean changeEndSeq = false;\r
+  boolean changeStartSeq = false;\r
   boolean changeEndRes = false;\r
   boolean changeStartRes = false;\r
   SequenceGroup stretchGroup = null;\r
 \r
+\r
   public void doMouseReleasedDefineMode(MouseEvent evt)\r
   {\r
     changeEndRes = false;\r
     changeStartRes = false;\r
+    stretchGroup = null;\r
   }\r
 \r
   public void doMouseDraggedDefineMode(MouseEvent evt)\r
   {\r
     int res = evt.getX()/av.getCharWidth() + av.getStartRes();\r
-    int seq = evt.getY()/av.getCharHeight() + av.getStartSeq();\r
+    Sequence seq = (Sequence)av.getAlignment().getSequenceAt(\r
+                    evt.getY()/av.getCharHeight() + av.getStartSeq());\r
+\r
+   // SequenceGroup newSeqGroup = av.alignment.findGroup(seq);\r
 \r
     if(res<av.getStartRes())\r
       res = av.getStartRes();\r
@@ -480,6 +416,16 @@ public class SeqPanel extends JPanel
       if(res<stretchGroup.getEndRes()+1)\r
         stretchGroup.setStartRes( res );\r
     }\r
+\r
+   /* if(newSeqGroup != stretchGroup)\r
+    {\r
+      if(newSeqGroup !=null)\r
+        av.getAlignment().removeFromGroup(newSeqGroup, seq );\r
+\r
+      if(stretchGroup!=null)\r
+        stretchGroup.addSequence( seq );\r
+    }*/\r
+\r
     seqCanvas.paintFlag = true;\r
     repaint();\r
 \r