X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFinder.java;h=af23cebca24d510715f9c224e577600866f602fd;hb=a38d7808b759178025820c8d220a37d1442a57b3;hp=4397a480b5874ae42a3bfc7a2e30ea898de274d2;hpb=7decfe4c414e18517411fc065ea363c4ae5934fd;p=jalview.git diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index 4397a48..af23ceb 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -20,24 +20,26 @@ */ package jalview.gui; +import jalview.datamodel.SearchResultMatchI; +import jalview.datamodel.SearchResultsI; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceI; +import jalview.jbgui.GFinder; +import jalview.util.MessageManager; +import jalview.viewmodel.AlignmentViewport; + import java.awt.event.ActionEvent; -import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; -import java.beans.PropertyVetoException; import java.util.Vector; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import javax.swing.AbstractAction; +import javax.swing.JComponent; import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; import javax.swing.JOptionPane; - -import jalview.datamodel.SearchResults; -import jalview.datamodel.SequenceFeature; -import jalview.datamodel.SequenceI; -import jalview.jbgui.GFinder; -import jalview.util.MessageManager; -import jalview.viewmodel.AlignmentViewport; +import javax.swing.KeyStroke; /** * Performs the menu option for searching the alignment, for the next or all @@ -66,7 +68,7 @@ public class Finder extends GFinder int resIndex = -1; - SearchResults searchResults; + SearchResultsI searchResults; /** * Creates a new Finder object with no associated viewport or panel. @@ -92,7 +94,7 @@ public class Finder extends GFinder frame = new JInternalFrame(); frame.setContentPane(this); frame.setLayer(JLayeredPane.PALETTE_LAYER); - addKeyListener(); + addEscapeHandler(); Desktop.addInternalFrame(frame, MessageManager.getString("label.find"), WIDTH, HEIGHT); @@ -100,43 +102,37 @@ public class Finder extends GFinder } /** - * Add a key listener that closes the find dialog on 'Esc' key press + * Add a handler for the Escape key when the window has focus */ - private void addKeyListener() + private void addEscapeHandler() { - /* - * add the listener to the field with focus - */ - textfield.addKeyListener(new KeyAdapter() + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Cancel"); + getRootPane().getActionMap().put("Cancel", new AbstractAction() { @Override - public void keyPressed(KeyEvent evt) + public void actionPerformed(ActionEvent e) { - switch (evt.getKeyCode()) - { - case 27: - // close this window on Esc key - Finder.this.setVisible(false); - try - { - Finder.this.frame.setClosed(true); - } catch (PropertyVetoException e) - { - // ignore - } - break; - default: - break; - } + escapeActionPerformed(); } }); } /** + * Close the panel on Escape key press + */ + protected void escapeActionPerformed() + { + setVisible(false); + frame.dispose(); + } + + /** * Performs the 'Find Next' action. * * @param e */ + @Override public void findNext_actionPerformed(ActionEvent e) { if (getFocusedViewport()) @@ -150,6 +146,7 @@ public class Finder extends GFinder * * @param e */ + @Override public void findAll_actionPerformed(ActionEvent e) { if (getFocusedViewport()) @@ -205,19 +202,22 @@ public class Finder extends GFinder * @param e * DOCUMENT ME! */ + @Override public void createNewGroup_actionPerformed(ActionEvent e) { SequenceI[] seqs = new SequenceI[searchResults.getSize()]; SequenceFeature[] features = new SequenceFeature[searchResults .getSize()]; - for (int i = 0; i < searchResults.getSize(); i++) + int i = 0; + for (SearchResultMatchI match : searchResults.getResults()) { - seqs[i] = searchResults.getResultSequence(i).getDatasetSequence(); + seqs[i] = match.getSequence().getDatasetSequence(); features[i] = new SequenceFeature(textfield.getText().trim(), - "Search Results", null, searchResults.getResultStart(i), - searchResults.getResultEnd(i), "Search Results"); + "Search Results", null, match.getStart(), match.getEnd(), + "Search Results"); + i++; } if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs, @@ -263,7 +263,7 @@ public class Finder extends GFinder searchResults = finder.getSearchResults(); // find(regex, // caseSensitive.isSelected(), ) - Vector idMatch = finder.getIdMatch(); + Vector idMatch = finder.getIdMatch(); boolean haveResults = false; // set or reset the GUI if ((idMatch.size() > 0)) @@ -293,9 +293,9 @@ public class Finder extends GFinder // 'SelectRegion' selection if (!haveResults) { - JOptionPane.showInternalMessageDialog(this, + JvOptionPane.showInternalMessageDialog(this, MessageManager.getString("label.finished_searching"), null, - JOptionPane.INFORMATION_MESSAGE); + JvOptionPane.INFORMATION_MESSAGE); resIndex = -1; seqIndex = 0; } @@ -315,8 +315,8 @@ public class Finder extends GFinder message += searchResults.getSize() + " subsequence matches found."; } - JOptionPane.showInternalMessageDialog(this, message, null, - JOptionPane.INFORMATION_MESSAGE); + JvOptionPane.showInternalMessageDialog(this, message, null, + JvOptionPane.INFORMATION_MESSAGE); resIndex = -1; seqIndex = 0; } @@ -338,9 +338,9 @@ public class Finder extends GFinder { return false; } - JOptionPane.showInternalMessageDialog(this, error, + JvOptionPane.showInternalMessageDialog(this, error, MessageManager.getString("label.invalid_search"), // $NON-NLS-1$ - JOptionPane.ERROR_MESSAGE); + JvOptionPane.ERROR_MESSAGE); return true; }