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.keys;
11:
12: import org.eclipse.jface.bindings.keys.IKeyLookup;
13: import org.eclipse.jface.bindings.keys.KeyLookupFactory;
14: import org.eclipse.ui.internal.util.Util;
15:
16: /**
17: * <p>
18: * <code>Key</code> is the abstract base class for all objects representing
19: * keys on the keyboard.
20: * </p>
21: * <p>
22: * All <code>Key</code> objects have a formal string representation, called
23: * the 'name' of the key, available via the <code>toString()</code> method.
24: * </p>
25: * <p>
26: * All <code>Key</code> objects, via the <code>format()</code> method,
27: * provide a version of their formal string representation translated by
28: * platform and locale, suitable for display to a user.
29: * </p>
30: * <p>
31: * <code>Key</code> objects are immutable. Clients are not permitted to extend
32: * this class.
33: * </p>
34: *
35: * @deprecated Please use org.eclipse.jface.bindings.keys.KeyStroke and
36: * org.eclipse.jface.bindings.keys.KeyLookupFactory
37: * @since 3.0
38: */
39: public abstract class Key implements Comparable {
40:
41: /**
42: * The key from which this key was constructed. This value is defined by
43: * <code>KeyLookupFactory.getDefault()</code>.
44: */
45: protected final int key;
46:
47: /**
48: * Constructs an instance of <code>Key</code> given its formal string
49: * representation.
50: *
51: * @param key
52: * the integer representation of this key, as defined by
53: * <code>KeyLookupFactory.getDefault()</code>.
54: */
55: Key(final int key) {
56: this .key = key;
57: }
58:
59: /**
60: * @see java.lang.Comparable#compareTo(java.lang.Object)
61: */
62: public final int compareTo(final Object object) {
63: return Util.compare(key, ((Key) object).key);
64: }
65:
66: /**
67: * @see java.lang.Object#equals(java.lang.Object)
68: */
69: public final boolean equals(final Object object) {
70: if (!(object instanceof Key)) {
71: return false;
72: }
73:
74: return key == ((Key) object).key;
75: }
76:
77: /**
78: * @see java.lang.Object#hashCode()
79: */
80: public final int hashCode() {
81: return Util.hashCode(key);
82: }
83:
84: /**
85: * Returns the formal string representation for this key.
86: *
87: * @return The formal string representation for this key. Guaranteed not to
88: * be <code>null</code>.
89: * @see java.lang.Object#toString()
90: */
91: public final String toString() {
92: final IKeyLookup lookup = KeyLookupFactory.getDefault();
93: return lookup.formalNameLookup(key);
94: }
95: }
|