01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 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.ResourceBundle;
14:
15: import org.eclipse.ui.internal.util.Util;
16: import org.eclipse.ui.keys.Key;
17: import org.eclipse.ui.keys.KeySequence;
18: import org.eclipse.ui.keys.KeyStroke;
19: import org.eclipse.ui.keys.ModifierKey;
20:
21: /**
22: * A key formatter providing the Emacs-style accelerators using single letters
23: * to represent the modifier keys.
24: *
25: * @since 3.0
26: */
27: public class EmacsKeyFormatter extends AbstractKeyFormatter {
28:
29: /**
30: * A comparator that guarantees that modifier keys will be sorted the same
31: * across different platforms.
32: */
33: private static final Comparator EMACS_MODIFIER_KEY_COMPARATOR = new AlphabeticModifierKeyComparator();
34:
35: /**
36: * The resource bundle used by <code>format()</code> to translate formal
37: * string representations by locale.
38: */
39: private final static ResourceBundle RESOURCE_BUNDLE = ResourceBundle
40: .getBundle(EmacsKeyFormatter.class.getName());
41:
42: /**
43: * Formats an individual key into a human readable format. This converts
44: * the key into a format similar to Xemacs.
45: *
46: * @param key
47: * The key to format; must not be <code>null</code>.
48: * @return The key formatted as a string; should not be <code>null</code>.
49: */
50: public String format(Key key) {
51: if (key instanceof ModifierKey) {
52: String formattedName = Util
53: .translateString(RESOURCE_BUNDLE, key.toString(),
54: null, false, false);
55: if (formattedName != null) {
56: return formattedName;
57: }
58: }
59:
60: return super .format(key).toLowerCase();
61: }
62:
63: /*
64: * (non-Javadoc)
65: *
66: * @see org.eclipse.ui.keys.AbstractKeyFormatter#getKeyDelimiter()
67: */
68: protected String getKeyDelimiter() {
69: return Util.translateString(RESOURCE_BUNDLE, KEY_DELIMITER_KEY,
70: KeyStroke.KEY_DELIMITER, false, false);
71: }
72:
73: /*
74: * (non-Javadoc)
75: *
76: * @see org.eclipse.ui.keys.AbstractKeyFormatter#getKeyStrokeDelimiter()
77: */
78: protected String getKeyStrokeDelimiter() {
79: return Util.translateString(RESOURCE_BUNDLE,
80: KEY_STROKE_DELIMITER_KEY,
81: KeySequence.KEY_STROKE_DELIMITER, false, false);
82: }
83:
84: /*
85: * (non-Javadoc)
86: *
87: * @see org.eclipse.ui.keys.AbstractKeyFormatter#getModifierKeyComparator()
88: */
89: protected Comparator getModifierKeyComparator() {
90: return EMACS_MODIFIER_KEY_COMPARATOR;
91: }
92:
93: }
|