KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > events > KeyEvent


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 package org.eclipse.swt.events;
12
13
14 import org.eclipse.swt.widgets.Event;
15
16 /**
17  * Instances of this class are sent as a result of
18  * keys being pressed and released on the keyboard.
19  * <p>
20  * When a key listener is added to a control, the control
21  * will take part in widget traversal. By default, all
22  * traversal keys (such as the tab key and so on) are
23  * delivered to the control. In order for a control to take
24  * part in traversal, it should listen for traversal events.
25  * Otherwise, the user can traverse into a control but not
26  * out. Note that native controls such as table and tree
27  * implement key traversal in the operating system. It is
28  * not necessary to add traversal listeners for these controls,
29  * unless you want to override the default traversal.
30  * </p>
31  * @see KeyListener
32  * @see TraverseListener
33  */

34
35 public class KeyEvent extends TypedEvent {
36     
37     /**
38      * the character represented by the key that was typed.
39      * This is the final character that results after all modifiers have been
40      * applied. For example, when the user types Ctrl+A, the character value
41      * is 0x01. It is important that applications do not attempt to modify the
42      * character value based on a stateMask (such as SWT.CTRL) or the resulting
43      * character will not be correct.
44      */

45     public char character;
46     
47     /**
48      * the key code of the key that was typed,
49      * as defined by the key code constants in class <code>SWT</code>.
50      * When the character field of the event is ambiguous, this field
51      * contains the unicode value of the original character. For example,
52      * typing Ctrl+M or Return both result in the character '\r' but the
53      * keyCode field will also contain '\r' when Return was typed.
54      *
55      * @see org.eclipse.swt.SWT
56      */

57     public int keyCode;
58     
59     /**
60      * the state of the keyboard modifier keys at the time
61      * the event was generated, as defined by the key code
62      * constants in class <code>SWT</code>.
63      *
64      * @see org.eclipse.swt.SWT
65      */

66     public int stateMask;
67     
68     /**
69      * A flag indicating whether the operation should be allowed.
70      * Setting this field to <code>false</code> will cancel the operation.
71      */

72     public boolean doit;
73
74     static final long serialVersionUID = 3256442491011412789L;
75     
76 /**
77  * Constructs a new instance of this class based on the
78  * information in the given untyped event.
79  *
80  * @param e the untyped event containing the information
81  */

82 public KeyEvent(Event e) {
83     super(e);
84     this.character = e.character;
85     this.keyCode = e.keyCode;
86     this.stateMask = e.stateMask;
87     this.doit = e.doit;
88 }
89
90 /**
91  * Returns a string containing a concise, human-readable
92  * description of the receiver.
93  *
94  * @return a string representation of the event
95  */

96 public String JavaDoc toString() {
97     String JavaDoc string = super.toString ();
98     return string.substring (0, string.length() - 1) // remove trailing '}'
99
+ " character='" + ((character == 0) ? "\\0" : "" + character) + "'"
100         + " keyCode=" + keyCode
101         + " stateMask=" + stateMask
102         + " doit=" + doit
103         + "}";
104 }
105 }
106
Popular Tags