Statistics
| Revision:

root / branches / v2_0_0_prep / frameworks / _fwAndami / src / org / gvsig / andami / ui / mdiFrame / KeyMapping.java @ 29593

History | View | Annotate | Download (4.54 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.andami.ui.mdiFrame;
42

    
43
import java.awt.event.KeyEvent;
44
import java.util.HashMap;
45

    
46
import org.gvsig.andami.messages.Messages;
47

    
48

    
49

    
50
/**
51
 * Clase que sirve para obtener los codigos de las teclas de la manera que las
52
 * requieren los JMenu a partir de un caracter que representa dicha tecla
53
 *
54
 * @author Fernando Gonz?lez Cort?s
55
 */
56
public class KeyMapping {
57
    /** Asocia caracteres con KeyEvents */
58
    private static HashMap key = new HashMap();
59

    
60
    static {
61
        key.put(new Character('a'), new Integer(KeyEvent.VK_A));
62
        key.put(new Character('b'), new Integer(KeyEvent.VK_B));
63
        key.put(new Character('c'), new Integer(KeyEvent.VK_C));
64
        key.put(new Character('d'), new Integer(KeyEvent.VK_D));
65
        key.put(new Character('e'), new Integer(KeyEvent.VK_E));
66
        key.put(new Character('f'), new Integer(KeyEvent.VK_F));
67
        key.put(new Character('g'), new Integer(KeyEvent.VK_G));
68
        key.put(new Character('h'), new Integer(KeyEvent.VK_H));
69
        key.put(new Character('i'), new Integer(KeyEvent.VK_I));
70
        key.put(new Character('j'), new Integer(KeyEvent.VK_J));
71
        key.put(new Character('k'), new Integer(KeyEvent.VK_K));
72
        key.put(new Character('l'), new Integer(KeyEvent.VK_L));
73
        key.put(new Character('m'), new Integer(KeyEvent.VK_M));
74
        key.put(new Character('n'), new Integer(KeyEvent.VK_N));
75
        key.put(new Character('o'), new Integer(KeyEvent.VK_O));
76
        key.put(new Character('p'), new Integer(KeyEvent.VK_P));
77
        key.put(new Character('q'), new Integer(KeyEvent.VK_Q));
78
        key.put(new Character('r'), new Integer(KeyEvent.VK_R));
79
        key.put(new Character('s'), new Integer(KeyEvent.VK_S));
80
        key.put(new Character('t'), new Integer(KeyEvent.VK_T));
81
        key.put(new Character('u'), new Integer(KeyEvent.VK_U));
82
        key.put(new Character('v'), new Integer(KeyEvent.VK_V));
83
        key.put(new Character('w'), new Integer(KeyEvent.VK_W));
84
        key.put(new Character('x'), new Integer(KeyEvent.VK_X));
85
        key.put(new Character('y'), new Integer(KeyEvent.VK_Y));
86
        key.put(new Character('z'), new Integer(KeyEvent.VK_Z));
87
        key.put(new Character('0'), new Integer(KeyEvent.VK_0));
88
        key.put(new Character('1'), new Integer(KeyEvent.VK_1));
89
        key.put(new Character('2'), new Integer(KeyEvent.VK_2));
90
        key.put(new Character('3'), new Integer(KeyEvent.VK_3));
91
        key.put(new Character('4'), new Integer(KeyEvent.VK_4));
92
        key.put(new Character('5'), new Integer(KeyEvent.VK_5));
93
        key.put(new Character('6'), new Integer(KeyEvent.VK_6));
94
        key.put(new Character('7'), new Integer(KeyEvent.VK_7));
95
        key.put(new Character('8'), new Integer(KeyEvent.VK_8));
96
        key.put(new Character('9'), new Integer(KeyEvent.VK_9));
97
    }
98

    
99
    /**
100
     * Obtiene dado un caracter el entero correspondiente al codigo que tiene
101
     * la tecla que produce dicho caracter
102
     *
103
     * @param a caracter
104
     *
105
     * @return Codigo de la tecla asociada
106
     *
107
     * @throws RuntimeException Si el caracter no tiene una tecla asociada
108
     */
109
    public static int getKey(char a) {
110
        Integer ret = (Integer) key.get(new Character(a));
111

    
112
        if (ret == null) {
113
            throw new RuntimeException(Messages.getString(
114
                    "KeyMapping.Caracter_no_valido") + a); //$NON-NLS-1$
115
        }
116

    
117
        return ret.intValue();
118
    }
119
}