+import jalview.api.AlignViewportI;
+import jalview.api.FinderI;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SearchResultMatchI;
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.SearchResultsI;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.util.Comparison;
+import jalview.util.MapList;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import com.stevesoft.pat.Regex;
+
+/**
+ * Implements the search algorithm for the Find dialog
+ */
+public class Finder implements FinderI
+{
+ /*
+ * matched residue locations
+ */
+ private SearchResultsI searchResults;
+
+ /*
+ * sequences matched by id or description
+ */
+ private List<SequenceI> idMatches;
+
+ /*
+ * the viewport to search over
+ */
+ private AlignViewportI viewport;
+
+ /*
+ * sequence index in alignment to search from
+ */
+ private int sequenceIndex;
+
+ /*
+ * position offset in sequence to search from, base 0
+ * (position after start of last match for a 'find next')
+ */
+ private int residueIndex;
+
+ /*
+ * the true sequence position of the start of the
+ * last sequence searched (when 'ignore hidden regions' does not apply)
+ */
+ private int searchedSequenceStartPosition;
+
+ /*
+ * when 'ignore hidden regions' applies, this holds the mapping from
+ * the visible sequence positions (1, 2, ...) to true sequence positions
+ */
+ private MapList searchedSequenceMap;
+
+ private String seqToSearch;
+
+ /**
+ * Constructor for searching a viewport
+ *
+ * @param av
+ */
+ public Finder(AlignViewportI av)
+ {
+ this.viewport = av;
+ this.sequenceIndex = 0;
+ this.residueIndex = -1;
+ }
+
+ @Override
+ public void findAll(String theSearchString, boolean matchCase,
+ boolean searchDescription, boolean ignoreHidden)
+ {
+ /*
+ * search from the start