]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AbstractEventAdapter.java
ef718456847e26c59b273c8c82429ba0594ad0c8
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / events / adapter / AbstractEventAdapter.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 /*
13  *
14  * @author Toni Kalajainen
15  */
16 package org.simantics.scenegraph.g2d.events.adapter;
17
18 import org.simantics.scenegraph.g2d.events.Event;
19 import org.simantics.scenegraph.g2d.events.EventTypes;
20 import org.simantics.scenegraph.g2d.events.IEventHandler;
21 import org.simantics.scenegraph.g2d.events.IEventQueue;
22
23 /**
24  * Adapts SWT, AWT and multitouch events
25  */
26 public abstract class AbstractEventAdapter {
27
28     /** Used for delegating events */
29     protected final IEventHandler delegator;
30     protected final IEventQueue   queue;
31     protected final Object        sender;
32
33     public AbstractEventAdapter(Object sender, IEventHandler delegator) {
34         if (delegator == null)
35             throw new IllegalArgumentException("null delegator");
36         this.delegator = delegator;
37         this.queue = null;
38         this.sender = sender;
39     }
40
41     public AbstractEventAdapter(Object sender, IEventQueue queue) {
42         if (queue == null)
43             throw new IllegalArgumentException("null event queue");
44         this.delegator = null;
45         this.queue = queue;
46         this.sender = sender;
47     }
48
49     protected void handleEvent(Event e) {
50         if (queue != null)
51             queue.queueEvent(e);
52         else if (EventTypes.passes(delegator, e))
53             delegator.handleEvent(e);
54     }
55
56 }