-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathAnimatedContainerTest.java
88 lines (68 loc) · 3.07 KB
/
AnimatedContainerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package eu.iamgio.animatedtest;
import animatefx.animation.FadeInUp;
import animatefx.animation.SlideOutLeft;
import eu.iamgio.animated.binding.Animated;
import eu.iamgio.animated.binding.presets.AnimatedOpacity;
import eu.iamgio.animated.common.Curve;
import eu.iamgio.animated.transition.AnimationPair;
import eu.iamgio.animated.transition.container.AnimatedVBox;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;
import static eu.iamgio.animatedtest.TestUtil.*;
// This demo animates the content of multi-children containers, such as VBoxes.
public class AnimatedContainerTest extends Application {
@Override
public void start(Stage primaryStage) {
// Setup scene
Pane root = new Pane();
Scene scene = new Scene(root, SCENE_WIDTH, SCENE_HEIGHT);
// Setup container
AnimatedVBox vBox = new AnimatedVBox(new AnimationPair(new FadeInUp(), new SlideOutLeft()).setSpeed(3, 3));
// Also try HBox:
// AnimatedHBox hBox = new AnimatedHBox(new AnimationPair(new FadeInDown(), new SlideOutUp()).setSpeed(3, 3));
// Setup + buttons
Button topButton = new Button("+ Add on top");
topButton.setPrefWidth(150);
topButton.relocate(400, 100);
topButton.setOnAction(e -> vBox.getChildren().add(0, new RectangleButton(vBox)));
Button bottomButton = new Button("+ Add on bottom");
bottomButton.setPrefWidth(150);
bottomButton.relocate(400, 150);
bottomButton.setOnAction(e -> vBox.getChildren().add(new RectangleButton(vBox)));
root.getChildren().addAll(vBox, topButton, bottomButton);
// Show
primaryStage.setTitle("AnimatedContainer");
primaryStage.setScene(scene);
primaryStage.show();
}
private static class RectangleButton extends AnchorPane {
// Random-colored rectangle with a "Click to remove" text that appears on hover on it.
public RectangleButton(Pane parent) {
Rectangle rectangle = randomRectangle();
setPrefSize(100, 100);
rectangle.setWidth(100);
rectangle.setHeight(100);
Label text = new Label("Click to remove");
text.setPrefSize(100, 100);
text.setAlignment(Pos.CENTER);
text.setOpacity(0);
hoverProperty().addListener((observable, oldValue, isHover) -> text.setOpacity(isHover ? 1 : 0));
StackPane.setAlignment(text, Pos.CENTER);
getChildren().addAll(
rectangle,
new Animated(text, new AnimatedOpacity())
.custom(settings -> settings.withDuration(Duration.millis(150)).withCurve(Curve.EASE_IN_OUT))
);
setOnMouseClicked(ev -> parent.getChildren().remove(this));
}
}
}