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