KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > widgets > Event


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.widgets;
12
13
14 import org.eclipse.swt.graphics.*;
15
16 /**
17  * Instances of this class provide a description of a particular
18  * event which occurred within SWT. The SWT <em>untyped listener</em>
19  * API uses these instances for all event dispatching.
20  * <p>
21  * Note: For a given event, only the fields which are appropriate
22  * will be filled in. The contents of the fields which are not used
23  * by the event are unspecified.
24  * </p>
25  *
26  * @see Listener
27  * @see org.eclipse.swt.events.TypedEvent
28  */

29
30 public class Event {
31     
32     /**
33      * the display where the event occurred
34      *
35      * @since 2.0
36      */

37     public Display display;
38         
39     /**
40      * the widget that issued the event
41      */

42     public Widget widget;
43     
44     /**
45      * the type of event, as defined by the event type constants
46      * in class <code>SWT</code>
47      *
48      * @see org.eclipse.swt.SWT
49      */

50     public int type;
51     
52     /**
53      * the event specific detail field, as defined by the detail constants
54      * in class <code>SWT</code>
55      *
56      * @see org.eclipse.swt.SWT
57      */

58     public int detail;
59     
60     /**
61      * the item that the event occurred in (can be null)
62      */

63     public Widget item;
64     
65     /**
66      * the index of the item where the event occurred
67      *
68      * @since 3.2
69      */

70     public int index;
71     
72     /**
73      * the graphics context to use when painting
74      * that is configured to use the colors, font and
75      * damaged region of the control. It is valid
76      * only during the paint and must not be disposed
77      */

78     public GC gc;
79     
80     /**
81      * depending on the event type, the x offset of the bounding
82      * rectangle of the region that requires painting or the
83      * widget-relative, x coordinate of the pointer at the
84      * time the mouse button was pressed or released
85      */

86     public int x;
87     
88     /**
89      * depending on the event type, the y offset of the bounding
90      * rectangle of the region that requires painting or the
91      * widget-relative, y coordinate of the pointer at the
92      * time the mouse button was pressed or released
93      */

94     public int y;
95     
96     /**
97      * the width of the bounding rectangle of the
98      * region that requires painting
99      */

100     public int width;
101     
102     /**
103      * the height of the bounding rectangle of the
104      * region that requires painting
105      */

106     public int height;
107
108     /**
109      * depending on the event type, the number of following
110      * paint events which are pending which may always be zero
111      * on some platforms or the number of lines or pages to
112      * scroll using the mouse wheel
113      */

114     public int count;
115     
116     /**
117      * the time that the event occurred.
118      *
119      * NOTE: This field is an unsigned integer and should
120      * be AND'ed with 0xFFFFFFFFL so that it can be treated
121      * as a signed long.
122      */

123     public int time;
124     
125     /**
126      * the button that was pressed or released; 1 for the
127      * first button, 2 for the second button, and 3 for the
128      * third button, etc.
129      */

130     public int button;
131     
132     /**
133      * depending on the event, the character represented by the key
134      * that was typed. This is the final character that results
135      * after all modifiers have been applied. For example, when the
136      * user types Ctrl+A, the character value is 0x01 (ASCII SOH).
137      * It is important that applications do not attempt to modify the
138      * character value based on a stateMask (such as SWT.CTRL) or the
139      * resulting character will not be correct.
140      */

141     public char character;
142     
143     /**
144      * depending on the event, the key code of the key that was typed,
145      * as defined by the key code constants in class <code>SWT</code>.
146      * When the character field of the event is ambiguous, this field
147      * contains the unaffected value of the original character. For
148      * example, typing Ctrl+M or Enter both result in the character '\r'
149      * but the keyCode field will also contain '\r' when Enter was typed
150      * and 'm' when Ctrl+M was typed.
151      *
152      * @see org.eclipse.swt.SWT
153      */

154     public int keyCode;
155     
156     /**
157      * depending on the event, the state of the keyboard modifier
158      * keys and mouse masks at the time the event was generated.
159      *
160      * @see org.eclipse.swt.SWT
161      */

162     public int stateMask;
163     
164     /**
165      * depending on the event, the range of text being modified.
166      * Setting these fields has no effect.
167      */

168     public int start, end;
169     
170     /**
171      * depending on the event, the new text that will be inserted.
172      * Setting this field will change the text that is about to
173      * be inserted or deleted.
174      */

175     public String JavaDoc text;
176
177     /**
178      * depending on the event, a flag indicating whether the operation
179      * should be allowed. Setting this field to false will cancel the
180      * operation.
181      */

182     public boolean doit = true;
183     
184     /**
185      * a field for application use
186      */

187     public Object JavaDoc data;
188     
189 /**
190  * Gets the bounds.
191  *
192  * @return a rectangle that is the bounds.
193  */

194 public Rectangle getBounds () {
195     return new Rectangle (x, y, width, height);
196 }
197
198 /**
199  * Sets the bounds.
200  *
201  * @param rect the new rectangle
202  */

203 public void setBounds (Rectangle rect) {
204     this.x = rect.x;
205     this.y = rect.y;
206     this.width = rect.width;
207     this.height = rect.height;
208 }
209
210 /**
211  * Returns a string containing a concise, human-readable
212  * description of the receiver.
213  *
214  * @return a string representation of the event
215  */

216 public String JavaDoc toString () {
217     return "Event {type=" + type + " " + widget + " time=" + time + " data=" + data + " x=" + x + " y=" + y + " width=" + width + " height=" + height + " detail=" + detail + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
218
}
219 }
220
Popular Tags