2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.datamodel.*;
26 import jalview.util.MessageManager;
28 public class Finder extends Panel implements ActionListener
36 SearchResults searchResults;
42 public Finder(final AlignmentPanel ap)
57 jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("action.find"), 340, 120);
59 frame.addWindowListener(new WindowAdapter()
61 public void windowClosing(WindowEvent evt)
63 ap.highlightSearchResults(null);
66 textfield.requestFocus();
69 public void actionPerformed(ActionEvent evt)
71 if (evt.getSource() == textfield)
76 else if (evt.getSource() == findNext)
81 else if (evt.getSource() == findAll)
87 else if (evt.getSource() == createNewGroup)
89 createNewGroup_actionPerformed();
93 public void createNewGroup_actionPerformed()
95 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
96 SequenceFeature[] features = new SequenceFeature[searchResults
99 for (int i = 0; i < searchResults.getSize(); i++)
101 seqs[i] = searchResults.getResultSequence(i);
103 features[i] = new SequenceFeature(textfield.getText().trim(),
104 "Search Results", null, searchResults.getResultStart(i),
105 searchResults.getResultEnd(i), "Search Results");
108 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
111 ap.alignFrame.sequenceFeatures.setState(true);
112 av.showSequenceFeatures(true);
113 ap.highlightSearchResults(null);
117 void doSearch(boolean findAll)
119 if (ap.av.applet.currentAlignFrame != null)
121 ap = ap.av.applet.currentAlignFrame.alignPanel;
124 createNewGroup.setEnabled(false);
125 jalview.analysis.Finder finder = new jalview.analysis.Finder(
126 av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
127 finder.setCaseSensitive(caseSensitive.getState());
128 finder.setFindAll(findAll);
130 String searchString = textfield.getText();
132 finder.find(searchString);
133 seqIndex = finder.getSeqIndex();
134 resIndex = finder.getResIndex();
135 searchResults = finder.getSearchResults();
136 Vector idMatch = finder.getIdMatch();
137 boolean haveResults = false;
138 // set or reset the GUI
139 if ((idMatch.size() > 0))
142 ap.idPanel.highlightSearchResults(idMatch);
146 ap.idPanel.highlightSearchResults(null);
149 if (searchResults.getSize() > 0)
152 createNewGroup.setEnabled(true);
157 searchResults = null;
160 // if allResults is null, this effectively switches displaySearch flag in
162 ap.highlightSearchResults(searchResults);
163 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
164 // 'SelectRegion' selection
167 ap.alignFrame.statusBar.setText(MessageManager.getString("label.finished_searching"));
175 String message = (idMatch.size() > 0) ? "" + idMatch.size()
177 if (idMatch.size() > 0 && searchResults != null
178 && searchResults.getSize() > 0)
182 if (searchResults != null)
184 message += searchResults.getSize() + " subsequence matches.";
186 ap.alignFrame.statusBar.setText(MessageManager.formatMessage("label.search_results", new String[] {searchString, message}));
191 // TODO: indicate sequence and matching position in status bar
192 ap.alignFrame.statusBar.setText(MessageManager.formatMessage("label.found_match_for", new String[]{searchString}));
197 Label jLabel1 = new Label();
199 protected TextField textfield = new TextField();
201 protected Button findAll = new Button();
203 protected Button findNext = new Button();
205 Panel jPanel1 = new Panel();
207 GridLayout gridLayout1 = new GridLayout();
209 protected Button createNewGroup = new Button();
211 Checkbox caseSensitive = new Checkbox();
213 private void jbInit() throws Exception
215 jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
216 jLabel1.setText(MessageManager.getString("action.find"));
217 jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
218 this.setLayout(null);
219 textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
220 textfield.setText("");
221 textfield.setBounds(new Rectangle(40, 27, 133, 21));
222 textfield.addKeyListener(new java.awt.event.KeyAdapter()
224 public void keyTyped(KeyEvent e)
226 textfield_keyTyped(e);
229 textfield.addActionListener(this);
230 findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
231 findAll.setLabel(MessageManager.getString("action.find_all"));
232 findAll.addActionListener(this);
233 findNext.setEnabled(false);
234 findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
235 findNext.setLabel(MessageManager.getString("action.find_next"));
236 findNext.addActionListener(this);
237 jPanel1.setBounds(new Rectangle(180, 5, 141, 64));
238 jPanel1.setLayout(gridLayout1);
239 gridLayout1.setHgap(0);
240 gridLayout1.setRows(3);
241 gridLayout1.setVgap(2);
242 createNewGroup.setEnabled(false);
243 createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
244 createNewGroup.setLabel(MessageManager.getString("label.new_feature"));
245 createNewGroup.addActionListener(this);
246 caseSensitive.setLabel(MessageManager.getString("label.match_case"));
247 caseSensitive.setBounds(new Rectangle(40, 49, 126, 23));
248 jPanel1.add(findNext, null);
249 jPanel1.add(findAll, null);
250 jPanel1.add(createNewGroup, null);
251 this.add(caseSensitive);
252 this.add(textfield, null);
253 this.add(jLabel1, null);
254 this.add(jPanel1, null);
257 void textfield_keyTyped(KeyEvent e)
259 findNext.setEnabled(true);