1*76b6b121SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*76b6b121SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*76b6b121SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*76b6b121SAndrew Rist  * distributed with this work for additional information
6*76b6b121SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*76b6b121SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*76b6b121SAndrew Rist  * "License"); you may not use this file except in compliance
9*76b6b121SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*76b6b121SAndrew Rist  *
11*76b6b121SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*76b6b121SAndrew Rist  *
13*76b6b121SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*76b6b121SAndrew Rist  * software distributed under the License is distributed on an
15*76b6b121SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*76b6b121SAndrew Rist  * KIND, either express or implied.  See the License for the
17*76b6b121SAndrew Rist  * specific language governing permissions and limitations
18*76b6b121SAndrew Rist  * under the License.
19*76b6b121SAndrew Rist  *
20*76b6b121SAndrew Rist  *************************************************************/
21*76b6b121SAndrew Rist 
22*76b6b121SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package complex.accelerators;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import java.util.HashMap;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir class KeyIdentifierInfo
29cdf0e10cSrcweir {
30cdf0e10cSrcweir     protected String sIdentifier;
31cdf0e10cSrcweir     protected Short nCode;
32cdf0e10cSrcweir 
KeyIdentifierInfo(String sID, Short nC)33cdf0e10cSrcweir     KeyIdentifierInfo(String sID, Short nC)
34cdf0e10cSrcweir     {
35cdf0e10cSrcweir         sIdentifier = sID;
36cdf0e10cSrcweir         nCode = nC;
37cdf0e10cSrcweir     }
38cdf0e10cSrcweir }
39cdf0e10cSrcweir 
40cdf0e10cSrcweir class IdentifierHashMap extends HashMap
41cdf0e10cSrcweir {
put(String sIdentifier, Short nCode)42cdf0e10cSrcweir     public void put(String sIdentifier, Short nCode)
43cdf0e10cSrcweir     {
44cdf0e10cSrcweir         super.put(sIdentifier, nCode);
45cdf0e10cSrcweir     }
get(String sIdentifier)46cdf0e10cSrcweir     public Short get(String sIdentifier)
47cdf0e10cSrcweir     {
48cdf0e10cSrcweir         return (Short)super.get(sIdentifier);
49cdf0e10cSrcweir     }
50cdf0e10cSrcweir }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir class CodeHashMap extends HashMap
53cdf0e10cSrcweir {
put(Short nCode, String sIdentifier)54cdf0e10cSrcweir     public void put(Short nCode, String sIdentifier)
55cdf0e10cSrcweir     {
56cdf0e10cSrcweir         super.put(nCode, sIdentifier);
57cdf0e10cSrcweir     }
get(Short nCode)58cdf0e10cSrcweir     public String get(Short nCode)
59cdf0e10cSrcweir     {
60cdf0e10cSrcweir         return (String)super.get(nCode);
61cdf0e10cSrcweir     }
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir public class KeyMapping
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     private IdentifierHashMap aIdentifierHashMap;
67cdf0e10cSrcweir     private CodeHashMap aCodeHashMap;
68cdf0e10cSrcweir 
KeyMapping()69cdf0e10cSrcweir     public KeyMapping()
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         KeyIdentifierInfo[] aInfoMap = {
72cdf0e10cSrcweir             new KeyIdentifierInfo("0", new Short(com.sun.star.awt.Key.NUM0)),
73cdf0e10cSrcweir             new KeyIdentifierInfo("1", new Short(com.sun.star.awt.Key.NUM1)),
74cdf0e10cSrcweir             new KeyIdentifierInfo("2", new Short(com.sun.star.awt.Key.NUM2)),
75cdf0e10cSrcweir             new KeyIdentifierInfo("3", new Short(com.sun.star.awt.Key.NUM3)),
76cdf0e10cSrcweir             new KeyIdentifierInfo("4", new Short(com.sun.star.awt.Key.NUM4)),
77cdf0e10cSrcweir             new KeyIdentifierInfo("5", new Short(com.sun.star.awt.Key.NUM5)),
78cdf0e10cSrcweir             new KeyIdentifierInfo("6", new Short(com.sun.star.awt.Key.NUM6)),
79cdf0e10cSrcweir             new KeyIdentifierInfo("7", new Short(com.sun.star.awt.Key.NUM7)),
80cdf0e10cSrcweir             new KeyIdentifierInfo("8", new Short(com.sun.star.awt.Key.NUM8)),
81cdf0e10cSrcweir             new KeyIdentifierInfo("9", new Short(com.sun.star.awt.Key.NUM9)),
82cdf0e10cSrcweir             new KeyIdentifierInfo("A", new Short(com.sun.star.awt.Key.A)),
83cdf0e10cSrcweir             new KeyIdentifierInfo("B", new Short(com.sun.star.awt.Key.B)),
84cdf0e10cSrcweir             new KeyIdentifierInfo("C", new Short(com.sun.star.awt.Key.C)),
85cdf0e10cSrcweir             new KeyIdentifierInfo("D", new Short(com.sun.star.awt.Key.D)),
86cdf0e10cSrcweir             new KeyIdentifierInfo("E", new Short(com.sun.star.awt.Key.E)),
87cdf0e10cSrcweir             new KeyIdentifierInfo("F", new Short(com.sun.star.awt.Key.F)),
88cdf0e10cSrcweir             new KeyIdentifierInfo("G", new Short(com.sun.star.awt.Key.G)),
89cdf0e10cSrcweir             new KeyIdentifierInfo("H", new Short(com.sun.star.awt.Key.H)),
90cdf0e10cSrcweir             new KeyIdentifierInfo("I", new Short(com.sun.star.awt.Key.I)),
91cdf0e10cSrcweir             new KeyIdentifierInfo("J", new Short(com.sun.star.awt.Key.J)),
92cdf0e10cSrcweir             new KeyIdentifierInfo("K", new Short(com.sun.star.awt.Key.K)),
93cdf0e10cSrcweir             new KeyIdentifierInfo("L", new Short(com.sun.star.awt.Key.L)),
94cdf0e10cSrcweir             new KeyIdentifierInfo("M", new Short(com.sun.star.awt.Key.M)),
95cdf0e10cSrcweir             new KeyIdentifierInfo("N", new Short(com.sun.star.awt.Key.N)),
96cdf0e10cSrcweir             new KeyIdentifierInfo("O", new Short(com.sun.star.awt.Key.O)),
97cdf0e10cSrcweir             new KeyIdentifierInfo("P", new Short(com.sun.star.awt.Key.P)),
98cdf0e10cSrcweir             new KeyIdentifierInfo("Q", new Short(com.sun.star.awt.Key.Q)),
99cdf0e10cSrcweir             new KeyIdentifierInfo("R", new Short(com.sun.star.awt.Key.R)),
100cdf0e10cSrcweir             new KeyIdentifierInfo("S", new Short(com.sun.star.awt.Key.S)),
101cdf0e10cSrcweir             new KeyIdentifierInfo("T", new Short(com.sun.star.awt.Key.T)),
102cdf0e10cSrcweir             new KeyIdentifierInfo("U", new Short(com.sun.star.awt.Key.U)),
103cdf0e10cSrcweir             new KeyIdentifierInfo("V", new Short(com.sun.star.awt.Key.V)),
104cdf0e10cSrcweir             new KeyIdentifierInfo("W", new Short(com.sun.star.awt.Key.W)),
105cdf0e10cSrcweir             new KeyIdentifierInfo("X", new Short(com.sun.star.awt.Key.X)),
106cdf0e10cSrcweir             new KeyIdentifierInfo("Y", new Short(com.sun.star.awt.Key.Y)),
107cdf0e10cSrcweir             new KeyIdentifierInfo("Z", new Short(com.sun.star.awt.Key.Z)),
108cdf0e10cSrcweir             new KeyIdentifierInfo("F1", new Short(com.sun.star.awt.Key.F1)),
109cdf0e10cSrcweir             new KeyIdentifierInfo("F2", new Short(com.sun.star.awt.Key.F2)),
110cdf0e10cSrcweir             new KeyIdentifierInfo("F3", new Short(com.sun.star.awt.Key.F3)),
111cdf0e10cSrcweir             new KeyIdentifierInfo("F4", new Short(com.sun.star.awt.Key.F4)),
112cdf0e10cSrcweir             new KeyIdentifierInfo("F5", new Short(com.sun.star.awt.Key.F5)),
113cdf0e10cSrcweir             new KeyIdentifierInfo("F6", new Short(com.sun.star.awt.Key.F6)),
114cdf0e10cSrcweir             new KeyIdentifierInfo("F7", new Short(com.sun.star.awt.Key.F7)),
115cdf0e10cSrcweir             new KeyIdentifierInfo("F8", new Short(com.sun.star.awt.Key.F8)),
116cdf0e10cSrcweir             new KeyIdentifierInfo("F9", new Short(com.sun.star.awt.Key.F9)),
117cdf0e10cSrcweir             new KeyIdentifierInfo("F10", new Short(com.sun.star.awt.Key.F10)),
118cdf0e10cSrcweir             new KeyIdentifierInfo("F11", new Short(com.sun.star.awt.Key.F11)),
119cdf0e10cSrcweir             new KeyIdentifierInfo("F12", new Short(com.sun.star.awt.Key.F12)),
120cdf0e10cSrcweir             new KeyIdentifierInfo("DOWN", new Short(com.sun.star.awt.Key.DOWN)),
121cdf0e10cSrcweir             new KeyIdentifierInfo("UP", new Short(com.sun.star.awt.Key.UP)),
122cdf0e10cSrcweir             new KeyIdentifierInfo("LEFT", new Short(com.sun.star.awt.Key.LEFT)),
123cdf0e10cSrcweir             new KeyIdentifierInfo("RIGHT", new Short(com.sun.star.awt.Key.RIGHT)),
124cdf0e10cSrcweir             new KeyIdentifierInfo("HOME", new Short(com.sun.star.awt.Key.HOME)),
125cdf0e10cSrcweir             new KeyIdentifierInfo("END", new Short(com.sun.star.awt.Key.END)),
126cdf0e10cSrcweir             new KeyIdentifierInfo("PAGEUP", new Short(com.sun.star.awt.Key.PAGEUP)),
127cdf0e10cSrcweir             new KeyIdentifierInfo("PAGEDOWN", new Short(com.sun.star.awt.Key.PAGEDOWN)),
128cdf0e10cSrcweir             new KeyIdentifierInfo("RETURN", new Short(com.sun.star.awt.Key.RETURN)),
129cdf0e10cSrcweir             new KeyIdentifierInfo("ESCAPE", new Short(com.sun.star.awt.Key.ESCAPE)),
130cdf0e10cSrcweir             new KeyIdentifierInfo("TAB", new Short(com.sun.star.awt.Key.TAB)),
131cdf0e10cSrcweir             new KeyIdentifierInfo("BACKSPACE", new Short(com.sun.star.awt.Key.BACKSPACE)),
132cdf0e10cSrcweir             new KeyIdentifierInfo("SPACE", new Short(com.sun.star.awt.Key.SPACE)),
133cdf0e10cSrcweir             new KeyIdentifierInfo("INSERT", new Short(com.sun.star.awt.Key.INSERT)),
134cdf0e10cSrcweir             new KeyIdentifierInfo("DELETE", new Short(com.sun.star.awt.Key.DELETE)),
135cdf0e10cSrcweir             new KeyIdentifierInfo("ADD", new Short(com.sun.star.awt.Key.ADD)),
136cdf0e10cSrcweir             new KeyIdentifierInfo("SUBTRACT", new Short(com.sun.star.awt.Key.SUBTRACT)),
137cdf0e10cSrcweir             new KeyIdentifierInfo("MULTIPLY", new Short(com.sun.star.awt.Key.MULTIPLY)),
138cdf0e10cSrcweir             new KeyIdentifierInfo("DIVIDE", new Short(com.sun.star.awt.Key.DIVIDE)),
139cdf0e10cSrcweir             new KeyIdentifierInfo("CUT", new Short(com.sun.star.awt.Key.CUT)),
140cdf0e10cSrcweir             new KeyIdentifierInfo("COPY", new Short(com.sun.star.awt.Key.COPY)),
141cdf0e10cSrcweir             new KeyIdentifierInfo("PASTE", new Short(com.sun.star.awt.Key.PASTE)),
142cdf0e10cSrcweir             new KeyIdentifierInfo("UNDO", new Short(com.sun.star.awt.Key.UNDO)),
143cdf0e10cSrcweir             new KeyIdentifierInfo("REPEAT", new Short(com.sun.star.awt.Key.REPEAT))
144cdf0e10cSrcweir         };
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         aIdentifierHashMap = new IdentifierHashMap();
147cdf0e10cSrcweir         aCodeHashMap = new CodeHashMap();
148cdf0e10cSrcweir         for (int i = 0; i<aInfoMap.length; i++)
149cdf0e10cSrcweir         {
150cdf0e10cSrcweir             aIdentifierHashMap.put(aInfoMap[i].sIdentifier, aInfoMap[i].nCode);
151cdf0e10cSrcweir             aCodeHashMap.put(aInfoMap[i].nCode, aInfoMap[i].sIdentifier);
152cdf0e10cSrcweir         }
153cdf0e10cSrcweir     }
154cdf0e10cSrcweir 
mapIdentifier2Code(String sIdentifier)155cdf0e10cSrcweir     public short mapIdentifier2Code(String sIdentifier)
156cdf0e10cSrcweir     {
157cdf0e10cSrcweir         return (aIdentifierHashMap.get(sIdentifier)).shortValue();
158cdf0e10cSrcweir     }
159cdf0e10cSrcweir 
mapCode2Identifier(short nCode)160cdf0e10cSrcweir     public String mapCode2Identifier(short nCode)
161cdf0e10cSrcweir     {
162cdf0e10cSrcweir         return (String)aCodeHashMap.get(new Short(nCode));
163cdf0e10cSrcweir     }
164cdf0e10cSrcweir }
165