KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > keys > ModifierKey


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.keys;
13
14 import java.util.SortedMap JavaDoc;
15 import java.util.TreeMap JavaDoc;
16
17 import org.eclipse.jface.bindings.keys.IKeyLookup;
18 import org.eclipse.jface.bindings.keys.KeyLookupFactory;
19 import org.eclipse.swt.SWT;
20
21 /**
22  * <p>
23  * Instances of <code>ModifierKey</code> represent the four keys on the
24  * keyboard recognized by convention as 'modifier keys', those keys typically
25  * pressed in combination with themselves and/or a
26  * {@link org.eclipse.ui.keys.NaturalKey}.
27  * </p>
28  * <p>
29  * <code>ModifierKey</code> objects are immutable. Clients are not permitted
30  * to 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  * @see org.eclipse.ui.keys.NaturalKey
37  */

38 public final class ModifierKey extends Key {
39
40     /**
41      * An internal map used to lookup instances of <code>ModifierKey</code>
42      * given the formal string representation of a modifier key.
43      */

44     static SortedMap JavaDoc modifierKeysByName = new TreeMap JavaDoc();
45
46     /**
47      * The single static instance of <code>ModifierKey</code> which represents
48      * the 'Alt' key.
49      */

50     public final static ModifierKey ALT;
51
52     /**
53      * The single static instance of <code>ModifierKey</code> which represents
54      * the 'Command' key.
55      */

56     public final static ModifierKey COMMAND;
57
58     /**
59      * The single static instance of <code>ModifierKey</code> which represents
60      * the 'Ctrl' key.
61      */

62     public final static ModifierKey CTRL;
63
64     /**
65      * The name of the 'M1' key.
66      */

67     private final static String JavaDoc M1_NAME = "M1"; //$NON-NLS-1$
68

69     /**
70      * The name of the 'M2' key.
71      */

72     private final static String JavaDoc M2_NAME = "M2"; //$NON-NLS-1$
73

74     /**
75      * The name of the 'M3' key.
76      */

77     private final static String JavaDoc M3_NAME = "M3"; //$NON-NLS-1$
78

79     /**
80      * The name of the 'M4' key.
81      */

82     private final static String JavaDoc M4_NAME = "M4"; //$NON-NLS-1$
83

84     /**
85      * The single static instance of <code>ModifierKey</code> which represents
86      * the 'Shift' key.
87      */

88     public final static ModifierKey SHIFT;
89
90     static {
91         final IKeyLookup lookup = KeyLookupFactory.getDefault();
92         ALT = new ModifierKey(lookup.getAlt());
93         COMMAND = new ModifierKey(lookup.getCommand());
94         CTRL = new ModifierKey(lookup.getCtrl());
95         SHIFT = new ModifierKey(lookup.getShift());
96         
97         modifierKeysByName.put(ModifierKey.ALT.toString(), ModifierKey.ALT);
98         modifierKeysByName.put(ModifierKey.COMMAND.toString(),
99                 ModifierKey.COMMAND);
100         modifierKeysByName.put(ModifierKey.CTRL.toString(), ModifierKey.CTRL);
101         modifierKeysByName.put(ModifierKey.SHIFT.toString(), ModifierKey.SHIFT);
102         modifierKeysByName
103                 .put(
104                         M1_NAME,
105                         "carbon".equals(SWT.getPlatform()) ? ModifierKey.COMMAND : ModifierKey.CTRL); //$NON-NLS-1$
106
modifierKeysByName.put(M2_NAME, ModifierKey.SHIFT);
107         modifierKeysByName.put(M3_NAME, ModifierKey.ALT);
108         modifierKeysByName
109                 .put(
110                         M4_NAME,
111                         "carbon".equals(SWT.getPlatform()) ? ModifierKey.CTRL : ModifierKey.COMMAND); //$NON-NLS-1$
112
}
113
114     /**
115      * Constructs an instance of <code>ModifierKey</code> given a name.
116      *
117      * @param key
118      * The key which this key wraps.
119      */

120     private ModifierKey(final int key) {
121         super(key);
122     }
123 }
124
Popular Tags