]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AbstractEventAdapter.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / events / adapter / AbstractEventAdapter.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 /*\r
13  *\r
14  * @author Toni Kalajainen\r
15  */\r
16 package org.simantics.scenegraph.g2d.events.adapter;\r
17 \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
22 \r
23 /**\r
24  * Adapts SWT, AWT and multitouch events\r
25  */\r
26 public abstract class AbstractEventAdapter {\r
27 \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
32 \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
37         this.queue = null;\r
38         this.sender = sender;\r
39     }\r
40 \r
41     public AbstractEventAdapter(Object sender, IEventQueue queue) {\r
42         if (queue == null)\r
43             throw new IllegalArgumentException("null event queue");\r
44         this.delegator = null;\r
45         this.queue = queue;\r
46         this.sender = sender;\r
47     }\r
48 \r
49     protected void handleEvent(Event e) {\r
50         if (queue != null)\r
51             queue.queueEvent(e);\r
52         else if (EventTypes.passes(delegator, e))\r
53             delegator.handleEvent(e);\r
54     }\r
55 \r
56 }\r