2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.datamodel.*;
28 public class Finder extends Panel implements ActionListener
36 SearchResults searchResults;
42 public Finder(final AlignmentPanel ap)
57 jalview.bin.JalviewLite.addFrame(frame, "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 (jalview.bin.JalviewLite.currentAlignFrame != null)
121 ap = jalview.bin.JalviewLite.currentAlignFrame.alignPanel;
124 createNewGroup.setEnabled(false);
125 jalview.analysis.Finder finder = new jalview.analysis.Finder(av
126 .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();
138 if (searchResults.getSize() == 0 && idMatch.size() > 0)
140 ap.idPanel.highlightSearchResults(idMatch);
143 if (searchResults.getSize() > 0)
145 createNewGroup.setEnabled(true);
150 searchResults = null;
155 // if allResults is null, this effectively switches displaySearch flag in
157 ap.highlightSearchResults(searchResults);
161 String message = (searchResults == null ? 0 : searchResults.getSize())
163 ap.alignFrame.statusBar.setText("Search results: " + searchString
169 Label jLabel1 = new Label();
171 protected TextField textfield = new TextField();
173 protected Button findAll = new Button();
175 protected Button findNext = new Button();
177 Panel jPanel1 = new Panel();
179 GridLayout gridLayout1 = new GridLayout();
181 protected Button createNewGroup = new Button();
183 Checkbox caseSensitive = new Checkbox();
185 private void jbInit() throws Exception
187 jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
188 jLabel1.setText("Find");
189 jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
190 this.setLayout(null);
191 textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
192 textfield.setText("");
193 textfield.setBounds(new Rectangle(40, 27, 133, 21));
194 textfield.addKeyListener(new java.awt.event.KeyAdapter()
196 public void keyTyped(KeyEvent e)
198 textfield_keyTyped(e);
201 textfield.addActionListener(this);
202 findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
203 findAll.setLabel("Find all");
204 findAll.addActionListener(this);
205 findNext.setEnabled(false);
206 findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
207 findNext.setLabel("Find Next");
208 findNext.addActionListener(this);
209 jPanel1.setBounds(new Rectangle(180, 5, 141, 64));
210 jPanel1.setLayout(gridLayout1);
211 gridLayout1.setHgap(0);
212 gridLayout1.setRows(3);
213 gridLayout1.setVgap(2);
214 createNewGroup.setEnabled(false);
215 createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
216 createNewGroup.setLabel("New Feature");
217 createNewGroup.addActionListener(this);
218 caseSensitive.setLabel("Match Case");
219 caseSensitive.setBounds(new Rectangle(40, 49, 126, 23));
220 jPanel1.add(findNext, null);
221 jPanel1.add(findAll, null);
222 jPanel1.add(createNewGroup, null);
223 this.add(caseSensitive);
224 this.add(textfield, null);
225 this.add(jLabel1, null);
226 this.add(jPanel1, null);
229 void textfield_keyTyped(KeyEvent e)
231 findNext.setEnabled(true);