KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > bindings > keys > KeyBinding


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 package org.eclipse.jface.bindings.keys;
12
13 import org.eclipse.core.commands.ParameterizedCommand;
14 import org.eclipse.jface.bindings.Binding;
15 import org.eclipse.jface.bindings.TriggerSequence;
16
17 /**
18  * <p>
19  * A keyboard shortcut. This is a binding between some keyboard input and the
20  * triggering of a command. This object is immutable.
21  * </p>
22  *
23  * @since 3.1
24  */

25 public final class KeyBinding extends Binding {
26
27     /**
28      * The key sequence which triggers this binding. This sequence is never
29      * <code>null</code>.
30      */

31     private final KeySequence keySequence;
32
33     /**
34      * Constructs a new instance of <code>KeyBinding</code>.
35      *
36      * @param keySequence
37      * The key sequence which should trigger this binding. This value
38      * must not be <code>null</code>. It also must be a complete,
39      * non-empty key sequence.
40      * @param command
41      * The parameterized command to which this binding applies; this
42      * value may be <code>null</code> if the binding is meant to
43      * "unbind" a previously defined binding.
44      * @param schemeId
45      * The scheme to which this binding belongs; this value must not
46      * be <code>null</code>.
47      * @param contextId
48      * The context to which this binding applies; this value must not
49      * be <code>null</code>.
50      * @param locale
51      * The locale to which this binding applies; this value may be
52      * <code>null</code> if it applies to all locales.
53      * @param platform
54      * The platform to which this binding applies; this value may be
55      * <code>null</code> if it applies to all platforms.
56      * @param windowManager
57      * The window manager to which this binding applies; this value
58      * may be <code>null</code> if it applies to all window
59      * managers. This value is currently ignored.
60      * @param type
61      * The type of binding. This should be either <code>SYSTEM</code>
62      * or <code>USER</code>.
63      */

64     public KeyBinding(final KeySequence keySequence,
65             final ParameterizedCommand command, final String JavaDoc schemeId,
66             final String JavaDoc contextId, final String JavaDoc locale, final String JavaDoc platform,
67             final String JavaDoc windowManager, final int type) {
68         super(command, schemeId, contextId, locale, platform, windowManager,
69                 type);
70
71         if (keySequence == null) {
72             throw new NullPointerException JavaDoc("The key sequence cannot be null"); //$NON-NLS-1$
73
}
74
75         if (!keySequence.isComplete()) {
76             throw new IllegalArgumentException JavaDoc(
77                     "Cannot bind to an incomplete key sequence"); //$NON-NLS-1$
78
}
79
80         if (keySequence.isEmpty()) {
81             throw new IllegalArgumentException JavaDoc(
82                     "Cannot bind to an empty key sequence"); //$NON-NLS-1$
83
}
84
85         this.keySequence = keySequence;
86     }
87
88     /**
89      * Returns the key sequence which triggers this binding. The key sequence
90      * will not be <code>null</code>, empty or incomplete.
91      *
92      * @return The key sequence; never <code>null</code>.
93      */

94     public final KeySequence getKeySequence() {
95         return keySequence;
96     }
97
98     /*
99      * (non-Javadoc)
100      *
101      * @see org.eclipse.jface.bindings.Binding#getTriggerSequence()
102      */

103     public TriggerSequence getTriggerSequence() {
104         return getKeySequence();
105     }
106 }
107
Popular Tags