*/
package jalview.appletgui;
+import jalview.api.AlignViewportI;
import jalview.datamodel.SearchResultMatchI;
import jalview.datamodel.SearchResultsI;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.util.MessageManager;
-import jalview.viewmodel.AlignmentViewport;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
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
{
- AlignmentViewport av;
+ private AlignViewportI av;
- AlignmentPanel ap;
+ private AlignmentPanel ap;
- Frame frame;
+ private TextField textfield = new TextField();
- SearchResultsI searchResults;
+ private Button findAll = new Button();
- int seqIndex = 0;
+ private Button findNext = new Button();
- int resIndex = -1;
+ private Button createFeatures = new Button();
+
+ private Checkbox caseSensitive = new Checkbox();
+
+ private Checkbox searchDescription = new Checkbox();
+
+ private SearchResultsI searchResults;
+
+ /*
+ * sequence index and residue position of last match,
+ * for current search and per viewport
+ */
+ private int seqIndex = 0;
+
+ private int resIndex = -1;
+
+ Map<AlignViewportI, Integer> seqIndices;
+
+ Map<AlignViewportI, Integer> resIndices;
public Finder(final AlignmentPanel ap)
{
+ seqIndices = new HashMap<>();
+ resIndices = new HashMap<>();
+
try
{
jbInit();
this.av = ap.av;
this.ap = ap;
- frame = new Frame();
+ Frame frame = new Frame();
frame.add(this);
jalview.bin.JalviewLite.addFrame(frame,
MessageManager.getString("action.find"), 340, 120);
seqIndex = 0;
doSearch(true);
}
- else if (evt.getSource() == createNewGroup)
+ else if (evt.getSource() == createFeatures)
{
- createNewGroup_actionPerformed();
+ createFeatures_actionPerformed();
}
}
- public void createNewGroup_actionPerformed()
+ public void createFeatures_actionPerformed()
{
List<SequenceI> seqs = new ArrayList<>();
List<SequenceFeature> features = new ArrayList<>();
}
}
- void doSearch(boolean findAll)
+ void doSearch(boolean doFindAll)
{
if (ap.av.applet.currentAlignFrame != null)
{
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();
+ }
}
- createNewGroup.setEnabled(false);
+ 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(findAll);
+ finder.setFindAll(doFindAll);
String searchString = textfield.getText();
finder.find(searchString);
+
seqIndex = finder.getSeqIndex();
resIndex = finder.getResIndex();
+ seqIndices.put(av, seqIndex);
+ resIndices.put(av, resIndex);
searchResults = finder.getSearchResults();
+
Vector<SequenceI> idMatch = finder.getIdMatch();
ap.idPanel.highlightSearchResults(idMatch);
}
else
{
- createNewGroup.setEnabled(true);
+ createFeatures.setEnabled(true);
}
// if allResults is null, this effectively switches displaySearch flag in
}
else
{
- if (findAll)
+ if (doFindAll)
{
String message = (idMatch.size() > 0) ? "" + idMatch.size() + " IDs"
: "";
}
}
- Label jLabel1 = new Label();
-
- protected TextField textfield = new TextField();
-
- protected Button findAll = new Button();
-
- protected Button findNext = new Button();
-
- Panel actionsPanel = new Panel();
-
- GridLayout gridLayout1 = new GridLayout();
-
- protected Button createNewGroup = new Button();
-
- Checkbox caseSensitive = new Checkbox();
-
- Checkbox searchDescription = new Checkbox();
-
private void jbInit() throws Exception
{
+ Label jLabel1 = new Label(MessageManager.getString("action.find"));
jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
- jLabel1.setText(MessageManager.getString("action.find"));
jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
this.setLayout(null);
textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
@Override
public void keyTyped(KeyEvent e)
{
- textfield_keyTyped(e);
+ textfield_keyTyped();
}
});
textfield.addActionListener(this);
findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
findNext.setLabel(MessageManager.getString("action.find_next"));
findNext.addActionListener(this);
+
+ Panel actionsPanel = new Panel();
actionsPanel.setBounds(new Rectangle(195, 5, 141, 64));
+ GridLayout gridLayout1 = new GridLayout();
actionsPanel.setLayout(gridLayout1);
gridLayout1.setHgap(0);
gridLayout1.setRows(3);
gridLayout1.setVgap(2);
- createNewGroup.setEnabled(false);
- createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- createNewGroup.setLabel(MessageManager.getString("label.new_feature"));
- createNewGroup.addActionListener(this);
+ createFeatures.setEnabled(false);
+ createFeatures.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
+ createFeatures.setLabel(MessageManager.getString("label.new_feature"));
+ createFeatures.addActionListener(this);
caseSensitive.setLabel(MessageManager.getString("label.match_case"));
caseSensitive.setBounds(new Rectangle(30, 39, 126, 23));
searchDescription.setBounds(new Rectangle(30, 59, 170, 23));
actionsPanel.add(findNext, null);
actionsPanel.add(findAll, null);
- actionsPanel.add(createNewGroup, null);
+ actionsPanel.add(createFeatures, null);
this.add(caseSensitive);
this.add(textfield, null);
this.add(jLabel1, null);
this.add(searchDescription);
}
- void textfield_keyTyped(KeyEvent e)
+ void textfield_keyTyped()
{
findNext.setEnabled(true);
}
*/
package jalview.gui;
+import jalview.api.AlignViewportI;
import jalview.datamodel.SearchResultMatchI;
import jalview.datamodel.SearchResultsI;
import jalview.datamodel.SequenceFeature;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
+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;
*/
public class Finder extends GFinder
{
+ private static final int MIN_WIDTH = 350;
+
+ private static final int MIN_HEIGHT = 120;
+
private static final int MY_HEIGHT = 120;
private static final int MY_WIDTH = 400;
- AlignmentViewport av;
+ private AlignViewportI av;
- AlignmentPanel ap;
+ private AlignmentPanel ap;
- private static final int MIN_WIDTH = 350;
+ private JInternalFrame frame;
- private static final int MIN_HEIGHT = 120;
+ /*
+ * sequence and column position of the last match,
+ * as currently used, and saved for each viewport
+ */
+ private int seqIndex = 0;
- JInternalFrame frame;
+ private int resIndex = -1;
- int seqIndex = 0;
+ Map<AlignViewportI, Integer> seqIndices;
- int resIndex = -1;
+ Map<AlignViewportI, Integer> resIndices;
- SearchResultsI searchResults;
+ private SearchResultsI searchResults;
/**
* Creates a new Finder object with no associated viewport or panel.
{
av = viewport;
ap = alignPanel;
+ seqIndices = new HashMap<>();
+ resIndices = new HashMap<>();
focusfixed = true;
frame = new JInternalFrame();
frame.setContentPane(this);
{
av = ((AlignFrame) alignFrame).viewport;
ap = ((AlignFrame) alignFrame).alignPanel;
+
+ /*
+ * restore search position if switching to a
+ * panel where we have previously searched
+ */
+ seqIndex = 0;
+ resIndex = -1;
+ if (seqIndices.containsKey(av))
+ {
+ seqIndex = seqIndices.get(av).intValue();
+ }
+ if (resIndices.containsKey(av))
+ {
+ resIndex = resIndices.get(av).intValue();
+ }
return true;
}
}
seqIndex = finder.getSeqIndex();
resIndex = finder.getResIndex();
+ seqIndices.put(av, seqIndex);
+ resIndices.put(av, resIndex);
searchResults = finder.getSearchResults();
Vector<SequenceI> idMatch = finder.getIdMatch();