Prioritized event handlers

John Hendrikx john.hendrikx at gmail.com
Thu Oct 26 07:36:58 UTC 2023


Hi Michael,

Yeah, I also think it is an oversight, or may even be qualified as a 
bug.  Now you have to be really careful to start event handlers with a 
`if (!event.isConsumed())` check, just in case there is another handler 
that is before you at the same level that may have consumed the event...

There docs are really light on details, and only this part seems 
relevant and could be a bit ambigious depending on what "propagation" 
would mean here (to another handler or to a different eventhandler manager):

/**

* Marks this {@code Event} as consumed. This stops its further propagation.

*/

publicvoidconsume() {

consumed= true;

}

--John

On 26/10/2023 04:06, Michael Strauß wrote:
>> - The consumed flag doesn't change any other behavior? Consumed events
>> only are passed to handlers at the same level, but are not bubbled up
>> (or captured down); having consumed events not be passed to event
>> handlers (even at the same level) seems like a more sane default for sure
> I pulled on this string a little bit more and decided to remove the
> `EventHandlerPolicy` record from the API, because I think the
> `EventHandlerPolicy.handleConsumedEvents` toggle is not required. Have
> a look at the PR to see the simplified API:
> https://github.com/openjdk/jfx/pull/1266
>
> While the current behavior of JavaFX events is strange with regards to
> handler invocation for consumed events, it doesn't need to be solved
> with the priority API. Here's an interesting thing: if I simply don't
> invoke any event handlers for an event that is already consumed, no
> tests break. This suggests to me that the current behavior is an
> oversight rather than a purposeful implementation, and we could change
> it in the future.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20231026/e178f460/attachment-0001.htm>


More information about the openjfx-dev mailing list