From a610da95329a58cbfd45a1fdaa89e1be23f204cd Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Fri, 27 Jul 2018 10:09:16 +0300 Subject: [PATCH] Option to disable duplicate MouseWheelMovedEvent in G2D EventQueue gitlab #64 Change-Id: Ifda3fb71ac2ddc71fc94dfdc198841a55e166953 --- .../scenegraph/g2d/events/EventQueue.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/EventQueue.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/EventQueue.java index b0a9c752b..9b0980600 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/EventQueue.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/EventQueue.java @@ -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()) { -- 2.47.1