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.
21 package jalview.appletgui;
26 import java.awt.event.*;
28 import jalview.datamodel.*;
29 import jalview.util.MessageManager;
31 public class Finder extends Panel implements ActionListener
39 SearchResults searchResults;
45 public Finder(final AlignmentPanel ap)
60 jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("action.find"), 340, 120);
62 frame.addWindowListener(new WindowAdapter()
64 public void windowClosing(WindowEvent evt)
66 ap.highlightSearchResults(null);
69 textfield.requestFocus();
72 public void actionPerformed(ActionEvent evt)
74 if (evt.getSource() == textfield)
79 else if (evt.getSource() == findNext)
84 else if (evt.getSource() == findAll)
90 else if (evt.getSource() == createNewGroup)
92 createNewGroup_actionPerformed();
96 public void createNewGroup_actionPerformed()
98 SequenceI[] seqs = new SequenceI[searchResults.getSize()];
99 SequenceFeature[] features = new SequenceFeature[searchResults
102 for (int i = 0; i < searchResults.getSize(); i++)
104 seqs[i] = searchResults.getResultSequence(i);
106 features[i] = new SequenceFeature(textfield.getText().trim(),
107 "Search Results", null, searchResults.getResultStart(i),
108 searchResults.getResultEnd(i), "Search Results");
111 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
114 ap.alignFrame.sequenceFeatures.setState(true);
115 av.showSequenceFeatures(true);
116 ap.highlightSearchResults(null);
120 void doSearch(boolean findAll)
122 if (ap.av.applet.currentAlignFrame != null)
124 ap = ap.av.applet.currentAlignFrame.alignPanel;
127 createNewGroup.setEnabled(false);
128 jalview.analysis.Finder finder = new jalview.analysis.Finder(
129 av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
130 finder.setCaseSensitive(caseSensitive.getState());
131 finder.setFindAll(findAll);
133 String searchString = textfield.getText();
135 finder.find(searchString);
136 seqIndex = finder.getSeqIndex();
137 resIndex = finder.getResIndex();
138 searchResults = finder.getSearchResults();
139 Vector idMatch = finder.getIdMatch();
140 boolean haveResults = false;
141 // set or reset the GUI
142 if ((idMatch.size() > 0))
145 ap.idPanel.highlightSearchResults(idMatch);
149 ap.idPanel.highlightSearchResults(null);
152 if (searchResults.getSize() > 0)
155 createNewGroup.setEnabled(true);
160 searchResults = null;
163 // if allResults is null, this effectively switches displaySearch flag in
165 ap.highlightSearchResults(searchResults);
166 // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or
167 // 'SelectRegion' selection
170 ap.alignFrame.statusBar.setText(MessageManager.getString("label.finished_searching"));
178 String message = (idMatch.size() > 0) ? "" + idMatch.size()
180 if (idMatch.size() > 0 && searchResults != null
181 && searchResults.getSize() > 0)
185 if (searchResults != null)
187 message += searchResults.getSize() + " subsequence matches.";
189 ap.alignFrame.statusBar.setText(MessageManager.formatMessage("label.search_results", new String[] {searchString, message}));
194 // TODO: indicate sequence and matching position in status bar
195 ap.alignFrame.statusBar.setText(MessageManager.formatMessage("label.found_match_for", new String[]{searchString}));
200 Label jLabel1 = new Label();
202 protected TextField textfield = new TextField();
204 protected Button findAll = new Button();
206 protected Button findNext = new Button();
208 Panel jPanel1 = new Panel();
210 GridLayout gridLayout1 = new GridLayout();
212 protected Button createNewGroup = new Button();
214 Checkbox caseSensitive = new Checkbox();
216 private void jbInit() throws Exception
218 jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
219 jLabel1.setText(MessageManager.getString("action.find"));
220 jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
221 this.setLayout(null);
222 textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
223 textfield.setText("");
224 textfield.setBounds(new Rectangle(40, 27, 133, 21));
225 textfield.addKeyListener(new java.awt.event.KeyAdapter()
227 public void keyTyped(KeyEvent e)
229 textfield_keyTyped(e);
232 textfield.addActionListener(this);
233 findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
234 findAll.setLabel(MessageManager.getString("action.find_all"));
235 findAll.addActionListener(this);
236 findNext.setEnabled(false);
237 findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
238 findNext.setLabel(MessageManager.getString("action.find_next"));
239 findNext.addActionListener(this);
240 jPanel1.setBounds(new Rectangle(180, 5, 141, 64));
241 jPanel1.setLayout(gridLayout1);
242 gridLayout1.setHgap(0);
243 gridLayout1.setRows(3);
244 gridLayout1.setVgap(2);
245 createNewGroup.setEnabled(false);
246 createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
247 createNewGroup.setLabel(MessageManager.getString("label.new_feature"));
248 createNewGroup.addActionListener(this);
249 caseSensitive.setLabel(MessageManager.getString("label.match_case"));
250 caseSensitive.setBounds(new Rectangle(40, 49, 126, 23));
251 jPanel1.add(findNext, null);
252 jPanel1.add(findAll, null);
253 jPanel1.add(createNewGroup, null);
254 this.add(caseSensitive);
255 this.add(textfield, null);
256 this.add(jLabel1, null);
257 this.add(jPanel1, null);
260 void textfield_keyTyped(KeyEvent e)
262 findNext.setEnabled(true);