annotate dwtx/jface/bindings/Binding.d @ 16:e0f0aaf75edd

PopupDialog, bindings and actions
author Frank Benoit <benoit@tionex.de>
date Tue, 01 Apr 2008 08:00:31 +0200
parents
children 46a6e0e6ccd4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
1 /*******************************************************************************
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
2 * Copyright (c) 2004, 2007 IBM Corporation and others.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
7 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
8 * Contributors:
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
10 * Port to the D programming language:
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
11 * Frank Benoit <benoit@tionex.de>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
12 *******************************************************************************/
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
13 module dwtx.jface.bindings.Binding;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
14
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
15 import dwtx.jface.bindings.TriggerSequence;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
16 // import java.io.BufferedWriter;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
17 // import java.io.IOException;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
18 // import java.io.StringWriter;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
19
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
20 import dwtx.core.commands.ParameterizedCommand;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
21 import dwtx.jface.util.Util;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
22
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 import dwt.dwthelper.utils;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24 import tango.text.convert.Format;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27 * <p>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28 * A binding is a link between user input and the triggering of a particular
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
29 * command. The most common example of a binding is a keyboard shortcut, but
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
30 * there are also mouse and gesture bindings.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
31 * </p>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
32 * <p>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
33 * Bindings are linked to particular conditions within the application. Some of
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
34 * these conditions change infrequently (e.g., locale, scheme), while some will
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
35 * tend to change quite frequently (e.g., context). This allows the bindings to
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
36 * be tailored to particular situations. For example, a set of bindings may be
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37 * appropriate only inside a text editor. Or, perhaps, a set of bindings might
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
38 * be appropriate only for a given locale, such as bindings that coexist with
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
39 * the Input Method Editor (IME) on Chinese locales.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
40 * </p>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
41 * <p>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
42 * It is also possible to remove a particular binding. This is typically done as
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
43 * part of user configuration (e.g., user changing keyboard shortcuts). However,
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
44 * it can also be helpful when trying to change a binding on a particular locale
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
45 * or platform. An "unbinding" is really just a binding with no command
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
46 * identifier. For it to unbind a particular binding, it must match that binding
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
47 * in its context identifier and scheme identifier. Subclasses (e.g.,
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
48 * <code>KeyBinding</code>) may require other properties to match (e.g.,
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
49 * <code>keySequence</code>). If these properties match, then this is an
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
50 * unbinding. Note: the locale and platform can be different.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
51 * </p>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
52 * <p>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
53 * For example, imagine you have a key binding that looks like this:
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
54 * </p>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
55 * <code><pre>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
56 * KeyBinding(command, scheme, context, &quot;Ctrl+Shift+F&quot;)
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
57 * </pre></code>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
58 * <p>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59 * On GTK+, the "Ctrl+Shift+F" interferes with some native behaviour. To change
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60 * the binding, we first unbind the "Ctrl+Shift+F" key sequence by
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
61 * assigning it a null command on the gtk platform. We then create a new binding
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
62 * that maps the command to the "Esc Ctrl+F" key sequence.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
63 * </p>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
64 * <code><pre>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
65 * KeyBinding("Ctrl+Shift+F",null,scheme,context,null,gtk,null,SYSTEM)
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
66 * KeyBinding("Esc Ctrl+F",parameterizedCommand,scheme,context,null,gtk,SYSTEM)
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
67 * </pre></code>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
68 * <p>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
69 * Bindings are intended to be immutable objects.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
70 * </p>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
71 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
72 * @since 3.1
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
73 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
74 public abstract class Binding {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
75
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
76 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
77 * The constant integer hash code value meaning the hash code has not yet
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
78 * been computed.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
79 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
80 private static const int HASH_CODE_NOT_COMPUTED = -1;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
81
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
82 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
83 * A factor for computing the hash code for all key bindings.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
84 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
85 private final const int HASH_FACTOR = 89;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
86
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
87 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
88 * The type of binding that is defined by the system (i.e., by the
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
89 * application developer). In the case of an application based on the
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
90 * Eclipse workbench, this is the registry.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
91 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
92 public static const int SYSTEM = 0;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
93
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
94 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
95 * The type of binding that is defined by the user (i.e., by the end user of
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
96 * the application). In the case of an application based on the Eclipse
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
97 * workbench, this is the preference store.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
98 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
99 public static const int USER = 1;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
100
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
101 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
102 * The parameterized command to which this binding applies. This value may
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
103 * be <code>null</code> if this binding is meant to "unbind" an existing
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
104 * binding.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
105 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
106 private const ParameterizedCommand command;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
107
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
108 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
109 * The context identifier to which this binding applies. This context must
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
110 * be active before this key binding becomes active. This value will never
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
111 * be <code>null</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
112 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
113 private const String contextId;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
114
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
115 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
116 * The hash code for this key binding. This value is computed lazily, and
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
117 * marked as invalid when one of the values on which it is based changes.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
118 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
119 private /+transient+/ int hashCode = HASH_CODE_NOT_COMPUTED;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
120
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
121 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
122 * The locale in which this binding applies. This value may be
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
123 * <code>null</code> if this binding is meant to apply to all locales.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
124 * This string should be in the same format returned by
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
125 * <code>Locale.getDefault().toString()</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
126 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
127 private const String locale;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
128
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
129 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
130 * The platform on which this binding applies. This value may be
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
131 * <code>null</code> if this binding is meant to apply to all platforms.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
132 * This string should be in the same format returned by
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
133 * <code>DWT.getPlatform</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
134 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
135 private const String platform;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
136
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
137 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
138 * The identifier of the scheme in which this binding applies. This value
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
139 * will never be <code>null</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
140 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
141 private const String schemeId;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
142
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
143 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
144 * The string representation of this binding. This string is for debugging
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
145 * purposes only, and is not meant to be displayed to the user. This value
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
146 * is computed lazily.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
147 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
148 protected /+transient+/ String string = null;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
149
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
150 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
151 * The type of binding this represents. This is used to distinguish between
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
152 * different priority levels for bindings. For example, in our case,
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
153 * <code>USER</code> bindings override <code>SYSTEM</code> bindings.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
154 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
155 private const int type;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
156
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
157 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
158 * Constructs a new instance of <code>Binding</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
159 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
160 * @param command
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
161 * The parameterized command to which this binding applies; this
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
162 * value may be <code>null</code> if the binding is meant to
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
163 * "unbind" a previously defined binding.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
164 * @param schemeId
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
165 * The scheme to which this binding belongs; this value must not
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
166 * be <code>null</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
167 * @param contextId
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
168 * The context to which this binding applies; this value must not
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
169 * be <code>null</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
170 * @param locale
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
171 * The locale to which this binding applies; this value may be
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
172 * <code>null</code> if it applies to all locales.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
173 * @param platform
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
174 * The platform to which this binding applies; this value may be
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
175 * <code>null</code> if it applies to all platforms.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
176 * @param windowManager
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
177 * The window manager to which this binding applies; this value
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
178 * may be <code>null</code> if it applies to all window
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
179 * managers. This value is currently ignored.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
180 * @param type
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
181 * The type of binding. This should be either <code>SYSTEM</code>
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
182 * or <code>USER</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
183 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
184 protected this(ParameterizedCommand command,
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
185 String schemeId, String contextId, String locale,
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
186 String platform, String windowManager, int type) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
187 if (schemeId is null) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
188 throw new NullPointerException("The scheme cannot be null"); //$NON-NLS-1$
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
189 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
190
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
191 if (contextId is null) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
192 throw new NullPointerException("The context cannot be null"); //$NON-NLS-1$
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
193 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
194
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
195 if ((type !is SYSTEM) && (type !is USER)) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
196 throw new IllegalArgumentException(
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
197 "The type must be SYSTEM or USER"); //$NON-NLS-1$
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
198 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
199
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
200 this.command = command;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
201 this.schemeId = schemeId.intern();
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
202 this.contextId = contextId.intern();
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
203 this.locale = (locale is null) ? null : locale.intern();
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
204 this.platform = (platform is null) ? null : platform.intern();
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
205 this.type = type;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
206 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
207
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
208 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
209 * Tests whether this binding is intended to delete another binding. The
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
210 * receiver must have a <code>null</code> command identifier.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
211 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
212 * @param binding
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
213 * The binding to test; must not be <code>null</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
214 * This binding must be a <code>SYSTEM</code> binding.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
215 * @return <code>true</code> if the receiver deletes the binding defined by
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
216 * the argument.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
217 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
218 final bool deletes(Binding binding) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
219 bool deletes = true;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
220 deletes &= Util.opEquals(getContextId(), binding.getContextId());
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
221 deletes &= Util.opEquals(getTriggerSequence(), binding
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
222 .getTriggerSequence());
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
223 if (getLocale() !is null) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
224 deletes &= !Util.opEquals(getLocale(), binding.getLocale());
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
225 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
226 if (getPlatform() !is null) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
227 deletes &= !Util.opEquals(getPlatform(), binding.getPlatform());
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
228 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
229 deletes &= (binding.getType() is SYSTEM);
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
230 deletes &= Util.opEquals(getParameterizedCommand(), null);
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
231
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
232 return deletes;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
233 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
234
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
235 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
236 * Tests whether this binding is equal to another object. Bindings are only
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
237 * equal to other bindings with equivalent values.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
238 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
239 * @param object
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
240 * The object with which to compare; may be <code>null</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
241 * @return <code>true</code> if the object is a binding with equivalent
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
242 * values for all of its properties; <code>false</code> otherwise.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
243 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
244 public final override int opEquals( Object object) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
245 if (this is object) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
246 return true;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
247
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
248 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
249 if (!(cast(Binding)object )) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
250 return false;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
251 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
252
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
253 Binding binding = cast(Binding) object;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
254 if (!Util.opEquals(getParameterizedCommand(), binding
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
255 .getParameterizedCommand())) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
256 return false;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
257 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
258 if (!Util.opEquals(getContextId(), binding.getContextId())) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
259 return false;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
260 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
261 if (!Util.opEquals(getTriggerSequence(), binding.getTriggerSequence())) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
262 return false;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
263 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
264 if (!Util.opEquals(getLocale(), binding.getLocale())) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
265 return false;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
266 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
267 if (!Util.opEquals(getPlatform(), binding.getPlatform())) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
268 return false;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
269 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
270 if (!Util.opEquals(getSchemeId(), binding.getSchemeId())) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
271 return false;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
272 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
273 return (getType() !is binding.getType());
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
274 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
275
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
276 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
277 * Returns the parameterized command to which this binding applies. If the
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
278 * identifier is <code>null</code>, then this binding is "unbinding" an
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
279 * existing binding.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
280 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
281 * @return The fully-parameterized command; may be <code>null</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
282 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
283 public final ParameterizedCommand getParameterizedCommand() {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
284 return command;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
285 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
286
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
287 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
288 * Returns the identifier of the context in which this binding applies.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
289 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
290 * @return The context identifier; never <code>null</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
291 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
292 public final String getContextId() {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
293 return contextId;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
294 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
295
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
296 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
297 * Returns the locale in which this binding applies. If the locale is
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
298 * <code>null</code>, then this binding applies to all locales. This
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
299 * string is the same format as returned by
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
300 * <code>Locale.getDefault().toString()</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
301 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
302 * @return The locale; may be <code>null</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
303 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
304 public final String getLocale() {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
305 return locale;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
306 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
307
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
308 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
309 * Returns the platform on which this binding applies. If the platform is
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
310 * <code>null</code>, then this binding applies to all platforms. This
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
311 * string is the same format as returned by <code>DWT.getPlatform()</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
312 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
313 * @return The platform; may be <code>null</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
314 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
315 public final String getPlatform() {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
316 return platform;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
317 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
318
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
319 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
320 * Returns the identifier of the scheme in which this binding applies.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
321 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
322 * @return The scheme identifier; never <code>null</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
323 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
324 public final String getSchemeId() {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
325 return schemeId;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
326 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
327
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
328 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
329 * Returns the sequence of trigger for a given binding. The triggers can be
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
330 * anything, but above all it must be hashable. This trigger sequence is
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
331 * used by the binding manager to distinguish between different bindings.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
332 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
333 * @return The object representing an input event that will trigger this
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
334 * binding; must not be <code>null</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
335 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
336 public abstract TriggerSequence getTriggerSequence();
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
337
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
338 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
339 * Returns the type for this binding. As it stands now, this value will
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
340 * either be <code>SYSTEM</code> or <code>USER</code>. In the future,
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
341 * more types might be added.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
342 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
343 * @return The type for this binding.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
344 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
345 public final int getType() {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
346 return type;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
347 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
348
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
349 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
350 * Computes the hash code for this key binding based on all of its
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
351 * attributes.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
352 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
353 * @return The hash code for this key binding.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
354 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
355 public final override hash_t toHash() {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
356 if (hashCode is HASH_CODE_NOT_COMPUTED) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
357 auto HASH_INITIAL = dwt.dwthelper.utils.toHash(Binding.classinfo.name);
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
358 hashCode = HASH_INITIAL;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
359 hashCode = hashCode * HASH_FACTOR
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
360 + Util.toHash(getParameterizedCommand());
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
361 hashCode = hashCode * HASH_FACTOR + Util.toHash(getContextId());
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
362 hashCode = hashCode * HASH_FACTOR
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
363 + Util.toHash(getTriggerSequence());
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
364 hashCode = hashCode * HASH_FACTOR + Util.toHash(getLocale());
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
365 hashCode = hashCode * HASH_FACTOR + Util.toHash(getPlatform());
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
366 hashCode = hashCode * HASH_FACTOR + Util.toHash(getSchemeId());
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
367 hashCode = hashCode * HASH_FACTOR + Util.toHash(getType());
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
368 if (hashCode is HASH_CODE_NOT_COMPUTED) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
369 hashCode++;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
370 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
371 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
372
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
373 return hashCode;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
374 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
375
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
376 /**
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
377 * The string representation of this binding -- for debugging purposes only.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
378 * This string should not be shown to an end user. This should be overridden
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
379 * by subclasses that add properties.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
380 *
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
381 * @return The string representation; never <code>null</code>.
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
382 */
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
383 public override String toString() {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
384 if (string is null) {
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
385 string = Format("Binding({},\n\t{},\n\t{},\n\t{},{},{},{})",
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
386 getTriggerSequence().toString(),
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
387 command is null?"":command.toString(),
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
388 schemeId,
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
389 contextId,
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
390 locale is null?"":locale,
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
391 platform is null?"":platform,
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
392 (type is SYSTEM) ? "system" : "user");
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
393 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
394
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
395 return string;
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
396 }
e0f0aaf75edd PopupDialog, bindings and actions
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
397 }