From: jsimomaa Date: Fri, 27 Jul 2018 07:09:16 +0000 (+0300) Subject: Option to disable duplicate MouseWheelMovedEvent in G2D EventQueue X-Git-Tag: v1.43.0~136^2~429 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=a610da95329a58cbfd45a1fdaa89e1be23f204cd;p=simantics%2Fplatform.git Option to disable duplicate MouseWheelMovedEvent in G2D EventQueue gitlab #64 Change-Id: Ifda3fb71ac2ddc71fc94dfdc198841a55e166953 --- 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()) {