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.swt.SWT; 19 import org.eclipse.ui.internal.util.Util; 20 import org.eclipse.ui.keys.CharacterKey; 21 import org.eclipse.ui.keys.Key; 22 import org.eclipse.ui.keys.KeySequence; 23 import org.eclipse.ui.keys.KeyStroke; 24 import org.eclipse.ui.keys.ModifierKey; 25 import org.eclipse.ui.keys.SpecialKey; 26 27 34 public class NativeKeyFormatter extends AbstractKeyFormatter { 35 36 40 private final static String CARBON_KEY_DELIMITER_KEY = "CARBON_KEY_DELIMITER"; 42 45 private final static HashMap CARBON_KEY_LOOK_UP = new HashMap (); 46 47 51 private final static Comparator MODIFIER_KEY_COMPARATOR = new NativeModifierKeyComparator(); 52 53 57 private final static ResourceBundle RESOURCE_BUNDLE; 58 59 63 private final static String WIN32_KEY_STROKE_DELIMITER_KEY = "WIN32_KEY_STROKE_DELIMITER"; 65 static { 66 RESOURCE_BUNDLE = ResourceBundle.getBundle(NativeKeyFormatter.class 67 .getName()); 68 69 CARBON_KEY_LOOK_UP.put(CharacterKey.BS.toString(), "\u232B"); CARBON_KEY_LOOK_UP.put(CharacterKey.CR.toString(), "\u21A9"); CARBON_KEY_LOOK_UP.put(CharacterKey.DEL.toString(), "\u2326"); CARBON_KEY_LOOK_UP.put(CharacterKey.SPACE.toString(), "\u2423"); CARBON_KEY_LOOK_UP.put(ModifierKey.ALT.toString(), "\u2325"); CARBON_KEY_LOOK_UP.put(ModifierKey.COMMAND.toString(), "\u2318"); CARBON_KEY_LOOK_UP.put(ModifierKey.CTRL.toString(), "\u2303"); CARBON_KEY_LOOK_UP.put(ModifierKey.SHIFT.toString(), "\u21E7"); CARBON_KEY_LOOK_UP.put(SpecialKey.ARROW_DOWN.toString(), "\u2193"); CARBON_KEY_LOOK_UP.put(SpecialKey.ARROW_LEFT.toString(), "\u2190"); CARBON_KEY_LOOK_UP.put(SpecialKey.ARROW_RIGHT.toString(), "\u2192"); CARBON_KEY_LOOK_UP.put(SpecialKey.ARROW_UP.toString(), "\u2191"); CARBON_KEY_LOOK_UP.put(SpecialKey.END.toString(), "\u2198"); CARBON_KEY_LOOK_UP.put(SpecialKey.NUMPAD_ENTER.toString(), "\u2324"); CARBON_KEY_LOOK_UP.put(SpecialKey.HOME.toString(), "\u2196"); CARBON_KEY_LOOK_UP.put(SpecialKey.PAGE_DOWN.toString(), "\u21DF"); CARBON_KEY_LOOK_UP.put(SpecialKey.PAGE_UP.toString(), "\u21DE"); } 87 88 97 public String format(Key key) { 98 String name = key.toString(); 99 100 if ("carbon".equals(SWT.getPlatform())) { String formattedName = (String ) CARBON_KEY_LOOK_UP.get(name); 103 if (formattedName != null) { 104 return formattedName; 105 } 106 } 107 108 return super.format(key); 109 } 110 111 116 protected String getKeyDelimiter() { 117 if ("carbon".equals(SWT.getPlatform())) { return Util.translateString(RESOURCE_BUNDLE, 120 CARBON_KEY_DELIMITER_KEY, Util.ZERO_LENGTH_STRING, false, 121 false); 122 } else { 123 return Util.translateString(RESOURCE_BUNDLE, KEY_DELIMITER_KEY, 124 KeyStroke.KEY_DELIMITER, false, false); 125 } 126 } 127 128 133 protected String getKeyStrokeDelimiter() { 134 if ("win32".equals(SWT.getPlatform())) { return Util.translateString(RESOURCE_BUNDLE, 137 WIN32_KEY_STROKE_DELIMITER_KEY, 138 KeySequence.KEY_STROKE_DELIMITER, false, false); 139 } else { 140 return Util.translateString(RESOURCE_BUNDLE, 141 KEY_STROKE_DELIMITER_KEY, KeySequence.KEY_STROKE_DELIMITER, 142 false, false); 143 } 144 } 145 146 151 protected Comparator getModifierKeyComparator() { 152 return MODIFIER_KEY_COMPARATOR; 153 } 154 } 155 | Popular Tags |