KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > 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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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

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

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