2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 import java.awt.event.*;
27 import jalview.datamodel.*;
28 import jalview.jbgui.*;
45 SearchResults searchResults;
48 * Creates a new Finder object.
50 * @param av DOCUMENT ME!
51 * @param ap DOCUMENT ME!
52 * @param f DOCUMENT ME!
56 frame = new JInternalFrame();
57 frame.setContentPane(this);
58 frame.setLayer(JLayeredPane.PALETTE_LAYER);
59 Desktop.addInternalFrame(frame, "Find", 340, 110);
61 textfield.requestFocus();
67 * @param e DOCUMENT ME!
69 public void findNext_actionPerformed(ActionEvent e)
71 if (getFocusedViewport())
80 * @param e DOCUMENT ME!
82 public void findAll_actionPerformed(ActionEvent e)
84 if (getFocusedViewport())
92 boolean getFocusedViewport()
94 JInternalFrame frame = Desktop.desktop.getAllFrames()[1];
96 if (frame != null && frame instanceof AlignFrame)
98 av = ( (AlignFrame) frame).viewport;
99 ap = ( (AlignFrame) frame).alignPanel;
108 * @param e DOCUMENT ME!
110 public void createNewGroup_actionPerformed(ActionEvent e)
112 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
113 SequenceFeature[] features = new SequenceFeature[searchResults.getSize()];
115 for (int i = 0; i < searchResults.getSize(); i++)
117 seqs[i] = searchResults.getResultSequence(i).getDatasetSequence();
119 features[i] = new SequenceFeature(textfield.getText().trim(),
120 "Search Results", null,
121 searchResults.getResultStart(i),
122 searchResults.getResultEnd(i),
126 if (ap.seqPanel.seqCanvas.getFeatureRenderer()
127 .amendFeatures(seqs, features, true, ap))
129 ap.alignFrame.showSeqFeatures.setSelected(true);
130 av.setShowSequenceFeatures(true);
131 ap.highlightSearchResults(null);
138 * @param findAll DOCUMENT ME!
140 void doSearch(boolean findAll)
142 createNewGroup.setEnabled(false);
144 String searchString = textfield.getText().trim();
146 if (searchString.length() < 1)
150 // TODO: extend finder to match descriptions, features and annotation, and other stuff
151 // TODO: add switches to control what is searched - sequences, IDS, descriptions, features
152 jalview.analysis.Finder finder = new jalview.analysis.Finder(av.alignment,
153 av.getSelectionGroup(), seqIndex, resIndex);
154 finder.setCaseSensitive(caseSensitive.isSelected());
155 finder.setFindAll(findAll);
157 finder.find(searchString); // returns true if anything was actually found
159 seqIndex = finder.getSeqIndex();
160 resIndex = finder.getResIndex();
162 searchResults = finder.getSearchResults(); // find(regex, caseSensitive.isSelected(), )
163 Vector idMatch = finder.getIdMatch();
164 // set or reset the GUI
165 if ( (searchResults.getSize() == 0) && (idMatch.size() > 0))
167 ap.idPanel.highlightSearchResults(idMatch);
170 int resultSize = searchResults.getSize();
172 if (searchResults.getSize() > 0)
174 createNewGroup.setEnabled(true);
178 searchResults = null;
181 // if allResults is null, this effectively switches displaySearch flag in seqCanvas
182 ap.highlightSearchResults(searchResults);
183 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or 'SelectRegion' selection
184 if (!findAll && resultSize == 0)
186 JOptionPane.showInternalMessageDialog(this, "Finished searching",
188 JOptionPane.INFORMATION_MESSAGE);
195 String message = resultSize + " matches found.";
196 JOptionPane.showInternalMessageDialog(this, message, null,
197 JOptionPane.INFORMATION_MESSAGE);