001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.keys;
011:
012: import java.util.SortedMap;
013: import java.util.TreeMap;
014:
015: import org.eclipse.jface.bindings.keys.IKeyLookup;
016: import org.eclipse.jface.bindings.keys.KeyLookupFactory;
017:
018: /**
019: * <p>
020: * Instances of <code>CharacterKey</code> represent keys on the keyboard which
021: * represent unicode characters.
022: * </p>
023: * <p>
024: * <code>CharacterKey</code> objects are immutable. Clients are not permitted
025: * to extend this class.
026: * </p>
027: *
028: * @deprecated Please use org.eclipse.jface.bindings.keys.KeyStroke and
029: * org.eclipse.jface.bindings.keys.KeyLookupFactory
030: * @since 3.0
031: */
032: public final class CharacterKey extends NaturalKey {
033:
034: /**
035: * An internal map used to lookup instances of <code>CharacterKey</code>
036: * given the formal string representation of a character key.
037: */
038: static SortedMap characterKeysByName = new TreeMap();
039:
040: /**
041: * The single static instance of <code>CharacterKey</code> which
042: * represents the backspace key (U+0008).
043: */
044: public final static CharacterKey BS;
045:
046: /**
047: * The single static instance of <code>CharacterKey</code> which
048: * represents the carriage return (U+000D) key
049: */
050: public final static CharacterKey CR;
051:
052: /**
053: * The single static instance of <code>CharacterKey</code> which
054: * represents the delete (U+007F) key.
055: */
056: public final static CharacterKey DEL;
057:
058: /**
059: * The single static instance of <code>CharacterKey</code> which
060: * represents the escape (U+001B) key.
061: */
062: public final static CharacterKey ESC;
063:
064: /**
065: * The single static instance of <code>CharacterKey</code> which
066: * represents the form feed (U+000C) key.
067: */
068: public final static CharacterKey FF;
069:
070: /**
071: * The single static instance of <code>CharacterKey</code> which
072: * represents the line feed (U+000A) key.
073: */
074: public final static CharacterKey LF;
075:
076: /**
077: * The single static instance of <code>CharacterKey</code> which
078: * represents the null (U+0000) key.
079: */
080: public final static CharacterKey NUL;
081:
082: /**
083: * The single static instance of <code>CharacterKey</code> which
084: * represents the space (U+0020) key.
085: */
086: public final static CharacterKey SPACE;
087:
088: /**
089: * The single static instance of <code>CharacterKey</code> which
090: * represents the tab (U+0009) key.
091: */
092: public final static CharacterKey TAB;
093:
094: /**
095: * The single static instance of <code>CharacterKey</code> which
096: * represents the vertical tab (U+000B) key.
097: */
098: public final static CharacterKey VT;
099:
100: /**
101: * Creates an instance of <code>CharacterKey</code> given a unicode
102: * character. This method determines the correct name for the key based on
103: * character. Typically, this name is a string of one-character in length
104: * equal to the character that this instance represents.
105: *
106: * @param character
107: * the character that the resultant <code>CharacterKey</code>
108: * instance is to represent.
109: * @return an instance of <code>CharacterKey</code> representing the
110: * character.
111: */
112: public static final CharacterKey getInstance(final char character) {
113: return new CharacterKey(character);
114: }
115:
116: static {
117: final IKeyLookup lookup = KeyLookupFactory.getDefault();
118: BS = new CharacterKey(lookup
119: .formalKeyLookup(IKeyLookup.BS_NAME));
120: CR = new CharacterKey(lookup
121: .formalKeyLookup(IKeyLookup.CR_NAME));
122: DEL = new CharacterKey(lookup
123: .formalKeyLookup(IKeyLookup.DEL_NAME));
124: ESC = new CharacterKey(lookup
125: .formalKeyLookup(IKeyLookup.ESC_NAME));
126: FF = new CharacterKey(lookup
127: .formalKeyLookup(IKeyLookup.FF_NAME));
128: LF = new CharacterKey(lookup
129: .formalKeyLookup(IKeyLookup.LF_NAME));
130: NUL = new CharacterKey(lookup
131: .formalKeyLookup(IKeyLookup.NUL_NAME));
132: SPACE = new CharacterKey(lookup
133: .formalKeyLookup(IKeyLookup.SPACE_NAME));
134: TAB = new CharacterKey(lookup
135: .formalKeyLookup(IKeyLookup.TAB_NAME));
136: VT = new CharacterKey(lookup
137: .formalKeyLookup(IKeyLookup.VT_NAME));
138:
139: characterKeysByName.put(IKeyLookup.BS_NAME, CharacterKey.BS);
140: characterKeysByName.put(IKeyLookup.BACKSPACE_NAME,
141: CharacterKey.BS);
142: characterKeysByName.put(IKeyLookup.CR_NAME, CharacterKey.CR);
143: characterKeysByName.put(IKeyLookup.ENTER_NAME, CharacterKey.CR);
144: characterKeysByName
145: .put(IKeyLookup.RETURN_NAME, CharacterKey.CR);
146: characterKeysByName.put(IKeyLookup.DEL_NAME, CharacterKey.DEL);
147: characterKeysByName.put(IKeyLookup.DELETE_NAME,
148: CharacterKey.DEL);
149: characterKeysByName.put(IKeyLookup.ESC_NAME, CharacterKey.ESC);
150: characterKeysByName.put(IKeyLookup.ESCAPE_NAME,
151: CharacterKey.ESC);
152: characterKeysByName.put(IKeyLookup.FF_NAME, CharacterKey.FF);
153: characterKeysByName.put(IKeyLookup.LF_NAME, CharacterKey.LF);
154: characterKeysByName.put(IKeyLookup.NUL_NAME, CharacterKey.NUL);
155: characterKeysByName.put(IKeyLookup.SPACE_NAME,
156: CharacterKey.SPACE);
157: characterKeysByName.put(IKeyLookup.TAB_NAME, CharacterKey.TAB);
158: characterKeysByName.put(IKeyLookup.VT_NAME, CharacterKey.VT);
159: }
160:
161: /**
162: * Constructs an instance of <code>CharacterKey</code> given a unicode
163: * character and a name.
164: *
165: * @param key
166: * The key to be wrapped.
167: */
168: private CharacterKey(final int key) {
169: super (key);
170: }
171:
172: /**
173: * Gets the character that this object represents.
174: *
175: * @return the character that this object represents.
176: */
177: public final char getCharacter() {
178: return (char) key;
179: }
180: }
|