X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2Fevents%2Fadapter%2FAbstractEventAdapter.java;h=a0e0fd47feaecdf4f834db1d24230ac29b535413;hp=0817c71dd70907ecb61104807432709c46580359;hb=96ae58fda842dcd8266192eeb1399324b092154a;hpb=969bd23cab98a79ca9101af33334000879fb60c5 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 index 0817c71dd..a0e0fd47f 100644 --- 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 @@ -1,56 +1,65 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -/* - * - * @author Toni Kalajainen - */ -package org.simantics.scenegraph.g2d.events.adapter; - -import org.simantics.scenegraph.g2d.events.Event; -import org.simantics.scenegraph.g2d.events.EventTypes; -import org.simantics.scenegraph.g2d.events.IEventHandler; -import org.simantics.scenegraph.g2d.events.IEventQueue; - -/** - * Adapts SWT, AWT and multitouch events - */ -public abstract class AbstractEventAdapter { - - /** Used for delegating events */ - protected final IEventHandler delegator; - protected final IEventQueue queue; - protected final Object sender; - - public AbstractEventAdapter(Object sender, IEventHandler delegator) { - if (delegator == null) - throw new IllegalArgumentException("null delegator"); - this.delegator = delegator; - this.queue = null; - this.sender = sender; - } - - public AbstractEventAdapter(Object sender, IEventQueue queue) { - if (queue == null) - throw new IllegalArgumentException("null event queue"); - this.delegator = null; - this.queue = queue; - this.sender = sender; - } - - protected void handleEvent(Event e) { - if (queue != null) - queue.queueEvent(e); - else if (EventTypes.passes(delegator, e)) - delegator.handleEvent(e); - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +/* + * + * @author Toni Kalajainen + */ +package org.simantics.scenegraph.g2d.events.adapter; + +import org.simantics.scenegraph.g2d.events.Event; +import org.simantics.scenegraph.g2d.events.EventTypes; +import org.simantics.scenegraph.g2d.events.IEventHandler; +import org.simantics.scenegraph.g2d.events.IEventQueue; + +/** + * Adapts SWT, AWT and multitouch events + */ +public abstract class AbstractEventAdapter { + + /** Used for delegating events */ + protected final IEventHandler delegator; + protected final IEventQueue queue; + protected final Object sender; + + public AbstractEventAdapter(Object sender, IEventHandler delegator) { + if (delegator == null) + throw new IllegalArgumentException("null delegator"); + this.delegator = delegator; + this.queue = null; + this.sender = sender; + } + + public AbstractEventAdapter(Object sender, IEventQueue queue) { + if (queue == null) + throw new IllegalArgumentException("null event queue"); + this.delegator = null; + this.queue = queue; + this.sender = sender; + } + + protected void handleEvent(Event e) { + if (queue != null) + queue.queueEvent(e); + else if (EventTypes.passes(delegator, e)) + delegator.handleEvent(e); + } + + protected void syncHandleEvent(Event e) { + if (queue instanceof IEventHandler) + ((IEventHandler) queue).handleEvent(e); + else if (delegator != null && EventTypes.passes(delegator, e)) + delegator.handleEvent(e); + else + throw new UnsupportedOperationException("Cannot handle event synchronously, no handler available: " + e); + } + +}