1 11 12 package org.eclipse.jface.bindings.keys.formatting; 13 14 import java.util.ResourceBundle ; 15 16 import org.eclipse.jface.bindings.keys.IKeyLookup; 17 import org.eclipse.jface.bindings.keys.KeyLookupFactory; 18 import org.eclipse.jface.bindings.keys.KeySequence; 19 import org.eclipse.jface.bindings.keys.KeyStroke; 20 import org.eclipse.jface.util.Util; 21 22 30 public final class EmacsKeyFormatter extends AbstractKeyFormatter { 31 32 36 private final static ResourceBundle RESOURCE_BUNDLE = ResourceBundle 37 .getBundle(EmacsKeyFormatter.class.getName()); 38 39 47 public String format(final int key) { 48 final IKeyLookup lookup = KeyLookupFactory.getDefault(); 49 if (lookup.isModifierKey(key)) { 50 String formattedName = Util.translateString(RESOURCE_BUNDLE, lookup 51 .formalNameLookup(key), null); 52 if (formattedName != null) { 53 return formattedName; 54 } 55 } 56 57 return super.format(key).toLowerCase(); 58 } 59 60 65 protected String getKeyDelimiter() { 66 return Util.translateString(RESOURCE_BUNDLE, KEY_DELIMITER_KEY, 67 KeyStroke.KEY_DELIMITER); 68 } 69 70 75 protected String getKeyStrokeDelimiter() { 76 return Util.translateString(RESOURCE_BUNDLE, KEY_STROKE_DELIMITER_KEY, 77 KeySequence.KEY_STROKE_DELIMITER); 78 } 79 80 85 protected int[] sortModifierKeys(int modifierKeys) { 86 final IKeyLookup lookup = KeyLookupFactory.getDefault(); 87 final int[] sortedKeys = new int[4]; 88 int index = 0; 89 90 if ((modifierKeys & lookup.getAlt()) != 0) { 91 sortedKeys[index++] = lookup.getAlt(); 92 } 93 if ((modifierKeys & lookup.getCommand()) != 0) { 94 sortedKeys[index++] = lookup.getCommand(); 95 } 96 if ((modifierKeys & lookup.getCtrl()) != 0) { 97 sortedKeys[index++] = lookup.getCtrl(); 98 } 99 if ((modifierKeys & lookup.getShift()) != 0) { 100 sortedKeys[index++] = lookup.getShift(); 101 } 102 103 return sortedKeys; 104 } 105 } 106 | Popular Tags |