X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFinder.java;h=cad734b297d7ae1932e621f0f5251a09a9b21c31;hb=6a7ed84443875e35d61de7f57c4aa6898c68775a;hp=c5a2cf4e0c090630bf0e255f5ecd119432b4e065;hpb=3e313eab680734bb0bd49d3366c5ae6ad8330ef4;p=jalview.git diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index c5a2cf4..cad734b 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -1,129 +1,214 @@ -package jalview.gui; - -import jalview.jbgui.GFinder; -import jalview.datamodel.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.*; -import java.util.*; - - -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() - { - 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{ - 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; - while( !found && seqIndex-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; - } - } - } - if(!found) - { - seqIndex++; - resIndex = 0; - } - } - - if(searchResults.size()>0) - { - - 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); + // TODO: add enablers for 'SelectSequences' or 'SelectColumns' or + // 'SelectRegion' selection + 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); + } + + } +}