Example usage for javafx.animation Interpolator EASE_BOTH

List of usage examples for javafx.animation Interpolator EASE_BOTH

Introduction

In this page you can find the example usage for javafx.animation Interpolator EASE_BOTH.

Prototype

Interpolator EASE_BOTH

To view the source code for javafx.animation Interpolator EASE_BOTH.

Click Source Link

Document

Built-in interpolator instance that provides ease in/out behavior.

Usage

From source file:com.github.vatbub.tictactoe.view.Main.java

private void updateAILevelLabel(boolean forceUpdate) {
    double sliderPos = 100 * Math.round(aiLevelSlider.getValue() * 3.0 / 100.0) / 3.0;

    if (sliderPos != aiLevelLabelPositionProperty.get() || forceUpdate) {
        aiLevelLabelPositionProperty.set(sliderPos);

        // request focus of the current ai label for accessibility
        aiLevelLabelHBox.getChildren().get((int) (sliderPos * 3 / 100)).requestFocus();
        updateAccessibleTexts();//from  w ww.  jav a 2  s.  c o m

        // get the slider position
        double[] xDouble = new double[] { 0, 100.0 / 3.0, 200.0 / 3.0, 300.0 / 3.0 };
        double[] translationYDouble = new double[4];
        double[] widthYDouble = new double[4];
        double[] trueWidthYDouble = new double[4];
        for (int i = 0; i < translationYDouble.length; i++) {
            // {-getAILevelLabelCenter(0), -getAILevelLabelCenter(1), -getAILevelLabelCenter(2), -getAILevelLabelCenter(3)};
            translationYDouble[i] = -getAILevelLabelCenter(i);
            widthYDouble[i] = Math.max(90, ((Label) aiLevelLabelHBox.getChildren().get(i)).getWidth()
                    + 8 * aiLevelLabelHBox.getSpacing());
            trueWidthYDouble[i] = ((Label) aiLevelLabelHBox.getChildren().get(i)).getWidth();
        }

        SplineInterpolator splineInterpolator = new SplineInterpolator();
        PolynomialSplineFunction translateFunction = splineInterpolator.interpolate(xDouble,
                translationYDouble);
        PolynomialSplineFunction widthFunction = splineInterpolator.interpolate(xDouble, widthYDouble);
        PolynomialSplineFunction trueWidthFunction = splineInterpolator.interpolate(xDouble, trueWidthYDouble);

        KeyValue hBoxLayoutXKeyValue1 = new KeyValue(aiLevelLabelHBox.layoutXProperty(),
                aiLevelLabelHBox.getLayoutX(), Interpolator.EASE_BOTH);
        KeyValue aiLevelLabelClipRectangleWidthKeyValue1 = new KeyValue(
                aiLevelLabelClipRectangle.widthProperty(), aiLevelLabelClipRectangle.getWidth(),
                Interpolator.EASE_BOTH);
        KeyValue aiLevelLabelClipRectangleXKeyValue1 = new KeyValue(aiLevelLabelClipRectangle.xProperty(),
                aiLevelLabelClipRectangle.getX(), Interpolator.EASE_BOTH);
        KeyValue aiLevelCenterLineStartXKeyValue1 = new KeyValue(aiLevelCenterLine.startXProperty(),
                aiLevelCenterLine.getStartX(), Interpolator.EASE_BOTH);
        KeyValue aiLevelCenterLineEndXKeyValue1 = new KeyValue(aiLevelCenterLine.endXProperty(),
                aiLevelCenterLine.getEndX(), Interpolator.EASE_BOTH);
        KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(0), hBoxLayoutXKeyValue1,
                aiLevelLabelClipRectangleWidthKeyValue1, aiLevelLabelClipRectangleXKeyValue1,
                aiLevelCenterLineStartXKeyValue1, aiLevelCenterLineEndXKeyValue1);

        double interpolatedLabelWidth = trueWidthFunction.value(sliderPos);

        KeyValue hBoxLayoutXKeyValue2 = new KeyValue(aiLevelLabelHBox.layoutXProperty(),
                translateFunction.value(sliderPos), Interpolator.EASE_BOTH);
        KeyValue aiLevelLabelClipRectangleWidthKeyValue2 = new KeyValue(
                aiLevelLabelClipRectangle.widthProperty(), widthFunction.value(sliderPos),
                Interpolator.EASE_BOTH);
        KeyValue aiLevelLabelClipRectangleXKeyValue2 = new KeyValue(aiLevelLabelClipRectangle.xProperty(),
                aiLevelLabelPane.getWidth() / 2 - widthFunction.value(sliderPos) / 2, Interpolator.EASE_BOTH);
        KeyValue aiLevelCenterLineStartXKeyValue2 = new KeyValue(aiLevelCenterLine.startXProperty(),
                (aiLevelLabelPane.getWidth() - interpolatedLabelWidth) / 2, Interpolator.EASE_BOTH);
        KeyValue aiLevelCenterLineEndXKeyValue2 = new KeyValue(aiLevelCenterLine.endXProperty(),
                (aiLevelLabelPane.getWidth() + interpolatedLabelWidth) / 2, Interpolator.EASE_BOTH);
        KeyFrame keyFrame2 = new KeyFrame(Duration.seconds(animationSpeed * 0.9), hBoxLayoutXKeyValue2,
                aiLevelLabelClipRectangleWidthKeyValue2, aiLevelLabelClipRectangleXKeyValue2,
                aiLevelCenterLineStartXKeyValue2, aiLevelCenterLineEndXKeyValue2);

        Timeline timeline = new Timeline(keyFrame1, keyFrame2);
        timeline.play();
    }
}

