3

I've got this partial scenegraph tree :

CustomPane (with onMouseClicked Handler)
 → ChildNode (with onMousePressed Handler)

When I catch the MousePressed event in the ChildNode, I can consume it, so that the parent doesn't receive a MousePressed event. But I would like to consume the associated MouseClicked event. So that pressing the mouse on the Child doesn't fire a MouseClicked event on the Parent.

Mad Dog Tannen
  • 7,129
  • 5
  • 31
  • 55
QuidNovi
  • 609
  • 6
  • 20
  • Why can't you just consume the MouseClicked event in the same way you are consuming the MousePressed event? – jewelsea Oct 21 '13 at 16:44
  • I ended up figuring that out, but it only works in this way. This solution stops working if you want to ignore the press events, only when it results in a click (the use case is clearer if you to handle the scroll events, but ignore those when you handle swipe events, etc.). Sergey Grivev's answer provides the generic way of dealing with those issues. – QuidNovi Oct 22 '13 at 13:07

1 Answers1

5
  1. You can add specific ChildNode#onMouse... handlers which will consume all events.

  2. or provide your own EventDispatcher:

    child.setEventDispatcher(new EventDispatcher() {
    
        @Override
        public Event dispatchEvent(Event event, EventDispatchChain tail) {
            boolean valid = myValidationLogicForEvents(event);
            return valid ? tail.dispatchEvent(event) : null;
        }
    });
    
Sergey Grinev
  • 34,078
  • 10
  • 128
  • 141