GPL license added
[jalview.git] / src / jalview / gui / Finder.java
index 5a2dfe9..d20cb65 100755 (executable)
@@ -1,3 +1,22 @@
+/*\r
+* Jalview - A Sequence Alignment Editor and Viewer\r
+* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+*\r
+* This program is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU General Public License\r
+* as published by the Free Software Foundation; either version 2\r
+* of the License, or (at your option) any later version.\r
+*\r
+* This program is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with this program; if not, write to the Free Software\r
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+*/\r
+\r
 package jalview.gui;\r
 \r
 import jalview.jbgui.GFinder;\r
@@ -14,6 +33,7 @@ public class Finder extends GFinder
   AlignmentPanel ap;\r
   JInternalFrame frame;\r
   SuperGroup searchGroup;\r
+  Vector searchResults;\r
 \r
   int seqIndex = 0;\r
   int resIndex = 0;\r
@@ -74,8 +94,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
+\r
+   Color [] newColors = new Color[24];\r
+   for(int i=0; i<24; i++)\r
+     newColors[i] = new Color(60,160,115);\r
+\r
+   jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(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
@@ -90,7 +134,7 @@ public class Finder extends GFinder
 \r
     com.stevesoft.pat.Regex regex = new  com.stevesoft.pat.Regex(searchString);\r
 \r
-    ArrayList searchResults = new ArrayList();\r
+    searchResults = new Vector();\r
     int [] allResults = null;\r
 \r
     Sequence seq;\r
@@ -115,12 +159,12 @@ public class Finder extends GFinder
     ///////////////////////////////////////////////\r
 \r
 \r
-    jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();\r
+\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
+    jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(newColors);\r
 \r
     searchGroup = new SuperGroup(searchString, ucs , true, true, false);\r
 \r
@@ -151,7 +195,7 @@ public class Finder extends GFinder
       ///Shall we ignore gaps????\r
       StringBuffer noGaps = new StringBuffer();\r
       int insertCount=0;\r
-      ArrayList spaces = new ArrayList();\r
+      Vector spaces = new Vector();\r
 \r
       for (int j=0; j < item.length(); j++)\r
       {\r
@@ -177,15 +221,12 @@ public class Finder extends GFinder
            continue;\r
 \r
          searchResults.add( Integer.toString( seqIndex) );\r
-         searchResults.add( Integer.toString( resIndex+ Integer.parseInt(spaces.get(resIndex).toString()) ) );\r
-         searchResults.add( Integer.toString( regex.matchedTo()-1 + Integer.parseInt(spaces.get(regex.matchedTo()-1).toString()) ) );\r
 \r
-         SequenceGroup sg = new SequenceGroup(searchString, ucs, true, true, false,\r
-                                             resIndex+ Integer.parseInt(spaces.get(resIndex).toString()) ,\r
-                                      regex.matchedTo()-1 + Integer.parseInt(spaces.get(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
+\r
+          searchResults.addElement( sres+"" );\r
+          searchResults.addElement( eres+"" );\r
 \r
          if(!findAll)\r
          {\r
@@ -206,7 +247,7 @@ public class Finder extends GFinder
     }\r
 \r
 \r
-    ArrayList idMatch = new ArrayList();\r
+    Vector idMatch = new Vector();\r
     for(int id = 0; id<av.alignment.getHeight(); id++)\r
     {\r
       if(   regex.search( av.alignment.getSequenceAt(id).getName() ) )\r