Search in sources :

Example 1 with KeyFrame

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

the class AnimatedFlowContainer method setViewContext.

@Override
public <U> void setViewContext(ViewContext<U> context) {
    updatePlaceholder(context.getRootNode());
    if (animation != null) {
        animation.stop();
    }
    animation = new Timeline();
    animation.getKeyFrames().addAll(animationProducer.apply(this));
    animation.getKeyFrames().add(new KeyFrame(duration, (e) -> clearPlaceholder()));
    animation.play();
}
Also used : Color(javafx.scene.paint.Color) KeyFrame(javafx.animation.KeyFrame) FlowContainer(io.datafx.controller.flow.FlowContainer) Node(javafx.scene.Node) Timeline(javafx.animation.Timeline) WritableImage(javafx.scene.image.WritableImage) ViewContext(io.datafx.controller.context.ViewContext) SnapshotParameters(javafx.scene.SnapshotParameters) StackPane(javafx.scene.layout.StackPane) Function(java.util.function.Function) Duration(javafx.util.Duration) List(java.util.List) ImageView(javafx.scene.image.ImageView) ContainerAnimations(io.datafx.controller.flow.container.ContainerAnimations) Image(javafx.scene.image.Image) Timeline(javafx.animation.Timeline) KeyFrame(javafx.animation.KeyFrame)

Example 2 with KeyFrame

use of javafx.animation.KeyFrame 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 3 with KeyFrame

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

the class JFXScrollPane method smoothScrolling.

public static void smoothScrolling(ScrollPane scrollPane) {
    final double[] frictions = { 0.99, 0.1, 0.05, 0.04, 0.03, 0.02, 0.01, 0.04, 0.01, 0.008, 0.008, 0.008, 0.008, 0.0006, 0.0005, 0.00003, 0.00001 };
    final double[] pushes = { 1 };
    final double[] derivatives = new double[frictions.length];
    Timeline timeline = new Timeline();
    scrollPane.getContent().addEventHandler(MouseEvent.DRAG_DETECTED, event -> timeline.stop());
    scrollPane.getContent().addEventHandler(ScrollEvent.ANY, event -> {
        if (event.getEventType().equals(ScrollEvent.SCROLL)) {
            int direction = event.getDeltaY() > 0 ? -1 : 1;
            for (int i = 0; i < pushes.length; i++) derivatives[i] += direction * pushes[i];
            if (timeline.getStatus().equals(Animation.Status.STOPPED))
                timeline.play();
            event.consume();
        }
    });
    timeline.getKeyFrames().add(new KeyFrame(Duration.millis(3), (event) -> {
        for (int i = 0; i < derivatives.length; i++) derivatives[i] *= frictions[i];
        for (int i = 1; i < derivatives.length; i++) derivatives[i] += derivatives[i - 1];
        double dy = derivatives[derivatives.length - 1];
        double height = scrollPane.getContent().getLayoutBounds().getHeight();
        scrollPane.setVvalue(Math.min(Math.max(scrollPane.getVvalue() + dy / height, 0), 1));
        if (Math.abs(dy) < 0.001)
            timeline.stop();
    }));
    timeline.setCycleCount(Animation.INDEFINITE);
}
Also used : Pos(javafx.geometry.Pos) Color(javafx.scene.paint.Color) KeyFrame(javafx.animation.KeyFrame) javafx.scene.layout(javafx.scene.layout) Node(javafx.scene.Node) MouseEvent(javafx.scene.input.MouseEvent) Timeline(javafx.animation.Timeline) Rectangle(javafx.scene.shape.Rectangle) ScrollEvent(javafx.scene.input.ScrollEvent) Duration(javafx.util.Duration) Insets(javafx.geometry.Insets) ScrollPane(javafx.scene.control.ScrollPane) DefaultProperty(javafx.beans.DefaultProperty) Scale(javafx.scene.transform.Scale) Transform(javafx.scene.transform.Transform) Animation(javafx.animation.Animation) Timeline(javafx.animation.Timeline) KeyFrame(javafx.animation.KeyFrame)

Example 4 with KeyFrame

use of javafx.animation.KeyFrame 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 5 with KeyFrame

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

the class JFXSpinner method layoutChildren.

/**
	 * {@inheritDoc}
	 */
@Override
protected void layoutChildren() {
    if (!initialized) {
        super.layoutChildren();
        initialColor = (Color) arc.getStroke();
        if (initialColor == null) {
            arc.setStroke(blueColor);
        }
        KeyFrame[] blueFrame = getKeyFrames(0, 0, initialColor == null ? blueColor : initialColor);
        KeyFrame[] redFrame = getKeyFrames(450, 1.4, initialColor == null ? redColor : initialColor);
        KeyFrame[] yellowFrame = getKeyFrames(900, 2.8, initialColor == null ? yellowColor : initialColor);
        KeyFrame[] greenFrame = getKeyFrames(1350, 4.2, initialColor == null ? greenColor : initialColor);
        KeyFrame endingFrame = new KeyFrame(Duration.seconds(5.6), new KeyValue(arc.lengthProperty(), 5, Interpolator.LINEAR), new KeyValue(arc.startAngleProperty(), 1845 + getStartingAngle(), Interpolator.LINEAR));
        if (timeline != null)
            timeline.stop();
        timeline = new Timeline(blueFrame[0], blueFrame[1], blueFrame[2], blueFrame[3], redFrame[0], redFrame[1], redFrame[2], redFrame[3], yellowFrame[0], yellowFrame[1], yellowFrame[2], yellowFrame[3], greenFrame[0], greenFrame[1], greenFrame[2], greenFrame[3], endingFrame);
        timeline.setCycleCount(Timeline.INDEFINITE);
        timeline.setRate(1);
        timeline.play();
        initialized = true;
    }
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) KeyFrame(javafx.animation.KeyFrame)

Aggregations

KeyFrame (javafx.animation.KeyFrame)232 Timeline (javafx.animation.Timeline)197 KeyValue (javafx.animation.KeyValue)150 ActionEvent (javafx.event.ActionEvent)66 FXML (javafx.fxml.FXML)54 Duration (javafx.util.Duration)48 EventHandler (javafx.event.EventHandler)43 Stage (javafx.stage.Stage)40 Alert (javafx.scene.control.Alert)35 Rotate (javafx.scene.transform.Rotate)26 IOException (java.io.IOException)25 URL (java.net.URL)24 ResourceBundle (java.util.ResourceBundle)24 Initializable (javafx.fxml.Initializable)23 Interpolator (javafx.animation.Interpolator)22 JFXButton (com.jfoenix.controls.JFXButton)21 FXMLLoader (javafx.fxml.FXMLLoader)21 MouseEvent (javafx.scene.input.MouseEvent)18 Pane (javafx.scene.layout.Pane)18 Node (javafx.scene.Node)17