01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.keys;
11:
12: import java.util.Comparator;
13: import java.util.HashMap;
14: import java.util.ResourceBundle;
15:
16: import org.eclipse.ui.internal.util.Util;
17: import org.eclipse.ui.keys.CharacterKey;
18: import org.eclipse.ui.keys.Key;
19: import org.eclipse.ui.keys.KeySequence;
20: import org.eclipse.ui.keys.ModifierKey;
21: import org.eclipse.ui.keys.SpecialKey;
22:
23: public final class MacKeyFormatter extends AbstractKeyFormatter {
24:
25: private final static class MacModifierKeyComparator extends
26: AbstractModifierKeyComparator {
27:
28: protected int rank(ModifierKey modifierKey) {
29: if (ModifierKey.SHIFT.equals(modifierKey)) {
30: return 0;
31: }
32:
33: if (ModifierKey.CTRL.equals(modifierKey)) {
34: return 1;
35: }
36:
37: if (ModifierKey.ALT.equals(modifierKey)) {
38: return 2;
39: }
40:
41: if (ModifierKey.COMMAND.equals(modifierKey)) {
42: return 3;
43: }
44:
45: return Integer.MAX_VALUE;
46: }
47: }
48:
49: private final static HashMap KEY_LOOKUP = new HashMap();
50:
51: private final static Comparator MODIFIER_KEY_COMPARATOR = new MacModifierKeyComparator();
52:
53: private final static ResourceBundle RESOURCE_BUNDLE = ResourceBundle
54: .getBundle(MacKeyFormatter.class.getName());
55:
56: static {
57: KEY_LOOKUP.put(CharacterKey.BS.toString(), "\u232B"); //$NON-NLS-1$
58: KEY_LOOKUP.put(CharacterKey.CR.toString(), "\u21A9"); //$NON-NLS-1$
59: KEY_LOOKUP.put(CharacterKey.DEL.toString(), "\u2326"); //$NON-NLS-1$
60: KEY_LOOKUP.put(CharacterKey.SPACE.toString(), "\u2423"); //$NON-NLS-1$
61: KEY_LOOKUP.put(ModifierKey.ALT.toString(), "\u2325"); //$NON-NLS-1$
62: KEY_LOOKUP.put(ModifierKey.COMMAND.toString(), "\u2318"); //$NON-NLS-1$
63: KEY_LOOKUP.put(ModifierKey.CTRL.toString(), "\u2303"); //$NON-NLS-1$
64: KEY_LOOKUP.put(ModifierKey.SHIFT.toString(), "\u21E7"); //$NON-NLS-1$
65: KEY_LOOKUP.put(SpecialKey.ARROW_DOWN.toString(), "\u2193"); //$NON-NLS-1$
66: KEY_LOOKUP.put(SpecialKey.ARROW_LEFT.toString(), "\u2190"); //$NON-NLS-1$
67: KEY_LOOKUP.put(SpecialKey.ARROW_RIGHT.toString(), "\u2192"); //$NON-NLS-1$
68: KEY_LOOKUP.put(SpecialKey.ARROW_UP.toString(), "\u2191"); //$NON-NLS-1$
69: KEY_LOOKUP.put(SpecialKey.END.toString(), "\u2198"); //$NON-NLS-1$
70: KEY_LOOKUP.put(SpecialKey.NUMPAD_ENTER.toString(), "\u2324"); //$NON-NLS-1$
71: KEY_LOOKUP.put(SpecialKey.HOME.toString(), "\u2196"); //$NON-NLS-1$
72: KEY_LOOKUP.put(SpecialKey.PAGE_DOWN.toString(), "\u21DF"); //$NON-NLS-1$
73: KEY_LOOKUP.put(SpecialKey.PAGE_UP.toString(), "\u21DE"); //$NON-NLS-1$
74: }
75:
76: public String format(Key key) {
77: String string = (String) KEY_LOOKUP.get(key.toString());
78: return string != null ? string : super .format(key);
79: }
80:
81: protected String getKeyDelimiter() {
82: return Util.translateString(RESOURCE_BUNDLE, KEY_DELIMITER_KEY,
83: Util.ZERO_LENGTH_STRING, false, false);
84: }
85:
86: protected String getKeyStrokeDelimiter() {
87: return Util.translateString(RESOURCE_BUNDLE,
88: KEY_STROKE_DELIMITER_KEY,
89: KeySequence.KEY_STROKE_DELIMITER, false, false);
90: }
91:
92: protected Comparator getModifierKeyComparator() {
93: return MODIFIER_KEY_COMPARATOR;
94: }
95: }
|