KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > keys > CharacterKey


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.keys;
13
14 import java.util.SortedMap JavaDoc;
15 import java.util.TreeMap JavaDoc;
16
17 import org.eclipse.jface.bindings.keys.IKeyLookup;
18 import org.eclipse.jface.bindings.keys.KeyLookupFactory;
19
20 /**
21  * <p>
22  * Instances of <code>CharacterKey</code> represent keys on the keyboard which
23  * represent unicode characters.
24  * </p>
25  * <p>
26  * <code>CharacterKey</code> objects are immutable. Clients are not permitted
27  * to extend this class.
28  * </p>
29  *
30  * @deprecated Please use org.eclipse.jface.bindings.keys.KeyStroke and
31  * org.eclipse.jface.bindings.keys.KeyLookupFactory
32  * @since 3.0
33  */

34 public final class CharacterKey extends NaturalKey {
35
36     /**
37      * An internal map used to lookup instances of <code>CharacterKey</code>
38      * given the formal string representation of a character key.
39      */

40     static SortedMap JavaDoc characterKeysByName = new TreeMap JavaDoc();
41
42     /**
43      * The single static instance of <code>CharacterKey</code> which
44      * represents the backspace key (U+0008).
45      */

46     public final static CharacterKey BS;
47
48     /**
49      * The single static instance of <code>CharacterKey</code> which
50      * represents the carriage return (U+000D) key
51      */

52     public final static CharacterKey CR;
53
54     /**
55      * The single static instance of <code>CharacterKey</code> which
56      * represents the delete (U+007F) key.
57      */

58     public final static CharacterKey DEL;
59
60     /**
61      * The single static instance of <code>CharacterKey</code> which
62      * represents the escape (U+001B) key.
63      */

64     public final static CharacterKey ESC;
65
66     /**
67      * The single static instance of <code>CharacterKey</code> which
68      * represents the form feed (U+000C) key.
69      */

70     public final static CharacterKey FF;
71
72     /**
73      * The single static instance of <code>CharacterKey</code> which
74      * represents the line feed (U+000A) key.
75      */

76     public final static CharacterKey LF;
77
78     /**
79      * The single static instance of <code>CharacterKey</code> which
80      * represents the null (U+0000) key.
81      */

82     public final static CharacterKey NUL;
83
84     /**
85      * The single static instance of <code>CharacterKey</code> which
86      * represents the space (U+0020) key.
87      */

88     public final static CharacterKey SPACE;
89
90     /**
91      * The single static instance of <code>CharacterKey</code> which
92      * represents the tab (U+0009) key.
93      */

94     public final static CharacterKey TAB;
95
96     /**
97      * The single static instance of <code>CharacterKey</code> which
98      * represents the vertical tab (U+000B) key.
99      */

100     public final static CharacterKey VT;
101
102     /**
103      * Creates an instance of <code>CharacterKey</code> given a unicode
104      * character. This method determines the correct name for the key based on
105      * character. Typically, this name is a string of one-character in length
106      * equal to the character that this instance represents.
107      *
108      * @param character
109      * the character that the resultant <code>CharacterKey</code>
110      * instance is to represent.
111      * @return an instance of <code>CharacterKey</code> representing the
112      * character.
113      */

114     public static final CharacterKey getInstance(final char character) {
115         return new CharacterKey(character);
116     }
117
118     static {
119         final IKeyLookup lookup = KeyLookupFactory.getDefault();
120         BS = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.BS_NAME));
121         CR = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.CR_NAME));
122         DEL = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.DEL_NAME));
123         ESC = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.ESC_NAME));
124         FF = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.FF_NAME));
125         LF = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.LF_NAME));
126         NUL = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.NUL_NAME));
127         SPACE = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.SPACE_NAME));
128         TAB = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.TAB_NAME));
129         VT = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.VT_NAME));
130
131         characterKeysByName.put(IKeyLookup.BS_NAME, CharacterKey.BS);
132         characterKeysByName.put(IKeyLookup.BACKSPACE_NAME, CharacterKey.BS);
133         characterKeysByName.put(IKeyLookup.CR_NAME, CharacterKey.CR);
134         characterKeysByName.put(IKeyLookup.ENTER_NAME, CharacterKey.CR);
135         characterKeysByName.put(IKeyLookup.RETURN_NAME, CharacterKey.CR);
136         characterKeysByName.put(IKeyLookup.DEL_NAME, CharacterKey.DEL);
137         characterKeysByName.put(IKeyLookup.DELETE_NAME, CharacterKey.DEL);
138         characterKeysByName.put(IKeyLookup.ESC_NAME, CharacterKey.ESC);
139         characterKeysByName.put(IKeyLookup.ESCAPE_NAME, CharacterKey.ESC);
140         characterKeysByName.put(IKeyLookup.FF_NAME, CharacterKey.FF);
141         characterKeysByName.put(IKeyLookup.LF_NAME, CharacterKey.LF);
142         characterKeysByName.put(IKeyLookup.NUL_NAME, CharacterKey.NUL);
143         characterKeysByName.put(IKeyLookup.SPACE_NAME, CharacterKey.SPACE);
144         characterKeysByName.put(IKeyLookup.TAB_NAME, CharacterKey.TAB);
145         characterKeysByName.put(IKeyLookup.VT_NAME, CharacterKey.VT);
146     }
147
148     /**
149      * Constructs an instance of <code>CharacterKey</code> given a unicode
150      * character and a name.
151      *
152      * @param key
153      * The key to be wrapped.
154      */

155     private CharacterKey(final int key) {
156         super(key);
157     }
158
159     /**
160      * Gets the character that this object represents.
161      *
162      * @return the character that this object represents.
163      */

164     public final char getCharacter() {
165         return (char) key;
166     }
167 }
168
Popular Tags