1 package de.lathanda.eos.robot.gui;
4 import java.io.FileInputStream;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7 import java.io.InputStream;
8 import java.io.OutputStream;
9 import java.util.LinkedList;
10 import java.util.Properties;
11 import de.lathanda.eos.base.ResourceLoader;
23 private Properties configuration;
24 private boolean dirty;
26 private int fallheight;
27 private int jumpheight;
32 }
catch (Exception e) {
36 private void load() throws IOException {
37 String home = System.getProperty(
"user.home");
38 File file =
new File(home +
"/.eos/config.ini");
40 try (InputStream in =
new FileInputStream(file)) {
44 try (InputStream in = ResourceLoader.getResourceAsStream(
"config.ini")) {
50 public void save() throws IOException {
51 String home = System.getProperty(
"user.home");
52 File dir =
new File(home +
"/.eos");
53 File file =
new File(home +
"/.eos/config.ini");
54 if (!(dir.exists() && dir.isDirectory())) {
57 save(
new FileOutputStream(file));
60 private void load(InputStream in)
throws IOException {
61 configuration =
new Properties();
62 configuration.load(in);
63 fallheight = Integer.valueOf(configuration.getProperty(
"fallheight"));
64 jumpheight = Integer.valueOf(configuration.getProperty(
"jumpheight"));
68 private void save(OutputStream out)
throws IOException {
69 configuration.setProperty(
"fallheight", Integer.toString(fallheight));
70 configuration.setProperty(
"jumpheight", Integer.toString(jumpheight));
71 configuration.store(out,
"EOS Configuration");
79 private void setDefault() {
88 if (this.fallheight != fallheight) {
89 this.fallheight = fallheight;
97 if (this.jumpheight != jumpheight) {
98 this.jumpheight = jumpheight;
103 private LinkedList<ConfigurationListener> configurationListener =
new LinkedList<>();
105 configurationListener.add(cf);
108 configurationListener.remove(cf);
112 configurationListener.forEach(cf -> cf.robotConfigurationChanged(fallheight, jumpheight));
synchronized void removeConfigurationListener(ConfigurationListener cf)
synchronized void addConfigurationListener(ConfigurationListener cf)
void setJumpheight(int jumpheight)
static final Configuration def
void setFallheight(int fallheight)
synchronized void fireRobotConfigurationChanged()
default void robotConfigurationChanged(int fallheight, int jumpheight)