1 /******************************************************************************* 2 * Copyright (c) 2000, 2015 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 15 package org.eclipse.ui.keys; 16 17 import java.util.SortedMap; 18 import java.util.TreeMap; 19 import org.eclipse.jface.bindings.keys.IKeyLookup; 20 import org.eclipse.jface.bindings.keys.KeyLookupFactory; 21 import org.eclipse.jface.util.Util; 22 23 /** 24 * <p> 25 * Instances of <code>ModifierKey</code> represent the four keys on the keyboard 26 * recognized by convention as 'modifier keys', those keys typically pressed in 27 * combination with themselves and/or a {@link org.eclipse.ui.keys.NaturalKey}. 28 * </p> 29 * <p> 30 * <code>ModifierKey</code> objects are immutable. Clients are not permitted to 31 * extend this class. 32 * </p> 33 * 34 * @deprecated Please use org.eclipse.jface.bindings.keys.KeyStroke and 35 * org.eclipse.jface.bindings.keys.KeyLookupFactory 36 * @since 3.0 37 * @see org.eclipse.ui.keys.NaturalKey 38 */ 39 @Deprecated 40 public final class ModifierKey extends Key { 41 42 /** 43 * An internal map used to lookup instances of <code>ModifierKey</code> given 44 * the formal string representation of a modifier key. 45 */ 46 static SortedMap<String, ModifierKey> modifierKeysByName = new TreeMap<>(); 47 48 /** 49 * The single static instance of <code>ModifierKey</code> which represents the 50 * 'Alt' key. 51 */ 52 public static final ModifierKey ALT; 53 54 /** 55 * The single static instance of <code>ModifierKey</code> which represents the 56 * 'Command' key. 57 */ 58 public static final ModifierKey COMMAND; 59 60 /** 61 * The single static instance of <code>ModifierKey</code> which represents the 62 * 'Ctrl' key. 63 */ 64 public static final ModifierKey CTRL; 65 66 /** 67 * The name of the 'M1' key. 68 */ 69 private static final String M1_NAME = "M1"; //$NON-NLS-1$ 70 71 /** 72 * The name of the 'M2' key. 73 */ 74 private static final String M2_NAME = "M2"; //$NON-NLS-1$ 75 76 /** 77 * The name of the 'M3' key. 78 */ 79 private static final String M3_NAME = "M3"; //$NON-NLS-1$ 80 81 /** 82 * The name of the 'M4' key. 83 */ 84 private static final String M4_NAME = "M4"; //$NON-NLS-1$ 85 86 /** 87 * The single static instance of <code>ModifierKey</code> which represents the 88 * 'Shift' key. 89 */ 90 public static final ModifierKey SHIFT; 91 92 static { 93 final IKeyLookup lookup = KeyLookupFactory.getDefault(); 94 ALT = new ModifierKey(lookup.getAlt()); 95 COMMAND = new ModifierKey(lookup.getCommand()); 96 CTRL = new ModifierKey(lookup.getCtrl()); 97 SHIFT = new ModifierKey(lookup.getShift()); 98 ModifierKey.ALT.toString()99 modifierKeysByName.put(ModifierKey.ALT.toString(), ModifierKey.ALT); ModifierKey.COMMAND.toString()100 modifierKeysByName.put(ModifierKey.COMMAND.toString(), ModifierKey.COMMAND); ModifierKey.CTRL.toString()101 modifierKeysByName.put(ModifierKey.CTRL.toString(), ModifierKey.CTRL); ModifierKey.SHIFT.toString()102 modifierKeysByName.put(ModifierKey.SHIFT.toString(), ModifierKey.SHIFT); modifierKeysByName.put(M1_NAME, Util.isMac() ? ModifierKey.COMMAND : ModifierKey.CTRL)103 modifierKeysByName.put(M1_NAME, Util.isMac() ? ModifierKey.COMMAND : ModifierKey.CTRL); modifierKeysByName.put(M2_NAME, ModifierKey.SHIFT)104 modifierKeysByName.put(M2_NAME, ModifierKey.SHIFT); modifierKeysByName.put(M3_NAME, ModifierKey.ALT)105 modifierKeysByName.put(M3_NAME, ModifierKey.ALT); modifierKeysByName.put(M4_NAME, Util.isMac() ? ModifierKey.CTRL : ModifierKey.COMMAND)106 modifierKeysByName.put(M4_NAME, Util.isMac() ? ModifierKey.CTRL : ModifierKey.COMMAND); 107 } 108 109 /** 110 * Constructs an instance of <code>ModifierKey</code> given a name. 111 * 112 * @param key The key which this key wraps. 113 */ ModifierKey(final int key)114 private ModifierKey(final int key) { 115 super(key); 116 } 117 } 118