2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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
20 package jalview.appletgui;
25 import java.awt.event.*;
27 import jalview.datamodel.*;
30 extends Panel implements ActionListener
36 SearchResults searchResults;
40 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.getSize()];
97 for (int i = 0; i < searchResults.getSize(); i++)
99 seqs[i] = searchResults.getResultSequence(i);
101 features[i] = new SequenceFeature(textfield.getText().trim(),
102 "Search Results", null,
103 searchResults.getResultStart(i),
104 searchResults.getResultEnd(i),
108 if (ap.seqPanel.seqCanvas.getFeatureRenderer()
109 .amendFeatures(seqs, features, true, ap))
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 seqCanvas
156 ap.highlightSearchResults(searchResults);
160 String message = (searchResults == null ? 0 : searchResults.getSize()) +
162 ap.alignFrame.statusBar.setText("Search results: " + searchString + " : " +
168 Label jLabel1 = new Label();
169 protected TextField textfield = new TextField();
170 protected Button findAll = new Button();
171 protected Button findNext = new Button();
172 Panel jPanel1 = new Panel();
173 GridLayout gridLayout1 = new GridLayout();
174 protected Button createNewGroup = new Button();
175 Checkbox caseSensitive = new Checkbox();
177 private void jbInit()
180 jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
181 jLabel1.setText("Find");
182 jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
183 this.setLayout(null);
184 textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
185 textfield.setText("");
186 textfield.setBounds(new Rectangle(40, 27, 133, 21));
187 textfield.addKeyListener(new java.awt.event.KeyAdapter()
189 public void keyTyped(KeyEvent e)
191 textfield_keyTyped(e);
194 textfield.addActionListener(this);
195 findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
196 findAll.setLabel("Find all");
197 findAll.addActionListener(this);
198 findNext.setEnabled(false);
199 findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
200 findNext.setLabel("Find Next");
201 findNext.addActionListener(this);
202 jPanel1.setBounds(new Rectangle(180, 5, 141, 64));
203 jPanel1.setLayout(gridLayout1);
204 gridLayout1.setHgap(0);
205 gridLayout1.setRows(3);
206 gridLayout1.setVgap(2);
207 createNewGroup.setEnabled(false);
208 createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
209 createNewGroup.setLabel("New Feature");
210 createNewGroup.addActionListener(this);
211 caseSensitive.setLabel("Match Case");
212 caseSensitive.setBounds(new Rectangle(40, 49, 126, 23));
213 jPanel1.add(findNext, null);
214 jPanel1.add(findAll, null);
215 jPanel1.add(createNewGroup, null);
216 this.add(caseSensitive);
217 this.add(textfield, null);
218 this.add(jLabel1, null);
219 this.add(jPanel1, null);
222 void textfield_keyTyped(KeyEvent e)
224 findNext.setEnabled(true);