2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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
21 import jalview.datamodel.*;
23 import jalview.jbgui.*;
26 import java.awt.event.*;
31 import javax.swing.event.*;
40 public class Finder extends GFinder
48 SearchResults searchResults;
51 * Creates a new Finder object.
53 * @param av DOCUMENT ME!
54 * @param ap DOCUMENT ME!
55 * @param f DOCUMENT ME!
59 frame = new JInternalFrame();
60 frame.setContentPane(this);
61 frame.setLayer(JLayeredPane.PALETTE_LAYER);
62 Desktop.addInternalFrame(frame, "Find", 340, 110);
64 textfield.requestFocus();
71 * @param e DOCUMENT ME!
73 public void findNext_actionPerformed(ActionEvent e)
75 if (getFocusedViewport())
82 * @param e DOCUMENT ME!
84 public void findAll_actionPerformed(ActionEvent e)
86 if(getFocusedViewport())
94 boolean getFocusedViewport()
96 JInternalFrame frame = Desktop.desktop.getAllFrames()[1];
98 if(frame!=null && frame instanceof AlignFrame)
100 av = ((AlignFrame)frame).viewport;
101 ap = ((AlignFrame)frame).alignPanel;
111 * @param e DOCUMENT ME!
113 public void createNewGroup_actionPerformed(ActionEvent e)
115 JLabel label = new JLabel("Enter name of new sequence feature");
116 JTextField textinput = new JTextField(textfield.getText());
117 JPanel panel = new JPanel(new BorderLayout());
118 panel.add(label, BorderLayout.NORTH);
119 panel.add(textinput, BorderLayout.SOUTH);
122 SequenceI [] seqs = new SequenceI[searchResults.getSize()];
123 SequenceFeature [] features = new SequenceFeature[searchResults.getSize()];
126 for (int i = 0; i < searchResults.getSize(); i ++ )
128 seqs[i] = searchResults.getResultSequence(i).getDatasetSequence();
130 features[i] = new SequenceFeature(textinput.getText(),
131 "Search Results", null,
132 searchResults.getResultStart(i),
133 searchResults.getResultEnd(i),
137 if( ap.seqPanel.seqCanvas.getFeatureRenderer()
138 .createNewFeatures(seqs, features))
140 ap.alignFrame.showSeqFeatures.setSelected(true);
141 av.setShowSequenceFeatures(true);
142 ap.highlightSearchResults(null);
149 * @param findAll DOCUMENT ME!
151 void doSearch(boolean findAll)
153 createNewGroup.setEnabled(false);
155 String searchString = textfield.getText().trim();
157 if(searchString.length()<1)
159 // TODO: extend finder to match descriptions, features and annotation, and other stuff
160 // TODO: add switches to control what is searched - sequences, IDS, descriptions, features
161 jalview.analysis.Finder finder=new jalview.analysis.Finder(av.alignment, av.getSelectionGroup(), seqIndex, resIndex);
162 finder.setCaseSensitive(caseSensitive.isSelected());
163 finder.setFindAll(findAll);
165 finder.find(searchString); // returns true if anything was actually found
167 seqIndex=finder.getSeqIndex();
168 resIndex=finder.getResIndex();
170 searchResults = finder.getSearchResults(); // find(regex, caseSensitive.isSelected(), )
171 Vector idMatch = finder.getIdMatch();
172 // set or reset the GUI
173 if ((searchResults.getSize() == 0) && (idMatch.size() > 0))
175 ap.idPanel.highlightSearchResults(idMatch);
179 int resultSize = searchResults.getSize();
181 if (searchResults.getSize() > 0)
182 createNewGroup.setEnabled(true);
184 searchResults = null;
186 // if allResults is null, this effectively switches displaySearch flag in seqCanvas
187 ap.highlightSearchResults(searchResults);
188 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or 'SelectRegion' selection
189 if(!findAll && resultSize==0)
191 JOptionPane.showInternalMessageDialog(this, "Finished searching",
192 null, JOptionPane.INFORMATION_MESSAGE);
199 String message = resultSize + " matches found.";
200 JOptionPane.showInternalMessageDialog(this, message, null,
201 JOptionPane.INFORMATION_MESSAGE);