/
DemoApplication.java
81 lines (65 loc) · 3.05 KB
/
DemoApplication.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
package com.lottie4j.fxdemo;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.lottie4j.core.handler.FileLoader;
import com.lottie4j.core.model.Animation;
import com.lottie4j.fxplayer.player.LottiePlayer;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import java.io.File;
import java.util.logging.Logger;
public class DemoApplication extends Application {
private static final Logger logger = Logger.getLogger(DemoApplication.class.getName());
private static final String TEST_FILE_LOTTIE = "/test/timeline-square.json";
private static final String TEST_FILE_IMAGE = "/test/timeline-square.png";
//private static final String TEST_FILE_LOTTIE = "/test/timeline.json";
//private static final String TEST_FILE_IMAGE = "/test/timeline_start.png";
//private static final String TEST_FILE_LOTTIE = "/duke/java_duke_still.json";
//private static final String TEST_FILE_IMAGE = "/duke/java_duke.png";
static {
System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF %1$tT] [%4$-7s] %2$s \t\t %5$s %n");
}
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
var r = this.getClass().getResource(TEST_FILE_LOTTIE);
if (r == null) {
logger.warning("The Lottie file can not be found");
return;
}
var f = new File(r.getFile());
var jsonFromFile = FileLoader.loadFileAsString(f);
var animation = (new ObjectMapper()).readValue(jsonFromFile, Animation.class);
logger.info("Starting with W/H " + animation.width() + "/" + animation.height());
logger.info("Number of assets: " + (animation.assets() == null ? "0" : animation.assets().size()));
logger.info("Number of layers: " + (animation.layers() == null ? "0" : animation.layers().size()));
var player = new LottiePlayer(animation);
var holder = new HBox();
holder.setMinWidth(animation.width() * 2);
holder.setMinHeight(animation.height());
var imageUrl = DemoApplication.class.getResource(TEST_FILE_IMAGE);
if (imageUrl == null) {
logger.warning("The image file can not be found");
} else {
ImageView preview = new ImageView(new Image(imageUrl.toExternalForm()));
preview.setFitHeight(animation.height());
preview.setFitWidth(animation.width());
holder.getChildren().add(preview);
}
var group = new Group();
group.getChildren().add(player);
group.getChildren().add(new TextField(TEST_FILE_LOTTIE));
holder.getChildren().add(group);
var scene = new Scene(holder, animation.width() * 2, animation.height());
primaryStage.setTitle(f.getName());
primaryStage.setScene(scene);
primaryStage.show();
}
}