3131public class TransitionPane extends StackPane {
3232
3333 private Node currentNode ;
34- private Animation oldAnimation ;
3534
3635 public TransitionPane () {
3736 FXUtils .setOverflowHidden (this );
@@ -51,11 +50,6 @@ public final void setContent(Node newView, AnimationProducer transition, Duratio
5150
5251 public void setContent (Node newView , AnimationProducer transition ,
5352 Duration duration , Interpolator interpolator ) {
54- if (oldAnimation != null ) {
55- oldAnimation .stop ();
56- oldAnimation = null ;
57- }
58-
5953 Node previousNode = currentNode != newView && getWidth () > 0 && getHeight () > 0 ? currentNode : null ;
6054 currentNode = newView ;
6155
@@ -86,19 +80,15 @@ public void setContent(Node newView, AnimationProducer transition,
8680 previousNode ,
8781 newView ,
8882 duration , interpolator );
89- newAnimation .statusProperty ().addListener ((observable , oldValue , newValue ) -> {
90- if (oldValue == Animation .Status .RUNNING && newValue != Animation .Status .RUNNING ) {
91- setMouseTransparent (false );
92- getChildren ().remove (previousNode );
93-
94- if (cacheHint != null ) {
95- newView .setCache (false );
96- }
83+ newAnimation .setOnFinished (e -> {
84+ setMouseTransparent (false );
85+ getChildren ().remove (previousNode );
86+
87+ if (cacheHint != null ) {
88+ newView .setCache (false );
9789 }
9890 });
99-
100- oldAnimation = newAnimation ;
101- newAnimation .play ();
91+ FXUtils .playAnimation (this , "transition_pane" , newAnimation );
10292 });
10393
10494 }
0 commit comments