1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
14 * @author Toni Kalajainen
\r
16 package org.simantics.scenegraph.g2d.events.adapter;
\r
18 import org.simantics.scenegraph.g2d.events.Event;
\r
19 import org.simantics.scenegraph.g2d.events.EventTypes;
\r
20 import org.simantics.scenegraph.g2d.events.IEventHandler;
\r
21 import org.simantics.scenegraph.g2d.events.IEventQueue;
\r
24 * Adapts SWT, AWT and multitouch events
\r
26 public abstract class AbstractEventAdapter {
\r
28 /** Used for delegating events */
\r
29 protected final IEventHandler delegator;
\r
30 protected final IEventQueue queue;
\r
31 protected final Object sender;
\r
33 public AbstractEventAdapter(Object sender, IEventHandler delegator) {
\r
34 if (delegator == null)
\r
35 throw new IllegalArgumentException("null delegator");
\r
36 this.delegator = delegator;
\r
38 this.sender = sender;
\r
41 public AbstractEventAdapter(Object sender, IEventQueue queue) {
\r
43 throw new IllegalArgumentException("null event queue");
\r
44 this.delegator = null;
\r
46 this.sender = sender;
\r
49 protected void handleEvent(Event e) {
\r
51 queue.queueEvent(e);
\r
52 else if (EventTypes.passes(delegator, e))
\r
53 delegator.handleEvent(e);
\r