1 11 12 package org.eclipse.jface.bindings.keys.formatting; 13 14 import java.util.HashMap ; 15 import java.util.ResourceBundle ; 16 17 import org.eclipse.jface.bindings.keys.IKeyLookup; 18 import org.eclipse.jface.bindings.keys.KeyLookupFactory; 19 import org.eclipse.jface.bindings.keys.KeySequence; 20 import org.eclipse.jface.bindings.keys.KeyStroke; 21 import org.eclipse.jface.util.Util; 22 import org.eclipse.swt.SWT; 23 24 33 public final class NativeKeyFormatter extends AbstractKeyFormatter { 34 35 39 private final static String CARBON_KEY_DELIMITER_KEY = "CARBON_KEY_DELIMITER"; 41 44 private final static HashMap CARBON_KEY_LOOK_UP = new HashMap (); 45 46 50 private final static ResourceBundle RESOURCE_BUNDLE; 51 52 56 private final static String WIN32_KEY_STROKE_DELIMITER_KEY = "WIN32_KEY_STROKE_DELIMITER"; 58 static { 59 RESOURCE_BUNDLE = ResourceBundle.getBundle(NativeKeyFormatter.class 60 .getName()); 61 62 final String carbonBackspace = "\u232B"; CARBON_KEY_LOOK_UP.put(IKeyLookup.BS_NAME, carbonBackspace); 64 CARBON_KEY_LOOK_UP.put(IKeyLookup.BACKSPACE_NAME, carbonBackspace); 65 CARBON_KEY_LOOK_UP 66 .put(IKeyLookup.CR_NAME, "\u21A9"); final String carbonDelete = "\u2326"; CARBON_KEY_LOOK_UP.put(IKeyLookup.DEL_NAME, carbonDelete); 69 CARBON_KEY_LOOK_UP.put(IKeyLookup.DELETE_NAME, carbonDelete); 70 CARBON_KEY_LOOK_UP.put(IKeyLookup.SPACE_NAME, "\u2423"); CARBON_KEY_LOOK_UP.put(IKeyLookup.ALT_NAME, "\u2325"); CARBON_KEY_LOOK_UP.put(IKeyLookup.COMMAND_NAME, "\u2318"); CARBON_KEY_LOOK_UP.put(IKeyLookup.CTRL_NAME, "\u2303"); CARBON_KEY_LOOK_UP.put(IKeyLookup.SHIFT_NAME, "\u21E7"); CARBON_KEY_LOOK_UP.put(IKeyLookup.ARROW_DOWN_NAME, "\u2193"); CARBON_KEY_LOOK_UP.put(IKeyLookup.ARROW_LEFT_NAME, "\u2190"); CARBON_KEY_LOOK_UP.put(IKeyLookup.ARROW_RIGHT_NAME, "\u2192"); CARBON_KEY_LOOK_UP.put(IKeyLookup.ARROW_UP_NAME, "\u2191"); CARBON_KEY_LOOK_UP.put(IKeyLookup.END_NAME, "\u2198"); CARBON_KEY_LOOK_UP.put(IKeyLookup.NUMPAD_ENTER_NAME, "\u2324"); CARBON_KEY_LOOK_UP.put(IKeyLookup.HOME_NAME, "\u2196"); CARBON_KEY_LOOK_UP.put(IKeyLookup.PAGE_DOWN_NAME, "\u21DF"); CARBON_KEY_LOOK_UP.put(IKeyLookup.PAGE_UP_NAME, "\u21DE"); } 85 86 95 public final String format(final int key) { 96 final IKeyLookup lookup = KeyLookupFactory.getDefault(); 97 final String name = lookup.formalNameLookup(key); 98 99 if ("carbon".equals(SWT.getPlatform())) { String formattedName = (String ) CARBON_KEY_LOOK_UP.get(name); 102 if (formattedName != null) { 103 return formattedName; 104 } 105 } 106 107 return super.format(key); 108 } 109 110 115 protected String getKeyDelimiter() { 116 if ("carbon".equals(SWT.getPlatform())) { return Util.translateString(RESOURCE_BUNDLE, 119 CARBON_KEY_DELIMITER_KEY, Util.ZERO_LENGTH_STRING); 120 } 121 122 return Util.translateString(RESOURCE_BUNDLE, KEY_DELIMITER_KEY, 123 KeyStroke.KEY_DELIMITER); 124 } 125 126 131 protected String getKeyStrokeDelimiter() { 132 if ("win32".equals(SWT.getPlatform())) { return Util.translateString(RESOURCE_BUNDLE, 135 WIN32_KEY_STROKE_DELIMITER_KEY, 136 KeySequence.KEY_STROKE_DELIMITER); 137 } 138 139 return Util.translateString(RESOURCE_BUNDLE, KEY_STROKE_DELIMITER_KEY, 140 KeySequence.KEY_STROKE_DELIMITER); 141 } 142 143 148 protected int[] sortModifierKeys(final int modifierKeys) { 149 final IKeyLookup lookup = KeyLookupFactory.getDefault(); 150 final String platform = SWT.getPlatform(); 151 final int[] sortedKeys = new int[4]; 152 int index = 0; 153 154 if ("win32".equals(platform) || "wpf".equals(platform)) { if ((modifierKeys & lookup.getCtrl()) != 0) { 156 sortedKeys[index++] = lookup.getCtrl(); 157 } 158 if ((modifierKeys & lookup.getAlt()) != 0) { 159 sortedKeys[index++] = lookup.getAlt(); 160 } 161 if ((modifierKeys & lookup.getShift()) != 0) { 162 sortedKeys[index++] = lookup.getShift(); 163 } 164 165 } else if ("gtk".equals(platform) || "motif".equals(platform)) { if ((modifierKeys & lookup.getShift()) != 0) { 167 sortedKeys[index++] = lookup.getShift(); 168 } 169 if ((modifierKeys & lookup.getCtrl()) != 0) { 170 sortedKeys[index++] = lookup.getCtrl(); 171 } 172 if ((modifierKeys & lookup.getAlt()) != 0) { 173 sortedKeys[index++] = lookup.getAlt(); 174 } 175 176 } else if ("carbon".equals(platform)) { if ((modifierKeys & lookup.getShift()) != 0) { 178 sortedKeys[index++] = lookup.getShift(); 179 } 180 if ((modifierKeys & lookup.getCtrl()) != 0) { 181 sortedKeys[index++] = lookup.getCtrl(); 182 } 183 if ((modifierKeys & lookup.getAlt()) != 0) { 184 sortedKeys[index++] = lookup.getAlt(); 185 } 186 if ((modifierKeys & lookup.getCommand()) != 0) { 187 sortedKeys[index++] = lookup.getCommand(); 188 } 189 190 } 191 192 return sortedKeys; 193 } 194 } 195 | Popular Tags |