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.SearchResults;
24 import jalview.datamodel.SequenceFeature;
25 import jalview.datamodel.SequenceI;
26 import jalview.util.MessageManager;
27 import jalview.viewmodel.AlignmentViewport;
29 import java.awt.Button;
30 import java.awt.Checkbox;
32 import java.awt.Frame;
33 import java.awt.GridLayout;
34 import java.awt.Label;
35 import java.awt.Panel;
36 import java.awt.Rectangle;
37 import java.awt.TextField;
38 import java.awt.event.ActionEvent;
39 import java.awt.event.ActionListener;
40 import java.awt.event.KeyEvent;
41 import java.awt.event.WindowAdapter;
42 import java.awt.event.WindowEvent;
43 import java.util.Vector;
45 public class Finder extends Panel implements ActionListener
53 SearchResults searchResults;
59 public Finder(final AlignmentPanel ap)
74 jalview.bin.JalviewLite.addFrame(frame,
75 MessageManager.getString("action.find"), 340, 120);
77 frame.addWindowListener(new WindowAdapter()
79 public void windowClosing(WindowEvent evt)
81 ap.highlightSearchResults(null);
84 textfield.requestFocus();
87 public void actionPerformed(ActionEvent evt)
89 if (evt.getSource() == textfield)
94 else if (evt.getSource() == findNext)
99 else if (evt.getSource() == findAll)
105 else if (evt.getSource() == createNewGroup)
107 createNewGroup_actionPerformed();
111 public void createNewGroup_actionPerformed()
113 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
114 SequenceFeature[] features = new SequenceFeature[searchResults
117 for (int i = 0; i < searchResults.getSize(); i++)
119 seqs[i] = searchResults.getResultSequence(i);
121 features[i] = new SequenceFeature(textfield.getText().trim(),
122 "Search Results", null, searchResults.getResultStart(i),
123 searchResults.getResultEnd(i), "Search Results");
126 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
129 ap.alignFrame.sequenceFeatures.setState(true);
130 av.setShowSequenceFeatures(true);
131 ap.highlightSearchResults(null);
135 void doSearch(boolean findAll)
137 if (ap.av.applet.currentAlignFrame != null)
139 ap = ap.av.applet.currentAlignFrame.alignPanel;
142 createNewGroup.setEnabled(false);
143 jalview.analysis.Finder finder = new jalview.analysis.Finder(
144 av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
145 finder.setCaseSensitive(caseSensitive.getState());
146 finder.setIncludeDescription(searchDescription.getState());
147 finder.setFindAll(findAll);
149 String searchString = textfield.getText();
151 finder.find(searchString);
152 seqIndex = finder.getSeqIndex();
153 resIndex = finder.getResIndex();
154 searchResults = finder.getSearchResults();
155 Vector idMatch = finder.getIdMatch();
156 boolean haveResults = false;
157 // set or reset the GUI
158 if ((idMatch.size() > 0))
161 ap.idPanel.highlightSearchResults(idMatch);
165 ap.idPanel.highlightSearchResults(null);
168 if (searchResults.getSize() > 0)
171 createNewGroup.setEnabled(true);
176 searchResults = null;
179 // if allResults is null, this effectively switches displaySearch flag in
181 ap.highlightSearchResults(searchResults);
182 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
183 // 'SelectRegion' selection
186 ap.alignFrame.statusBar.setText(MessageManager
187 .getString("label.finished_searching"));
195 String message = (idMatch.size() > 0) ? "" + idMatch.size()
197 if (idMatch.size() > 0 && searchResults != null
198 && searchResults.getSize() > 0)
202 if (searchResults != null)
204 message += searchResults.getSize() + " subsequence matches.";
206 ap.alignFrame.statusBar.setText(MessageManager.formatMessage(
207 "label.search_results", new String[]
208 { searchString, message }));
213 // TODO: indicate sequence and matching position in status bar
214 ap.alignFrame.statusBar.setText(MessageManager.formatMessage(
215 "label.found_match_for", new String[]
221 Label jLabel1 = new Label();
223 protected TextField textfield = new TextField();
225 protected Button findAll = new Button();
227 protected Button findNext = new Button();
229 Panel actionsPanel = new Panel();
231 GridLayout gridLayout1 = new GridLayout();
233 protected Button createNewGroup = new Button();
235 Checkbox caseSensitive = new Checkbox();
237 Checkbox searchDescription = new Checkbox();
239 private void jbInit() throws Exception
241 jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
242 jLabel1.setText(MessageManager.getString("action.find"));
243 jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
244 this.setLayout(null);
245 textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
246 textfield.setText("");
247 textfield.setBounds(new Rectangle(40, 17, 133, 21));
248 textfield.addKeyListener(new java.awt.event.KeyAdapter()
250 public void keyTyped(KeyEvent e)
252 textfield_keyTyped(e);
255 textfield.addActionListener(this);
256 findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
257 findAll.setLabel(MessageManager.getString("action.find_all"));
258 findAll.addActionListener(this);
259 findNext.setEnabled(false);
260 findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
261 findNext.setLabel(MessageManager.getString("action.find_next"));
262 findNext.addActionListener(this);
263 actionsPanel.setBounds(new Rectangle(195, 5, 141, 64));
264 actionsPanel.setLayout(gridLayout1);
265 gridLayout1.setHgap(0);
266 gridLayout1.setRows(3);
267 gridLayout1.setVgap(2);
268 createNewGroup.setEnabled(false);
269 createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
270 createNewGroup.setLabel(MessageManager.getString("label.new_feature"));
271 createNewGroup.addActionListener(this);
272 caseSensitive.setLabel(MessageManager.getString("label.match_case"));
273 caseSensitive.setBounds(new Rectangle(30, 39, 126, 23));
275 searchDescription.setLabel(MessageManager
276 .getString("label.include_description"));
277 searchDescription.setBounds(new Rectangle(30, 59, 170, 23));
278 actionsPanel.add(findNext, null);
279 actionsPanel.add(findAll, null);
280 actionsPanel.add(createNewGroup, null);
281 this.add(caseSensitive);
282 this.add(textfield, null);
283 this.add(jLabel1, null);
284 this.add(actionsPanel, null);
285 this.add(searchDescription);
288 void textfield_keyTyped(KeyEvent e)
290 findNext.setEnabled(true);