KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.internal.SWTEventListener;
15 import org.eclipse.swt.*;
16 import org.eclipse.swt.events.*;
17
18 /**
19  * Instances of this class are <em>internal SWT implementation</em>
20  * objects which provide a mapping between the typed and untyped
21  * listener mechanisms that SWT supports.
22  * <p>
23  * <b>IMPORTANT:</b> This class is <em>not</em> part of the SWT
24  * public API. It is marked public only so that it can be shared
25  * within the packages provided by SWT. It should never be
26  * referenced from application code.
27  * </p>
28  *
29  * @see Listener
30  */

31 public class TypedListener implements Listener {
32     
33     /**
34      * The receiver's event listener
35      */

36     protected SWTEventListener eventListener;
37
38 /**
39  * Constructs a new instance of this class for the given event listener.
40  * <p>
41  * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
42  * public API. It is marked public only so that it can be shared
43  * within the packages provided by SWT. It should never be
44  * referenced from application code.
45  * </p>
46  *
47  * @param listener the event listener to store in the receiver
48  */

49 public TypedListener (SWTEventListener listener) {
50     eventListener = listener;
51 }
52
53 /**
54  * Returns the receiver's event listener.
55  * <p>
56  * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
57  * public API. It is marked public only so that it can be shared
58  * within the packages provided by SWT. It should never be
59  * referenced from application code.
60  * </p>
61  *
62  * @return the receiver's event listener
63  */

64 public SWTEventListener getEventListener () {
65     return eventListener;
66 }
67
68 /**
69  * Handles the given event.
70  * <p>
71  * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
72  * public API. It is marked public only so that it can be shared
73  * within the packages provided by SWT. It should never be
74  * referenced from application code.
75  * </p>
76  * @param e the event to handle
77  */

78 public void handleEvent (Event e) {
79     switch (e.type) {
80         case SWT.Activate: {
81             ((ShellListener) eventListener).shellActivated(new ShellEvent(e));
82             break;
83         }
84         case SWT.Arm: {
85             ((ArmListener) eventListener).widgetArmed (new ArmEvent (e));
86             break;
87         }
88         case SWT.Close: {
89             /* Fields set by Decorations */
90             ShellEvent event = new ShellEvent (e);
91             ((ShellListener) eventListener).shellClosed(event);
92             e.doit = event.doit;
93             break;
94         }
95         case SWT.Collapse: {
96             if (eventListener instanceof TreeListener) {
97                 ((TreeListener) eventListener).treeCollapsed(new TreeEvent(e));
98             } else {
99                 ((ExpandListener) eventListener).itemCollapsed(new ExpandEvent(e));
100             }
101             break;
102         }
103         case SWT.Deactivate: {
104             ((ShellListener) eventListener).shellDeactivated(new ShellEvent(e));
105             break;
106         }
107         case SWT.Deiconify: {
108             ((ShellListener) eventListener).shellDeiconified(new ShellEvent(e));
109             break;
110         }
111         case SWT.DefaultSelection: {
112             ((SelectionListener)eventListener).widgetDefaultSelected(new SelectionEvent(e));
113             break;
114         }
115         case SWT.Dispose: {
116             ((DisposeListener) eventListener).widgetDisposed(new DisposeEvent(e));
117             break;
118         }
119         case SWT.DragDetect: {
120             ((DragDetectListener) eventListener).dragDetected(new DragDetectEvent(e));
121             break;
122         }
123         case SWT.Expand: {
124             if (eventListener instanceof TreeListener) {
125                 ((TreeListener) eventListener).treeExpanded(new TreeEvent(e));
126             } else {
127                 ((ExpandListener) eventListener).itemExpanded(new ExpandEvent(e));
128             }
129             break;
130         }
131         case SWT.FocusIn: {
132             ((FocusListener) eventListener).focusGained(new FocusEvent(e));
133             break;
134         }
135         case SWT.FocusOut: {
136             ((FocusListener) eventListener).focusLost(new FocusEvent(e));
137             break;
138         }
139         case SWT.Help: {
140             ((HelpListener) eventListener).helpRequested (new HelpEvent (e));
141             break;
142         }
143         case SWT.Hide: {
144             ((MenuListener) eventListener).menuHidden(new MenuEvent(e));
145             break;
146         }
147         case SWT.Iconify: {
148             ((ShellListener) eventListener).shellIconified(new ShellEvent(e));
149             break;
150         }
151         case SWT.KeyDown: {
152             /* Fields set by Control */
153             KeyEvent event = new KeyEvent(e);
154             ((KeyListener) eventListener).keyPressed(event);
155             e.doit = event.doit;
156             break;
157         }
158         case SWT.KeyUp: {
159             /* Fields set by Control */
160             KeyEvent event = new KeyEvent(e);
161             ((KeyListener) eventListener).keyReleased(event);
162             e.doit = event.doit;
163             break;
164         }
165         case SWT.Modify: {
166             ((ModifyListener) eventListener).modifyText(new ModifyEvent(e));
167             break;
168         }
169         case SWT.MenuDetect: {
170             MenuDetectEvent event = new MenuDetectEvent(e);
171             ((MenuDetectListener) eventListener).menuDetected(event);
172             e.x = event.x;
173             e.y = event.y;
174             e.doit = event.doit;
175             break;
176         }
177         case SWT.MouseDown: {
178             ((MouseListener) eventListener).mouseDown(new MouseEvent(e));
179             break;
180         }
181         case SWT.MouseDoubleClick: {
182             ((MouseListener) eventListener).mouseDoubleClick(new MouseEvent(e));
183             break;
184         }
185         case SWT.MouseEnter: {
186             ((MouseTrackListener) eventListener).mouseEnter (new MouseEvent (e));
187             break;
188         }
189         case SWT.MouseExit: {
190             ((MouseTrackListener) eventListener).mouseExit (new MouseEvent (e));
191             break;
192         }
193         case SWT.MouseHover: {
194             ((MouseTrackListener) eventListener).mouseHover (new MouseEvent (e));
195             break;
196         }
197         case SWT.MouseMove: {
198             ((MouseMoveListener) eventListener).mouseMove(new MouseEvent(e));
199             return;
200         }
201         case SWT.MouseWheel: {
202             ((MouseWheelListener) eventListener).mouseScrolled(new MouseEvent(e));
203             return;
204         }
205         case SWT.MouseUp: {
206             ((MouseListener) eventListener).mouseUp(new MouseEvent(e));
207             break;
208         }
209         case SWT.Move: {
210             ((ControlListener) eventListener).controlMoved(new ControlEvent(e));
211             break;
212         }
213         case SWT.Paint: {
214             /* Fields set by Control */
215             PaintEvent event = new PaintEvent (e);
216             ((PaintListener) eventListener).paintControl (event);
217             e.gc = event.gc;
218             break;
219         }
220         case SWT.Resize: {
221             ((ControlListener) eventListener).controlResized(new ControlEvent(e));
222             break;
223         }
224         case SWT.Selection: {
225             /* Fields set by Sash */
226             SelectionEvent event = new SelectionEvent (e);
227             ((SelectionListener) eventListener).widgetSelected (event);
228             e.x = event.x;
229             e.y = event.y;
230             e.doit = event.doit;
231             break;
232         }
233         case SWT.Show: {
234             ((MenuListener) eventListener).menuShown(new MenuEvent(e));
235             break;
236         }
237         case SWT.Traverse: {
238             /* Fields set by Control */
239             TraverseEvent event = new TraverseEvent (e);
240             ((TraverseListener) eventListener).keyTraversed (event);
241             e.detail = event.detail;
242             e.doit = event.doit;
243             break;
244         }
245         case SWT.Verify: {
246             /* Fields set by Text, RichText */
247             VerifyEvent event = new VerifyEvent (e);
248             ((VerifyListener) eventListener).verifyText (event);
249             e.text = event.text;
250             e.doit = event.doit;
251             break;
252         }
253     }
254 }
255
256 }
257
Popular Tags