KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > bindings > keys > formatting > FormalKeyFormatter


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.jface.bindings.keys.formatting;
13
14 import org.eclipse.jface.bindings.keys.IKeyLookup;
15 import org.eclipse.jface.bindings.keys.KeyLookupFactory;
16 import org.eclipse.jface.bindings.keys.KeySequence;
17 import org.eclipse.jface.bindings.keys.KeyStroke;
18
19 /**
20  * <p>
21  * Formats the keys in the internal key sequence grammar. This is used for
22  * persistence, and is not really intended for display to the user.
23  * </p>
24  *
25  * @since 3.1
26  */

27 public final class FormalKeyFormatter extends AbstractKeyFormatter {
28
29     /*
30      * (non-Javadoc)
31      *
32      * @see org.eclipse.jface.bindings.keys.KeyFormatter#format(org.eclipse.ui.keys.KeySequence)
33      */

34     public String JavaDoc format(final int key) {
35         final IKeyLookup lookup = KeyLookupFactory.getDefault();
36         return lookup.formalNameLookup(key);
37     }
38
39     /*
40      * (non-Javadoc)
41      *
42      * @see org.eclipse.jface.bindings.keys.AbstractKeyFormatter#getKeyDelimiter()
43      */

44     protected String JavaDoc getKeyDelimiter() {
45         return KeyStroke.KEY_DELIMITER;
46     }
47
48     /*
49      * (non-Javadoc)
50      *
51      * @see org.eclipse.jface.bindings.keys.AbstractKeyFormatter#getKeyStrokeDelimiter()
52      */

53     protected String JavaDoc getKeyStrokeDelimiter() {
54         return KeySequence.KEY_STROKE_DELIMITER;
55     }
56
57     /*
58      * (non-Javadoc)
59      *
60      * @see org.eclipse.jface.bindings.keys.AbstractKeyFormatter#sortModifierKeys(int)
61      */

62     protected int[] sortModifierKeys(final int modifierKeys) {
63         final IKeyLookup lookup = KeyLookupFactory.getDefault();
64         final int[] sortedKeys = new int[4];
65         int index = 0;
66
67         if ((modifierKeys & lookup.getAlt()) != 0) {
68             sortedKeys[index++] = lookup.getAlt();
69         }
70         if ((modifierKeys & lookup.getCommand()) != 0) {
71             sortedKeys[index++] = lookup.getCommand();
72         }
73         if ((modifierKeys & lookup.getCtrl()) != 0) {
74             sortedKeys[index++] = lookup.getCtrl();
75         }
76         if ((modifierKeys & lookup.getShift()) != 0) {
77             sortedKeys[index++] = lookup.getShift();
78         }
79
80         return sortedKeys;
81     }
82 }
83
Popular Tags