KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > keys > Key


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.keys;
13
14 import org.eclipse.jface.bindings.keys.IKeyLookup;
15 import org.eclipse.jface.bindings.keys.KeyLookupFactory;
16 import org.eclipse.ui.internal.util.Util;
17
18 /**
19  * <p>
20  * <code>Key</code> is the abstract base class for all objects representing
21  * keys on the keyboard.
22  * </p>
23  * <p>
24  * All <code>Key</code> objects have a formal string representation, called
25  * the 'name' of the key, available via the <code>toString()</code> method.
26  * </p>
27  * <p>
28  * All <code>Key</code> objects, via the <code>format()</code> method,
29  * provide a version of their formal string representation translated by
30  * platform and locale, suitable for display to a user.
31  * </p>
32  * <p>
33  * <code>Key</code> objects are immutable. Clients are not permitted to extend
34  * this class.
35  * </p>
36  *
37  * @deprecated Please use org.eclipse.jface.bindings.keys.KeyStroke and
38  * org.eclipse.jface.bindings.keys.KeyLookupFactory
39  * @since 3.0
40  */

41 public abstract class Key implements Comparable JavaDoc {
42
43     /**
44      * The key from which this key was constructed. This value is defined by
45      * <code>KeyLookupFactory.getDefault()</code>.
46      */

47     protected final int key;
48
49     /**
50      * Constructs an instance of <code>Key</code> given its formal string
51      * representation.
52      *
53      * @param key
54      * the integer representation of this key, as defined by
55      * <code>KeyLookupFactory.getDefault()</code>.
56      */

57     Key(final int key) {
58         this.key = key;
59     }
60
61     /**
62      * @see java.lang.Comparable#compareTo(java.lang.Object)
63      */

64     public final int compareTo(final Object JavaDoc object) {
65         return Util.compare(key, ((Key) object).key);
66     }
67
68     /**
69      * @see java.lang.Object#equals(java.lang.Object)
70      */

71     public final boolean equals(final Object JavaDoc object) {
72         if (!(object instanceof Key)) {
73             return false;
74         }
75
76         return key == ((Key) object).key;
77     }
78
79     /**
80      * @see java.lang.Object#hashCode()
81      */

82     public final int hashCode() {
83         return Util.hashCode(key);
84     }
85
86     /**
87      * Returns the formal string representation for this key.
88      *
89      * @return The formal string representation for this key. Guaranteed not to
90      * be <code>null</code>.
91      * @see java.lang.Object#toString()
92      */

93     public final String JavaDoc toString() {
94         final IKeyLookup lookup = KeyLookupFactory.getDefault();
95         return lookup.formalNameLookup(key);
96     }
97 }
98
Popular Tags