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.SearchResultsI;
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 SearchResultsI 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()
80 public void windowClosing(WindowEvent evt)
82 ap.highlightSearchResults(null);
85 textfield.requestFocus();
89 public void actionPerformed(ActionEvent evt)
91 if (evt.getSource() == textfield)
96 else if (evt.getSource() == findNext)
101 else if (evt.getSource() == findAll)
107 else if (evt.getSource() == createNewGroup)
109 createNewGroup_actionPerformed();
113 public void createNewGroup_actionPerformed()
115 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
116 SequenceFeature[] features = new SequenceFeature[searchResults
119 for (int i = 0; i < searchResults.getSize(); i++)
121 seqs[i] = searchResults.getResultSequence(i);
123 features[i] = new SequenceFeature(textfield.getText().trim(),
124 "Search Results", null, searchResults.getResultStart(i),
125 searchResults.getResultEnd(i), "Search Results");
128 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
131 ap.alignFrame.sequenceFeatures.setState(true);
132 av.setShowSequenceFeatures(true);
133 ap.highlightSearchResults(null);
137 void doSearch(boolean findAll)
139 if (ap.av.applet.currentAlignFrame != null)
141 ap = ap.av.applet.currentAlignFrame.alignPanel;
144 createNewGroup.setEnabled(false);
145 jalview.analysis.Finder finder = new jalview.analysis.Finder(
146 av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
147 finder.setCaseSensitive(caseSensitive.getState());
148 finder.setIncludeDescription(searchDescription.getState());
149 finder.setFindAll(findAll);
151 String searchString = textfield.getText();
153 finder.find(searchString);
154 seqIndex = finder.getSeqIndex();
155 resIndex = finder.getResIndex();
156 searchResults = finder.getSearchResults();
157 Vector<SequenceI> idMatch = finder.getIdMatch();
158 boolean haveResults = false;
159 // set or reset the GUI
160 if ((idMatch.size() > 0))
163 ap.idPanel.highlightSearchResults(idMatch);
167 ap.idPanel.highlightSearchResults(null);
170 if (searchResults.getSize() > 0)
173 createNewGroup.setEnabled(true);
178 searchResults = null;
181 // if allResults is null, this effectively switches displaySearch flag in
183 ap.highlightSearchResults(searchResults);
184 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
185 // 'SelectRegion' selection
188 ap.alignFrame.statusBar.setText(MessageManager
189 .getString("label.finished_searching"));
197 String message = (idMatch.size() > 0) ? "" + idMatch.size()
199 if (idMatch.size() > 0 && searchResults != null
200 && searchResults.getSize() > 0)
204 if (searchResults != null)
206 message += searchResults.getSize() + " subsequence matches.";
208 ap.alignFrame.statusBar.setText(MessageManager.formatMessage(
209 "label.search_results", new String[] { searchString,
215 // TODO: indicate sequence and matching position in status bar
216 ap.alignFrame.statusBar.setText(MessageManager.formatMessage(
217 "label.found_match_for", new String[] { searchString }));
222 Label jLabel1 = new Label();
224 protected TextField textfield = new TextField();
226 protected Button findAll = new Button();
228 protected Button findNext = new Button();
230 Panel actionsPanel = new Panel();
232 GridLayout gridLayout1 = new GridLayout();
234 protected Button createNewGroup = new Button();
236 Checkbox caseSensitive = new Checkbox();
238 Checkbox searchDescription = new Checkbox();
240 private void jbInit() throws Exception
242 jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
243 jLabel1.setText(MessageManager.getString("action.find"));
244 jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
245 this.setLayout(null);
246 textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
247 textfield.setText("");
248 textfield.setBounds(new Rectangle(40, 17, 133, 21));
249 textfield.addKeyListener(new java.awt.event.KeyAdapter()
252 public void keyTyped(KeyEvent e)
254 textfield_keyTyped(e);
257 textfield.addActionListener(this);
258 findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
259 findAll.setLabel(MessageManager.getString("action.find_all"));
260 findAll.addActionListener(this);
261 findNext.setEnabled(false);
262 findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
263 findNext.setLabel(MessageManager.getString("action.find_next"));
264 findNext.addActionListener(this);
265 actionsPanel.setBounds(new Rectangle(195, 5, 141, 64));
266 actionsPanel.setLayout(gridLayout1);
267 gridLayout1.setHgap(0);
268 gridLayout1.setRows(3);
269 gridLayout1.setVgap(2);
270 createNewGroup.setEnabled(false);
271 createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
272 createNewGroup.setLabel(MessageManager.getString("label.new_feature"));
273 createNewGroup.addActionListener(this);
274 caseSensitive.setLabel(MessageManager.getString("label.match_case"));
275 caseSensitive.setBounds(new Rectangle(30, 39, 126, 23));
277 searchDescription.setLabel(MessageManager
278 .getString("label.include_description"));
279 searchDescription.setBounds(new Rectangle(30, 59, 170, 23));
280 actionsPanel.add(findNext, null);
281 actionsPanel.add(findAll, null);
282 actionsPanel.add(createNewGroup, null);
283 this.add(caseSensitive);
284 this.add(textfield, null);
285 this.add(jLabel1, null);
286 this.add(actionsPanel, null);
287 this.add(searchDescription);
290 void textfield_keyTyped(KeyEvent e)
292 findNext.setEnabled(true);