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();
}
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();
}
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);
}
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)));
}
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;
}
}
Aggregations