1 /*******************************************************************************
2  * Copyright (c) 2000, 2015 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 
15 package org.eclipse.ui.keys;
16 
17 import java.util.SortedMap;
18 import java.util.TreeMap;
19 
20 import org.eclipse.jface.bindings.keys.IKeyLookup;
21 import org.eclipse.jface.bindings.keys.KeyLookupFactory;
22 
23 /**
24  * <p>
25  * Instances of <code>CharacterKey</code> represent keys on the keyboard which
26  * represent unicode characters.
27  * </p>
28  * <p>
29  * <code>CharacterKey</code> objects are immutable. Clients are not permitted to
30  * extend this class.
31  * </p>
32  *
33  * @deprecated Please use org.eclipse.jface.bindings.keys.KeyStroke and
34  *             org.eclipse.jface.bindings.keys.KeyLookupFactory
35  * @since 3.0
36  */
37 @Deprecated
38 public final class CharacterKey extends NaturalKey {
39 
40 	/**
41 	 * An internal map used to lookup instances of <code>CharacterKey</code> given
42 	 * the formal string representation of a character key.
43 	 */
44 	static SortedMap characterKeysByName = new TreeMap();
45 
46 	/**
47 	 * The single static instance of <code>CharacterKey</code> which represents the
48 	 * backspace key (U+0008).
49 	 */
50 	public static final CharacterKey BS;
51 
52 	/**
53 	 * The single static instance of <code>CharacterKey</code> which represents the
54 	 * carriage return (U+000D) key
55 	 */
56 	public static final CharacterKey CR;
57 
58 	/**
59 	 * The single static instance of <code>CharacterKey</code> which represents the
60 	 * delete (U+007F) key.
61 	 */
62 	public static final CharacterKey DEL;
63 
64 	/**
65 	 * The single static instance of <code>CharacterKey</code> which represents the
66 	 * escape (U+001B) key.
67 	 */
68 	public static final CharacterKey ESC;
69 
70 	/**
71 	 * The single static instance of <code>CharacterKey</code> which represents the
72 	 * form feed (U+000C) key.
73 	 */
74 	public static final CharacterKey FF;
75 
76 	/**
77 	 * The single static instance of <code>CharacterKey</code> which represents the
78 	 * line feed (U+000A) key.
79 	 */
80 	public static final CharacterKey LF;
81 
82 	/**
83 	 * The single static instance of <code>CharacterKey</code> which represents the
84 	 * null (U+0000) key.
85 	 */
86 	public static final CharacterKey NUL;
87 
88 	/**
89 	 * The single static instance of <code>CharacterKey</code> which represents the
90 	 * space (U+0020) key.
91 	 */
92 	public static final CharacterKey SPACE;
93 
94 	/**
95 	 * The single static instance of <code>CharacterKey</code> which represents the
96 	 * tab (U+0009) key.
97 	 */
98 	public static final CharacterKey TAB;
99 
100 	/**
101 	 * The single static instance of <code>CharacterKey</code> which represents the
102 	 * vertical tab (U+000B) key.
103 	 */
104 	public static final CharacterKey VT;
105 
106 	/**
107 	 * Creates an instance of <code>CharacterKey</code> given a unicode character.
108 	 * This method determines the correct name for the key based on character.
109 	 * Typically, this name is a string of one-character in length equal to the
110 	 * character that this instance represents.
111 	 *
112 	 * @param character the character that the resultant <code>CharacterKey</code>
113 	 *                  instance is to represent.
114 	 * @return an instance of <code>CharacterKey</code> representing the character.
115 	 */
getInstance(final char character)116 	public static CharacterKey getInstance(final char character) {
117 		return new CharacterKey(character);
118 	}
119 
120 	static {
121 		final IKeyLookup lookup = KeyLookupFactory.getDefault();
122 		BS = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.BS_NAME));
123 		CR = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.CR_NAME));
124 		DEL = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.DEL_NAME));
125 		ESC = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.ESC_NAME));
126 		FF = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.FF_NAME));
127 		LF = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.LF_NAME));
128 		NUL = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.NUL_NAME));
129 		SPACE = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.SPACE_NAME));
130 		TAB = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.TAB_NAME));
131 		VT = new CharacterKey(lookup.formalKeyLookup(IKeyLookup.VT_NAME));
132 
characterKeysByName.put(IKeyLookup.BS_NAME, CharacterKey.BS)133 		characterKeysByName.put(IKeyLookup.BS_NAME, CharacterKey.BS);
characterKeysByName.put(IKeyLookup.BACKSPACE_NAME, CharacterKey.BS)134 		characterKeysByName.put(IKeyLookup.BACKSPACE_NAME, CharacterKey.BS);
characterKeysByName.put(IKeyLookup.CR_NAME, CharacterKey.CR)135 		characterKeysByName.put(IKeyLookup.CR_NAME, CharacterKey.CR);
characterKeysByName.put(IKeyLookup.ENTER_NAME, CharacterKey.CR)136 		characterKeysByName.put(IKeyLookup.ENTER_NAME, CharacterKey.CR);
characterKeysByName.put(IKeyLookup.RETURN_NAME, CharacterKey.CR)137 		characterKeysByName.put(IKeyLookup.RETURN_NAME, CharacterKey.CR);
characterKeysByName.put(IKeyLookup.DEL_NAME, CharacterKey.DEL)138 		characterKeysByName.put(IKeyLookup.DEL_NAME, CharacterKey.DEL);
characterKeysByName.put(IKeyLookup.DELETE_NAME, CharacterKey.DEL)139 		characterKeysByName.put(IKeyLookup.DELETE_NAME, CharacterKey.DEL);
characterKeysByName.put(IKeyLookup.ESC_NAME, CharacterKey.ESC)140 		characterKeysByName.put(IKeyLookup.ESC_NAME, CharacterKey.ESC);
characterKeysByName.put(IKeyLookup.ESCAPE_NAME, CharacterKey.ESC)141 		characterKeysByName.put(IKeyLookup.ESCAPE_NAME, CharacterKey.ESC);
characterKeysByName.put(IKeyLookup.FF_NAME, CharacterKey.FF)142 		characterKeysByName.put(IKeyLookup.FF_NAME, CharacterKey.FF);
characterKeysByName.put(IKeyLookup.LF_NAME, CharacterKey.LF)143 		characterKeysByName.put(IKeyLookup.LF_NAME, CharacterKey.LF);
characterKeysByName.put(IKeyLookup.NUL_NAME, CharacterKey.NUL)144 		characterKeysByName.put(IKeyLookup.NUL_NAME, CharacterKey.NUL);
characterKeysByName.put(IKeyLookup.SPACE_NAME, CharacterKey.SPACE)145 		characterKeysByName.put(IKeyLookup.SPACE_NAME, CharacterKey.SPACE);
characterKeysByName.put(IKeyLookup.TAB_NAME, CharacterKey.TAB)146 		characterKeysByName.put(IKeyLookup.TAB_NAME, CharacterKey.TAB);
characterKeysByName.put(IKeyLookup.VT_NAME, CharacterKey.VT)147 		characterKeysByName.put(IKeyLookup.VT_NAME, CharacterKey.VT);
148 	}
149 
150 	/**
151 	 * Constructs an instance of <code>CharacterKey</code> given a unicode character
152 	 * and a name.
153 	 *
154 	 * @param key The key to be wrapped.
155 	 */
CharacterKey(final int key)156 	private CharacterKey(final int key) {
157 		super(key);
158 	}
159 
160 	/**
161 	 * Gets the character that this object represents.
162 	 *
163 	 * @return the character that this object represents.
164 	 */
getCharacter()165 	public char getCharacter() {
166 		return (char) key;
167 	}
168 }
169