KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > scripting > php > dbginterface > ui > FilteredKeymap


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.scripting.php.dbginterface.ui;
21
22 import javax.swing.Action JavaDoc;
23 import javax.swing.KeyStroke JavaDoc;
24 import javax.swing.text.Keymap JavaDoc;
25
26 /**
27  * A keymap that filters ENTER, ESC and TAB, which have special meaning in dialogs
28  *
29  * @author Martin Entlicher
30  */

31 public class FilteredKeymap implements Keymap JavaDoc {
32
33     private final javax.swing.KeyStroke JavaDoc enter = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, 0);
34     private final javax.swing.KeyStroke JavaDoc esc = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0);
35     private final javax.swing.KeyStroke JavaDoc tab = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_TAB, 0);
36     private final Keymap JavaDoc keyMap; // The original keymap
37

38     /** Creates a new instance of FilteredKeymap */
39     public FilteredKeymap(Keymap JavaDoc keyMap) {
40         this.keyMap = keyMap;
41     }
42     
43     public void addActionForKeyStroke(KeyStroke JavaDoc key, Action JavaDoc a) {
44         keyMap.addActionForKeyStroke(key, a);
45     }
46     public Action JavaDoc getAction(KeyStroke JavaDoc key) {
47         if (enter.equals(key) ||
48             esc.equals(key) ||
49             tab.equals(key)) {
50
51             return null;
52         } else {
53             return keyMap.getAction(key);
54         }
55     }
56     public Action JavaDoc[] getBoundActions() {
57         return keyMap.getBoundActions();
58     }
59     public KeyStroke JavaDoc[] getBoundKeyStrokes() {
60         return keyMap.getBoundKeyStrokes();
61     }
62     public Action JavaDoc getDefaultAction() {
63         return keyMap.getDefaultAction();
64     }
65     public KeyStroke JavaDoc[] getKeyStrokesForAction(Action JavaDoc a) {
66         return keyMap.getKeyStrokesForAction(a);
67     }
68     public String JavaDoc getName() {
69         return keyMap.getName()+"_Filtered"; //NOI18N
70
}
71     public javax.swing.text.Keymap JavaDoc getResolveParent() {
72         return keyMap.getResolveParent();
73     }
74     public boolean isLocallyDefined(KeyStroke JavaDoc key) {
75         if (enter.equals(key) ||
76             esc.equals(key) ||
77             tab.equals(key)) {
78             
79             return false;
80         } else {
81             return keyMap.isLocallyDefined(key);
82         }
83     }
84     public void removeBindings() {
85         keyMap.removeBindings();
86     }
87     public void removeKeyStrokeBinding(KeyStroke JavaDoc keys) {
88         keyMap.removeKeyStrokeBinding(keys);
89     }
90     public void setDefaultAction(Action JavaDoc a) {
91         keyMap.setDefaultAction(a);
92     }
93     public void setResolveParent(javax.swing.text.Keymap JavaDoc parent) {
94         keyMap.setResolveParent(parent);
95     }
96 }
97
Popular Tags