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.bin.JalviewLite;
24 import jalview.datamodel.SearchResults;
25 import jalview.datamodel.SequenceFeature;
26 import jalview.datamodel.SequenceI;
27 import jalview.util.MessageManager;
28 import jalview.viewmodel.AlignmentViewport;
30 import awt2swing.Button;
31 import awt2swing.Checkbox;
33 import awt2swing.Frame;
34 import java.awt.GridLayout;
35 import awt2swing.Label;
36 import awt2swing.Panel;
37 import java.awt.Rectangle;
38 import awt2swing.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 SearchResults searchResults;
60 public Finder(final AlignmentPanel ap)
75 JalviewLite.addFrame(frame,
76 MessageManager.getString("action.find"), 340, 120);
78 frame.addWindowListener(new WindowAdapter()
80 public void windowClosing(WindowEvent evt)
82 ap.highlightSearchResults(null);
85 textfield.requestFocus();
88 public void actionPerformed(ActionEvent evt)
90 if (evt.getSource() == textfield)
95 else if (evt.getSource() == findNext)
100 else if (evt.getSource() == findAll)
106 else if (evt.getSource() == createNewGroup)
108 createNewGroup_actionPerformed();
112 public void createNewGroup_actionPerformed()
114 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
115 SequenceFeature[] features = new SequenceFeature[searchResults
118 for (int i = 0; i < searchResults.getSize(); i++)
120 seqs[i] = searchResults.getResultSequence(i);
122 features[i] = new SequenceFeature(textfield.getText().trim(),
123 "Search Results", null, searchResults.getResultStart(i),
124 searchResults.getResultEnd(i), "Search Results");
127 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
130 ap.alignFrame.sequenceFeatures.setState(true);
131 av.setShowSequenceFeatures(true);
132 ap.highlightSearchResults(null);
136 void doSearch(boolean findAll)
138 if (ap.av.applet.currentAlignFrame != null)
140 ap = ap.av.applet.currentAlignFrame.alignPanel;
143 createNewGroup.setEnabled(false);
144 jalview.analysis.Finder finder = new jalview.analysis.Finder(
145 av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
146 finder.setCaseSensitive(caseSensitive.getState());
147 finder.setIncludeDescription(searchDescription.getState());
148 finder.setFindAll(findAll);
150 String searchString = textfield.getText();
152 finder.find(searchString);
153 seqIndex = finder.getSeqIndex();
154 resIndex = finder.getResIndex();
155 searchResults = finder.getSearchResults();
156 Vector idMatch = finder.getIdMatch();
157 boolean haveResults = false;
158 // set or reset the GUI
159 if ((idMatch.size() > 0))
162 ap.idPanel.highlightSearchResults(idMatch);
166 ap.idPanel.highlightSearchResults(null);
169 if (searchResults.getSize() > 0)
172 createNewGroup.setEnabled(true);
177 searchResults = null;
180 // if allResults is null, this effectively switches displaySearch flag in
182 ap.highlightSearchResults(searchResults);
183 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
184 // 'SelectRegion' selection
187 ap.alignFrame.setStatus(MessageManager
188 .getString("label.finished_searching"));
196 String message = (idMatch.size() > 0) ? "" + idMatch.size()
198 if (idMatch.size() > 0 && searchResults != null
199 && searchResults.getSize() > 0)
203 if (searchResults != null)
205 message += searchResults.getSize() + " subsequence matches.";
207 ap.alignFrame.setStatus(MessageManager.formatMessage(
208 "label.search_results", new String[]
209 { searchString, message }));
214 // TODO: indicate sequence and matching position in status bar
215 ap.alignFrame.setStatus(MessageManager.formatMessage(
216 "label.found_match_for", new String[]
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()
251 public void keyTyped(KeyEvent e)
253 textfield_keyTyped(e);
256 textfield.addActionListener(this);
257 findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
258 findAll.setLabel(MessageManager.getString("action.find_all"));
259 findAll.addActionListener(this);
260 findNext.setEnabled(false);
261 findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
262 findNext.setLabel(MessageManager.getString("action.find_next"));
263 findNext.addActionListener(this);
264 actionsPanel.setBounds(new Rectangle(195, 5, 141, 64));
265 actionsPanel.setLayout(gridLayout1);
266 gridLayout1.setHgap(0);
267 gridLayout1.setRows(3);
268 gridLayout1.setVgap(2);
269 createNewGroup.setEnabled(false);
270 createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
271 createNewGroup.setLabel(MessageManager.getString("label.new_feature"));
272 createNewGroup.addActionListener(this);
273 caseSensitive.setLabel(MessageManager.getString("label.match_case"));
274 caseSensitive.setBounds(new Rectangle(30, 39, 126, 23));
276 searchDescription.setLabel(MessageManager
277 .getString("label.include_description"));
278 searchDescription.setBounds(new Rectangle(30, 59, 170, 23));
279 actionsPanel.add(findNext, null);
280 actionsPanel.add(findAll, null);
281 actionsPanel.add(createNewGroup, null);
282 this.add(caseSensitive);
283 this.add(textfield, null);
284 this.add(jLabel1, null);
285 this.add(actionsPanel, null);
286 this.add(searchDescription);
289 void textfield_keyTyped(KeyEvent e)
291 findNext.setEnabled(true);