From source file:com.github.vatbub.tictactoe.view.Main.java

private void setLowerRightAnchorPaneDimensions(Labeled nodeToShow, Labeled nodeToHide, boolean noAnimation,
        double widthOffset) {
    final double secondAnimationOffset = 0.1;
    if (widthOffset > 0) {
        nodeToShow.setPrefWidth(nodeToShow.getWidth() + widthOffset);
    }/*ww  w .  j  a  va  2  s .com*/

    if (noAnimation) {
        nodeToShow.setOpacity(1);
        nodeToShow.setVisible(true);
        nodeToHide.setVisible(false);
        playOnlineAnchorPane.setPrefHeight(nodeToShow.getHeight());
        playOnlineAnchorPane.setPrefWidth(nodeToShow.getWidth());
    } else {
        nodeToShow.setOpacity(0);
        nodeToShow.setVisible(true);
        nodeToShow.setPrefWidth(nodeToShow.getWidth());
        nodeToShow.setPrefHeight(nodeToShow.getHeight());

        DoubleProperty firstProperty;
        DoubleProperty secondProperty;
        double firstPropertyValue;
        double secondPropertyValue;
        double secondPropertyInitialValue;

        if (nodeToShow.getHeight() > nodeToShow.getWidth()) {
            firstProperty = playOnlineAnchorPane.prefHeightProperty();
            firstPropertyValue = nodeToShow.getHeight() + AnchorPane.getBottomAnchor(nodeToShow);
            secondProperty = playOnlineAnchorPane.prefWidthProperty();
            secondPropertyValue = nodeToShow.getWidth() + AnchorPane.getRightAnchor(nodeToShow);
            secondPropertyInitialValue = nodeToHide.getWidth();
        } else {
            firstProperty = playOnlineAnchorPane.prefWidthProperty();
            firstPropertyValue = nodeToShow.getWidth() + AnchorPane.getRightAnchor(nodeToShow);
            secondProperty = playOnlineAnchorPane.prefHeightProperty();
            secondPropertyValue = nodeToShow.getHeight() + AnchorPane.getBottomAnchor(nodeToShow);
            secondPropertyInitialValue = nodeToHide.getHeight();
        }

        KeyValue keyValueFirstProperty = new KeyValue(firstProperty, firstPropertyValue,
                Interpolator.EASE_BOTH);
        KeyValue keyValueNodeToHideOpacity1 = new KeyValue(nodeToHide.opacityProperty(), 0,
                Interpolator.EASE_IN);
        KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(animationSpeed), keyValueFirstProperty,
                keyValueNodeToHideOpacity1);

        KeyValue keyValueSecondProperty1 = new KeyValue(secondProperty, secondPropertyInitialValue);
        KeyValue keyValueNodeToShowOpacity1 = new KeyValue(nodeToShow.opacityProperty(),
                nodeToShow.getOpacity());
        KeyFrame keyFrame2 = new KeyFrame(Duration.seconds(secondAnimationOffset * animationSpeed),
                keyValueSecondProperty1, keyValueNodeToShowOpacity1);

        KeyValue keyValueSecondProperty2 = new KeyValue(secondProperty, secondPropertyValue,
                Interpolator.EASE_BOTH);
        KeyValue keyValueNodeToShowOpacity2 = new KeyValue(nodeToShow.opacityProperty(), 1,
                Interpolator.EASE_OUT);
        KeyFrame keyFrame3 = new KeyFrame(Duration.seconds((1 + secondAnimationOffset) * animationSpeed),
                keyValueSecondProperty2, keyValueNodeToShowOpacity2);

        Timeline timeline = new Timeline(keyFrame1, keyFrame2, keyFrame3);
        timeline.setOnFinished((event) -> nodeToHide.setVisible(false));
        timeline.play();
    }
}

From source file:com.github.vatbub.tictactoe.view.Main.java

private void updateMenuHeight(boolean includeAILevelSlider) {
    double toHeight = 0;
    int effectiveChildCount = 0;
    for (Node child : menuSubBox.getChildren()) {
        if (child.isVisible() && child != aiLevelTitleLabel && child != aiLevelSlider
                && child != aiLevelLabelPane) {
            toHeight = toHeight + child.getBoundsInParent().getHeight();
            effectiveChildCount = effectiveChildCount + 1;
        }/*from   w w w .ja va2 s.  co  m*/
    }

    if (includeAILevelSlider) {
        toHeight = toHeight + aiLevelLabelPane.getPrefHeight();
        toHeight = toHeight + aiLevelSlider.getPrefHeight();
        toHeight = toHeight + aiLevelTitleLabel.getPrefHeight();
        effectiveChildCount = effectiveChildCount + 3;
    }

    toHeight = toHeight + menuSubBox.getSpacing() * (effectiveChildCount - 1);

    if (updateMenuHeightTimeline != null && updateMenuHeightTimeline.getStatus() == Animation.Status.RUNNING) {
        updateMenuHeightTimeline.stop();
    }

    updateMenuHeightTimeline = new Timeline();
    KeyValue keyValue0 = new KeyValue(menuSubBox.prefHeightProperty(), toHeight, Interpolator.EASE_BOTH);
    KeyFrame keyFrame0 = new KeyFrame(Duration.seconds(animationSpeed), keyValue0);
    updateMenuHeightTimeline.getKeyFrames().add(keyFrame0);

    updateMenuHeightTimeline.play();
}