SplitPane.Divider Transition

Wrote a small utility class to control animated sliding of a SplitPane.Divider.

You can find the complete code in my Bitbucket repo here.

I intend to make it as simple as possible to attach a slide-animation to a standard SplitPane:

splitPane          The SplitPane to be animated.
dividerIndex     Index of the divider to be controlled.
direction           Direction to slide out the layout container
(horizontal SplitPane: LEFT/RIGHT, vertical SplitPane: UP/DOWN)
cycleDuration   Duration/Speed of the slide animation.

SplitPaneDividerSlider( SplitPane splitPane,
                                int dividerIndex,
                                Direction direction,
                                Duration cycleDuration )

SplitPaneTransitionDemo1

E.g. create a divider controller for divider at index 0:

SplitPaneDividerSlider leftSplitPaneDividerSlider = new SplitPaneDividerSlider(centerSplitPane, 0, SplitPaneDividerSlider.Direction.LEFT);

This guy can be triggered by a ToggleButton:

leftToggleButton.selectedProperty().addListener((ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) -> {
leftSplitPaneDividerSlider.setAimContentVisible(t1);
});

Set a font-icon on the ToogleButton:

AwesomeDude.setIcon(leftToggleButton, AwesomeIcon.TOGGLE_LEFT, "2em");

leftToggleButton.selectedProperty().addListener((ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) -> {
      if (t1) {
          AwesomeDude.setIcon(leftToggleButton, AwesomeIcon.TOGGLE_LEFT, "2em"
      } else {
           AwesomeDude.setIcon(leftToggleButton, AwesomeIcon.TOGGLE_RIGHT, "2.5em")          
      }
});

SplitPanes in JavaFX do respect the min/max sizes of layout containers.

Movement of the divider is stopped when reaching these values.
To overrule this constraint when animation is started to slide out the content, min size is set to 0.0 and the original size will be restored when sliding in the content is finished. The right pane is figured out based on the divider index and the direction to side out:

        switch (direction) {
            case LEFT:
            case UP:
                content = (Region) splitPane.getItems().get(dividerIndex);
                break;
            case RIGHT:
            case DOWN:
                content = (Region) splitPane.getItems().get(dividerIndex + 1);
                break;
        }

Custom Component: Starter with hover effect

I was looking for a starter component for to use on the dock like main entry page of our application. It should have a hover effect on mouse enter/ mouse exit and a start effect on mouse click.

As JavaFX has already very useful Transition implementations I gave the ScaleTransition a try. I wanted a smooth expand and shrink effect on mouse enter and exit. Unfortunately transitions can on be played backwards. Reverse play is only supported when using the auto reverse option combined with an appropriate cycle count.

But I saw that changing the properties of an existing ScaleTransition instance and playFromStart() is a working approach:

        setOnMouseEntered(new EventHandler()
        {
            @Override
            public void handle(MouseEvent t)
            {
                scaleTransition.setFromX(getScaleX());
                scaleTransition.setFromY(getScaleY());
                scaleTransition.setToX(expandToMaxProperty.get());
                scaleTransition.setToY(expandToMaxProperty.get());
                scaleTransition.playFromStart();
            }
        });

        setOnMouseExited(new EventHandler()
        {
            @Override
            public void handle(MouseEvent t)
            {
                scaleTransition.setFromX(getScaleX());
                scaleTransition.setFromY(getScaleY());
                scaleTransition.setToX(1);
                scaleTransition.setToY(1);
                scaleTransition.playFromStart();
            }
        });

The start effect played on mouse click is a combination of both sequential and parallel played transitions: scale and fade out are played in parallel and in the end the starter goes back to an initial position:

        fadeTransition = new FadeTransition(Duration.millis(200), this);
        fadeTransition.setCycleCount(1);
        fadeTransition
                .setInterpolator(Interpolator.EASE_BOTH);
      
        startTransition = new ParallelTransition();
        startTransition.setCycleCount(2);
        startTransition.setAutoReverse(true);
        startTransition.getChildren()
                .addAll(scaleTransition,
                fadeTransition);

        initTransition = new ScaleTransition(Duration.millis(200), this);
        initTransition.setToX(1);
        initTransition.setToY(1);
        initTransition.setCycleCount(1);
        initTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        startsSequentialTransition = new SequentialTransition();
        startsSequentialTransition.getChildren()
                .addAll(
                startTransition,
                initTransition);

Whole Starter code

public class Starter extends StackPane
{

    private ParallelTransition startTransition;
    private ScaleTransition scaleTransition;
    private ScaleTransition initTransition;
    private FadeTransition fadeTransition;
    private SequentialTransition startsSequentialTransition;
    private DoubleProperty expandToMaxProperty;
    private ImageView baseImage;

    public Starter(String base, double fitWidth, double fitHeight)
    {
        baseImage = new ImageView(base);
        init(fitWidth, fitHeight);
    }

    public Starter(Image base, double fitWidth, double fitHeight)
    {
        baseImage = new ImageView(base);
        init(fitWidth, fitHeight);
    }

    private void init(double fitWidth, double fitHeight)
    {
        expandToMaxProperty = new SimpleDoubleProperty(1.2);

        baseImage.setFitWidth(fitWidth);
        baseImage.setFitHeight(fitHeight);

        Color selectedColor = Color.rgb(0, 0, 0, 0.5);
        DropShadow dropShadow = DropShadowBuilder.create()
                .color(selectedColor)
                .build();
        setEffect(dropShadow);

        dropShadow.radiusProperty()
                .bind(scaleXProperty()
                .multiply(8));
        dropShadow.offsetXProperty()
                .bind(scaleXProperty()
                .multiply(8));
        dropShadow.offsetYProperty()
                .bind(scaleYProperty()
                .multiply(8));

        scaleTransition =
                new ScaleTransition(Duration.millis(200), this);
        scaleTransition.setCycleCount(1);
        scaleTransition
                .setInterpolator(Interpolator.EASE_BOTH);



        fadeTransition = new FadeTransition(Duration.millis(200), this);
        fadeTransition.setCycleCount(1);
        fadeTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        startTransition = new ParallelTransition();
        startTransition.setCycleCount(2);
        startTransition.setAutoReverse(true);
        startTransition.getChildren()
                .addAll(scaleTransition,
                fadeTransition);

        initTransition =
                new ScaleTransition(Duration.millis(200), this);
        initTransition.setToX(1);
        initTransition.setToY(1);
        initTransition.setCycleCount(1);
        initTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        startsSequentialTransition = new SequentialTransition();
        startsSequentialTransition.getChildren()
                .addAll(
                startTransition,
                initTransition);

        getChildren()
                .addAll(baseImage);

        setOnMouseEntered(new EventHandler<MouseEvent>()
        {
            @Override
            public void handle(MouseEvent t)
            {
                scaleTransition.setFromX(getScaleX());
                scaleTransition.setFromY(getScaleY());
                scaleTransition.setToX(expandToMaxProperty.get());
                scaleTransition.setToY(expandToMaxProperty.get());
                scaleTransition.playFromStart();
            }
        });

        setOnMouseExited(new EventHandler<MouseEvent>()
        {
            @Override
            public void handle(MouseEvent t)
            {
                scaleTransition.setFromX(getScaleX());
                scaleTransition.setFromY(getScaleY());
                scaleTransition.setToX(1);
                scaleTransition.setToY(1);
                scaleTransition.playFromStart();
            }
        });

        setOnMouseClicked(new EventHandler<MouseEvent>()
        {
            @Override
            public void handle(MouseEvent t)
            {
                scaleTransition.setFromX(getScaleX());
                scaleTransition.setFromY(getScaleY());
                scaleTransition.setToX(2);
                scaleTransition.setToY(2);
                fadeTransition.setFromValue(1.0f);
                fadeTransition.setToValue(0.5f);
                startsSequentialTransition.playFromStart();
            }
        });
    }

    public DoubleProperty expandToMaxProperty()
    {
        return expandToMaxProperty;
    }
}

[ U P D A T E 21-10-2014]

Made some modifications to get the Starter running on Java 8:

public class Starter extends StackPane
{

    private ParallelTransition startTransition;
    private ScaleTransition scaleTransition;
    private ScaleTransition startScaleTransition;
    private ScaleTransition initTransition;
    private FadeTransition fadeTransition;
    private SequentialTransition startsSequentialTransition;
    private DoubleProperty expandToMaxProperty;
    private final ImageView baseImage;

    public Starter(String base, double fitWidth, double fitHeight)
    {
        baseImage = new ImageView(base);
        init(fitWidth, fitHeight);
    }

    public Starter(Image base, double fitWidth, double fitHeight)
    {
        baseImage = new ImageView(base);
        init(fitWidth, fitHeight);
    }

    private void init(double fitWidth, double fitHeight)
    {
        expandToMaxProperty = new SimpleDoubleProperty(1.2);

        baseImage.setFitWidth(fitWidth);
        baseImage.setFitHeight(fitHeight);

        Color selectedColor = Color.rgb(0, 0, 0, 0.5);
        DropShadow dropShadow = DropShadowBuilder.create()
                .color(selectedColor)
                .build();
        setEffect(dropShadow);

        dropShadow.radiusProperty()
                .bind(scaleXProperty()
                .multiply(8));
        dropShadow.offsetXProperty()
                .bind(scaleXProperty()
                .multiply(8));
        dropShadow.offsetYProperty()
                .bind(scaleYProperty()
                .multiply(8));

        scaleTransition =
                new ScaleTransition(Duration.millis(200), this);
        scaleTransition.setCycleCount(1);
        scaleTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        startScaleTransition =
                new ScaleTransition(Duration.millis(200), this);
        startScaleTransition.setCycleCount(1);
        startScaleTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        fadeTransition = new FadeTransition(Duration.millis(200), this);
        fadeTransition.setCycleCount(1);
        fadeTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        startTransition = new ParallelTransition();
        startTransition.setCycleCount(2);
        startTransition.setAutoReverse(true);
        startTransition.getChildren()
                .addAll(startScaleTransition, fadeTransition);

        initTransition =
                new ScaleTransition(Duration.millis(200), this);
        initTransition.setToX(1);
        initTransition.setToY(1);
        initTransition.setCycleCount(1);
        initTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        startsSequentialTransition = new SequentialTransition();
        startsSequentialTransition.getChildren()
                .addAll(
                startTransition,
                initTransition);

        getChildren()
                .addAll(baseImage);

        setOnMouseEntered((MouseEvent t) -> {
            scaleTransition.setFromX(getScaleX());
            scaleTransition.setFromY(getScaleY());
            scaleTransition.setToX(expandToMaxProperty.get());
            scaleTransition.setToY(expandToMaxProperty.get());
            scaleTransition.playFromStart();
        });

        setOnMouseExited((MouseEvent t) -> {
            scaleTransition.setFromX(getScaleX());
            scaleTransition.setFromY(getScaleY());
            scaleTransition.setToX(1);
            scaleTransition.setToY(1);
            scaleTransition.playFromStart();
        });

        setOnMouseClicked((MouseEvent t) -> {
            startScaleTransition.setFromX(getScaleX());
            startScaleTransition.setFromY(getScaleY());
            startScaleTransition.setToX(2);
            startScaleTransition.setToY(2);
            fadeTransition.setFromValue(1.0f);
            fadeTransition.setToValue(0.5f);
            startsSequentialTransition.playFromStart();
        });
    }

    public DoubleProperty expandToMaxProperty()
    {
        return expandToMaxProperty;
    }
}

Find complete code repo at BitBucket.