Search in sources :

Example 6 with Timeline

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

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

the class JFXSnackbar method show.

public void show(String message, String actionText, long timeout, EventHandler<? super MouseEvent> actionHandler) {
    toast.setText(message);
    if (actionText != null && !actionText.isEmpty()) {
        action.setVisible(true);
        actionContainer.setVisible(true);
        actionContainer.setManaged(true);
        // to force updating the layout bounds
        action.setText("");
        action.setText(actionText);
        action.setOnMouseClicked(actionHandler);
    } else {
        actionContainer.setVisible(false);
        actionContainer.setManaged(false);
        action.setVisible(false);
    }
    Timeline animation = getTimeline(timeout);
    animation.play();
}
Also used : Timeline(javafx.animation.Timeline)

Example 8 with Timeline

use of javafx.animation.Timeline 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 9 with Timeline

use of javafx.animation.Timeline 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)

Example 10 with Timeline

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

the class JFXTabPaneSkin method layoutChildren.

@Override
protected void layoutChildren(final double x, final double y, final double w, final double h) {
    double headerHeight = snapSize(headerContainer.prefHeight(-1));
    headerContainer.resize(w, headerHeight);
    headerContainer.relocate(x, y);
    headerContainerClip.setX(0);
    headerContainerClip.setY(0);
    headerContainerClip.setWidth(w);
    // 10 is the height of the shadow effect
    headerContainerClip.setHeight(headerHeight + 10);
    // position the tab content for the selected tab only
    double contentStartX = 0;
    double contentStartY = 0;
    contentStartX = x;
    contentStartY = y + headerHeight;
    double contentWidth = w - (0);
    double contentHeight = h - (headerHeight);
    Rectangle clip = new Rectangle(contentWidth, contentHeight);
    tabsContainerHolder.setClip(clip);
    tabsContainerHolder.resize(contentWidth, contentHeight);
    tabsContainerHolder.relocate(contentStartX, contentStartY);
    tabsContainer.resize(contentWidth * tabContentHolders.size(), contentHeight);
    for (int i = 0, max = tabContentHolders.size(); i < max; i++) {
        TabContentHolder tabContentHolder = tabContentHolders.get(i);
        tabContentHolder.setVisible(true);
        tabContentHolder.setTranslateX(contentWidth * i);
        if (tabContentHolder.getClip() != null) {
            ((Rectangle) tabContentHolder.getClip()).setWidth(contentWidth);
            ((Rectangle) tabContentHolder.getClip()).setHeight(contentHeight);
        }
        if (tabContentHolder.tab == selectedTab) {
            int index = getSkinnable().getTabs().indexOf(selectedTab);
            if (index != i) {
                tabsContainer.setTranslateX(-contentWidth * i);
                diffTabsIndices = i - index;
            } else {
                // fix X translation after changing the tabs
                if (diffTabsIndices != 0) {
                    tabsContainer.setTranslateX(tabsContainer.getTranslateX() + contentWidth * diffTabsIndices);
                    diffTabsIndices = 0;
                }
                // animate upon tab selection only otherwise just translate the selected tab 
                if (isSelectingTab) {
                    new CachedTransition(tabsContainer, new Timeline(new KeyFrame(Duration.millis(1000), new KeyValue(tabsContainer.translateXProperty(), -contentWidth * index, Interpolator.EASE_BOTH)))) {

                        {
                            setCycleDuration(Duration.seconds(0.320));
                            setDelay(Duration.seconds(0));
                        }
                    }.play();
                } else
                    tabsContainer.setTranslateX(-contentWidth * index);
            }
        }
        tabContentHolder.resize(contentWidth, contentHeight);
    }
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) Rectangle(javafx.scene.shape.Rectangle) KeyFrame(javafx.animation.KeyFrame) CachedTransition(com.jfoenix.transitions.CachedTransition)

Aggregations

Timeline (javafx.animation.Timeline)91 KeyFrame (javafx.animation.KeyFrame)87 KeyValue (javafx.animation.KeyValue)77 Rotate (javafx.scene.transform.Rotate)14 MouseEvent (javafx.scene.input.MouseEvent)13 Duration (javafx.util.Duration)13 Interpolator (javafx.animation.Interpolator)12 Insets (javafx.geometry.Insets)9 PerspectiveCamera (javafx.scene.PerspectiveCamera)9 Scene (javafx.scene.Scene)8 ActionEvent (javafx.event.ActionEvent)7 Group (javafx.scene.Group)7 Node (javafx.scene.Node)7 KeyCode (javafx.scene.input.KeyCode)7 Color (javafx.scene.paint.Color)7 AnimationTimer (javafx.animation.AnimationTimer)6 EventHandler (javafx.event.EventHandler)6 Label (javafx.scene.control.Label)6 Rectangle (javafx.scene.shape.Rectangle)6 ArrayList (java.util.ArrayList)5