-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathAnimatedSwitcherTest.java
More file actions
55 lines (45 loc) Β· 1.9 KB
/
AnimatedSwitcherTest.java
File metadata and controls
55 lines (45 loc) Β· 1.9 KB
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
package eu.iamgio.animatedtest;
import eu.iamgio.animated.transition.AnimatedSwitcher;
import eu.iamgio.animated.transition.AnimationPair;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.util.Duration;
import static eu.iamgio.animatedtest.TestUtil.*;
// This demo dynamically generates random rectangles and plays a transition upon attaching it to the screen.
// A zoom-in is played on the 'new' rectangle, while the 'old' one disappears with a zoom-out animation.
public class AnimatedSwitcherTest extends Application {
public void start(Stage primaryStage) {
// Setup scene
Pane root = new Pane();
Scene scene = new Scene(root, SCENE_WIDTH, SCENE_HEIGHT);
// Setup switcher and attach it to the root
AnimatedSwitcher switcher = new AnimatedSwitcher(AnimationPair.zoom().setSpeed(2, .8));
root.getChildren().add(switcher);
// Setup timeline
Timeline timeline = new Timeline();
startTimeline(scene, timeline, switcher);
// Show
primaryStage.setTitle("AnimatedSwitcher");
primaryStage.setScene(scene);
primaryStage.show();
}
// This is called every second
private void startTimeline(Scene scene, Timeline timeline, AnimatedSwitcher switcher) {
// Generate a random rectangle
Pane pane = new Pane(randomRectangle());
// Center it
center(pane, scene);
// Update the child (plays the transition)
switcher.setChild(pane);
// Calls the same function after a 1s delay
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1), e -> startTimeline(scene, timeline, switcher)));
timeline.playFromStart();
}
public static void main(String[] args) {
launch(args);
}
}