X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FFinder.java;fp=src%2Fjalview%2Fappletgui%2FFinder.java;h=4b555743d278ecee0b33720c840e80127949d608;hb=24de2d6a6f3db1b9d55f367e2bf8ba112e202a8a;hp=286cd5f16b46a4e15d8fe91b087d5da752bee85a;hpb=85b18307da5f85a9cb5c13bb6be97eaf2c7f7965;p=jalview.git diff --git a/src/jalview/appletgui/Finder.java b/src/jalview/appletgui/Finder.java index 286cd5f..4b55574 100644 --- a/src/jalview/appletgui/Finder.java +++ b/src/jalview/appletgui/Finder.java @@ -21,9 +21,11 @@ package jalview.appletgui; import jalview.api.AlignViewportI; +import jalview.api.FinderI; import jalview.datamodel.SearchResultMatchI; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.util.MessageManager; @@ -45,7 +47,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 +69,13 @@ public class Finder extends Panel implements ActionListener private SearchResultsI searchResults; /* - * sequence index and column position of last match, - * for current search and per viewport + * Finder agent per viewport searched */ - private int seqIndex = 0; - - private int colIndex = -1; - - Map seqIndices; - - Map colIndices; + Map finders; public Finder(final AlignmentPanel ap) { - seqIndices = new HashMap<>(); - colIndices = new HashMap<>(); + finders = new HashMap<>(); try { @@ -126,8 +119,6 @@ public class Finder extends Panel implements ActionListener else if (evt.getSource() == findAll) { - colIndex = -1; - seqIndex = 0; doSearch(true); } else if (evt.getSource() == createFeatures) @@ -164,36 +155,37 @@ public class Finder extends Panel implements ActionListener { ap = ap.av.applet.currentAlignFrame.alignPanel; av = ap.av; - seqIndex = 0; - colIndex = -1; - if (seqIndices.containsKey(av)) - { - seqIndex = seqIndices.get(av).intValue(); - } - if (colIndices.containsKey(av)) - { - colIndex = colIndices.get(av).intValue(); - } } createFeatures.setEnabled(false); - jalview.analysis.Finder finder = new jalview.analysis.Finder( - av.getAlignment(), av.getSelectionGroup(), seqIndex, colIndex); - 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.getAlignment()); + finders.put(av, finder); + } String searchString = textfield.getText(); + SequenceGroup selectionGroup = av.getSelectionGroup(); + boolean isCaseSensitive = caseSensitive.getState(); + boolean doSearchDescription = searchDescription.getState(); + if (doFindAll) + { + finder.findAll(searchString, selectionGroup, isCaseSensitive, + doSearchDescription); + } + else + { + finder.findNext(searchString, selectionGroup, isCaseSensitive, + doSearchDescription); + } - finder.find(searchString); - - seqIndex = finder.getSequenceIndex(); - colIndex = finder.getColumnIndex(); - seqIndices.put(av, seqIndex); - colIndices.put(av, colIndex); searchResults = finder.getSearchResults(); - Vector idMatch = finder.getIdMatch(); - ap.idPanel.highlightSearchResults(idMatch); + List idMatches = finder.getIdMatches(); + ap.idPanel.highlightSearchResults(idMatches); if (searchResults.isEmpty()) { @@ -209,20 +201,18 @@ 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")); - colIndex = -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 + if (idMatches.size() > 0 && searchResults != null && searchResults.getSize() > 0) { message += " and ";