*/
package jalview.gui;
-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 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.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;
+
/**
* Performs the menu option for searching the alignment, for the next or all
* matches. If matches are found, they are highlighted, and the user has the
frame = new JInternalFrame();
frame.setContentPane(this);
frame.setLayer(JLayeredPane.PALETTE_LAYER);
+ addKeyListener();
Desktop.addInternalFrame(frame, MessageManager.getString("label.find"),
WIDTH, HEIGHT);
}
/**
+ * Add a key listener that closes the find dialog on 'Esc' key press
+ */
+ private void addKeyListener()
+ {
+ /*
+ * add the listener to the field with focus
+ */
+ textfield.addKeyListener(new KeyAdapter()
+ {
+ @Override
+ public void keyPressed(KeyEvent evt)
+ {
+ 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;
+ }
+ }
+ });
+ }
+
+ /**
* Performs the 'Find Next' action.
*
* @param e