JAL-966 JAL-1738 JAL-345 interfaces for SearchResults and SearchResults.Match
[jalview.git] / src / jalview / gui / Finder.java
index 4397a48..a73728a 100755 (executable)
  */
 package jalview.gui;
 
+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 +67,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 +93,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,39 +101,31 @@ 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