comparison dwt/events/TraverseEvent.d @ 0:380af2bdd8e5

Upload of whole dwt tree
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sat, 09 Aug 2008 17:00:02 +0200
parents
children 649b8e223d5a
comparison
equal deleted inserted replaced
-1:000000000000 0:380af2bdd8e5
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 module dwt.events.TraverseEvent;
12
13 import dwt.dwthelper.utils;
14
15
16 import dwt.widgets.Event;
17
18 /**
19 * Instances of this class are sent as a result of
20 * widget traversal actions.
21 * <p>
22 * The traversal event allows fine control over keyboard traversal
23 * in a control both to implement traversal and override the default
24 * traversal behavior defined by the system. This is achieved using
25 * two fields, <code>detail</code> and <code>doit</code>.
26 * </p><p>
27 * When a control is traversed, a traverse event is sent. The detail
28 * describes the type of traversal and the doit field indicates the default
29 * behavior of the system. For example, when a right arrow key is pressed
30 * in a text control, the detail field is <code>TRAVERSE_ARROW_NEXT</code>
31 * and the doit field is <code>false</code>, indicating that the system
32 * will not traverse to the next tab item and the arrow key will be
33 * delivered to the text control. If the same key is pressed in a radio
34 * button, the doit field will be <code>true</code>, indicating that
35 * traversal is to proceed to the next tab item, possibly another radio
36 * button in the group and that the arrow key is not to be delivered
37 * to the radio button.
38 * </p><p>
39 * How can the traversal event be used to implement traversal?
40 * When a tab key is pressed in a canvas, the detail field will be
41 * <code>TRAVERSE_TAB_NEXT</code> and the doit field will be
42 * <code>false</code>. The default behavior of the system is to
43 * provide no traversal for canvas controls. This means that by
44 * default in a canvas, a key listener will see every key that the
45 * user types, including traversal keys. To understand why this
46 * is so, it is important to understand that only the widget implementor
47 * can decide which traversal is appropriate for the widget. Returning
48 * to the <code>TRAVERSE_TAB_NEXT</code> example, a text widget implemented
49 * by a canvas would typically want to use the tab key to insert a
50 * tab character into the widget. A list widget implementation, on the
51 * other hand, would like the system default traversal behavior. Using
52 * only the doit flag, both implementations are possible. The text widget
53 * implementor sets doit to <code>false</code>, ensuring that the system
54 * will not traverse and that the tab key will be delivered to key listeners.
55 * The list widget implementor sets doit to <code>true</code>, indicating
56 * that the system should perform tab traversal and that the key should not
57 * be delivered to the list widget.
58 * </p><p>
59 * How can the traversal event be used to override system traversal?
60 * When the return key is pressed in a single line text control, the
61 * detail field is <code>TRAVERSE_RETURN</code> and the doit field
62 * is <code>true</code>. This means that the return key will be processed
63 * by the default button, not the text widget. If the text widget has
64 * a default selection listener, it will not run because the return key
65 * will be processed by the default button. Imagine that the text control
66 * is being used as an in-place editor and return is used to dispose the
67 * widget. Setting doit to <code>false</code> will stop the system from
68 * activating the default button but the key will be delivered to the text
69 * control, running the key and selection listeners for the text. How
70 * can <code>TRAVERSE_RETURN</code> be implemented so that the default button
71 * will not be activated and the text widget will not see the return key?
72 * This is achieved by setting doit to <code>true</code>, and the detail
73 * to <code>TRAVERSE_NONE</code>.
74 * </p><p>
75 * Note: A widget implementor will typically implement traversal using
76 * only the doit flag to either enable or disable system traversal.
77 * </p>
78 *
79 * @see TraverseListener
80 */
81
82 public final class TraverseEvent extends KeyEvent {
83
84 /**
85 * The traversal type.
86 * <p><ul>
87 * <li>{@link dwt.DWT#TRAVERSE_NONE}</li>
88 * <li>{@link dwt.DWT#TRAVERSE_ESCAPE}</li>
89 * <li>{@link dwt.DWT#TRAVERSE_RETURN}</li>
90 * <li>{@link dwt.DWT#TRAVERSE_TAB_NEXT}</li>
91 * <li>{@link dwt.DWT#TRAVERSE_TAB_PREVIOUS}</li>
92 * <li>{@link dwt.DWT#TRAVERSE_ARROW_NEXT}</li>
93 * <li>{@link dwt.DWT#TRAVERSE_ARROW_PREVIOUS}</li>
94 * <li>{@link dwt.DWT#TRAVERSE_MNEMONIC}</li>
95 * <li>{@link dwt.DWT#TRAVERSE_PAGE_NEXT}</li>
96 * <li>{@link dwt.DWT#TRAVERSE_PAGE_PREVIOUS}</li>
97 * </ul></p>
98 *
99 * Setting this field will change the type of traversal.
100 * For example, setting the detail to <code>TRAVERSE_NONE</code>
101 * causes no traversal action to be taken.
102 *
103 * When used in conjunction with the <code>doit</code> field, the
104 * traversal detail field can be useful when overriding the default
105 * traversal mechanism for a control. For example, setting the doit
106 * field to <code>false</code> will cancel the operation and allow
107 * the traversal key stroke to be delivered to the control. Setting
108 * the doit field to <code>true</code> indicates that the traversal
109 * described by the detail field is to be performed.
110 */
111 public int detail;
112
113 static final long serialVersionUID = 3257565105301239349L;
114
115 /**
116 * Constructs a new instance of this class based on the
117 * information in the given untyped event.
118 *
119 * @param e the untyped event containing the information
120 */
121 public TraverseEvent(Event e) {
122 super(e);
123 this.detail = e.detail;
124 }
125
126 /**
127 * Returns a string containing a concise, human-readable
128 * description of the receiver.
129 *
130 * @return a string representation of the event
131 */
132 public String toString() {
133 String string = super.toString ();
134 return string.substring (0, string.length() - 1) // remove trailing '}'
135 + " detail=" + detail
136 + "}";
137 }
138 }