How to remove event filters when filterEvents() is used?

321 views Asked by At

Hello I want to use rxscala and scalafx together so I did this to re-package mouse events:

def mouseEvents: Observable[MouseEvent] = Observable.create(observer => {
  stage.filterEvent(MouseEvent.Any)((event: MouseEvent) => {
    observer.onNext(event)
    event.consume
  })
  Subscription { ??? }
})

The problem is that inside the Subscription { ??? } block I want to remove the event filter that was registered by filterEvent() but looking at it I see that filterEvent() doesn't keep a reference to the event filter so I can't use stage.removeEventFilter(). I don't see a removeFilterEvent() equivalent either, so how are event filters registered using filterEvent() removed?

I guess a workaround is not to use filterEvent() and instead use the javafx's addEventFilter() but the syntax is worse.

1

There are 1 answers

0
Jarek On BEST ANSWER

Currently you can use addEventFilter(eventType, eventHandler) and removeEventFilter(eventType, eventHandler).

In the latest ScalaFX 1.0.0-M8-SNAPSHOT method filterEvent returns subscription as expected. (see ScalaFX Issue 115)