2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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
24 import java.awt.event.*;
27 import jalview.datamodel.*;
28 import jalview.jbgui.*;
36 public class Finder extends GFinder
48 SearchResults searchResults;
51 * Creates a new Finder object.
62 frame = new JInternalFrame();
63 frame.setContentPane(this);
64 frame.setLayer(JLayeredPane.PALETTE_LAYER);
65 Desktop.addInternalFrame(frame, "Find", 340, 110);
67 textfield.requestFocus();
76 public void findNext_actionPerformed(ActionEvent e)
78 if (getFocusedViewport())
90 public void findAll_actionPerformed(ActionEvent e)
92 if (getFocusedViewport())
100 boolean getFocusedViewport()
102 JInternalFrame frame = Desktop.desktop.getAllFrames()[1];
104 if (frame != null && frame instanceof AlignFrame)
106 av = ((AlignFrame) frame).viewport;
107 ap = ((AlignFrame) frame).alignPanel;
119 public void createNewGroup_actionPerformed(ActionEvent e)
121 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
122 SequenceFeature[] features = new SequenceFeature[searchResults
125 for (int i = 0; i < searchResults.getSize(); i++)
127 seqs[i] = searchResults.getResultSequence(i).getDatasetSequence();
129 features[i] = new SequenceFeature(textfield.getText().trim(),
130 "Search Results", null, searchResults.getResultStart(i),
131 searchResults.getResultEnd(i), "Search Results");
134 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
137 ap.alignFrame.showSeqFeatures.setSelected(true);
138 av.setShowSequenceFeatures(true);
139 ap.highlightSearchResults(null);
149 void doSearch(boolean findAll)
151 createNewGroup.setEnabled(false);
153 String searchString = textfield.getText().trim();
155 if (searchString.length() < 1)
159 // TODO: extend finder to match descriptions, features and annotation, and
161 // TODO: add switches to control what is searched - sequences, IDS,
162 // descriptions, features
163 jalview.analysis.Finder finder = new jalview.analysis.Finder(
164 av.alignment, av.getSelectionGroup(), seqIndex, resIndex);
165 finder.setCaseSensitive(caseSensitive.isSelected());
166 finder.setFindAll(findAll);
168 finder.find(searchString); // returns true if anything was actually found
170 seqIndex = finder.getSeqIndex();
171 resIndex = finder.getResIndex();
173 searchResults = finder.getSearchResults(); // find(regex,
174 // caseSensitive.isSelected(), )
175 Vector idMatch = finder.getIdMatch();
176 // set or reset the GUI
177 if ((searchResults.getSize() == 0) && (idMatch.size() > 0))
179 ap.idPanel.highlightSearchResults(idMatch);
182 int resultSize = searchResults.getSize();
184 if (searchResults.getSize() > 0)
186 createNewGroup.setEnabled(true);
190 searchResults = null;
193 // if allResults is null, this effectively switches displaySearch flag in
195 ap.highlightSearchResults(searchResults);
196 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
197 // 'SelectRegion' selection
198 if (!findAll && resultSize == 0)
200 JOptionPane.showInternalMessageDialog(this, "Finished searching",
201 null, JOptionPane.INFORMATION_MESSAGE);
208 String message = resultSize + " matches found.";
209 JOptionPane.showInternalMessageDialog(this, message, null,
210 JOptionPane.INFORMATION_MESSAGE);