KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > keys > MacKeyFormatter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.keys;
13
14 import java.util.Comparator JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.ResourceBundle JavaDoc;
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 JavaDoc KEY_LOOKUP = new HashMap JavaDoc();
52
53     private final static Comparator JavaDoc MODIFIER_KEY_COMPARATOR = new MacModifierKeyComparator();
54
55     private final static ResourceBundle JavaDoc RESOURCE_BUNDLE = ResourceBundle
56             .getBundle(MacKeyFormatter.class.getName());
57
58     static {
59         KEY_LOOKUP
60                 .put(CharacterKey.BS.toString(), "\u232B"); //$NON-NLS-1$
61
KEY_LOOKUP
62                 .put(CharacterKey.CR.toString(), "\u21A9"); //$NON-NLS-1$
63
KEY_LOOKUP.put(CharacterKey.DEL.toString(), "\u2326"); //$NON-NLS-1$
64
KEY_LOOKUP.put(CharacterKey.SPACE.toString(), "\u2423"); //$NON-NLS-1$
65
KEY_LOOKUP
66                 .put(ModifierKey.ALT.toString(), "\u2325"); //$NON-NLS-1$
67
KEY_LOOKUP.put(ModifierKey.COMMAND.toString(), "\u2318"); //$NON-NLS-1$
68
KEY_LOOKUP.put(ModifierKey.CTRL.toString(), "\u2303"); //$NON-NLS-1$
69
KEY_LOOKUP.put(ModifierKey.SHIFT.toString(), "\u21E7"); //$NON-NLS-1$
70
KEY_LOOKUP.put(SpecialKey.ARROW_DOWN.toString(), "\u2193"); //$NON-NLS-1$
71
KEY_LOOKUP.put(SpecialKey.ARROW_LEFT.toString(), "\u2190"); //$NON-NLS-1$
72
KEY_LOOKUP.put(SpecialKey.ARROW_RIGHT.toString(), "\u2192"); //$NON-NLS-1$
73
KEY_LOOKUP.put(SpecialKey.ARROW_UP.toString(), "\u2191"); //$NON-NLS-1$
74
KEY_LOOKUP.put(SpecialKey.END.toString(), "\u2198"); //$NON-NLS-1$
75
KEY_LOOKUP.put(SpecialKey.NUMPAD_ENTER.toString(), "\u2324"); //$NON-NLS-1$
76
KEY_LOOKUP
77                 .put(SpecialKey.HOME.toString(), "\u2196"); //$NON-NLS-1$
78
KEY_LOOKUP.put(SpecialKey.PAGE_DOWN.toString(), "\u21DF"); //$NON-NLS-1$
79
KEY_LOOKUP.put(SpecialKey.PAGE_UP.toString(), "\u21DE"); //$NON-NLS-1$
80
}
81
82     public String JavaDoc format(Key key) {
83         String JavaDoc string = (String JavaDoc) KEY_LOOKUP.get(key.toString());
84         return string != null ? string : super.format(key);
85     }
86
87     protected String JavaDoc getKeyDelimiter() {
88         return Util.translateString(RESOURCE_BUNDLE, KEY_DELIMITER_KEY,
89                 Util.ZERO_LENGTH_STRING, false, false);
90     }
91
92     protected String JavaDoc getKeyStrokeDelimiter() {
93         return Util.translateString(RESOURCE_BUNDLE, KEY_STROKE_DELIMITER_KEY,
94                 KeySequence.KEY_STROKE_DELIMITER, false, false);
95     }
96
97     protected Comparator JavaDoc getModifierKeyComparator() {
98         return MODIFIER_KEY_COMPARATOR;
99     }
100 }
101
Popular Tags