Animated transitions between views in Flow

64 views
Skip to first unread message

Robert Ross

unread,
Mar 12, 2014, 11:33:37 AM3/12/14
to dataf...@googlegroups.com
Has anyone had any luck adding JavaFX transitions between views in a DataFX Flow?  Is this even possible?

Hendrik Ebbers

unread,
Mar 12, 2014, 12:17:54 PM3/12/14
to dataf...@googlegroups.com
Hi,
you can do this by implementing your own FlowContaine instead of using the DefaultFlowContainer. A additional implementation with CSS definable Animations is planned for the DataFX 8 release this summer. Sadly the sources are not documented until now...

See https://bitbucket.org/datafx/datafx/src/196844514a39b24d7ecef60fecbb260166ddb4c1/datafx-flow/src/main/java/org/datafx/controller/flow/FlowContainer.java?at=default

Hendrik Ebbers

unread,
Mar 12, 2014, 12:19:30 PM3/12/14
to dataf...@googlegroups.com

Jason Pollastrini

unread,
May 26, 2014, 12:27:30 PM5/26/14
to dataf...@googlegroups.com
public class FadeFlowContainer implements FlowContainer<StackPane>{

    private Timeline timeline;
    private final StackPane root;
    private final Duration fadeTime;

    public FadeFlowContainer(StackPane root, Duration dur) {
        this.root = root;
        this.fadeTime = dur;
    }
   
   
    @Override
    public <U> void setViewContext(ViewContext<U> context) {
        if(timeline != null){
            timeline.stop();
        }
        timeline = new Timeline();
        timeline.getKeyFrames().addAll(
                //start fade out
                new KeyFrame(Duration.ZERO, new KeyValue(root.opacityProperty(), 1.0, Interpolator.EASE_BOTH)),
                new KeyFrame(fadeTime.divide(2), e ->{
                    root.getChildren().clear();
                    root.getChildren().add(context.getRootNode());
                }, new KeyValue(root.opacityProperty(), 0.0, Interpolator.EASE_BOTH)),
                //start fade in
                new KeyFrame(fadeTime, new KeyValue(root.opacityProperty(), 0.0, Interpolator.EASE_BOTH)),
                new KeyFrame(fadeTime.multiply(2), new KeyValue(root.opacityProperty(), 1.0, Interpolator.EASE_BOTH))
        );
        timeline.play();
    }

    @Override
    public StackPane getView() {
        return root;

Hendrik Ebbers

unread,
May 27, 2014, 3:47:01 AM5/27/14
to dataf...@googlegroups.com
Hi,

Hi Jason,

thanks for the code. Currently I see one problem with your solution: Once the setViewContext method will be called the old view must disapear from screen. The @PreDestroy annotated method of the view controller is called and that can result in strange issues if a user clicks a button on the old view while it fades out. I think it's a better idea to use an image of the old view instead of the real view. The workflow should be like this: - create a snapshot of the old view - replace old view with snapshot - fade out snapshot By doing so the nodes of the old view aren't on screen any more and a user can't interact with them. If you are interessted in doing this you can create a pull request :)

    Reply all
    Reply to author
    Forward
    0 new messages