Search in sources :

Example 71 with Timeline

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

the class JFXTableColumnHeader method layoutChildren.

@Override
protected void layoutChildren() {
    super.layoutChildren();
    double w = snapSize(getWidth()) - (snappedLeftInset() + snappedRightInset());
    container.resizeRelocate(snappedLeftInset(), 0, w, getHeight());
    if (!getChildren().contains(container)) {
        invalid = true;
        container.getChildren().remove(arrowContainer);
        for (int i = 0; i < getChildren().size(); ) {
            Node child = getChildren().get(i);
            container.getChildren().add(child);
        }
        getChildren().add(container);
    }
    // add animation to sorting arrow
    if (invalid) {
        if (container.getChildren().size() > 1 && !container.getChildren().contains(arrowContainer)) {
            // setup children
            arrowPane = (GridPane) container.getChildren().get(1);
            arrow = (Region) arrowPane.getChildren().get(0);
            arrowContainer.getChildren().clear();
            container.getChildren().remove(1);
            container.getChildren().add(arrowContainer);
            for (int i = 0; i < arrowPane.getChildren().size(); ) {
                Node child = arrowPane.getChildren().get(i);
                arrowContainer.getChildren().add(child);
                if (child instanceof HBox) {
                    HBox dotsContainer = (HBox) child;
                    dotsContainer.setMaxHeight(5);
                    dotsContainer.translateYProperty().bind(Bindings.createDoubleBinding(() -> {
                        return arrow.getHeight() + 2;
                    }, arrow.heightProperty()));
                } else if (child instanceof Label) {
                    Label labelContainer = (Label) child;
                    labelContainer.setMaxHeight(5);
                    labelContainer.translateYProperty().bind(Bindings.createDoubleBinding(() -> {
                        return arrow.getHeight() + 3;
                    }, arrow.heightProperty()));
                }
            }
            arrowContainer.maxWidthProperty().bind(arrow.widthProperty());
            StackPane.setAlignment(arrowContainer, Pos.CENTER_RIGHT);
            // set padding to the label to replace it with ... if it's too close to the sorting arrow
            Label label = (Label) container.getChildren().get(0);
            oldMargin = StackPane.getMargin(label);
            StackPane.setMargin(label, new Insets(oldMargin == null ? 0 : oldMargin.getTop(), oldMargin == null || oldMargin.getRight() < 30 ? 30 : oldMargin.getRight(), oldMargin == null ? 0 : oldMargin.getBottom(), oldMargin == null || oldMargin.getLeft() < 30 ? 30 : oldMargin.getLeft()));
            // fixed the issue of arrow translate X while resizing the column header
            arrowContainer.translateXProperty().bind(Bindings.createDoubleBinding(() -> {
                if (arrowContainer.getLayoutX() <= 8)
                    return -arrowContainer.getLayoutX() - 2;
                return -10.0;
            }, arrowContainer.layoutXProperty()));
            if (arrowAnimation != null && arrowAnimation.getStatus().equals(Status.RUNNING))
                arrowAnimation.stop();
            if (arrow.getRotate() == 180 && arrow.getRotate() != currentArrowRotation) {
                arrowContainer.setOpacity(0);
                arrowContainer.setTranslateY(getHeight() / 4);
                arrowAnimation = new Timeline(new KeyFrame(Duration.millis(320), new KeyValue(arrowContainer.opacityProperty(), 1, Interpolator.EASE_BOTH), new KeyValue(arrowContainer.translateYProperty(), 0, Interpolator.EASE_BOTH)));
            } else if (arrow.getRotate() == 0 && arrow.getRotate() != currentArrowRotation) {
                arrow.setRotate(-180);
                arrowAnimation = new Timeline(new KeyFrame(Duration.millis(160), new KeyValue(arrow.rotateProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(arrowContainer.opacityProperty(), 1, Interpolator.EASE_BOTH), new KeyValue(arrowContainer.translateYProperty(), 0, Interpolator.EASE_BOTH)));
            }
            arrowAnimation.setOnFinished((finish) -> currentArrowRotation = arrow.getRotate());
            arrowAnimation.play();
        }
        if (arrowContainer != null && arrowPane != null && container.getChildren().size() == 1 && !arrowPane.isVisible()) {
            if (arrowAnimation != null && arrowAnimation.getStatus().equals(Status.RUNNING))
                arrowAnimation.stop();
            Label label = (Label) container.getChildren().get(0);
            // dont change the padding if arrow is not showing
            if (currentArrowRotation == 0)
                StackPane.setMargin(label, new Insets(oldMargin == null ? 0 : oldMargin.getTop(), oldMargin == null || oldMargin.getRight() < 30 ? 30 : oldMargin.getRight(), oldMargin == null ? 0 : oldMargin.getBottom(), oldMargin == null || oldMargin.getLeft() < 30 ? 30 : oldMargin.getLeft()));
            container.getChildren().add(arrowContainer);
            arrowAnimation = new Timeline(new KeyFrame(Duration.millis(320), new KeyValue(arrowContainer.opacityProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(arrowContainer.translateYProperty(), getHeight() / 4, Interpolator.EASE_BOTH)));
            arrowAnimation.setOnFinished((finish) -> {
                currentArrowRotation = -1;
                StackPane.setMargin(label, null);
            });
            arrowAnimation.play();
        }
    }
}
Also used : HBox(javafx.scene.layout.HBox) Timeline(javafx.animation.Timeline) Insets(javafx.geometry.Insets) KeyValue(javafx.animation.KeyValue) Node(javafx.scene.Node) Label(javafx.scene.control.Label) KeyFrame(javafx.animation.KeyFrame)

Example 72 with Timeline

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

the class JFXListCell method layoutChildren.

/**
	 * {@inheritDoc}
	 */
@Override
protected void layoutChildren() {
    super.layoutChildren();
    cellRippler.resizeRelocate(0, 0, getWidth(), getHeight());
    double gap = getGap();
    if (clip == null) {
        clip = new Rectangle(0, gap / 2, getWidth(), getHeight() - gap);
        setClip(clip);
    } else {
        if (gap != 0) {
            if (playExpandAnimation || selectionChanged) {
                // fake list collapse state
                if (playExpandAnimation) {
                    this.setTranslateY(-gap / 2 + (-gap * (getIndex())));
                    clip.setY(gap / 2);
                    clip.setHeight(getHeight() - gap);
                    gapAnimation = new Timeline(new KeyFrame(Duration.millis(240), new KeyValue(this.translateYProperty(), 0, Interpolator.EASE_BOTH)));
                    playExpandAnimation = false;
                } else if (selectionChanged) {
                    clip.setY(0);
                    clip.setHeight(getHeight());
                    gapAnimation = new Timeline(new KeyFrame(Duration.millis(240), new KeyValue(clip.yProperty(), gap / 2, Interpolator.EASE_BOTH), new KeyValue(clip.heightProperty(), getHeight() - gap, Interpolator.EASE_BOTH)));
                }
                playExpandAnimation = false;
                selectionChanged = false;
                gapAnimation.play();
            } else {
                if (gapAnimation != null)
                    gapAnimation.stop();
                this.setTranslateY(0);
                clip.setY(gap / 2);
                clip.setHeight(getHeight() - gap);
            }
        } else {
            this.setTranslateY(0);
            clip.setY(0);
            clip.setHeight(getHeight());
        }
        clip.setX(0);
        clip.setWidth(getWidth());
    }
    if (!getChildren().contains(cellRippler)) {
        makeChildrenTransparent();
        getChildren().add(0, cellRippler);
        cellRippler.rippler.clear();
    }
    // refresh sublist style class
    if (this.getGraphic() != null && this.getGraphic().getStyleClass().contains("sublist-container"))
        this.getStyleClass().add("sublist-item");
    else
        this.getStyleClass().remove("sublist-item");
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) Rectangle(javafx.scene.shape.Rectangle) KeyFrame(javafx.animation.KeyFrame)

Example 73 with Timeline

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

the class MasonryPaneController method init.

@PostConstruct
public void init() throws FlowException, VetoException {
    ArrayList<Node> children = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        StackPane child = new StackPane();
        double width = Math.random() * 100 + 100;
        child.setMinWidth(width);
        child.setMaxWidth(width);
        child.setPrefWidth(width);
        double height = Math.random() * 100 + 100;
        child.setMinHeight(height);
        child.setMaxHeight(height);
        child.setPrefHeight(height);
        JFXDepthManager.setDepth(child, 1);
        children.add(child);
        // create content
        VBox content = new VBox();
        StackPane header = new StackPane();
        String headerColor = getDefaultColor(i % 12);
        header.setStyle("-fx-background-radius: 5 5 0 0; -fx-background-color: " + headerColor);
        VBox.setVgrow(header, Priority.ALWAYS);
        StackPane body = new StackPane();
        body.setMinHeight(Math.random() * 20 + 50);
        content.getChildren().addAll(header, body);
        body.setStyle("-fx-background-radius: 0 0 5 5; -fx-background-color: rgb(255,255,255,0.87);");
        // create button
        JFXButton button = new JFXButton("");
        button.setButtonType(ButtonType.RAISED);
        button.setStyle("-fx-background-radius: 40;-fx-background-color: " + getDefaultColor((int) ((Math.random() * 12) % 12)));
        button.setPrefSize(40, 40);
        button.setRipplerFill(Color.valueOf(headerColor));
        button.setScaleX(0);
        button.setScaleY(0);
        SVGGlyph glyph = new SVGGlyph(-1, "test", "M1008 6.286q18.857 13.714 15.429 36.571l-146.286 877.714q-2.857 16.571-18.286 25.714-8 4.571-17.714 4.571-6.286 0-13.714-2.857l-258.857-105.714-138.286 168.571q-10.286 13.143-28 13.143-7.429 0-12.571-2.286-10.857-4-17.429-13.429t-6.571-20.857v-199.429l493.714-605.143-610.857 528.571-225.714-92.571q-21.143-8-22.857-31.429-1.143-22.857 18.286-33.714l950.857-548.571q8.571-5.143 18.286-5.143 11.429 0 20.571 6.286z", Color.WHITE);
        glyph.setSize(20, 20);
        button.setGraphic(glyph);
        button.translateYProperty().bind(Bindings.createDoubleBinding(() -> {
            return header.getBoundsInParent().getHeight() - button.getHeight() / 2;
        }, header.boundsInParentProperty(), button.heightProperty()));
        StackPane.setMargin(button, new Insets(0, 12, 0, 0));
        StackPane.setAlignment(button, Pos.TOP_RIGHT);
        Timeline animation = new Timeline(new KeyFrame(Duration.millis(240), new KeyValue(button.scaleXProperty(), 1, Interpolator.EASE_BOTH), new KeyValue(button.scaleYProperty(), 1, Interpolator.EASE_BOTH)));
        animation.setDelay(Duration.millis(100 * i + (1000)));
        animation.play();
        child.getChildren().addAll(content, button);
    }
    masonryPane.getChildren().addAll(children);
    Platform.runLater(() -> scrollPane.requestLayout());
    JFXScrollPane.smoothScrolling(scrollPane);
}
Also used : Insets(javafx.geometry.Insets) KeyValue(javafx.animation.KeyValue) Node(javafx.scene.Node) ArrayList(java.util.ArrayList) JFXButton(com.jfoenix.controls.JFXButton) Timeline(javafx.animation.Timeline) SVGGlyph(com.jfoenix.svg.SVGGlyph) KeyFrame(javafx.animation.KeyFrame) VBox(javafx.scene.layout.VBox) StackPane(javafx.scene.layout.StackPane) PostConstruct(javax.annotation.PostConstruct)

Example 74 with Timeline

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

the class ProgressBarController method init.

@PostConstruct
public void init() throws FlowException, VetoException {
    Timeline task = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(progress1.progressProperty(), 0), new KeyValue(progress2.progressProperty(), 0)), new KeyFrame(Duration.seconds(2), new KeyValue(progress1.progressProperty(), 1), new KeyValue(progress2.progressProperty(), 1)));
    task.setCycleCount(Timeline.INDEFINITE);
    task.play();
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) KeyFrame(javafx.animation.KeyFrame) PostConstruct(javax.annotation.PostConstruct)

