2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import java.awt.event.*;
28 import jalview.datamodel.*;
29 import jalview.jbgui.*;
30 import jalview.util.MessageManager;
38 public class Finder extends GFinder
50 SearchResults searchResults;
53 * Creates a new Finder object.
68 public Finder(AlignViewport viewport, AlignmentPanel alignPanel)
73 frame = new JInternalFrame();
74 frame.setContentPane(this);
75 frame.setLayer(JLayeredPane.PALETTE_LAYER);
76 Desktop.addInternalFrame(frame, "Find", 340, 110);
78 textfield.requestFocus();
87 public void findNext_actionPerformed(ActionEvent e)
89 if (getFocusedViewport())
101 public void findAll_actionPerformed(ActionEvent e)
103 if (getFocusedViewport())
112 * do we only search a given alignment view ?
114 private boolean focusfixed;
117 * if !focusfixed and not in a desktop environment, checks that av and ap are
118 * valid. Otherwise, gets the topmost alignment window and sets av and ap
121 * @return false if no alignment window was found
123 boolean getFocusedViewport()
125 if (focusfixed || Desktop.desktop == null)
127 if (ap != null && av != null)
131 // we aren't in a desktop environment, so give up now.
134 // now checks further down the window stack to fix bug
135 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36008
136 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
137 for (int f = 0; f < frames.length; f++)
139 JInternalFrame frame = frames[f];
140 if (frame != null && frame instanceof AlignFrame)
142 av = ((AlignFrame) frame).viewport;
143 ap = ((AlignFrame) frame).alignPanel;
156 public void createNewGroup_actionPerformed(ActionEvent e)
158 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
159 SequenceFeature[] features = new SequenceFeature[searchResults
162 for (int i = 0; i < searchResults.getSize(); i++)
164 seqs[i] = searchResults.getResultSequence(i).getDatasetSequence();
166 features[i] = new SequenceFeature(textfield.getText().trim(),
167 "Search Results", null, searchResults.getResultStart(i),
168 searchResults.getResultEnd(i), "Search Results");
171 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
174 ap.alignFrame.showSeqFeatures.setSelected(true);
175 av.setShowSequenceFeatures(true);
176 ap.highlightSearchResults(null);
181 * incrementally search the alignment
184 * true means find all results and raise a dialog box
186 void doSearch(boolean findAll)
188 createNewGroup.setEnabled(false);
190 String searchString = textfield.getText().trim();
192 if (searchString.length() < 1)
196 // TODO: extend finder to match descriptions, features and annotation, and
198 // TODO: add switches to control what is searched - sequences, IDS,
199 // descriptions, features
200 jalview.analysis.Finder finder = new jalview.analysis.Finder(
201 av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
202 finder.setCaseSensitive(caseSensitive.isSelected());
203 finder.setFindAll(findAll);
205 finder.find(searchString); // returns true if anything was actually found
207 seqIndex = finder.getSeqIndex();
208 resIndex = finder.getResIndex();
210 searchResults = finder.getSearchResults(); // find(regex,
211 // caseSensitive.isSelected(), )
212 Vector idMatch = finder.getIdMatch();
213 boolean haveResults = false;
214 // set or reset the GUI
215 if ((idMatch.size() > 0))
218 ap.idPanel.highlightSearchResults(idMatch);
222 ap.idPanel.highlightSearchResults(null);
225 if (searchResults.getSize() > 0)
228 createNewGroup.setEnabled(true);
232 searchResults = null;
235 // if allResults is null, this effectively switches displaySearch flag in
237 ap.highlightSearchResults(searchResults);
238 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
239 // 'SelectRegion' selection
242 JOptionPane.showInternalMessageDialog(this,
243 MessageManager.getString("label.finished_searching"), null,
244 JOptionPane.INFORMATION_MESSAGE);
252 // then we report the matches that were found
253 String message = (idMatch.size() > 0) ? "" + idMatch.size()
255 if (searchResults != null)
257 if (idMatch.size() > 0 && searchResults.getSize() > 0)
261 message += searchResults.getSize()
262 + " subsequence matches found.";
264 JOptionPane.showInternalMessageDialog(this, message, null,
265 JOptionPane.INFORMATION_MESSAGE);