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