1 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 31 public class TypedListener implements Listener { 32 33 36 protected SWTEventListener eventListener; 37 38 49 public TypedListener (SWTEventListener listener) { 50 eventListener = listener; 51 } 52 53 64 public SWTEventListener getEventListener () { 65 return eventListener; 66 } 67 68 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 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 153 KeyEvent event = new KeyEvent(e); 154 ((KeyListener) eventListener).keyPressed(event); 155 e.doit = event.doit; 156 break; 157 } 158 case SWT.KeyUp: { 159 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 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 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 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 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 |