01: /* ====================================================================
02: * The QueryForm License, Version 1.1
03: *
04: * Copyright (c) 1998 - 2003 David F. Glasser. All rights
05: * reserved.
06: *
07: * Redistribution and use in source and binary forms, with or without
08: * modification, are permitted provided that the following conditions
09: * are met:
10: *
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: *
14: * 2. Redistributions in binary form must reproduce the above copyright
15: * notice, this list of conditions and the following disclaimer in
16: * the documentation and/or other materials provided with the
17: * distribution.
18: *
19: * 3. The end-user documentation included with the redistribution,
20: * if any, must include the following acknowledgment:
21: * "This product includes software developed by
22: * David F. Glasser."
23: * Alternately, this acknowledgment may appear in the software itself,
24: * if and wherever such third-party acknowledgments normally appear.
25: *
26: * 4. The names "QueryForm" and "David F. Glasser" must
27: * not be used to endorse or promote products derived from this
28: * software without prior written permission. For written
29: * permission, please contact dglasser@pobox.com.
30: *
31: * 5. Products derived from this software may not be called "QueryForm",
32: * nor may "QueryForm" appear in their name, without prior written
33: * permission of David F. Glasser.
34: *
35: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38: * DISCLAIMED. IN NO EVENT SHALL DAVID F. GLASSER, THE APACHE SOFTWARE
39: * FOUNDATION OR ITS CONTRIBUTORS, OR ANY AUTHORS OR DISTRIBUTORS
40: * OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47: * SUCH DAMAGE.
48: * ====================================================================
49: *
50: * This product includes software developed by the
51: * Apache Software Foundation (http://www.apache.org/).
52: *
53: * ====================================================================
54: *
55: * $Source: /cvsroot/qform/qform/src/org/glasser/swing/EnterEscapeKeyHandler.java,v $
56: * $Revision: 1.1 $
57: * $Author: dglasser $
58: * $Date: 2003/01/26 01:02:15 $
59: *
60: * --------------------------------------------------------------------
61: */
62: package org.glasser.swing;
63:
64: import java.awt.event.*;
65: import javax.swing.*;
66:
67: public class EnterEscapeKeyHandler extends KeyAdapter {
68:
69: JButton enterButton = null;
70: JButton escapeButton = null;
71:
72: public EnterEscapeKeyHandler(JButton enterButton,
73: JButton escapeButton) {
74:
75: this .enterButton = enterButton;
76: this .escapeButton = escapeButton;
77:
78: }
79:
80: public void keyReleased(KeyEvent e) {
81: int key = e.getKeyCode();
82: if (key == e.VK_ENTER) {
83: if (enterButton != null)
84: enterButton.doClick();
85: } else if (key == e.VK_ESCAPE) {
86: if (escapeButton != null)
87: escapeButton.doClick();
88: }
89: }
90:
91: }
|