2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5.1)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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.*;
27 public class Finder extends Panel implements ActionListener
35 SearchResults searchResults;
41 public Finder(final AlignmentPanel ap)
56 jalview.bin.JalviewLite.addFrame(frame, "Find", 340, 120);
58 frame.addWindowListener(new WindowAdapter()
60 public void windowClosing(WindowEvent evt)
62 ap.highlightSearchResults(null);
65 textfield.requestFocus();
68 public void actionPerformed(ActionEvent evt)
70 if (evt.getSource() == textfield)
75 else if (evt.getSource() == findNext)
80 else if (evt.getSource() == findAll)
86 else if (evt.getSource() == createNewGroup)
88 createNewGroup_actionPerformed();
92 public void createNewGroup_actionPerformed()
94 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
95 SequenceFeature[] features = new SequenceFeature[searchResults
98 for (int i = 0; i < searchResults.getSize(); i++)
100 seqs[i] = searchResults.getResultSequence(i);
102 features[i] = new SequenceFeature(textfield.getText().trim(),
103 "Search Results", null, searchResults.getResultStart(i),
104 searchResults.getResultEnd(i), "Search Results");
107 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
110 ap.alignFrame.sequenceFeatures.setState(true);
111 av.showSequenceFeatures(true);
112 ap.highlightSearchResults(null);
116 void doSearch(boolean findAll)
118 if (jalview.bin.JalviewLite.currentAlignFrame != null)
120 ap = jalview.bin.JalviewLite.currentAlignFrame.alignPanel;
123 createNewGroup.setEnabled(false);
124 jalview.analysis.Finder finder = new jalview.analysis.Finder(av
125 .getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
126 finder.setCaseSensitive(caseSensitive.getState());
127 finder.setFindAll(findAll);
129 String searchString = textfield.getText();
131 finder.find(searchString);
132 seqIndex = finder.getSeqIndex();
133 resIndex = finder.getResIndex();
134 searchResults = finder.getSearchResults();
135 Vector idMatch = finder.getIdMatch();
136 boolean haveResults = false;
137 // set or reset the GUI
138 if ((idMatch.size() > 0))
141 ap.idPanel.highlightSearchResults(idMatch);
145 ap.idPanel.highlightSearchResults(null);
148 if (searchResults.getSize() > 0)
151 createNewGroup.setEnabled(true);
156 searchResults = null;
159 // if allResults is null, this effectively switches displaySearch flag in
161 ap.highlightSearchResults(searchResults);
162 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
163 // 'SelectRegion' selection
166 ap.alignFrame.statusBar.setText("Finished searching.");
172 String message = (idMatch.size() > 0) ? "" + idMatch.size() + " IDs"
174 if (idMatch.size() > 0 && searchResults != null
175 && searchResults.getSize() > 0)
179 if (searchResults != null)
181 message += searchResults.getSize() + " subsequence matches.";
183 ap.alignFrame.statusBar.setText("Search results: " + searchString
190 Label jLabel1 = new Label();
192 protected TextField textfield = new TextField();
194 protected Button findAll = new Button();
196 protected Button findNext = new Button();
198 Panel jPanel1 = new Panel();
200 GridLayout gridLayout1 = new GridLayout();
202 protected Button createNewGroup = new Button();
204 Checkbox caseSensitive = new Checkbox();
206 private void jbInit() throws Exception
208 jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
209 jLabel1.setText("Find");
210 jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
211 this.setLayout(null);
212 textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
213 textfield.setText("");
214 textfield.setBounds(new Rectangle(40, 27, 133, 21));
215 textfield.addKeyListener(new java.awt.event.KeyAdapter()
217 public void keyTyped(KeyEvent e)
219 textfield_keyTyped(e);
222 textfield.addActionListener(this);
223 findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
224 findAll.setLabel("Find all");
225 findAll.addActionListener(this);
226 findNext.setEnabled(false);
227 findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
228 findNext.setLabel("Find Next");
229 findNext.addActionListener(this);
230 jPanel1.setBounds(new Rectangle(180, 5, 141, 64));
231 jPanel1.setLayout(gridLayout1);
232 gridLayout1.setHgap(0);
233 gridLayout1.setRows(3);
234 gridLayout1.setVgap(2);
235 createNewGroup.setEnabled(false);
236 createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
237 createNewGroup.setLabel("New Feature");
238 createNewGroup.addActionListener(this);
239 caseSensitive.setLabel("Match Case");
240 caseSensitive.setBounds(new Rectangle(40, 49, 126, 23));
241 jPanel1.add(findNext, null);
242 jPanel1.add(findAll, null);
243 jPanel1.add(createNewGroup, null);
244 this.add(caseSensitive);
245 this.add(textfield, null);
246 this.add(jLabel1, null);
247 this.add(jPanel1, null);
250 void textfield_keyTyped(KeyEvent e)
252 findNext.setEnabled(true);