KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ResourceBundle JavaDoc;
16
17 import org.eclipse.ui.internal.util.Util;
18 import org.eclipse.ui.keys.Key;
19 import org.eclipse.ui.keys.KeySequence;
20 import org.eclipse.ui.keys.KeyStroke;
21 import org.eclipse.ui.keys.ModifierKey;
22
23 /**
24  * A key formatter providing the Emacs-style accelerators using single letters
25  * to represent the modifier keys.
26  *
27  * @since 3.0
28  */

29 public class EmacsKeyFormatter extends AbstractKeyFormatter {
30
31     /**
32      * A comparator that guarantees that modifier keys will be sorted the same
33      * across different platforms.
34      */

35     private static final Comparator JavaDoc EMACS_MODIFIER_KEY_COMPARATOR = new AlphabeticModifierKeyComparator();
36
37     /**
38      * The resource bundle used by <code>format()</code> to translate formal
39      * string representations by locale.
40      */

41     private final static ResourceBundle JavaDoc RESOURCE_BUNDLE = ResourceBundle
42             .getBundle(EmacsKeyFormatter.class.getName());
43
44     /**
45      * Formats an individual key into a human readable format. This converts
46      * the key into a format similar to Xemacs.
47      *
48      * @param key
49      * The key to format; must not be <code>null</code>.
50      * @return The key formatted as a string; should not be <code>null</code>.
51      */

52     public String JavaDoc format(Key key) {
53         if (key instanceof ModifierKey) {
54             String JavaDoc formattedName = Util.translateString(RESOURCE_BUNDLE, key
55                     .toString(), null, false, false);
56             if (formattedName != null) {
57                 return formattedName;
58             }
59         }
60
61         return super.format(key).toLowerCase();
62     }
63
64     /*
65      * (non-Javadoc)
66      *
67      * @see org.eclipse.ui.keys.AbstractKeyFormatter#getKeyDelimiter()
68      */

69     protected String JavaDoc getKeyDelimiter() {
70         return Util.translateString(RESOURCE_BUNDLE, KEY_DELIMITER_KEY,
71                 KeyStroke.KEY_DELIMITER, false, false);
72     }
73
74     /*
75      * (non-Javadoc)
76      *
77      * @see org.eclipse.ui.keys.AbstractKeyFormatter#getKeyStrokeDelimiter()
78      */

79     protected String JavaDoc getKeyStrokeDelimiter() {
80         return Util.translateString(RESOURCE_BUNDLE, 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 JavaDoc getModifierKeyComparator() {
90         return EMACS_MODIFIER_KEY_COMPARATOR;
91     }
92
93 }
94
Popular Tags