X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FFinder.java;h=f44387f0b0a1b7cd92de10abaf34c6f521d89d74;hb=ca87cef11606dd9b1ba66222cea87e000e556817;hp=ee0d4a074478478911c1622b5220021e6c1588be;hpb=dfc18d64376ae95cfdbf3c112825587a8891179c;p=jalview.git diff --git a/src/jalview/appletgui/Finder.java b/src/jalview/appletgui/Finder.java index ee0d4a0..f44387f 100644 --- a/src/jalview/appletgui/Finder.java +++ b/src/jalview/appletgui/Finder.java @@ -20,12 +20,12 @@ */ 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; @@ -42,25 +42,48 @@ import java.awt.event.KeyEvent; 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 seqIndices; + + Map resIndices; public Finder(final AlignmentPanel ap) { + seqIndices = new HashMap<>(); + resIndices = new HashMap<>(); + try { jbInit(); @@ -72,7 +95,7 @@ public class Finder extends Panel implements ActionListener 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); @@ -107,13 +130,13 @@ public class Finder extends Panel implements ActionListener 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 seqs = new ArrayList<>(); List features = new ArrayList<>(); @@ -135,26 +158,40 @@ public class Finder extends Panel implements ActionListener } } - 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 idMatch = finder.getIdMatch(); ap.idPanel.highlightSearchResults(idMatch); @@ -164,7 +201,7 @@ public class Finder extends Panel implements ActionListener } else { - createNewGroup.setEnabled(true); + createFeatures.setEnabled(true); } // if allResults is null, this effectively switches displaySearch flag in @@ -181,7 +218,7 @@ public class Finder extends Panel implements ActionListener } else { - if (findAll) + if (doFindAll) { String message = (idMatch.size() > 0) ? "" + idMatch.size() + " IDs" : ""; @@ -209,28 +246,10 @@ public class Finder extends Panel implements ActionListener } } - 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)); @@ -241,7 +260,7 @@ public class Finder extends Panel implements ActionListener @Override public void keyTyped(KeyEvent e) { - textfield_keyTyped(e); + textfield_keyTyped(); } }); textfield.addActionListener(this); @@ -252,15 +271,18 @@ public class Finder extends Panel implements ActionListener 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)); @@ -269,7 +291,7 @@ public class Finder extends Panel implements ActionListener 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); @@ -277,7 +299,7 @@ public class Finder extends Panel implements ActionListener this.add(searchDescription); } - void textfield_keyTyped(KeyEvent e) + void textfield_keyTyped() { findNext.setEnabled(true); }