X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFinder.java;h=e8c16d234f398bce693cd176b1601c56abf6a501;hb=174230b4233d9ce80f94527768d2cd2f76da11ab;hp=909ba1f39957075ebbecdf01ca16db114944ffde;hpb=587fef46179c0daf041e240c10b03ac5910718a8;p=jalview.git diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index 909ba1f..e8c16d2 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -1,171 +1,338 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ package jalview.gui; -import jalview.jbgui.GFinder; import jalview.datamodel.*; + +import jalview.jbgui.*; + +import java.awt.*; import java.awt.event.*; + +import java.util.*; + import javax.swing.*; import javax.swing.event.*; -import java.util.*; +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ public class Finder extends GFinder { - AlignViewport av; - AlignmentPanel ap; - JInternalFrame frame; - String searchString; - - int seqIndex = 0; - int resIndex = 0; - public Finder(AlignViewport av, AlignmentPanel ap, JInternalFrame f) - { - this.av = av; - this.ap = ap; - frame = f; - - // all a big pain, but we need to wait until the frame is visible before the textfield can - // obtain the focus///////////////////////// - frame.addInternalFrameListener(new InternalFrameAdapter() + AlignViewport av; + AlignmentPanel ap; + JInternalFrame frame; + int seqIndex = 0; + int resIndex = 0; + + SearchResults searchResults; + + /** + * Creates a new Finder object. + * + * @param av DOCUMENT ME! + * @param ap DOCUMENT ME! + * @param f DOCUMENT ME! + */ + public Finder(AlignViewport av, AlignmentPanel ap, JInternalFrame f) { - public void internalFrameOpened(InternalFrameEvent evt) - { - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - textfield.requestFocus(); - } - }); - } -}); - - } - - public void textfield_actionPerformed(ActionEvent e) - { - doSearch(false); - } - - public void findNext_actionPerformed(ActionEvent e) - { - doSearch(false); - } - - public void findAll_actionPerformed(ActionEvent e) - { - resIndex=0; - seqIndex=0; - doSearch(true); - } - - public void cancel_actionPerformed(ActionEvent e) - { - try{ - // if allResults is null, this effectively switches displaySearch flag in seqCanvas - ap.highlightSearchResults( null ); - frame.setClosed(true); - }catch(Exception ex){ } - - } - - void doSearch(boolean findAll) - { - searchString = textfield.getText().toUpperCase(); - - ArrayList searchResults = new ArrayList(); - int [] allResults = null; - - Sequence seq; - String item; - boolean found = false; - - /// is the searchString a residue number? - try{ - int res = Integer.parseInt(searchString); - found = true; - - if(av.getSelection().size()>0) - seq = (Sequence)(av.getSelection().sequenceAt(0)); - else - seq = (Sequence)av.getAlignment().getSequenceAt(0); - - searchResults.add( Integer.toString( av.getAlignment().findIndex(seq) ) ); - searchResults.add( Integer.toString( seq.findIndex(res)-1 ) ); - searchResults.add( Integer.toString( seq.findIndex(res)-1 ) ); - - - //av.getAlignment().getSequenceAt(seq).findPosition(res) - }catch(NumberFormatException ex){} - - - while( !found && seqIndex0 && !av.getSelection().contains(seq)) - { - // if a selection has been made, only search within that selection - seqIndex++; - resIndex=0; - continue; - } - - item = seq.getSequence(); - - for(int r = resIndex; r-1) - { - resIndex = item.indexOf(searchString,r); - - searchResults.add( Integer.toString(seqIndex) ); - searchResults.add( Integer.toString( resIndex) ); - searchResults.add( Integer.toString( (resIndex+searchString.length()-1) ) ); - if(!findAll) - { - // thats enough, break and display the result - found = true; - resIndex++; - break; - } - - r=resIndex+1; - } - } - if(!found) - { - seqIndex++; resIndex = 0; - } + seqIndex = 0; + doSearch(true); } - if(searchResults.size()>0) + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void createNewGroup_actionPerformed(ActionEvent e) { + JLabel label = new JLabel("Enter name of new sequence feature"); + JTextField textinput = new JTextField(textfield.getText()); + JPanel panel = new JPanel(new BorderLayout()); + panel.add(label, BorderLayout.NORTH); + panel.add(textinput, BorderLayout.SOUTH); - allResults = new int[searchResults.size()]; - for(int i=0; i 0)) + { + ap.idPanel.highlightSearchResults(idMatch); + } + + + int resultSize = searchResults.getSize(); + + if (searchResults.getSize() > 0) + createNewGroup.setEnabled(true); + else + searchResults = null; + + // if allResults is null, this effectively switches displaySearch flag in seqCanvas + ap.highlightSearchResults(searchResults); + + if(!findAll && resultSize==0) + { + JOptionPane.showInternalMessageDialog(this, "Finished searching", + null, JOptionPane.INFORMATION_MESSAGE); + resIndex = 0; + seqIndex = 0; + } + + if (findAll) + { + String message = resultSize + " matches found."; + JOptionPane.showInternalMessageDialog(this, message, null, + JOptionPane.INFORMATION_MESSAGE); + } + + } }