1 package kaka.cakelight;
3 import java.io.FileInputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
7 import java.util.stream.Collectors;
9 public class Configuration {
10 private List<Map.Entry<String, String>> settings = new ArrayList<>();
11 public VideoConfiguration video;
12 public LedConfiguration leds;
14 private Configuration(Properties prop) {
15 video = new VideoConfiguration(prop);
16 leds = new LedConfiguration(prop);
19 public static Configuration from(String propertiesFile) {
20 InputStream input = null;
22 input = new FileInputStream(propertiesFile);
23 Properties prop = new Properties();
25 return new Configuration(prop);
26 } catch (IOException ex) {
32 } catch (IOException e) {
40 private String get(Properties prop, String name) {
41 return addSetting(name, prop.getProperty(name));
44 private String get(Properties prop, String name, String dflt) {
45 return addSetting(name, prop.getProperty(name, dflt));
48 private String addSetting(String name, String value) {
49 settings.add(new AbstractMap.SimpleEntry<>(name, value));
54 public String toString() {
55 return settings.stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.joining("\n"));
58 public class VideoConfiguration {
62 public CropConfiguration crop;
64 private VideoConfiguration(Properties prop) {
65 width = Integer.parseInt(get(prop, "video.width", "720"));
66 height = Integer.parseInt(get(prop, "video.height", "576"));
67 bpp = Integer.parseInt(get(prop, "video.bpp", "2"));
68 crop = new CropConfiguration(prop);
71 public class CropConfiguration {
72 public int left, right, top, bottom;
74 private CropConfiguration(Properties prop) {
75 left = Integer.parseInt(get(prop, "video.crop.left", "0"));
76 right = Integer.parseInt(get(prop, "video.crop.right", "0"));
77 top = Integer.parseInt(get(prop, "video.crop.top", "0"));
78 bottom = Integer.parseInt(get(prop, "video.crop.bottom", "0"));
83 public class LedConfiguration {
87 private LedConfiguration(Properties prop) {
88 cols = Integer.parseInt(get(prop, "leds.cols"));
89 rows = Integer.parseInt(get(prop, "leds.rows"));