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

TimeLine: Special KeyValue for current value

    XMLWordPrintable

Details

    Description

      Timeline's will interpolate a KeyValue between two points. One of the nice features of Timelines is that when you play them from the start, they will start the interpolation (if not specifically specified) from the *current* value of that property, so the following Timeline:

          final Timeline timeline = new Timeline(
            new KeyFrame(Duration.seconds(1.0), new KeyValue(button.opacityProperty(), 0.0))
          );
        
      ...will interpolate from opacity 1.0 to 0.0, or from 0.5 to 0.0 etc, depending on the current value of opacity. This is very convenient when a Timeline is restarted for smooth transitions.

      However, what if I wanted a small delay at the start? Like this Timeline:

          final Timeline timeline = new Timeline(
            new KeyFrame(Duration.seconds(0.5)),
            new KeyFrame(Duration.seconds(1.0), new KeyValue(button.opacityProperty(), 0.0))
          );

      Unfortunately, this will not work. The additional KeyFrame has no impact on the opacity interpolation. The same goes for more complex Timelines like for example:

              final Timeline timeline = new Timeline(
                new KeyFrame(Duration.seconds(0.0), new KeyValue(carouselCell.scaleXProperty(), 1.0)),
                new KeyFrame(Duration.seconds(0.5), "Middle"),
                new KeyFrame(Duration.seconds(5.5), new KeyValue(carouselCell.scaleXProperty(), 1.2))
              );

      The idea of this Timeline is that it always runs from the cue point "Middle" either towards the start or towards the end (depending on Rate); however the scaleXProperty is immediately set at the Middle cue point to a value in between 1.0 and 1.2, and does not progress from the current value.

      This makes it harder than necessary to create Timelines that can be easily interrupted or jumped to different positions without jumping artifacts.

      My suggestion is to implement the concept of a current value for KeyValues, which could be as simple as omitting the value. The two above examples could be made to work as I'd like by writing them as:

          final Timeline timeline = new Timeline(
            new KeyFrame(Duration.seconds(0.5), new KeyValue(button.opacityProperty())), // from opacity current value
            new KeyFrame(Duration.seconds(1.0), new KeyValue(button.opacityProperty(), 0.0)) // to opacity 0.0
          );

              final Timeline timeline = new Timeline(
                new KeyFrame(Duration.seconds(0.0), new KeyValue(carouselCell.scaleXProperty(), 1.0)),
                new KeyFrame(Duration.seconds(0.5), "Middle", new KeyValue(carouselCell.scaleXProperty())),
                new KeyFrame(Duration.seconds(5.5), new KeyValue(carouselCell.scaleXProperty(), 1.2))
              );

      Attachments

        Activity

          People

            Unassigned Unassigned
            jhendrikx John Hendrikx
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Imported: