-/*******************************************************************************\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;\r
-\r
-import java.util.concurrent.atomic.AtomicBoolean;\r
-\r
-import org.simantics.utils.datastructures.prioritystack.PriorityStack;\r
-import org.simantics.utils.threads.CurrentThread;\r
-import org.simantics.utils.threads.IThreadWorkQueue;\r
-import org.simantics.utils.threads.ThreadUtils;\r
-\r
-/**\r
- * @see IEventHandlerStack\r
- * \r
- * @author Toni Kalajainen\r
- */\r
-public class EventHandlerStack extends PriorityStack<IEventHandler> implements IEventHandlerStack {\r
-\r
- IThreadWorkQueue thread;\r
-\r
- /**\r
- * Creates a new event handler stack.\r
- * \r
- * Any event handled with this stack is handled in current thread.\r
- */\r
- public EventHandlerStack() {\r
- super(IEventHandler.class);\r
- this.thread = CurrentThread.getThreadAccess();\r
- }\r
-\r
- /**\r
- * Creates a new event handler stack. Any event handled with this stack is\r
- * handled in the given thread.\r
- * \r
- * @param eventHandlingThread\r
- */\r
- public EventHandlerStack(IThreadWorkQueue eventHandlingThread) {\r
- super(IEventHandler.class);\r
- this.thread = eventHandlingThread;\r
- }\r
-\r
- @Override\r
- public int getEventMask() {\r
- return EventTypes.AnyMask;\r
- }\r
-\r
- @Override\r
- public boolean handleEvent(final Event e) {\r
- final int eventType = EventTypes.toTypeMask(e);\r
- if (thread.currentThreadAccess()) {\r
- // Send event through interactor stack\r
- IEventHandler list[] = toArray();\r
- for (int i = list.length - 1; i >= 0; i--)\r
- if (EventTypes.passes(list[i], eventType) && list[i].handleEvent(e))\r
- return true;\r
- return false;\r
- } else {\r
- final AtomicBoolean result = new AtomicBoolean(false);\r
- Runnable run = new Runnable() {\r
- @Override\r
- public void run() {\r
- // Send event through interactor stack\r
- IEventHandler list[] = toArray();\r
- for (int i = list.length - 1; i >= 0; i--)\r
- if (EventTypes.passes(list[i], eventType) && list[i].handleEvent(e)) {\r
- result.set(true);\r
- return;\r
- }\r
- }\r
- };\r
- ThreadUtils.syncExec(thread, run);\r
- return result.get();\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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<IEventHandler> 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();
+ }
+ }
+
+}