1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package complex.accelerators;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import java.util.HashMap;
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir class KeyIdentifierInfo
33*cdf0e10cSrcweir {
34*cdf0e10cSrcweir     protected String sIdentifier;
35*cdf0e10cSrcweir     protected Short nCode;
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir     KeyIdentifierInfo(String sID, Short nC)
38*cdf0e10cSrcweir     {
39*cdf0e10cSrcweir         sIdentifier = sID;
40*cdf0e10cSrcweir         nCode = nC;
41*cdf0e10cSrcweir     }
42*cdf0e10cSrcweir }
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir class IdentifierHashMap extends HashMap
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir     public void put(String sIdentifier, Short nCode)
47*cdf0e10cSrcweir     {
48*cdf0e10cSrcweir         super.put(sIdentifier, nCode);
49*cdf0e10cSrcweir     }
50*cdf0e10cSrcweir     public Short get(String sIdentifier)
51*cdf0e10cSrcweir     {
52*cdf0e10cSrcweir         return (Short)super.get(sIdentifier);
53*cdf0e10cSrcweir     }
54*cdf0e10cSrcweir }
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir class CodeHashMap extends HashMap
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir     public void put(Short nCode, String sIdentifier)
59*cdf0e10cSrcweir     {
60*cdf0e10cSrcweir         super.put(nCode, sIdentifier);
61*cdf0e10cSrcweir     }
62*cdf0e10cSrcweir     public String get(Short nCode)
63*cdf0e10cSrcweir     {
64*cdf0e10cSrcweir         return (String)super.get(nCode);
65*cdf0e10cSrcweir     }
66*cdf0e10cSrcweir }
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir public class KeyMapping
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir     private IdentifierHashMap aIdentifierHashMap;
71*cdf0e10cSrcweir     private CodeHashMap aCodeHashMap;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir     public KeyMapping()
74*cdf0e10cSrcweir     {
75*cdf0e10cSrcweir         KeyIdentifierInfo[] aInfoMap = {
76*cdf0e10cSrcweir             new KeyIdentifierInfo("0", new Short(com.sun.star.awt.Key.NUM0)),
77*cdf0e10cSrcweir             new KeyIdentifierInfo("1", new Short(com.sun.star.awt.Key.NUM1)),
78*cdf0e10cSrcweir             new KeyIdentifierInfo("2", new Short(com.sun.star.awt.Key.NUM2)),
79*cdf0e10cSrcweir             new KeyIdentifierInfo("3", new Short(com.sun.star.awt.Key.NUM3)),
80*cdf0e10cSrcweir             new KeyIdentifierInfo("4", new Short(com.sun.star.awt.Key.NUM4)),
81*cdf0e10cSrcweir             new KeyIdentifierInfo("5", new Short(com.sun.star.awt.Key.NUM5)),
82*cdf0e10cSrcweir             new KeyIdentifierInfo("6", new Short(com.sun.star.awt.Key.NUM6)),
83*cdf0e10cSrcweir             new KeyIdentifierInfo("7", new Short(com.sun.star.awt.Key.NUM7)),
84*cdf0e10cSrcweir             new KeyIdentifierInfo("8", new Short(com.sun.star.awt.Key.NUM8)),
85*cdf0e10cSrcweir             new KeyIdentifierInfo("9", new Short(com.sun.star.awt.Key.NUM9)),
86*cdf0e10cSrcweir             new KeyIdentifierInfo("A", new Short(com.sun.star.awt.Key.A)),
87*cdf0e10cSrcweir             new KeyIdentifierInfo("B", new Short(com.sun.star.awt.Key.B)),
88*cdf0e10cSrcweir             new KeyIdentifierInfo("C", new Short(com.sun.star.awt.Key.C)),
89*cdf0e10cSrcweir             new KeyIdentifierInfo("D", new Short(com.sun.star.awt.Key.D)),
90*cdf0e10cSrcweir             new KeyIdentifierInfo("E", new Short(com.sun.star.awt.Key.E)),
91*cdf0e10cSrcweir             new KeyIdentifierInfo("F", new Short(com.sun.star.awt.Key.F)),
92*cdf0e10cSrcweir             new KeyIdentifierInfo("G", new Short(com.sun.star.awt.Key.G)),
93*cdf0e10cSrcweir             new KeyIdentifierInfo("H", new Short(com.sun.star.awt.Key.H)),
94*cdf0e10cSrcweir             new KeyIdentifierInfo("I", new Short(com.sun.star.awt.Key.I)),
95*cdf0e10cSrcweir             new KeyIdentifierInfo("J", new Short(com.sun.star.awt.Key.J)),
96*cdf0e10cSrcweir             new KeyIdentifierInfo("K", new Short(com.sun.star.awt.Key.K)),
97*cdf0e10cSrcweir             new KeyIdentifierInfo("L", new Short(com.sun.star.awt.Key.L)),
98*cdf0e10cSrcweir             new KeyIdentifierInfo("M", new Short(com.sun.star.awt.Key.M)),
99*cdf0e10cSrcweir             new KeyIdentifierInfo("N", new Short(com.sun.star.awt.Key.N)),
100*cdf0e10cSrcweir             new KeyIdentifierInfo("O", new Short(com.sun.star.awt.Key.O)),
101*cdf0e10cSrcweir             new KeyIdentifierInfo("P", new Short(com.sun.star.awt.Key.P)),
102*cdf0e10cSrcweir             new KeyIdentifierInfo("Q", new Short(com.sun.star.awt.Key.Q)),
103*cdf0e10cSrcweir             new KeyIdentifierInfo("R", new Short(com.sun.star.awt.Key.R)),
104*cdf0e10cSrcweir             new KeyIdentifierInfo("S", new Short(com.sun.star.awt.Key.S)),
105*cdf0e10cSrcweir             new KeyIdentifierInfo("T", new Short(com.sun.star.awt.Key.T)),
106*cdf0e10cSrcweir             new KeyIdentifierInfo("U", new Short(com.sun.star.awt.Key.U)),
107*cdf0e10cSrcweir             new KeyIdentifierInfo("V", new Short(com.sun.star.awt.Key.V)),
108*cdf0e10cSrcweir             new KeyIdentifierInfo("W", new Short(com.sun.star.awt.Key.W)),
109*cdf0e10cSrcweir             new KeyIdentifierInfo("X", new Short(com.sun.star.awt.Key.X)),
110*cdf0e10cSrcweir             new KeyIdentifierInfo("Y", new Short(com.sun.star.awt.Key.Y)),
111*cdf0e10cSrcweir             new KeyIdentifierInfo("Z", new Short(com.sun.star.awt.Key.Z)),
112*cdf0e10cSrcweir             new KeyIdentifierInfo("F1", new Short(com.sun.star.awt.Key.F1)),
113*cdf0e10cSrcweir             new KeyIdentifierInfo("F2", new Short(com.sun.star.awt.Key.F2)),
114*cdf0e10cSrcweir             new KeyIdentifierInfo("F3", new Short(com.sun.star.awt.Key.F3)),
115*cdf0e10cSrcweir             new KeyIdentifierInfo("F4", new Short(com.sun.star.awt.Key.F4)),
116*cdf0e10cSrcweir             new KeyIdentifierInfo("F5", new Short(com.sun.star.awt.Key.F5)),
117*cdf0e10cSrcweir             new KeyIdentifierInfo("F6", new Short(com.sun.star.awt.Key.F6)),
118*cdf0e10cSrcweir             new KeyIdentifierInfo("F7", new Short(com.sun.star.awt.Key.F7)),
119*cdf0e10cSrcweir             new KeyIdentifierInfo("F8", new Short(com.sun.star.awt.Key.F8)),
120*cdf0e10cSrcweir             new KeyIdentifierInfo("F9", new Short(com.sun.star.awt.Key.F9)),
121*cdf0e10cSrcweir             new KeyIdentifierInfo("F10", new Short(com.sun.star.awt.Key.F10)),
122*cdf0e10cSrcweir             new KeyIdentifierInfo("F11", new Short(com.sun.star.awt.Key.F11)),
123*cdf0e10cSrcweir             new KeyIdentifierInfo("F12", new Short(com.sun.star.awt.Key.F12)),
124*cdf0e10cSrcweir             new KeyIdentifierInfo("DOWN", new Short(com.sun.star.awt.Key.DOWN)),
125*cdf0e10cSrcweir             new KeyIdentifierInfo("UP", new Short(com.sun.star.awt.Key.UP)),
126*cdf0e10cSrcweir             new KeyIdentifierInfo("LEFT", new Short(com.sun.star.awt.Key.LEFT)),
127*cdf0e10cSrcweir             new KeyIdentifierInfo("RIGHT", new Short(com.sun.star.awt.Key.RIGHT)),
128*cdf0e10cSrcweir             new KeyIdentifierInfo("HOME", new Short(com.sun.star.awt.Key.HOME)),
129*cdf0e10cSrcweir             new KeyIdentifierInfo("END", new Short(com.sun.star.awt.Key.END)),
130*cdf0e10cSrcweir             new KeyIdentifierInfo("PAGEUP", new Short(com.sun.star.awt.Key.PAGEUP)),
131*cdf0e10cSrcweir             new KeyIdentifierInfo("PAGEDOWN", new Short(com.sun.star.awt.Key.PAGEDOWN)),
132*cdf0e10cSrcweir             new KeyIdentifierInfo("RETURN", new Short(com.sun.star.awt.Key.RETURN)),
133*cdf0e10cSrcweir             new KeyIdentifierInfo("ESCAPE", new Short(com.sun.star.awt.Key.ESCAPE)),
134*cdf0e10cSrcweir             new KeyIdentifierInfo("TAB", new Short(com.sun.star.awt.Key.TAB)),
135*cdf0e10cSrcweir             new KeyIdentifierInfo("BACKSPACE", new Short(com.sun.star.awt.Key.BACKSPACE)),
136*cdf0e10cSrcweir             new KeyIdentifierInfo("SPACE", new Short(com.sun.star.awt.Key.SPACE)),
137*cdf0e10cSrcweir             new KeyIdentifierInfo("INSERT", new Short(com.sun.star.awt.Key.INSERT)),
138*cdf0e10cSrcweir             new KeyIdentifierInfo("DELETE", new Short(com.sun.star.awt.Key.DELETE)),
139*cdf0e10cSrcweir             new KeyIdentifierInfo("ADD", new Short(com.sun.star.awt.Key.ADD)),
140*cdf0e10cSrcweir             new KeyIdentifierInfo("SUBTRACT", new Short(com.sun.star.awt.Key.SUBTRACT)),
141*cdf0e10cSrcweir             new KeyIdentifierInfo("MULTIPLY", new Short(com.sun.star.awt.Key.MULTIPLY)),
142*cdf0e10cSrcweir             new KeyIdentifierInfo("DIVIDE", new Short(com.sun.star.awt.Key.DIVIDE)),
143*cdf0e10cSrcweir             new KeyIdentifierInfo("CUT", new Short(com.sun.star.awt.Key.CUT)),
144*cdf0e10cSrcweir             new KeyIdentifierInfo("COPY", new Short(com.sun.star.awt.Key.COPY)),
145*cdf0e10cSrcweir             new KeyIdentifierInfo("PASTE", new Short(com.sun.star.awt.Key.PASTE)),
146*cdf0e10cSrcweir             new KeyIdentifierInfo("UNDO", new Short(com.sun.star.awt.Key.UNDO)),
147*cdf0e10cSrcweir             new KeyIdentifierInfo("REPEAT", new Short(com.sun.star.awt.Key.REPEAT))
148*cdf0e10cSrcweir         };
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir         aIdentifierHashMap = new IdentifierHashMap();
151*cdf0e10cSrcweir         aCodeHashMap = new CodeHashMap();
152*cdf0e10cSrcweir         for (int i = 0; i<aInfoMap.length; i++)
153*cdf0e10cSrcweir         {
154*cdf0e10cSrcweir             aIdentifierHashMap.put(aInfoMap[i].sIdentifier, aInfoMap[i].nCode);
155*cdf0e10cSrcweir             aCodeHashMap.put(aInfoMap[i].nCode, aInfoMap[i].sIdentifier);
156*cdf0e10cSrcweir         }
157*cdf0e10cSrcweir     }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir     public short mapIdentifier2Code(String sIdentifier)
160*cdf0e10cSrcweir     {
161*cdf0e10cSrcweir         return (aIdentifierHashMap.get(sIdentifier)).shortValue();
162*cdf0e10cSrcweir     }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir     public String mapCode2Identifier(short nCode)
165*cdf0e10cSrcweir     {
166*cdf0e10cSrcweir         return (String)aCodeHashMap.get(new Short(nCode));
167*cdf0e10cSrcweir     }
168*cdf0e10cSrcweir }
169