2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 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.
61 frame = new JInternalFrame();
62 frame.setContentPane(this);
63 frame.setLayer(JLayeredPane.PALETTE_LAYER);
64 Desktop.addInternalFrame(frame, "Find", 340, 110);
66 textfield.requestFocus();
75 public void findNext_actionPerformed(ActionEvent e)
77 if (getFocusedViewport())
89 public void findAll_actionPerformed(ActionEvent e)
91 if (getFocusedViewport())
100 * 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
107 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36008
108 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
109 for (int f = 0; f < frames.length; f++)
111 JInternalFrame frame = frames[f];
112 if (frame != null && frame instanceof AlignFrame)
114 av = ((AlignFrame) frame).viewport;
115 ap = ((AlignFrame) frame).alignPanel;
128 public void createNewGroup_actionPerformed(ActionEvent e)
130 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
131 SequenceFeature[] features = new SequenceFeature[searchResults
134 for (int i = 0; i < searchResults.getSize(); i++)
136 seqs[i] = searchResults.getResultSequence(i).getDatasetSequence();
138 features[i] = new SequenceFeature(textfield.getText().trim(),
139 "Search Results", null, searchResults.getResultStart(i),
140 searchResults.getResultEnd(i), "Search Results");
143 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
146 ap.alignFrame.showSeqFeatures.setSelected(true);
147 av.setShowSequenceFeatures(true);
148 ap.highlightSearchResults(null);
153 * incrementally search the alignment
156 * true means find all results and raise a dialog box
158 void doSearch(boolean findAll)
160 createNewGroup.setEnabled(false);
162 String searchString = textfield.getText().trim();
164 if (searchString.length() < 1)
168 // TODO: extend finder to match descriptions, features and annotation, and
170 // TODO: add switches to control what is searched - sequences, IDS,
171 // descriptions, features
172 jalview.analysis.Finder finder = new jalview.analysis.Finder(
173 av.alignment, av.getSelectionGroup(), seqIndex, resIndex);
174 finder.setCaseSensitive(caseSensitive.isSelected());
175 finder.setFindAll(findAll);
177 finder.find(searchString); // returns true if anything was actually found
179 seqIndex = finder.getSeqIndex();
180 resIndex = finder.getResIndex();
182 searchResults = finder.getSearchResults(); // find(regex,
183 // caseSensitive.isSelected(), )
184 Vector idMatch = finder.getIdMatch();
185 boolean haveResults = false;
186 // set or reset the GUI
187 if ((idMatch.size() > 0))
190 ap.idPanel.highlightSearchResults(idMatch);
194 ap.idPanel.highlightSearchResults(null);
197 if (searchResults.getSize() > 0)
200 createNewGroup.setEnabled(true);
204 searchResults = null;
207 // if allResults is null, this effectively switches displaySearch flag in
209 ap.highlightSearchResults(searchResults);
210 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
211 // 'SelectRegion' selection
214 JOptionPane.showInternalMessageDialog(this, "Finished searching",
215 null, JOptionPane.INFORMATION_MESSAGE);
222 String message = (idMatch.size() > 0) ? "" + idMatch.size() + " IDs"
224 if (idMatch.size() > 0 && searchResults.getSize() > 0)
228 message += searchResults.getSize() + " subsequence matches found.";
229 JOptionPane.showInternalMessageDialog(this, message, null,
230 JOptionPane.INFORMATION_MESSAGE);