Example 75 with Timeline

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

the class ProgressBarDemo method start.

@Override
public void start(Stage stage) throws Exception {
    pane = new VBox();
    pane.setSpacing(30);
    pane.setStyle("-fx-background-color:WHITE");
    ProgressBar bar = new ProgressBar();
    bar.setPrefWidth(500);
    ProgressBar cssBar = new ProgressBar();
    cssBar.setPrefWidth(500);
    cssBar.setProgress(-1.0f);
    JFXProgressBar jfxBar = new JFXProgressBar();
    jfxBar.setPrefWidth(500);
    JFXProgressBar jfxBarInf = new JFXProgressBar();
    jfxBarInf.setPrefWidth(500);
    jfxBarInf.setProgress(-1.0f);
    Timeline timeline = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(bar.progressProperty(), 0), new KeyValue(jfxBar.progressProperty(), 0)), new KeyFrame(Duration.seconds(2), new KeyValue(bar.progressProperty(), 1), new KeyValue(jfxBar.progressProperty(), 1)));
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.play();
    pane.getChildren().addAll(bar, jfxBar, cssBar, jfxBarInf);
    StackPane main = new StackPane();
    main.getChildren().add(pane);
    main.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
    StackPane.setMargin(pane, new Insets(20, 0, 0, 20));
    final Scene scene = new Scene(main, 600, 200, Color.WHITE);
    scene.getStylesheets().add(ProgressBarDemo.class.getResource("/resources/css/jfoenix-components.css").toExternalForm());
    stage.setTitle("JFX ProgressBar Demo ");
    stage.setScene(scene);
    stage.setResizable(false);
    stage.show();
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) Insets(javafx.geometry.Insets) JFXProgressBar(com.jfoenix.controls.JFXProgressBar) KeyFrame(javafx.animation.KeyFrame) Scene(javafx.scene.Scene) JFXProgressBar(com.jfoenix.controls.JFXProgressBar) ProgressBar(javafx.scene.control.ProgressBar)

Aggregations

Timeline (javafx.animation.Timeline)111 KeyFrame (javafx.animation.KeyFrame)107 KeyValue (javafx.animation.KeyValue)81 Duration (javafx.util.Duration)32 ActionEvent (javafx.event.ActionEvent)22 JFXButton (com.jfoenix.controls.JFXButton)20 IOException (java.io.IOException)19 URL (java.net.URL)19 ResourceBundle (java.util.ResourceBundle)19 FXML (javafx.fxml.FXML)19 Initializable (javafx.fxml.Initializable)18 FXMLLoader (javafx.fxml.FXMLLoader)17 Pane (javafx.scene.layout.Pane)17 AnchorPane (javafx.scene.layout.AnchorPane)16 Level (java.util.logging.Level)15 Logger (java.util.logging.Logger)15 MouseEvent (javafx.scene.input.MouseEvent)14 Rotate (javafx.scene.transform.Rotate)14 JFXTextField (com.jfoenix.controls.JFXTextField)12 Interpolator (javafx.animation.Interpolator)12