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
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())
101 * gets the topmost alignment window and sets av and ap accordingly
102 * @return false if no alignment window was found
104 boolean getFocusedViewport()
106 // now checks further down the window stack to fix bug https://mantis.lifesci.dundee.ac.uk/view.php?id=36008
107 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
108 for (int f=0;f<frames.length; f++) {
109 JInternalFrame frame = frames[f];
110 if (frame != null && frame instanceof AlignFrame)
112 av = ((AlignFrame) frame).viewport;
113 ap = ((AlignFrame) frame).alignPanel;
126 public void createNewGroup_actionPerformed(ActionEvent e)
128 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
129 SequenceFeature[] features = new SequenceFeature[searchResults
132 for (int i = 0; i < searchResults.getSize(); i++)
134 seqs[i] = searchResults.getResultSequence(i).getDatasetSequence();
136 features[i] = new SequenceFeature(textfield.getText().trim(),
137 "Search Results", null, searchResults.getResultStart(i),
138 searchResults.getResultEnd(i), "Search Results");
141 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
144 ap.alignFrame.showSeqFeatures.setSelected(true);
145 av.setShowSequenceFeatures(true);
146 ap.highlightSearchResults(null);
156 void doSearch(boolean findAll)
158 createNewGroup.setEnabled(false);
160 String searchString = textfield.getText().trim();
162 if (searchString.length() < 1)
166 // TODO: extend finder to match descriptions, features and annotation, and
168 // TODO: add switches to control what is searched - sequences, IDS,
169 // descriptions, features
170 jalview.analysis.Finder finder = new jalview.analysis.Finder(
171 av.alignment, av.getSelectionGroup(), seqIndex, resIndex);
172 finder.setCaseSensitive(caseSensitive.isSelected());
173 finder.setFindAll(findAll);
175 finder.find(searchString); // returns true if anything was actually found
177 seqIndex = finder.getSeqIndex();
178 resIndex = finder.getResIndex();
180 searchResults = finder.getSearchResults(); // find(regex,
181 // caseSensitive.isSelected(), )
182 Vector idMatch = finder.getIdMatch();
183 // set or reset the GUI
184 if ((searchResults.getSize() == 0) && (idMatch.size() > 0))
186 ap.idPanel.highlightSearchResults(idMatch);
189 int resultSize = searchResults.getSize();
191 if (searchResults.getSize() > 0)
193 createNewGroup.setEnabled(true);
197 searchResults = null;
200 // if allResults is null, this effectively switches displaySearch flag in
202 ap.highlightSearchResults(searchResults);
203 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
204 // 'SelectRegion' selection
205 if (!findAll && resultSize == 0)
207 JOptionPane.showInternalMessageDialog(this, "Finished searching",
208 null, JOptionPane.INFORMATION_MESSAGE);
215 String message = resultSize + " matches found.";
216 JOptionPane.showInternalMessageDialog(this, message, null,
217 JOptionPane.INFORMATION_MESSAGE);