2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 import java.awt.event.*;
26 import jalview.datamodel.*;
27 import jalview.jbgui.*;
28 import jalview.util.MessageManager;
36 public class Finder extends GFinder
48 SearchResults searchResults;
51 * Creates a new Finder object.
66 public Finder(AlignViewport viewport, AlignmentPanel alignPanel)
71 frame = new JInternalFrame();
72 frame.setContentPane(this);
73 frame.setLayer(JLayeredPane.PALETTE_LAYER);
74 Desktop.addInternalFrame(frame, "Find", 340, 110);
76 textfield.requestFocus();
85 public void findNext_actionPerformed(ActionEvent e)
87 if (getFocusedViewport())
99 public void findAll_actionPerformed(ActionEvent e)
101 if (getFocusedViewport())
110 * do we only search a given alignment view ?
112 private boolean focusfixed;
115 * if !focusfixed and not in a desktop environment, checks that av and ap are
116 * valid. Otherwise, gets the topmost alignment window and sets av and ap
119 * @return false if no alignment window was found
121 boolean getFocusedViewport()
123 if (focusfixed || Desktop.desktop == null)
125 if (ap != null && av != null)
129 // we aren't in a desktop environment, so give up now.
132 // now checks further down the window stack to fix bug
133 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36008
134 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
135 for (int f = 0; f < frames.length; f++)
137 JInternalFrame frame = frames[f];
138 if (frame != null && frame instanceof AlignFrame)
140 av = ((AlignFrame) frame).viewport;
141 ap = ((AlignFrame) frame).alignPanel;
154 public void createNewGroup_actionPerformed(ActionEvent e)
156 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
157 SequenceFeature[] features = new SequenceFeature[searchResults
160 for (int i = 0; i < searchResults.getSize(); i++)
162 seqs[i] = searchResults.getResultSequence(i).getDatasetSequence();
164 features[i] = new SequenceFeature(textfield.getText().trim(),
165 "Search Results", null, searchResults.getResultStart(i),
166 searchResults.getResultEnd(i), "Search Results");
169 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
172 ap.alignFrame.showSeqFeatures.setSelected(true);
173 av.setShowSequenceFeatures(true);
174 ap.highlightSearchResults(null);
179 * incrementally search the alignment
182 * true means find all results and raise a dialog box
184 void doSearch(boolean findAll)
186 createNewGroup.setEnabled(false);
188 String searchString = textfield.getText().trim();
190 if (searchString.length() < 1)
194 // TODO: extend finder to match descriptions, features and annotation, and
196 // TODO: add switches to control what is searched - sequences, IDS,
197 // descriptions, features
198 jalview.analysis.Finder finder = new jalview.analysis.Finder(
199 av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
200 finder.setCaseSensitive(caseSensitive.isSelected());
201 finder.setFindAll(findAll);
203 finder.find(searchString); // returns true if anything was actually found
205 seqIndex = finder.getSeqIndex();
206 resIndex = finder.getResIndex();
208 searchResults = finder.getSearchResults(); // find(regex,
209 // caseSensitive.isSelected(), )
210 Vector idMatch = finder.getIdMatch();
211 boolean haveResults = false;
212 // set or reset the GUI
213 if ((idMatch.size() > 0))
216 ap.idPanel.highlightSearchResults(idMatch);
220 ap.idPanel.highlightSearchResults(null);
223 if (searchResults.getSize() > 0)
226 createNewGroup.setEnabled(true);
230 searchResults = null;
233 // if allResults is null, this effectively switches displaySearch flag in
235 ap.highlightSearchResults(searchResults);
236 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
237 // 'SelectRegion' selection
240 JOptionPane.showInternalMessageDialog(this, MessageManager.getString("label.finished_searching"),
241 null, JOptionPane.INFORMATION_MESSAGE);
247 // then we report the matches that were found
248 String message = (idMatch.size() > 0) ? "" + idMatch.size()
250 if (searchResults != null)
252 if (idMatch.size() > 0 && searchResults.getSize() > 0)
256 message += searchResults.getSize()
257 + " subsequence matches found.";
259 JOptionPane.showInternalMessageDialog(this, message, null,
260 JOptionPane.INFORMATION_MESSAGE);