Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8091406

Support multiple onFinished event handlers in class Animation

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • P4
    • tbd
    • fx2.0
    • javafx
    • None

    Description

      Class Animation allows you to listen for the completion of animation playback using an event handler, which you set by invoking Animation.setOnFinished(EventHandler);

      In our application this design has proven to be too limited. We have a super class S which uses an animation. Any subclass of S may specify which animation to use, but if such a subclass of S does not specify the animation, S has a default animation which is used instead.

      Once the animation completes, S has some cleanup to do, and to time this cleanup correctly, S always sets the onFinished event handler of the animation used and makes this event handler do the cleaning up. And therein lies the rub... because sometimes subclasses of S have some cleaning up to do too, and if they too have set the onFinished event handler, their event handler is replaced by S's event handler, which means the subclass' cleanup is never carried out.

      I am aware, that there a several ways to work around this - for instance, we could have S invoke a childCleanup() method which subclasses of S could implement and tell developers, that they are not allowed to use the setOnFinished method.

      However, I think our case proves that the design of the Animation class could be improved by introducing a list of event handlers, allowing us to invoke

      void addOnFinished(EventHandler);

      as well as

      void removeOnFinished(EventHandler);

      Please note that this feature can be implemented in a backwards compatible manner, since the existing setOnFinished() method can just be rewritten to invoke addOnFinished().

      Also notice that the design change suggested here aligns the design of the Animation class with other parts of JavaFX, where multiple event handlers can be added. For instance, all subclasses of ObservableValue (including all bindings), allows us to add multiple change listeners. So why shouldn't Animation too?

      Attachments

        Issue Links

          Activity

            People

              nlisker Nir Lisker
              risaksen Randahl Isaksen
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Imported: