Option to disable duplicate MouseWheelMovedEvent in G2D EventQueue 62/1962/3
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 27 Jul 2018 07:09:16 +0000 (10:09 +0300)
committerJani Simomaa <jani.simomaa@semantum.fi>
Mon, 30 Jul 2018 05:49:20 +0000 (05:49 +0000)
gitlab #64

Change-Id: Ifda3fb71ac2ddc71fc94dfdc198841a55e166953

bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/EventQueue.java

index b0a9c752b4cbecdad1d38f73574251971eb79502..9b0980600990695e785e2d1040c58ae6e13f4a16 100644 (file)
@@ -14,6 +14,7 @@ package org.simantics.scenegraph.g2d.events;
 import java.lang.reflect.Method;
 import java.util.LinkedList;
 
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseWheelMovedEvent;
 import org.simantics.utils.datastructures.ListenerList;
 import org.simantics.utils.threads.IThreadWorkQueue;
 import org.simantics.utils.threads.SyncListenerList;
@@ -41,8 +42,28 @@ public class EventQueue implements IEventQueue, IEventHandler {
         return EventTypes.AnyMask;
     }
 
+    /**
+     * 
+     */
+    private MouseWheelMovedEvent lastMouseWheelMovedEvent;
+    
+    private static final String DISABLE_DUPLICATE_REMOVAL = "org.simantics.scenegraph.g2d.events.disableDuplicateMouseWheelEvent";
+    private static final boolean IGNORE_DUPLICATE = !Boolean.parseBoolean(System.getProperty(DISABLE_DUPLICATE_REMOVAL));
+    
+    private boolean ignoreDuplicateMouseWheelMovedEvent(Event e) {
+        if (IGNORE_DUPLICATE && e instanceof MouseWheelMovedEvent) {
+            if (e.time > 0 && (lastMouseWheelMovedEvent != null && lastMouseWheelMovedEvent.time < 0)) {
+                return true;
+            }
+            lastMouseWheelMovedEvent = (MouseWheelMovedEvent) e;
+        }
+        return false;
+    }
+    
     @Override
     public synchronized void queueEvent(Event e) {
+        if (ignoreDuplicateMouseWheelMovedEvent(e))
+            return;
         // coalesce with last
         EventCoalescer[] css = coalescers.getListeners();
         if (css.length > 0 && !queue.isEmpty()) {