diff --git a/simulation/src/de/c3ma/ollo/WS2812Simulation.java b/simulation/src/de/c3ma/ollo/WS2812Simulation.java index 073942d..148e20f 100644 --- a/simulation/src/de/c3ma/ollo/WS2812Simulation.java +++ b/simulation/src/de/c3ma/ollo/WS2812Simulation.java @@ -4,7 +4,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; -import javax.management.RuntimeErrorException; import javax.swing.SwingUtilities; import org.luaj.vm2.Globals; @@ -128,7 +127,7 @@ public class WS2812Simulation implements LuaSimulation { private void setWS2812Layout(File file) { if (file.exists()) { - ws2812.setLayout(file); + ws2812.setLayout(file, this); } else { throw new RuntimeException("WS2812 Layout: " + file.getAbsolutePath() + " does not exists"); } diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java index a6fc6c3..ee5e04e 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java +++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java @@ -11,6 +11,7 @@ import org.luaj.vm2.lib.OneArgFunction; import org.luaj.vm2.lib.TwoArgFunction; import org.luaj.vm2.lib.ZeroArgFunction; +import de.c3ma.ollo.LuaSimulation; import de.c3ma.ollo.mockup.ui.WS2812Layout; /** @@ -79,9 +80,9 @@ public class ESP8266Ws2812 extends TwoArgFunction { } } - public void setLayout(File file) { + public void setLayout(File file, LuaSimulation nodemcuSimu) { if (ESP8266Ws2812.layout == null) { - ESP8266Ws2812.layout = WS2812Layout.parse(file); + ESP8266Ws2812.layout = WS2812Layout.parse(file, nodemcuSimu); } } } diff --git a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java index bcf22c3..935b40d 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java +++ b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java @@ -10,7 +10,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import javax.swing.BorderFactory; @@ -18,7 +17,8 @@ import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.SwingUtilities; + +import de.c3ma.ollo.LuaSimulation; /** * created at 02.01.2018 - 12:57:02
@@ -40,14 +40,20 @@ public class WS2812Layout extends JFrame { private int mRow = 0; private Element[][] mElements; - public static WS2812Layout parse(File file) { + private LuaSimulation nodemcuSimu; + + public WS2812Layout(LuaSimulation nodemcuSimu) { + this.nodemcuSimu = nodemcuSimu; + } + + public static WS2812Layout parse(File file, LuaSimulation nodemcuSimu) { WS2812Layout layout = null; try { BufferedReader br = new BufferedReader(new FileReader(file)); try { String line = br.readLine(); if (line != null) { - layout = new WS2812Layout(); + layout = new WS2812Layout(nodemcuSimu); } while (line != null) { @@ -92,15 +98,18 @@ public class WS2812Layout extends JFrame { } } contentPane.add(ledPanel, BorderLayout.CENTER); - JButton button = new JButton("Do something"); - button.setActionCommand("Do something"); - button.addActionListener(new ActionListener() { + final JButton btnReboot = new JButton("Reboot"); + btnReboot.setActionCommand("Reboot simulation"); + btnReboot.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JButton but = (JButton) ae.getSource(); - // FIXME some clever logic + if (but.equals(btnReboot)) { + System.out.println("[Node] Restart"); + nodemcuSimu.rebootTriggered(); + } } }); - contentPane.add(button, BorderLayout.SOUTH); + contentPane.add(btnReboot, BorderLayout.SOUTH); setContentPane(contentPane); pack();