X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2Fevents%2FEventHandlerStack.java;h=8324f97704639b073dfc514a5fa49d6d32b62079;hb=bdb7180f6425b460b8566a3223b319caf9dbc56f;hp=f66023b97c48b269ae020b3e64bb243ff31a864d;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/EventHandlerStack.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/EventHandlerStack.java index f66023b97..8324f9770 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/EventHandlerStack.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/EventHandlerStack.java @@ -1,89 +1,89 @@ -/******************************************************************************* - * 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; - -import java.util.concurrent.atomic.AtomicBoolean; - -import org.simantics.utils.datastructures.prioritystack.PriorityStack; -import org.simantics.utils.threads.CurrentThread; -import org.simantics.utils.threads.IThreadWorkQueue; -import org.simantics.utils.threads.ThreadUtils; - -/** - * @see IEventHandlerStack - * - * @author Toni Kalajainen - */ -public class EventHandlerStack extends PriorityStack implements IEventHandlerStack { - - IThreadWorkQueue thread; - - /** - * Creates a new event handler stack. - * - * Any event handled with this stack is handled in current thread. - */ - public EventHandlerStack() { - super(IEventHandler.class); - this.thread = CurrentThread.getThreadAccess(); - } - - /** - * Creates a new event handler stack. Any event handled with this stack is - * handled in the given thread. - * - * @param eventHandlingThread - */ - public EventHandlerStack(IThreadWorkQueue eventHandlingThread) { - super(IEventHandler.class); - this.thread = eventHandlingThread; - } - - @Override - public int getEventMask() { - return EventTypes.AnyMask; - } - - @Override - public boolean handleEvent(final Event e) { - final int eventType = EventTypes.toTypeMask(e); - if (thread.currentThreadAccess()) { - // Send event through interactor stack - IEventHandler list[] = toArray(); - for (int i = list.length - 1; i >= 0; i--) - if (EventTypes.passes(list[i], eventType) && list[i].handleEvent(e)) - return true; - return false; - } else { - final AtomicBoolean result = new AtomicBoolean(false); - Runnable run = new Runnable() { - @Override - public void run() { - // Send event through interactor stack - IEventHandler list[] = toArray(); - for (int i = list.length - 1; i >= 0; i--) - if (EventTypes.passes(list[i], eventType) && list[i].handleEvent(e)) { - result.set(true); - return; - } - } - }; - ThreadUtils.syncExec(thread, run); - return result.get(); - } - } - -} +/******************************************************************************* + * 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; + +import java.util.concurrent.atomic.AtomicBoolean; + +import org.simantics.utils.datastructures.prioritystack.PriorityStack; +import org.simantics.utils.threads.CurrentThread; +import org.simantics.utils.threads.IThreadWorkQueue; +import org.simantics.utils.threads.ThreadUtils; + +/** + * @see IEventHandlerStack + * + * @author Toni Kalajainen + */ +public class EventHandlerStack extends PriorityStack implements IEventHandlerStack { + + IThreadWorkQueue thread; + + /** + * Creates a new event handler stack. + * + * Any event handled with this stack is handled in current thread. + */ + public EventHandlerStack() { + super(IEventHandler.class); + this.thread = CurrentThread.getThreadAccess(); + } + + /** + * Creates a new event handler stack. Any event handled with this stack is + * handled in the given thread. + * + * @param eventHandlingThread + */ + public EventHandlerStack(IThreadWorkQueue eventHandlingThread) { + super(IEventHandler.class); + this.thread = eventHandlingThread; + } + + @Override + public int getEventMask() { + return EventTypes.AnyMask; + } + + @Override + public boolean handleEvent(final Event e) { + final int eventType = EventTypes.toTypeMask(e); + if (thread.currentThreadAccess()) { + // Send event through interactor stack + IEventHandler list[] = toArray(); + for (int i = list.length - 1; i >= 0; i--) + if (EventTypes.passes(list[i], eventType) && list[i].handleEvent(e)) + return true; + return false; + } else { + final AtomicBoolean result = new AtomicBoolean(false); + Runnable run = new Runnable() { + @Override + public void run() { + // Send event through interactor stack + IEventHandler list[] = toArray(); + for (int i = list.length - 1; i >= 0; i--) + if (EventTypes.passes(list[i], eventType) && list[i].handleEvent(e)) { + result.set(true); + return; + } + } + }; + ThreadUtils.syncExec(thread, run); + return result.get(); + } + } + +}