X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FFinder.java;h=31c914ac53dcff78d7469ab34b6760306d2f1180;hb=71b8b157747abb849fb50316450a22d4559873da;hp=f44387f0b0a1b7cd92de10abaf34c6f521d89d74;hpb=ca87cef11606dd9b1ba66222cea87e000e556817;p=jalview.git diff --git a/src/jalview/appletgui/Finder.java b/src/jalview/appletgui/Finder.java index f44387f..31c914a 100644 --- a/src/jalview/appletgui/Finder.java +++ b/src/jalview/appletgui/Finder.java @@ -21,6 +21,7 @@ package jalview.appletgui; import jalview.api.AlignViewportI; +import jalview.api.FinderI; import jalview.datamodel.SearchResultMatchI; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceFeature; @@ -45,7 +46,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Vector; public class Finder extends Panel implements ActionListener { @@ -68,21 +68,13 @@ public class Finder extends Panel implements ActionListener private SearchResultsI searchResults; /* - * sequence index and residue position of last match, - * for current search and per viewport + * Finder agent per viewport searched */ - private int seqIndex = 0; - - private int resIndex = -1; - - Map seqIndices; - - Map resIndices; + Map finders; public Finder(final AlignmentPanel ap) { - seqIndices = new HashMap<>(); - resIndices = new HashMap<>(); + finders = new HashMap<>(); try { @@ -126,8 +118,6 @@ public class Finder extends Panel implements ActionListener else if (evt.getSource() == findAll) { - resIndex = -1; - seqIndex = 0; doSearch(true); } else if (evt.getSource() == createFeatures) @@ -164,36 +154,36 @@ public class Finder extends Panel implements ActionListener { ap = ap.av.applet.currentAlignFrame.alignPanel; av = ap.av; - seqIndex = 0; - resIndex = -1; - if (seqIndices.containsKey(av)) - { - seqIndex = seqIndices.get(av).intValue(); - } - if (resIndices.containsKey(av)) - { - resIndex = resIndices.get(av).intValue(); - } } createFeatures.setEnabled(false); - jalview.analysis.Finder finder = new jalview.analysis.Finder( - av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex); - finder.setCaseSensitive(caseSensitive.getState()); - finder.setIncludeDescription(searchDescription.getState()); - finder.setFindAll(doFindAll); + FinderI finder = finders.get(av); + if (finder == null) + { + /* + * first time we searched this viewport + */ + finder = new jalview.analysis.Finder(av); + finders.put(av, finder); + } String searchString = textfield.getText(); + boolean isCaseSensitive = caseSensitive.getState(); + boolean doSearchDescription = searchDescription.getState(); + if (doFindAll) + { + finder.findAll(searchString, isCaseSensitive, doSearchDescription, + false); + } + else + { + finder.findNext(searchString, isCaseSensitive, doSearchDescription, + false); + } - finder.find(searchString); - - seqIndex = finder.getSeqIndex(); - resIndex = finder.getResIndex(); - seqIndices.put(av, seqIndex); - resIndices.put(av, resIndex); searchResults = finder.getSearchResults(); - Vector idMatch = finder.getIdMatch(); - ap.idPanel.highlightSearchResults(idMatch); + List idMatches = finder.getIdMatches(); + ap.idPanel.highlightSearchResults(idMatches); if (searchResults.isEmpty()) { @@ -209,27 +199,26 @@ public class Finder extends Panel implements ActionListener ap.highlightSearchResults(searchResults); // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or // 'SelectRegion' selection - if (idMatch.isEmpty() && searchResults == null) + if (idMatches.isEmpty() && searchResults == null) { ap.alignFrame.statusBar.setText( MessageManager.getString("label.finished_searching")); - resIndex = -1; - seqIndex = 0; } else { if (doFindAll) { - String message = (idMatch.size() > 0) ? "" + idMatch.size() + " IDs" + String message = (idMatches.size() > 0) + ? "" + idMatches.size() + " IDs" : ""; - if (idMatch.size() > 0 && searchResults != null - && searchResults.getSize() > 0) + if (idMatches.size() > 0 && searchResults != null + && searchResults.getCount() > 0) { message += " and "; } if (searchResults != null) { - message += searchResults.getSize() + " subsequence matches."; + message += searchResults.getCount() + " subsequence matches."; } ap.alignFrame.statusBar.setText(MessageManager .formatMessage("label.search_results", new String[]