2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 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/>.
23 import java.awt.event.*;
26 import jalview.datamodel.*;
27 import jalview.jbgui.*;
35 public class Finder extends GFinder
47 SearchResults searchResults;
50 * Creates a new Finder object.
65 public Finder(AlignViewport viewport, AlignmentPanel alignPanel)
70 frame = new JInternalFrame();
71 frame.setContentPane(this);
72 frame.setLayer(JLayeredPane.PALETTE_LAYER);
73 Desktop.addInternalFrame(frame, "Find", 340, 110);
75 textfield.requestFocus();
84 public void findNext_actionPerformed(ActionEvent e)
86 if (getFocusedViewport())
98 public void findAll_actionPerformed(ActionEvent e)
100 if (getFocusedViewport())
109 * do we only search a given alignment view ?
111 private boolean focusfixed;
114 * if !focusfixed and not in a desktop environment, checks that av and ap are
115 * valid. Otherwise, gets the topmost alignment window and sets av and ap
118 * @return false if no alignment window was found
120 boolean getFocusedViewport()
122 if (focusfixed || Desktop.desktop == null)
124 if (ap != null && av != null)
128 // we aren't in a desktop environment, so give up now.
131 // now checks further down the window stack to fix bug
132 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36008
133 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
134 for (int f = 0; f < frames.length; f++)
136 JInternalFrame frame = frames[f];
137 if (frame != null && frame instanceof AlignFrame)
139 av = ((AlignFrame) frame).viewport;
140 ap = ((AlignFrame) frame).alignPanel;
153 public void createNewGroup_actionPerformed(ActionEvent e)
155 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
156 SequenceFeature[] features = new SequenceFeature[searchResults
159 for (int i = 0; i < searchResults.getSize(); i++)
161 seqs[i] = searchResults.getResultSequence(i).getDatasetSequence();
163 features[i] = new SequenceFeature(textfield.getText().trim(),
164 "Search Results", null, searchResults.getResultStart(i),
165 searchResults.getResultEnd(i), "Search Results");
168 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
171 ap.alignFrame.showSeqFeatures.setSelected(true);
172 av.setShowSequenceFeatures(true);
173 ap.highlightSearchResults(null);
178 * incrementally search the alignment
181 * true means find all results and raise a dialog box
183 void doSearch(boolean findAll)
185 createNewGroup.setEnabled(false);
187 String searchString = textfield.getText().trim();
189 if (searchString.length() < 1)
193 // TODO: extend finder to match descriptions, features and annotation, and
195 // TODO: add switches to control what is searched - sequences, IDS,
196 // descriptions, features
197 jalview.analysis.Finder finder = new jalview.analysis.Finder(
198 av.alignment, av.getSelectionGroup(), seqIndex, resIndex);
199 finder.setCaseSensitive(caseSensitive.isSelected());
200 finder.setFindAll(findAll);
202 finder.find(searchString); // returns true if anything was actually found
204 seqIndex = finder.getSeqIndex();
205 resIndex = finder.getResIndex();
207 searchResults = finder.getSearchResults(); // find(regex,
208 // caseSensitive.isSelected(), )
209 Vector idMatch = finder.getIdMatch();
210 boolean haveResults = false;
211 // set or reset the GUI
212 if ((idMatch.size() > 0))
215 ap.idPanel.highlightSearchResults(idMatch);
219 ap.idPanel.highlightSearchResults(null);
222 if (searchResults.getSize() > 0)
225 createNewGroup.setEnabled(true);
229 searchResults = null;
232 // if allResults is null, this effectively switches displaySearch flag in
234 ap.highlightSearchResults(searchResults);
235 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
236 // 'SelectRegion' selection
239 JOptionPane.showInternalMessageDialog(this, "Finished searching",
240 null, JOptionPane.INFORMATION_MESSAGE);
247 String message = (idMatch.size() > 0) ? "" + idMatch.size() + " IDs"
249 if (searchResults != null)
251 if (idMatch.size() > 0 && searchResults.getSize() > 0)
255 message += searchResults.getSize() + " subsequence matches found.";
257 JOptionPane.showInternalMessageDialog(this, message, null,
258 JOptionPane.INFORMATION_MESSAGE);