]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AbstractEventAdapter.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AbstractEventAdapter.java
new file mode 100644 (file)
index 0000000..0817c71
--- /dev/null
@@ -0,0 +1,56 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+/*\r
+ *\r
+ * @author Toni Kalajainen\r
+ */\r
+package org.simantics.scenegraph.g2d.events.adapter;\r
+\r
+import org.simantics.scenegraph.g2d.events.Event;\r
+import org.simantics.scenegraph.g2d.events.EventTypes;\r
+import org.simantics.scenegraph.g2d.events.IEventHandler;\r
+import org.simantics.scenegraph.g2d.events.IEventQueue;\r
+\r
+/**\r
+ * Adapts SWT, AWT and multitouch events\r
+ */\r
+public abstract class AbstractEventAdapter {\r
+\r
+    /** Used for delegating events */\r
+    protected final IEventHandler delegator;\r
+    protected final IEventQueue   queue;\r
+    protected final Object        sender;\r
+\r
+    public AbstractEventAdapter(Object sender, IEventHandler delegator) {\r
+        if (delegator == null)\r
+            throw new IllegalArgumentException("null delegator");\r
+        this.delegator = delegator;\r
+        this.queue = null;\r
+        this.sender = sender;\r
+    }\r
+\r
+    public AbstractEventAdapter(Object sender, IEventQueue queue) {\r
+        if (queue == null)\r
+            throw new IllegalArgumentException("null event queue");\r
+        this.delegator = null;\r
+        this.queue = queue;\r
+        this.sender = sender;\r
+    }\r
+\r
+    protected void handleEvent(Event e) {\r
+        if (queue != null)\r
+            queue.queueEvent(e);\r
+        else if (EventTypes.passes(delegator, e))\r
+            delegator.handleEvent(e);\r
+    }\r
+\r
+}\r