Search in sources :

Example 6 with KeyValue

use of javafx.animation.KeyValue in project JFoenix by jfoenixadmin.

the class JFXNodesList method initDefaultAnimation.

// init default animation keyvalues
private ArrayList<KeyValue> initDefaultAnimation(Region region, boolean expanded) {
    ArrayList<KeyValue> defaultAnimationValues = new ArrayList<>();
    defaultAnimationValues.add(new KeyValue(region.scaleXProperty(), expanded ? 1 : 0, Interpolator.EASE_BOTH));
    defaultAnimationValues.add(new KeyValue(region.scaleYProperty(), expanded ? 1 : 0, Interpolator.EASE_BOTH));
    return defaultAnimationValues;
}
Also used : KeyValue(javafx.animation.KeyValue) ArrayList(java.util.ArrayList)

Example 7 with KeyValue

use of javafx.animation.KeyValue in project JFoenix by jfoenixadmin.

the class JFXNodesList method animateList.

/**
	 * animates the list to show/hide the nodes
	 */
public void animateList() {
    expanded = !expanded;
    if (animateTimeline.getStatus().equals(Status.RUNNING))
        animateTimeline.stop();
    animateTimeline.getKeyFrames().clear();
    double duration = 120 / (double) this.getChildren().size();
    // show child nodes 
    if (expanded)
        this.getChildren().forEach(child -> child.setVisible(true));
    // add child nodes animation
    for (int i = 1; i < this.getChildren().size(); i++) {
        Node child = this.getChildren().get(i);
        ArrayList<KeyValue> keyValues = animationsMap.get(child).call(expanded);
        animateTimeline.getKeyFrames().add(new KeyFrame(Duration.millis(i * duration), keyValues.toArray(new KeyValue[keyValues.size()])));
    }
    // add 1st element animation
    ArrayList<KeyValue> keyValues = animationsMap.get(this.getChildren().get(0)).call(expanded);
    animateTimeline.getKeyFrames().add(new KeyFrame(Duration.millis(160), keyValues.toArray(new KeyValue[keyValues.size()])));
    // hide child nodes to allow mouse events on the nodes behind them
    if (!expanded) {
        animateTimeline.setOnFinished((finish) -> {
            for (int i = 1; i < this.getChildren().size(); i++) this.getChildren().get(i).setVisible(false);
        });
    } else {
        animateTimeline.setOnFinished(null);
    }
    animateTimeline.play();
}
Also used : Button(javafx.scene.control.Button) KeyFrame(javafx.animation.KeyFrame) Status(javafx.animation.Animation.Status) Node(javafx.scene.Node) Timeline(javafx.animation.Timeline) StackPane(javafx.scene.layout.StackPane) HashMap(java.util.HashMap) VBox(javafx.scene.layout.VBox) ArrayList(java.util.ArrayList) Duration(javafx.util.Duration) Region(javafx.scene.layout.Region) Interpolator(javafx.animation.Interpolator) KeyValue(javafx.animation.KeyValue) Callback(javafx.util.Callback) KeyValue(javafx.animation.KeyValue) Node(javafx.scene.Node) KeyFrame(javafx.animation.KeyFrame)

Example 8 with KeyValue

use of javafx.animation.KeyValue in project JFoenix by jfoenixadmin.

the class JFXNodesList method addAnimatedNode.

/**
	 * add node to list with a specified callback that is triggered after the node animation is finished. 
	 * Note: this method must be called instead of getChildren().add().
	 * 
	 * @param node
	 */
public void addAnimatedNode(Region node, Callback<Boolean, ArrayList<KeyValue>> animationCallBack) {
    // create container for the node if it's a sub nodes list
    if (node instanceof JFXNodesList) {
        StackPane container = new StackPane(node);
        container.setPickOnBounds(false);
        addAnimatedNode(container, animationCallBack);
        return;
    }
    // init node property
    node.setVisible(false);
    node.minWidthProperty().bind(node.prefWidthProperty());
    node.minHeightProperty().bind(node.prefHeightProperty());
    if (this.getChildren().size() > 0)
        initNode(node);
    else {
        if (node instanceof Button)
            ((Button) node).setOnAction((action) -> this.animateList());
        else
            node.setOnMouseClicked((click) -> this.animateList());
        node.getStyleClass().add("trigger-node");
    }
    // init the list height and width
    if (this.getChildren().size() == 0) {
        node.setVisible(true);
        this.minHeightProperty().bind(node.prefHeightProperty());
        this.maxHeightProperty().bind(node.prefHeightProperty());
        this.minWidthProperty().bind(node.prefWidthProperty());
        this.maxWidthProperty().bind(node.prefWidthProperty());
    }
    // add the node and its listeners
    this.getChildren().add(node);
    this.rotateProperty().addListener((o, oldVal, newVal) -> node.setRotate(newVal.doubleValue() % 180 == 0 ? newVal.doubleValue() : -newVal.doubleValue()));
    if (animationCallBack == null && this.getChildren().size() != 1)
        animationCallBack = (expanded) -> {
            return initDefaultAnimation(node, expanded);
        };
    else if (animationCallBack == null && this.getChildren().size() == 1)
        animationCallBack = (expanded) -> {
            return new ArrayList<KeyValue>();
        };
    animationsMap.put(node, animationCallBack);
}
Also used : Button(javafx.scene.control.Button) KeyFrame(javafx.animation.KeyFrame) Status(javafx.animation.Animation.Status) Node(javafx.scene.Node) Timeline(javafx.animation.Timeline) StackPane(javafx.scene.layout.StackPane) HashMap(java.util.HashMap) VBox(javafx.scene.layout.VBox) ArrayList(java.util.ArrayList) Duration(javafx.util.Duration) Region(javafx.scene.layout.Region) Interpolator(javafx.animation.Interpolator) KeyValue(javafx.animation.KeyValue) Callback(javafx.util.Callback) Button(javafx.scene.control.Button) ArrayList(java.util.ArrayList) StackPane(javafx.scene.layout.StackPane)

