2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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
20 package jalview.appletgui;
25 import java.awt.event.*;
27 import jalview.datamodel.*;
30 extends Panel implements ActionListener
36 SearchResults searchResults;
40 public Finder(final AlignmentPanel ap)
55 jalview.bin.JalviewLite.addFrame(frame, "Find", 340, 120);
57 frame.addWindowListener(new WindowAdapter()
59 public void windowClosing(WindowEvent evt)
61 ap.highlightSearchResults(null);
66 public void actionPerformed(ActionEvent evt)
68 if (evt.getSource() == textfield)
73 else if (evt.getSource() == findNext)
78 else if (evt.getSource() == findAll)
84 else if (evt.getSource() == createNewGroup)
86 createNewGroup_actionPerformed();
90 public void createNewGroup_actionPerformed()
93 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, null);
94 cap.accept.setLabel("Accept");
95 Dialog dialog = new Dialog(ap.alignFrame, "Enter New Feature Name", true);
98 cap.setText(textfield.getText());
100 dialog.setBounds(frame.getLocation().x + frame.getSize().width + 5,
101 frame.getLocation().y + 20, 300, 100);
104 String featureName = cap.getText().trim();
105 if (featureName.length() < 1)
110 for (int i = 0; i < searchResults.getSize(); i++)
112 SequenceI seq = searchResults.getResultSequence(i);
114 SequenceFeature sf = new SequenceFeature(featureName,
116 searchResults.getResultStart(i),
117 searchResults.getResultEnd(i),
120 ap.seqPanel.seqCanvas.getFeatureRenderer().addNewFeature(
121 featureName, new Color(60, 160, 115));
122 seq.addSequenceFeature(sf);
125 ap.seqPanel.seqCanvas.getFeatureRenderer().findAllFeatures();
126 ap.alignFrame.sequenceFeatures.setState(true);
127 av.showSequenceFeatures(true);
128 ap.highlightSearchResults(null);
131 void doSearch(boolean findAll)
133 if (jalview.bin.JalviewLite.currentAlignFrame != null)
135 ap = jalview.bin.JalviewLite.currentAlignFrame.alignPanel;
138 createNewGroup.setEnabled(false);
139 jalview.analysis.Finder finder = new jalview.analysis.Finder(av.
140 getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
141 finder.setCaseSensitive(caseSensitive.getState());
142 finder.setFindAll(findAll);
144 String searchString = textfield.getText();
146 finder.find(searchString);
147 seqIndex = finder.getSeqIndex();
148 resIndex = finder.getResIndex();
149 searchResults = finder.getSearchResults();
150 Vector idMatch = finder.getIdMatch();
152 if (searchResults.getSize() == 0 && idMatch.size() > 0)
154 ap.idPanel.highlightSearchResults(idMatch);
157 if (searchResults.getSize() > 0)
159 createNewGroup.setEnabled(true);
164 searchResults = null;
169 // if allResults is null, this effectively switches displaySearch flag in seqCanvas
170 ap.highlightSearchResults(searchResults);
174 String message = (searchResults == null ? 0 : searchResults.getSize()) +
176 ap.alignFrame.statusBar.setText("Search results: " + searchString + " : " +
182 Label jLabel1 = new Label();
183 protected TextField textfield = new TextField();
184 protected Button findAll = new Button();
185 protected Button findNext = new Button();
186 Panel jPanel1 = new Panel();
187 GridLayout gridLayout1 = new GridLayout();
188 protected Button createNewGroup = new Button();
189 Checkbox caseSensitive = new Checkbox();
191 private void jbInit()
194 jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
195 jLabel1.setText("Find");
196 jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
197 this.setLayout(null);
198 textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
199 textfield.setText("");
200 textfield.setBounds(new Rectangle(40, 27, 133, 21));
201 textfield.addKeyListener(new java.awt.event.KeyAdapter()
203 public void keyTyped(KeyEvent e)
205 textfield_keyTyped(e);
208 textfield.addActionListener(this);
209 findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
210 findAll.setLabel("Find all");
211 findAll.addActionListener(this);
212 findNext.setEnabled(false);
213 findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
214 findNext.setLabel("Find Next");
215 findNext.addActionListener(this);
216 jPanel1.setBounds(new Rectangle(180, 5, 141, 64));
217 jPanel1.setLayout(gridLayout1);
218 gridLayout1.setHgap(0);
219 gridLayout1.setRows(3);
220 gridLayout1.setVgap(2);
221 createNewGroup.setEnabled(false);
222 createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
223 createNewGroup.setLabel("New Feature");
224 createNewGroup.addActionListener(this);
225 caseSensitive.setLabel("Match Case");
226 caseSensitive.setBounds(new Rectangle(40, 49, 126, 23));
227 jPanel1.add(findNext, null);
228 jPanel1.add(findAll, null);
229 jPanel1.add(createNewGroup, null);
230 this.add(caseSensitive);
231 this.add(textfield, null);
232 this.add(jLabel1, null);
233 this.add(jPanel1, null);
236 void textfield_keyTyped(KeyEvent e)
238 findNext.setEnabled(true);