package jalview.gui;
import jalview.api.AlignViewportI;
+import jalview.api.FinderI;
import jalview.datamodel.SearchResultMatchI;
import jalview.datamodel.SearchResultsI;
import jalview.datamodel.SequenceFeature;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Vector;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
private JInternalFrame frame;
/*
- * sequence and column position of the last match,
- * as currently used, and saved for each viewport
+ * Finder agent per viewport searched
*/
- private int seqIndex = 0;
-
- private int colIndex = -1;
-
- private Map<AlignViewportI, Integer> seqIndices;
-
- private Map<AlignViewportI, Integer> colIndices;
+ private Map<AlignViewportI, FinderI> finders;
private SearchResultsI searchResults;
{
av = viewport;
ap = alignPanel;
- seqIndices = new HashMap<>();
- colIndices = new HashMap<>();
+ finders = new HashMap<>();
focusfixed = viewport != null;
frame = new JInternalFrame();
frame.setContentPane(this);
{
if (getFocusedViewport())
{
- colIndex = -1;
- seqIndex = 0;
doSearch(true);
}
}
{
av = ((AlignFrame) alignFrame).viewport;
ap = ((AlignFrame) alignFrame).alignPanel;
-
- /*
- * restore search position if switching to a
- * panel where we have previously searched
- */
- seqIndex = 0;
- colIndex = -1;
- if (seqIndices.containsKey(av))
- {
- seqIndex = seqIndices.get(av).intValue();
- }
- if (colIndices.containsKey(av))
- {
- colIndex = colIndices.get(av).intValue();
- }
return true;
}
}
// other stuff
// TODO: add switches to control what is searched - sequences, IDS,
// descriptions, features
- jalview.analysis.Finder finder = new jalview.analysis.Finder(
- av.getAlignment(), av.getSelectionGroup(), seqIndex, colIndex);
- finder.setCaseSensitive(caseSensitive.isSelected());
- finder.setIncludeDescription(searchDescription.isSelected());
-
- finder.setFindAll(doFindAll);
-
- finder.find(searchString);
+ FinderI finder = finders.get(av);
+ if (finder == null)
+ {
+ /*
+ * first time we've searched this viewport
+ */
+ finder = new jalview.analysis.Finder(av);
+ finders.put(av, finder);
+ }
- seqIndex = finder.getSequenceIndex();
- colIndex = finder.getColumnIndex();
- seqIndices.put(av, seqIndex);
- colIndices.put(av, colIndex);
+ boolean isCaseSensitive = caseSensitive.isSelected();
+ boolean doSearchDescription = searchDescription.isSelected();
+ if (doFindAll)
+ {
+ finder.findAll(searchString, isCaseSensitive, doSearchDescription);
+ }
+ else
+ {
+ finder.findNext(searchString, isCaseSensitive, doSearchDescription);
+ }
searchResults = finder.getSearchResults();
- Vector<SequenceI> idMatch = finder.getIdMatch();
+ List<SequenceI> idMatch = finder.getIdMatches();
ap.getIdPanel().highlightSearchResults(idMatch);
if (searchResults.isEmpty())
JvOptionPane.showInternalMessageDialog(this,
MessageManager.getString("label.finished_searching"), null,
JvOptionPane.INFORMATION_MESSAGE);
- colIndex = -1;
- seqIndex = 0;
}
else
{
}
JvOptionPane.showInternalMessageDialog(this, message, null,
JvOptionPane.INFORMATION_MESSAGE);
- colIndex = -1;
- seqIndex = 0;
}
}
searchBox.updateCache();