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.Vector;
46 public class Finder extends Panel implements ActionListener
54 SearchResultsI searchResults;
60 public Finder(final AlignmentPanel ap)
75 jalview.bin.JalviewLite.addFrame(frame,
76 MessageManager.getString("action.find"), 340, 120);
78 frame.addWindowListener(new WindowAdapter()
81 public void windowClosing(WindowEvent evt)
83 ap.highlightSearchResults(null);
86 textfield.requestFocus();
90 public void actionPerformed(ActionEvent evt)
92 if (evt.getSource() == textfield)
97 else if (evt.getSource() == findNext)
102 else if (evt.getSource() == findAll)
108 else if (evt.getSource() == createNewGroup)
110 createNewGroup_actionPerformed();
114 public void createNewGroup_actionPerformed()
116 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
117 SequenceFeature[] features = new SequenceFeature[searchResults
121 for (SearchResultMatchI match : searchResults.getResults())
123 seqs[i] = match.getSequence().getDatasetSequence();
125 features[i] = new SequenceFeature(textfield.getText().trim(),
126 "Search Results", null, match.getStart(), match.getEnd(),
131 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
134 ap.alignFrame.sequenceFeatures.setState(true);
135 av.setShowSequenceFeatures(true);
136 ap.highlightSearchResults(null);
140 void doSearch(boolean findAll)
142 if (ap.av.applet.currentAlignFrame != null)
144 ap = ap.av.applet.currentAlignFrame.alignPanel;
147 createNewGroup.setEnabled(false);
148 jalview.analysis.Finder finder = new jalview.analysis.Finder(
149 av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
150 finder.setCaseSensitive(caseSensitive.getState());
151 finder.setIncludeDescription(searchDescription.getState());
152 finder.setFindAll(findAll);
154 String searchString = textfield.getText();
156 finder.find(searchString);
157 seqIndex = finder.getSeqIndex();
158 resIndex = finder.getResIndex();
159 searchResults = finder.getSearchResults();
160 Vector<SequenceI> idMatch = finder.getIdMatch();
161 boolean haveResults = false;
162 // set or reset the GUI
163 if ((idMatch.size() > 0))
166 ap.idPanel.highlightSearchResults(idMatch);
170 ap.idPanel.highlightSearchResults(null);
173 if (searchResults.getSize() > 0)
176 createNewGroup.setEnabled(true);
181 searchResults = null;
184 // if allResults is null, this effectively switches displaySearch flag in
186 ap.highlightSearchResults(searchResults);
187 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
188 // 'SelectRegion' selection
191 ap.alignFrame.statusBar.setText(MessageManager
192 .getString("label.finished_searching"));
200 String message = (idMatch.size() > 0) ? "" + idMatch.size()
202 if (idMatch.size() > 0 && searchResults != null
203 && searchResults.getSize() > 0)
207 if (searchResults != null)
209 message += searchResults.getSize() + " subsequence matches.";
211 ap.alignFrame.statusBar.setText(MessageManager.formatMessage(
212 "label.search_results", new String[] { searchString,
218 // TODO: indicate sequence and matching position in status bar
219 ap.alignFrame.statusBar.setText(MessageManager.formatMessage(
220 "label.found_match_for", new String[] { searchString }));
225 Label jLabel1 = new Label();
227 protected TextField textfield = new TextField();
229 protected Button findAll = new Button();
231 protected Button findNext = new Button();
233 Panel actionsPanel = new Panel();
235 GridLayout gridLayout1 = new GridLayout();
237 protected Button createNewGroup = new Button();
239 Checkbox caseSensitive = new Checkbox();
241 Checkbox searchDescription = new Checkbox();
243 private void jbInit() throws Exception
245 jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
246 jLabel1.setText(MessageManager.getString("action.find"));
247 jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
248 this.setLayout(null);
249 textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
250 textfield.setText("");
251 textfield.setBounds(new Rectangle(40, 17, 133, 21));
252 textfield.addKeyListener(new java.awt.event.KeyAdapter()
255 public void keyTyped(KeyEvent e)
257 textfield_keyTyped(e);
260 textfield.addActionListener(this);
261 findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
262 findAll.setLabel(MessageManager.getString("action.find_all"));
263 findAll.addActionListener(this);
264 findNext.setEnabled(false);
265 findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
266 findNext.setLabel(MessageManager.getString("action.find_next"));
267 findNext.addActionListener(this);
268 actionsPanel.setBounds(new Rectangle(195, 5, 141, 64));
269 actionsPanel.setLayout(gridLayout1);
270 gridLayout1.setHgap(0);
271 gridLayout1.setRows(3);
272 gridLayout1.setVgap(2);
273 createNewGroup.setEnabled(false);
274 createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
275 createNewGroup.setLabel(MessageManager.getString("label.new_feature"));
276 createNewGroup.addActionListener(this);
277 caseSensitive.setLabel(MessageManager.getString("label.match_case"));
278 caseSensitive.setBounds(new Rectangle(30, 39, 126, 23));
280 searchDescription.setLabel(MessageManager
281 .getString("label.include_description"));
282 searchDescription.setBounds(new Rectangle(30, 59, 170, 23));
283 actionsPanel.add(findNext, null);
284 actionsPanel.add(findAll, null);
285 actionsPanel.add(createNewGroup, null);
286 this.add(caseSensitive);
287 this.add(textfield, null);
288 this.add(jLabel1, null);
289 this.add(actionsPanel, null);
290 this.add(searchDescription);
293 void textfield_keyTyped(KeyEvent e)
295 findNext.setEnabled(true);