2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.datamodel.SearchResultMatchI;
24 import jalview.datamodel.SearchResultsI;
25 import jalview.datamodel.SequenceFeature;
26 import jalview.datamodel.SequenceI;
27 import jalview.util.MessageManager;
28 import jalview.viewmodel.AlignmentViewport;
30 import java.awt.Button;
31 import java.awt.Checkbox;
33 import java.awt.Frame;
34 import java.awt.GridLayout;
35 import java.awt.Label;
36 import java.awt.Panel;
37 import java.awt.Rectangle;
38 import java.awt.TextField;
39 import java.awt.event.ActionEvent;
40 import java.awt.event.ActionListener;
41 import java.awt.event.KeyEvent;
42 import java.awt.event.WindowAdapter;
43 import java.awt.event.WindowEvent;
44 import java.util.ArrayList;
45 import java.util.List;
46 import java.util.Vector;
48 public class Finder extends Panel implements ActionListener
56 SearchResultsI searchResults;
62 public Finder(final AlignmentPanel ap)
77 jalview.bin.JalviewLite.addFrame(frame,
78 MessageManager.getString("action.find"), 340, 120);
80 frame.addWindowListener(new WindowAdapter()
83 public void windowClosing(WindowEvent evt)
85 ap.highlightSearchResults(null);
88 textfield.requestFocus();
92 public void actionPerformed(ActionEvent evt)
94 if (evt.getSource() == textfield)
99 else if (evt.getSource() == findNext)
104 else if (evt.getSource() == findAll)
110 else if (evt.getSource() == createNewGroup)
112 createNewGroup_actionPerformed();
116 public void createNewGroup_actionPerformed()
118 List<SequenceI> seqs = new ArrayList<SequenceI>();
119 List<SequenceFeature> features = new ArrayList<SequenceFeature>();
120 String searchString = textfield.getText().trim();
122 for (SearchResultMatchI match : searchResults.getResults())
124 seqs.add(match.getSequence().getDatasetSequence());
125 features.add(new SequenceFeature(searchString, "Search Results",
126 match.getStart(), match.getEnd(), "Search Results"));
129 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
132 ap.alignFrame.sequenceFeatures.setState(true);
133 av.setShowSequenceFeatures(true);
134 ap.highlightSearchResults(null);
138 void doSearch(boolean findAll)
140 if (ap.av.applet.currentAlignFrame != null)
142 ap = ap.av.applet.currentAlignFrame.alignPanel;
145 createNewGroup.setEnabled(false);
146 jalview.analysis.Finder finder = new jalview.analysis.Finder(
147 av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
148 finder.setCaseSensitive(caseSensitive.getState());
149 finder.setIncludeDescription(searchDescription.getState());
150 finder.setFindAll(findAll);
152 String searchString = textfield.getText();
154 finder.find(searchString);
155 seqIndex = finder.getSeqIndex();
156 resIndex = finder.getResIndex();
157 searchResults = finder.getSearchResults();
158 Vector<SequenceI> idMatch = finder.getIdMatch();
159 boolean haveResults = false;
160 // set or reset the GUI
161 if ((idMatch.size() > 0))
164 ap.idPanel.highlightSearchResults(idMatch);
168 ap.idPanel.highlightSearchResults(null);
171 if (searchResults.getSize() > 0)
174 createNewGroup.setEnabled(true);
179 searchResults = null;
182 // if allResults is null, this effectively switches displaySearch flag in
184 ap.highlightSearchResults(searchResults);
185 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
186 // 'SelectRegion' selection
189 ap.alignFrame.statusBar.setText(
190 MessageManager.getString("label.finished_searching"));
198 String message = (idMatch.size() > 0) ? "" + idMatch.size() + " IDs"
200 if (idMatch.size() > 0 && searchResults != null
201 && searchResults.getSize() > 0)
205 if (searchResults != null)
207 message += searchResults.getSize() + " subsequence matches.";
209 ap.alignFrame.statusBar.setText(MessageManager
210 .formatMessage("label.search_results", new String[]
211 { searchString, message }));
216 // TODO: indicate sequence and matching position in status bar
217 ap.alignFrame.statusBar.setText(MessageManager
218 .formatMessage("label.found_match_for", new String[]
224 Label jLabel1 = new Label();
226 protected TextField textfield = new TextField();
228 protected Button findAll = new Button();
230 protected Button findNext = new Button();
232 Panel actionsPanel = new Panel();
234 GridLayout gridLayout1 = new GridLayout();
236 protected Button createNewGroup = new Button();
238 Checkbox caseSensitive = new Checkbox();
240 Checkbox searchDescription = new Checkbox();
242 private void jbInit() throws Exception
244 jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
245 jLabel1.setText(MessageManager.getString("action.find"));
246 jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
247 this.setLayout(null);
248 textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
249 textfield.setText("");
250 textfield.setBounds(new Rectangle(40, 17, 133, 21));
251 textfield.addKeyListener(new java.awt.event.KeyAdapter()
254 public void keyTyped(KeyEvent e)
256 textfield_keyTyped(e);
259 textfield.addActionListener(this);
260 findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
261 findAll.setLabel(MessageManager.getString("action.find_all"));
262 findAll.addActionListener(this);
263 findNext.setEnabled(false);
264 findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
265 findNext.setLabel(MessageManager.getString("action.find_next"));
266 findNext.addActionListener(this);
267 actionsPanel.setBounds(new Rectangle(195, 5, 141, 64));
268 actionsPanel.setLayout(gridLayout1);
269 gridLayout1.setHgap(0);
270 gridLayout1.setRows(3);
271 gridLayout1.setVgap(2);
272 createNewGroup.setEnabled(false);
273 createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
274 createNewGroup.setLabel(MessageManager.getString("label.new_feature"));
275 createNewGroup.addActionListener(this);
276 caseSensitive.setLabel(MessageManager.getString("label.match_case"));
277 caseSensitive.setBounds(new Rectangle(30, 39, 126, 23));
279 searchDescription.setLabel(
280 MessageManager.getString("label.include_description"));
281 searchDescription.setBounds(new Rectangle(30, 59, 170, 23));
282 actionsPanel.add(findNext, null);
283 actionsPanel.add(findAll, null);
284 actionsPanel.add(createNewGroup, null);
285 this.add(caseSensitive);
286 this.add(textfield, null);
287 this.add(jLabel1, null);
288 this.add(actionsPanel, null);
289 this.add(searchDescription);
292 void textfield_keyTyped(KeyEvent e)
294 findNext.setEnabled(true);