corrections for find when edit takes place
[jalview.git] / src / jalview / appletgui / Finder.java
index 0b1e319..ab4cd7b 100755 (executable)
@@ -12,6 +12,7 @@ public class Finder extends GFinder
   AlignmentPanel ap;\r
   Frame frame;\r
   SuperGroup searchGroup;\r
+  Vector searchResults;\r
 \r
   int seqIndex = 0;\r
   int resIndex = 0;\r
@@ -59,8 +60,32 @@ public class Finder extends GFinder
 \r
   public void createNewGroup_actionPerformed(ActionEvent e)\r
   {\r
-    for(int i=0; i<searchGroup.getSize(); i++)\r
-      av.alignment.addGroup( searchGroup.getGroupeAt(i));\r
+    jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();\r
+   Color [] newColors = new Color[24];\r
+   for(int i=0; i<24; i++)\r
+     newColors[i] = new Color(60,160,115);\r
+\r
+   ucs.setColourScheme(newColors);\r
+   String searchString = textfield.getText();\r
+\r
+   searchGroup = new SuperGroup(searchString, ucs , true, true, false);\r
+\r
+\r
+    for(int i=0; i<searchResults.size(); i+=3)\r
+    {\r
+      // its possible edits may have occurred since search was performed\r
+      // account for this here\r
+\r
+      SequenceI seq = av.alignment.getSequenceAt( Integer.parseInt(searchResults.elementAt(i).toString()) );\r
+      int startRes = seq.findIndex( Integer.parseInt(searchResults.elementAt(i+1).toString()) )-1;\r
+      int endRes = seq.findIndex(   Integer.parseInt(searchResults.elementAt(i+2).toString()) )-1;\r
+\r
+      SequenceGroup sg = new SequenceGroup(searchString, ucs, true, true, false, startRes , endRes  );\r
+      sg.addSequence(seq);\r
+      av.alignment.addGroup(sg);\r
+      searchGroup.addGroup( sg );\r
+\r
+    }\r
 \r
     ap.av.alignment.addSuperGroup(searchGroup);\r
     ap.highlightSearchResults( null );\r
@@ -75,7 +100,7 @@ public class Finder extends GFinder
 \r
     com.stevesoft.pat.Regex regex = new  com.stevesoft.pat.Regex(searchString);\r
 \r
-    Vector searchResults = new Vector();\r
+    searchResults = new Vector();\r
     int [] allResults = null;\r
 \r
     Sequence seq;\r
@@ -100,15 +125,6 @@ public class Finder extends GFinder
     ///////////////////////////////////////////////\r
 \r
 \r
-    jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();\r
-    Color [] newColors = new Color[24];\r
-    for(int i=0; i<24; i++)\r
-      newColors[i] = new Color(60,160,115);\r
-\r
-    ucs.setColourScheme(newColors);\r
-\r
-    searchGroup = new SuperGroup(searchString, ucs , true, true, false);\r
-\r
     int end = av.alignment.getHeight();\r
 \r
     SequenceGroup selection = av.getSelectionGroup();\r
@@ -162,15 +178,11 @@ public class Finder extends GFinder
            continue;\r
 \r
          searchResults.addElement( Integer.toString( seqIndex) );\r
-         searchResults.addElement( Integer.toString( resIndex+ Integer.parseInt(spaces.elementAt(resIndex).toString()) ) );\r
-         searchResults.addElement( Integer.toString( regex.matchedTo()-1 + Integer.parseInt(spaces.elementAt(regex.matchedTo()-1).toString()) ) );\r
-\r
-         SequenceGroup sg = new SequenceGroup(searchString, ucs, true, true, false,\r
-                                             resIndex+ Integer.parseInt(spaces.elementAt(resIndex).toString()) ,\r
-                                      regex.matchedTo()-1 + Integer.parseInt(spaces.elementAt(regex.matchedTo()-1).toString())\r
-            );\r
-         sg.addSequence((Sequence)av.getAlignment().getSequenceAt(seqIndex));\r
-         searchGroup.addGroup( sg );\r
+         int sres = seq.findPosition( resIndex+ Integer.parseInt(spaces.elementAt(resIndex).toString()) );\r
+         int eres = seq.findPosition( regex.matchedTo()-1 + Integer.parseInt(spaces.elementAt(regex.matchedTo()-1).toString()) );\r
+          searchResults.addElement( sres+"" );\r
+          searchResults.addElement( eres+"" );\r
+\r
 \r
          if(!findAll)\r
          {\r