1 11 12 package org.eclipse.ui.internal.keys; 13 14 import java.util.Comparator ; 15 import java.util.HashMap ; 16 import java.util.ResourceBundle ; 17 18 import org.eclipse.ui.internal.util.Util; 19 import org.eclipse.ui.keys.CharacterKey; 20 import org.eclipse.ui.keys.Key; 21 import org.eclipse.ui.keys.KeySequence; 22 import org.eclipse.ui.keys.ModifierKey; 23 import org.eclipse.ui.keys.SpecialKey; 24 25 public final class MacKeyFormatter extends AbstractKeyFormatter { 26 27 private final static class MacModifierKeyComparator extends 28 AbstractModifierKeyComparator { 29 30 protected int rank(ModifierKey modifierKey) { 31 if (ModifierKey.SHIFT.equals(modifierKey)) { 32 return 0; 33 } 34 35 if (ModifierKey.CTRL.equals(modifierKey)) { 36 return 1; 37 } 38 39 if (ModifierKey.ALT.equals(modifierKey)) { 40 return 2; 41 } 42 43 if (ModifierKey.COMMAND.equals(modifierKey)) { 44 return 3; 45 } 46 47 return Integer.MAX_VALUE; 48 } 49 } 50 51 private final static HashMap KEY_LOOKUP = new HashMap (); 52 53 private final static Comparator MODIFIER_KEY_COMPARATOR = new MacModifierKeyComparator(); 54 55 private final static ResourceBundle RESOURCE_BUNDLE = ResourceBundle 56 .getBundle(MacKeyFormatter.class.getName()); 57 58 static { 59 KEY_LOOKUP 60 .put(CharacterKey.BS.toString(), "\u232B"); KEY_LOOKUP 62 .put(CharacterKey.CR.toString(), "\u21A9"); KEY_LOOKUP.put(CharacterKey.DEL.toString(), "\u2326"); KEY_LOOKUP.put(CharacterKey.SPACE.toString(), "\u2423"); KEY_LOOKUP 66 .put(ModifierKey.ALT.toString(), "\u2325"); KEY_LOOKUP.put(ModifierKey.COMMAND.toString(), "\u2318"); KEY_LOOKUP.put(ModifierKey.CTRL.toString(), "\u2303"); KEY_LOOKUP.put(ModifierKey.SHIFT.toString(), "\u21E7"); KEY_LOOKUP.put(SpecialKey.ARROW_DOWN.toString(), "\u2193"); KEY_LOOKUP.put(SpecialKey.ARROW_LEFT.toString(), "\u2190"); KEY_LOOKUP.put(SpecialKey.ARROW_RIGHT.toString(), "\u2192"); KEY_LOOKUP.put(SpecialKey.ARROW_UP.toString(), "\u2191"); KEY_LOOKUP.put(SpecialKey.END.toString(), "\u2198"); KEY_LOOKUP.put(SpecialKey.NUMPAD_ENTER.toString(), "\u2324"); KEY_LOOKUP 77 .put(SpecialKey.HOME.toString(), "\u2196"); KEY_LOOKUP.put(SpecialKey.PAGE_DOWN.toString(), "\u21DF"); KEY_LOOKUP.put(SpecialKey.PAGE_UP.toString(), "\u21DE"); } 81 82 public String format(Key key) { 83 String string = (String ) KEY_LOOKUP.get(key.toString()); 84 return string != null ? string : super.format(key); 85 } 86 87 protected String getKeyDelimiter() { 88 return Util.translateString(RESOURCE_BUNDLE, KEY_DELIMITER_KEY, 89 Util.ZERO_LENGTH_STRING, false, false); 90 } 91 92 protected String getKeyStrokeDelimiter() { 93 return Util.translateString(RESOURCE_BUNDLE, KEY_STROKE_DELIMITER_KEY, 94 KeySequence.KEY_STROKE_DELIMITER, false, false); 95 } 96 97 protected Comparator getModifierKeyComparator() { 98 return MODIFIER_KEY_COMPARATOR; 99 } 100 } 101 | Popular Tags |