JAL-2933 pass viewport in Finder constructor, find acts on viewport selection if any
[jalview.git] / src / jalview / analysis / Finder.java
index 0996830..3cbef6d 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.analysis;
 
+import jalview.api.AlignViewportI;
 import jalview.api.FinderI;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Range;
@@ -52,14 +53,9 @@ public class Finder implements FinderI
   private Vector<SequenceI> idMatches;
 
   /*
-   * the alignment to search over
+   * the viewport to search over
    */
-  private AlignmentI alignment;
-
-  /*
-   * (optional) selection to restrict search to
-   */
-  private SequenceGroup selection;
+  private AlignViewportI viewport;
 
   /*
    * sequence index in alignment to search from
@@ -74,20 +70,20 @@ public class Finder implements FinderI
   private int columnIndex;
 
   /**
-   * Constructor for searching an alignment
+   * Constructor for searching a viewport
    * 
-   * @param al
+   * @param av
    */
-  public Finder(AlignmentI al)
+  public Finder(AlignViewportI av)
   {
-    this.alignment = al;
+    this.viewport = av;
     this.sequenceIndex = 0;
     this.columnIndex = -1;
   }
 
   @Override
-  public void findAll(String theSearchString, SequenceGroup sg,
-          boolean matchCase, boolean searchDescription)
+  public void findAll(String theSearchString, boolean matchCase,
+          boolean searchDescription)
   {
     /*
      * search from the start
@@ -95,7 +91,7 @@ public class Finder implements FinderI
     sequenceIndex = 0;
     columnIndex = -1;
 
-    doFind(theSearchString, sg, matchCase, searchDescription, true);
+    doFind(theSearchString, matchCase, searchDescription, true);
 
     /*
      * reset to start for next search
@@ -105,10 +101,10 @@ public class Finder implements FinderI
   }
 
   @Override
-  public void findNext(String theSearchString, SequenceGroup sg,
-          boolean matchCase, boolean searchDescription)
+  public void findNext(String theSearchString, boolean matchCase,
+          boolean searchDescription)
   {
-    doFind(theSearchString, sg, matchCase, searchDescription, false);
+    doFind(theSearchString, matchCase, searchDescription, false);
     
     if (searchResults.isEmpty() && idMatches.isEmpty())
     {
@@ -121,19 +117,16 @@ public class Finder implements FinderI
   }
 
   /**
-   * Performs a 'find next' or 'find all', optionally restricted to the
-   * specified selection region
+   * Performs a 'find next' or 'find all'
    * 
    * @param theSearchString
-   * @param selectionRegion
    * @param matchCase
    * @param searchDescription
    * @param findAll
    */
-  protected void doFind(String theSearchString, SequenceGroup selectionRegion,
-          boolean matchCase, boolean searchDescription, boolean findAll)
+  protected void doFind(String theSearchString, boolean matchCase,
+          boolean searchDescription, boolean findAll)
   {
-    this.selection = selectionRegion;
     String searchString = matchCase ? theSearchString
             : theSearchString.toUpperCase();
     Regex searchPattern = new Regex(searchString);
@@ -142,11 +135,13 @@ public class Finder implements FinderI
     searchResults = new SearchResults();
     idMatches = new Vector<>();
 
+    SequenceGroup selection = viewport.getSelectionGroup();
     if (selection != null && selection.getSize() < 1)
     {
       selection = null; // ? ignore column-only selection
     }
 
+    AlignmentI alignment = viewport.getAlignment();
     int end = alignment.getHeight();
 
     while (sequenceIndex < end)
@@ -184,6 +179,7 @@ public class Finder implements FinderI
      * restrict search to (next) visible column region, 
      * in case there are hidden columns
      */
+    AlignmentI alignment = viewport.getAlignment();
     VisibleContigsIterator visibleRegions = alignment.getHiddenColumns()
             .getVisContigsIterator(column, alignment.getWidth(),
                     false);
@@ -199,6 +195,7 @@ public class Finder implements FinderI
     /*
      * restrict search to selected region if there is one
      */
+    SequenceGroup selection = viewport.getSelectionGroup();
     if (selection != null)
     {
       int selectionStart = selection.getStartRes();
@@ -233,6 +230,7 @@ public class Finder implements FinderI
   protected boolean findNextMatch(SequenceI seq, String searchString,
           Regex searchPattern, boolean matchDescription)
   {
+    SequenceGroup selection = viewport.getSelectionGroup();
     if (selection != null && !selection.contains(seq))
     {
       /*