From 7decfe4c414e18517411fc065ea363c4ae5934fd Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 18 May 2015 11:29:18 +0100 Subject: [PATCH] JAL-1652 Escape key now closes Find dialog --- src/jalview/gui/Finder.java | 51 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index 3cce82c..4397a48 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -20,14 +20,10 @@ */ 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; @@ -36,6 +32,13 @@ 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; + /** * 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 @@ -89,6 +92,7 @@ public class Finder extends GFinder frame = new JInternalFrame(); frame.setContentPane(this); frame.setLayer(JLayeredPane.PALETTE_LAYER); + addKeyListener(); Desktop.addInternalFrame(frame, MessageManager.getString("label.find"), WIDTH, HEIGHT); @@ -96,6 +100,39 @@ public class Finder extends GFinder } /** + * 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 -- 1.7.10.2