001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.keys;
011:
012: import java.util.SortedMap;
013: import java.util.TreeMap;
014:
015: import org.eclipse.jface.bindings.keys.IKeyLookup;
016: import org.eclipse.jface.bindings.keys.KeyLookupFactory;
017: import org.eclipse.swt.SWT;
018:
019: /**
020: * <p>
021: * Instances of <code>ModifierKey</code> represent the four keys on the
022: * keyboard recognized by convention as 'modifier keys', those keys typically
023: * pressed in combination with themselves and/or a
024: * {@link org.eclipse.ui.keys.NaturalKey}.
025: * </p>
026: * <p>
027: * <code>ModifierKey</code> objects are immutable. Clients are not permitted
028: * to extend this class.
029: * </p>
030: *
031: * @deprecated Please use org.eclipse.jface.bindings.keys.KeyStroke and
032: * org.eclipse.jface.bindings.keys.KeyLookupFactory
033: * @since 3.0
034: * @see org.eclipse.ui.keys.NaturalKey
035: */
036: public final class ModifierKey extends Key {
037:
038: /**
039: * An internal map used to lookup instances of <code>ModifierKey</code>
040: * given the formal string representation of a modifier key.
041: */
042: static SortedMap modifierKeysByName = new TreeMap();
043:
044: /**
045: * The single static instance of <code>ModifierKey</code> which represents
046: * the 'Alt' key.
047: */
048: public final static ModifierKey ALT;
049:
050: /**
051: * The single static instance of <code>ModifierKey</code> which represents
052: * the 'Command' key.
053: */
054: public final static ModifierKey COMMAND;
055:
056: /**
057: * The single static instance of <code>ModifierKey</code> which represents
058: * the 'Ctrl' key.
059: */
060: public final static ModifierKey CTRL;
061:
062: /**
063: * The name of the 'M1' key.
064: */
065: private final static String M1_NAME = "M1"; //$NON-NLS-1$
066:
067: /**
068: * The name of the 'M2' key.
069: */
070: private final static String M2_NAME = "M2"; //$NON-NLS-1$
071:
072: /**
073: * The name of the 'M3' key.
074: */
075: private final static String M3_NAME = "M3"; //$NON-NLS-1$
076:
077: /**
078: * The name of the 'M4' key.
079: */
080: private final static String M4_NAME = "M4"; //$NON-NLS-1$
081:
082: /**
083: * The single static instance of <code>ModifierKey</code> which represents
084: * the 'Shift' key.
085: */
086: public final static ModifierKey SHIFT;
087:
088: static {
089: final IKeyLookup lookup = KeyLookupFactory.getDefault();
090: ALT = new ModifierKey(lookup.getAlt());
091: COMMAND = new ModifierKey(lookup.getCommand());
092: CTRL = new ModifierKey(lookup.getCtrl());
093: SHIFT = new ModifierKey(lookup.getShift());
094:
095: modifierKeysByName.put(ModifierKey.ALT.toString(),
096: ModifierKey.ALT);
097: modifierKeysByName.put(ModifierKey.COMMAND.toString(),
098: ModifierKey.COMMAND);
099: modifierKeysByName.put(ModifierKey.CTRL.toString(),
100: ModifierKey.CTRL);
101: modifierKeysByName.put(ModifierKey.SHIFT.toString(),
102: ModifierKey.SHIFT);
103: modifierKeysByName
104: .put(
105: M1_NAME,
106: "carbon".equals(SWT.getPlatform()) ? ModifierKey.COMMAND : ModifierKey.CTRL); //$NON-NLS-1$
107: modifierKeysByName.put(M2_NAME, ModifierKey.SHIFT);
108: modifierKeysByName.put(M3_NAME, ModifierKey.ALT);
109: modifierKeysByName
110: .put(
111: M4_NAME,
112: "carbon".equals(SWT.getPlatform()) ? ModifierKey.CTRL : ModifierKey.COMMAND); //$NON-NLS-1$
113: }
114:
115: /**
116: * Constructs an instance of <code>ModifierKey</code> given a name.
117: *
118: * @param key
119: * The key which this key wraps.
120: */
121: private ModifierKey(final int key) {
122: super(key);
123: }
124: }
|