Animation: onStart method
Martin Sladecek
martin.sladecek at oracle.com
Fri May 10 01:15:41 PDT 2013
On 05/10/2013 10:00 AM, Sebastian Rheinnecker wrote:
> Hi Martin,
>
> thanks for the clarification. The issue is promising, but the fixed
> version is "Van Ness". I don't know which version this code name is
> referencing to, but my guess is that it's beyond Javafx 8.0, so that
> makes me a sad panda.
Yes, it's beyond 8.0.
>
> I tried to fiddle around a bit:
> - Subclassing Animation and wrapping an Animation to call a handler
> prior to play(): Didn't work, my Idea told me that I needed to
> implement a package-private method that I couldn't call on the wrapped
> animation.
This is something that also needs to be addressed in future releases.
Currently, it's impossible to implement your own Animation class due to
abstract package-private methods, which supplement the lack of mature
public API.
>
> - Subclassing Transition and wrapping a Transition: doesn't work
> because I cannot call the protected method interpolate from my wrapper.
>
> However, I found out that the statusProperty of an animation is
> changing prior to executing the animation:
>
> (in Animation.java)
> void impl_start(boolean forceSync) {
> impl_sync(forceSync);
> setStatus(Status.RUNNING); // <<<
> clipEnvelope.start();
> setCurrentRate(clipEnvelope.getCurrentRate());
> lastPulse = 0;
> }
>
> called from play() via:
>
> lastPlayedFinished = false;
> impl_start(forceSync);
> startReceiver(TickCalculation.fromDuration(getDelay()));
>
>
> So I tried to bind a ChangeListener to the statusProperty of the
> animation and waited for changes to "RUNNING". In my local test this
> was satisfying:
>
> ft = new Transition(){
> {
> setCycleDuration(Duration.millis(2000));
> }
> @Override
> protected void interpolate(double frac) {
> System.out.println("interpolating");
> }
> };
>
> ft.statusProperty().addListener(new
> ChangeListener<Animation.Status>() {
> @Override
> public void changed(ObservableValue<? extends Animation.Status>
> observable, Animation.Status oldValue, Animation.Status newValue) {
> if (newValue.equals(Animation.Status.RUNNING)){
> System.out.println("starting");
> }
> }
> });
>
> ft.setOnFinished(new EventHandler<ActionEvent>() {
> @Override
> public void handle(ActionEvent event) {
> System.out.println("finished");
> }
> });
>
> -->
>
> starting
> interpolating
> interpolating
> (...)
> interpolating
> interpolating
> finished
>
> But I didn't try it in my real application yet and I'm not sure if
> this listener really gets called prior to starting the animation or
> not. Would do you think?
>
This will work unless you pause the application or do some jump. Then
it's possible to get new RUNNING state with the animation not being at
it's starting position. If you just want to play your animation from
it's start to the end, you should be good with this approach.
-Martin
More information about the openjfx-dev
mailing list