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
20 package jalview.appletgui;
25 import java.awt.event.*;
27 import jalview.datamodel.*;
28 import java.awt.Rectangle;
30 public class Finder 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)
71 else if (evt.getSource() == findNext)
74 else if (evt.getSource() == findAll)
80 else if(evt.getSource() == createNewGroup)
81 createNewGroup_actionPerformed();
85 public void createNewGroup_actionPerformed()
88 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, null);
89 cap.accept.setLabel("Accept");
90 Dialog dialog = new Dialog(ap.alignFrame, "Enter New Feature Name", true);
93 cap.setText(textfield.getText());
95 dialog.setBounds( frame.getLocation().x+frame.getSize().width+5,
96 frame.getLocation().y+20,300,100);
100 String featureName = cap.getText().trim();
101 if(featureName.length()<1)
105 for (int i = 0; i < searchResults.getSize(); i ++ )
107 SequenceI seq = searchResults.getResultSequence(i);
109 SequenceFeature sf = new SequenceFeature(featureName,
111 searchResults.getResultStart(i),
112 searchResults.getResultEnd(i), "Search Results");
114 ap.seqPanel.seqCanvas.getFeatureRenderer().addNewFeature(
115 featureName, new Color(60,160,115));
116 seq.addSequenceFeature(sf);
119 ap.seqPanel.seqCanvas.getFeatureRenderer().findAllFeatures();
120 ap.alignFrame.sequenceFeatures.setState(true);
121 av.showSequenceFeatures(true);
122 ap.highlightSearchResults(null);
125 void doSearch(boolean findAll)
127 if(jalview.bin.JalviewLite.currentAlignFrame!=null)
129 ap = jalview.bin.JalviewLite.currentAlignFrame.alignPanel;
132 createNewGroup.setEnabled(false);
133 jalview.analysis.Finder finder=new jalview.analysis.Finder(av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex);
134 finder.setCaseSensitive(caseSensitive.getState());
135 finder.setFindAll(findAll);
137 String searchString = textfield.getText();
139 finder.find(searchString);
140 seqIndex=finder.getSeqIndex();
141 resIndex=finder.getResIndex();
142 searchResults = finder.getSearchResults();
143 Vector idMatch = finder.getIdMatch();
145 if (searchResults.getSize() == 0 && idMatch.size() > 0)
147 ap.idPanel.highlightSearchResults(idMatch);
150 if (searchResults.getSize() > 0)
152 createNewGroup.setEnabled(true);
157 searchResults = null;
162 // if allResults is null, this effectively switches displaySearch flag in seqCanvas
163 ap.highlightSearchResults(searchResults);
167 String message = (searchResults==null?0 : searchResults.getSize()) + " matches found.";
168 ap.alignFrame.statusBar.setText("Search results: "+searchString+" : "+message);
173 Label jLabel1 = new Label();
174 protected TextField textfield = new TextField();
175 protected Button findAll = new Button();
176 protected Button findNext = new Button();
177 Panel jPanel1 = new Panel();
178 GridLayout gridLayout1 = new GridLayout();
179 protected Button createNewGroup = new Button();
180 Checkbox caseSensitive = new Checkbox();
182 private void jbInit() throws Exception {
183 jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
184 jLabel1.setText("Find");
185 jLabel1.setBounds(new Rectangle(3, 30, 34, 15));
186 this.setLayout(null);
187 textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
188 textfield.setText("");
189 textfield.setBounds(new Rectangle(40, 27, 133, 21));
190 textfield.addKeyListener(new java.awt.event.KeyAdapter() {
191 public void keyTyped(KeyEvent e) {
192 textfield_keyTyped(e);
195 textfield.addActionListener(this);
196 findAll.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
197 findAll.setLabel("Find all");
198 findAll.addActionListener(this);
199 findNext.setEnabled(false);
200 findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
201 findNext.setLabel("Find Next");
202 findNext.addActionListener(this);
203 jPanel1.setBounds(new Rectangle(180, 5, 141, 64));
204 jPanel1.setLayout(gridLayout1);
205 gridLayout1.setHgap(0);
206 gridLayout1.setRows(3);
207 gridLayout1.setVgap(2);
208 createNewGroup.setEnabled(false);
209 createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
210 createNewGroup.setLabel("New Feature");
211 createNewGroup.addActionListener(this);
212 caseSensitive.setLabel("Match Case");
213 caseSensitive.setBounds(new Rectangle(40, 49, 126, 23));
214 jPanel1.add(findNext, null);
215 jPanel1.add(findAll, null);
216 jPanel1.add(createNewGroup, null);
217 this.add(caseSensitive);
218 this.add(textfield, null);
219 this.add(jLabel1, null);
220 this.add(jPanel1, null);
223 void textfield_keyTyped(KeyEvent e) {
224 findNext.setEnabled(true);