Example 9 with KeyValue

use of javafx.animation.KeyValue in project JFoenix by jfoenixadmin.

the class JFXRadioButtonSkin method updateAnimation.

private void updateAnimation() {
    Color unSelectedColor = ((JFXRadioButton) getSkinnable()).getUnSelectedColor();
    Color selectedColor = ((JFXRadioButton) getSkinnable()).getSelectedColor();
    timeline = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(dot.scaleXProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(dot.scaleYProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(radio.strokeProperty(), unSelectedColor, Interpolator.EASE_BOTH)), new KeyFrame(Duration.millis(200), new KeyValue(dot.scaleXProperty(), 0.6, Interpolator.EASE_BOTH), new KeyValue(dot.scaleYProperty(), 0.6, Interpolator.EASE_BOTH), new KeyValue(radio.strokeProperty(), selectedColor, Interpolator.EASE_BOTH)));
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) JFXRadioButton(com.jfoenix.controls.JFXRadioButton) Color(javafx.scene.paint.Color) KeyFrame(javafx.animation.KeyFrame)

Example 10 with KeyValue

use of javafx.animation.KeyValue in project JFoenix by jfoenixadmin.

the class JFXSliderSkin method initAnimation.

private void initAnimation(Orientation orientation) {
    double thumbPos, thumbNewPos;
    DoubleProperty layoutProperty;
    if (orientation == Orientation.HORIZONTAL) {
        if (((JFXSlider) getSkinnable()).getIndicatorPosition() == IndicatorPosition.RIGHT) {
            thumbPos = thumb.getLayoutY() - thumb.getHeight();
            thumbNewPos = thumbPos - shifting;
        } else {
            thumbPos = thumb.getLayoutY() - animatedThumb.getHeight() / 2;
            thumbNewPos = thumb.getLayoutY() - animatedThumb.getHeight() - thumb.getHeight();
        }
        layoutProperty = animatedThumb.translateYProperty();
    } else {
        if (((JFXSlider) getSkinnable()).getIndicatorPosition() == IndicatorPosition.RIGHT) {
            thumbPos = thumb.getLayoutX() - thumb.getWidth();
            thumbNewPos = thumbPos - shifting;
        } else {
            thumbPos = thumb.getLayoutX() - animatedThumb.getWidth() / 2;
            thumbNewPos = thumb.getLayoutX() - animatedThumb.getWidth() - thumb.getWidth();
        }
        layoutProperty = animatedThumb.translateXProperty();
    }
    timeline = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(animatedThumb.scaleXProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(animatedThumb.scaleYProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(layoutProperty, thumbPos, Interpolator.EASE_BOTH)), new KeyFrame(Duration.seconds(0.2), new KeyValue(animatedThumb.scaleXProperty(), 1, Interpolator.EASE_BOTH), new KeyValue(animatedThumb.scaleYProperty(), 1, Interpolator.EASE_BOTH), new KeyValue(layoutProperty, thumbNewPos, Interpolator.EASE_BOTH)));
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) KeyFrame(javafx.animation.KeyFrame) DoubleProperty(javafx.beans.property.DoubleProperty)

Aggregations

KeyValue (javafx.animation.KeyValue)81 KeyFrame (javafx.animation.KeyFrame)79 Timeline (javafx.animation.Timeline)78 Interpolator (javafx.animation.Interpolator)12 Rotate (javafx.scene.transform.Rotate)12 PerspectiveCamera (javafx.scene.PerspectiveCamera)9 MouseEvent (javafx.scene.input.MouseEvent)9 Duration (javafx.util.Duration)9 ArrayList (java.util.ArrayList)8 Insets (javafx.geometry.Insets)8 Scene (javafx.scene.Scene)7 Group (javafx.scene.Group)6 Node (javafx.scene.Node)6 KeyCode (javafx.scene.input.KeyCode)6 StackPane (javafx.scene.layout.StackPane)6 VBox (javafx.scene.layout.VBox)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 AnimationTimer (javafx.animation.AnimationTimer)5 ActionEvent (javafx.event.ActionEvent)5 PointLight (javafx.scene.PointLight)5