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.
64 public Finder(AlignViewport viewport, AlignmentPanel alignPanel)
69 frame = new JInternalFrame();
70 frame.setContentPane(this);
71 frame.setLayer(JLayeredPane.PALETTE_LAYER);
72 Desktop.addInternalFrame(frame, "Find", 340, 110);
74 textfield.requestFocus();
83 public void findNext_actionPerformed(ActionEvent e)
85 if (getFocusedViewport())
97 public void findAll_actionPerformed(ActionEvent e)
99 if (getFocusedViewport())
107 * do we only search a given alignment view ?
109 private boolean focusfixed;
112 * if !focusfixed and not in a desktop environment, checks that av and ap are
113 * valid. Otherwise, gets the topmost alignment window and sets av and ap
116 * @return false if no alignment window was found
118 boolean getFocusedViewport()
120 if (focusfixed || Desktop.desktop==null)
122 if (ap!=null && av!=null)
126 // we aren't in a desktop environment, so give up now.
129 // now checks further down the window stack to fix bug
130 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36008
131 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
132 for (int f = 0; f < frames.length; f++)
134 JInternalFrame frame = frames[f];
135 if (frame != null && frame instanceof AlignFrame)
137 av = ((AlignFrame) frame).viewport;
138 ap = ((AlignFrame) frame).alignPanel;
151 public void createNewGroup_actionPerformed(ActionEvent e)
153 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
154 SequenceFeature[] features = new SequenceFeature[searchResults
157 for (int i = 0; i < searchResults.getSize(); i++)
159 seqs[i] = searchResults.getResultSequence(i).getDatasetSequence();
161 features[i] = new SequenceFeature(textfield.getText().trim(),
162 "Search Results", null, searchResults.getResultStart(i),
163 searchResults.getResultEnd(i), "Search Results");
166 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
169 ap.alignFrame.showSeqFeatures.setSelected(true);
170 av.setShowSequenceFeatures(true);
171 ap.highlightSearchResults(null);
176 * incrementally search the alignment
179 * true means find all results and raise a dialog box
181 void doSearch(boolean findAll)
183 createNewGroup.setEnabled(false);
185 String searchString = textfield.getText().trim();
187 if (searchString.length() < 1)
191 // TODO: extend finder to match descriptions, features and annotation, and
193 // TODO: add switches to control what is searched - sequences, IDS,
194 // descriptions, features
195 jalview.analysis.Finder finder = new jalview.analysis.Finder(
196 av.alignment, av.getSelectionGroup(), seqIndex, resIndex);
197 finder.setCaseSensitive(caseSensitive.isSelected());
198 finder.setFindAll(findAll);
200 finder.find(searchString); // returns true if anything was actually found
202 seqIndex = finder.getSeqIndex();
203 resIndex = finder.getResIndex();
205 searchResults = finder.getSearchResults(); // find(regex,
206 // caseSensitive.isSelected(), )
207 Vector idMatch = finder.getIdMatch();
208 boolean haveResults = false;
209 // set or reset the GUI
210 if ((idMatch.size() > 0))
213 ap.idPanel.highlightSearchResults(idMatch);
217 ap.idPanel.highlightSearchResults(null);
220 if (searchResults.getSize() > 0)
223 createNewGroup.setEnabled(true);
227 searchResults = null;
230 // if allResults is null, this effectively switches displaySearch flag in
232 ap.highlightSearchResults(searchResults);
233 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
234 // 'SelectRegion' selection
237 JOptionPane.showInternalMessageDialog(this, "Finished searching",
238 null, JOptionPane.INFORMATION_MESSAGE);
245 String message = (idMatch.size() > 0) ? "" + idMatch.size() + " IDs"
247 if (idMatch.size() > 0 && searchResults.getSize() > 0)
251 message += searchResults.getSize() + " subsequence matches found.";
252 JOptionPane.showInternalMessageDialog(this, message, null,
253 JOptionPane.INFORMATION_MESSAGE);