Browse Source

Refactors Simulation

* Simulation moved to SimulationManager
* Access via SimulationController
* Multiple SimulationConfigurator represent the same simulation
Andreas T. Meyer-Berg 5 years ago
parent
commit
96e372902f

+ 162 - 16
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/SimulationController.java

@@ -1,9 +1,10 @@
 package de.tu_darmstadt.tk.SmartHomeNetworkSim.control;
 
+import java.io.File;
+import java.util.Observer;
+
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SimulationManager;
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
 
 /**
  * Controller which enables configuration and manipulation of the simulation
@@ -22,7 +23,10 @@ public class SimulationController {
 	 * Model which can be manipulated
 	 */
 	private Model model;
-	
+	/**
+	 * Simulation Manager
+	 */
+	private SimulationManager sim;
 	/**
 	 * Creates a new Simulation
 	 * @param model
@@ -31,28 +35,170 @@ public class SimulationController {
 	public SimulationController(Model model, Controller controller) {
 		this.model = model;
 		this.controller = controller;
+		this.sim = model.getSim();
 	}
 
 	/**
-	 * Reset Simulation 
+	 * Returns the Simulation Manager of the Program
+	 * 
+	 * @return Simulation Manager
+	 */
+	public SimulationManager getSimulationManager() {
+		return model.getSim();
+	}
+	
+	/**
+	 * Returns true if the simulations will print the packets
 	 * 
-	 * @param controller TODO
-	 * @param timestep
+	 * @return if the packets are printed
 	 */
-	public void resetSimulation(long timestep){
-		for(SmartDevice d: model.getDevices())
-			for(Port p:d.getPorts())
-				if(p.getLastTrigger()>timestep)
-					p.setLastTrigger(timestep);
+	public boolean getPrintPackets() {
+		return sim.getPrintPackets();
 	}
 
 	/**
-	 * Returns the Simulation Manager of the Program
+	 * Sets Print Packets, if true, the simulation will print the packets
+	 * @param printPackets true if simulation should print the packets
+	 */
+	public void setPrintPackets(boolean printPackets) {
+		sim.setPrintPackets(printPackets);
+	}
+
+	/**
+	 * Get BaseFile of packet exports
 	 * 
-	 * @param controller TODO
-	 * @return Simulation Manager
+	 * @return ExportFile File, where the packets are written to
 	 */
-	public SimulationManager getSimulationManager() {
-		return model.getSim();
+	public File getExportFile() {
+		return sim.getExportFile();
+	}
+	
+	/**
+	 * Set BaseFile for the packet export
+	 * 
+	 * @param exportFile File, where the packets are written to
+	 */
+	public void setExportFile(File exportFile) {
+		sim.setExportFile(exportFile);
+	}
+
+	/**
+	 * True if each links uses a separated File: e.g. exportFile_link.log
+	 * @return true, if each links uses a single file for export
+	 */
+	public boolean isSplitLinkExportFiles() {
+		return sim.isSplitLinkExportFiles();
+	}
+
+	/**
+	 * Set whether packets should be split into different files for each link
+	 * @param splitLinkExportFiles true if each link should export to a single file
+	 */
+	public void setSplitLinkExportFiles(boolean splitLinkExportFiles) {
+		sim.setSplitLinkExportFiles(splitLinkExportFiles);
+	}
+	
+	/**
+	 * Start the simulation
+	 */
+	public void startSimulation(){
+		sim.startSimulation();
+	}
+	
+	/**
+	 * Stop the simulation
+	 */
+	public void stopSimulation(){
+		sim.stopSimulation();
+	}
+	
+	public void resetSimulation(){
+		sim.resetSimulation();
+	}
+	
+	/**
+	 * Returns true if the simulation is running, false if not
+	 * @return
+	 */
+	public boolean isRunning(){
+		return sim.isRunning();
+	}
+	
+	/**
+	 * Returns the StartTime of the simulation
+	 * @return startTime
+	 */
+	public long getStartTime(){
+		return sim.getStartTime();
+	}
+	
+	/**
+	 * Sets the new startTime
+	 * @param startTime time the simulations starts
+	 */
+	public void setStartTime(long startTime){
+		sim.setStartTime(startTime);
+	}
+	
+	/**
+	 * Returns the end time of the simulation
+	 * @return End time of the simulation
+	 */
+	public long getEndTime(){
+		return sim.getEndTime();
+	}
+	
+	/**
+	 * Sets the new startTime
+	 * @return true on success
+	 */
+	public void setEndTime(long endTime){
+		sim.setEndTime(endTime);;
+	}
+	
+	/**
+	 * @return the currentTime
+	 */
+	public long getCurrentTime() {
+		return sim.getCurrentTime();
+	}
+
+	/**
+	 * @param currentTime the currentTime to set
+	 */
+	public void setCurrentTime(long currentTime) {
+		sim.setCurrentTime(currentTime);
+	}
+
+	/**
+	 * Returns the simulation step duration in milliseconds
+	 * @return duration of each simulation step in milliseconds
+	 */
+	public long getStepDuration(){
+		return sim.getStepDuration();
+	}
+	
+	/**
+	 * Sets the duration of simulation steps
+	 * @param duration duration in milliseconds of a step
+	 */
+	public void setStepDuration(long duration){
+		sim.setStepDuration(duration);
+	}
+	
+	/**
+	 * Adds observer, which will receive an notification on each time step
+	 * @param o Observer, which should be notified
+	 */
+	public void addObserver(Observer o){
+		sim.addObserver(o);
+	}
+	
+	/**
+	 * Removes Observer from the simulation, will no longer be notified on step change
+	 * @param o Observer to be removed
+	 */
+	public void removeObserver(Observer o){
+		sim.deleteObserver(o);
 	}
 }

+ 228 - 14
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/SimulationManager.java

@@ -4,32 +4,67 @@ import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.util.Observable;
+
+import javax.swing.Timer;
 
 /**
  * Manages the Simulation by calling the relevant methods.
  *
  * @author Andreas T. Meyer-Berg
  */
-public class SimulationManager {
+public class SimulationManager extends Observable{
 	/**
 	 * Model which should be simulated
 	 */
-	Model model;
+	private Model model;
 	
 	/**
 	 * True if packets should be printed
 	 */
-	boolean printPackets = false;
+	private boolean printPackets = false;
 	
 	/**
 	 * Whether the model status changed during the last simulation and the panel should be repainted
 	 */
-	boolean statusChanged = false;
+	private boolean statusChanged = false;
 	
 	/**
 	 * Writer to write the packets to a file
 	 */
-	BufferedWriter writer;
+	private BufferedWriter writer;
+	
+	/**
+	 * Base File for the exported Packages
+	 */
+	private File exportFile = new File("testPackets.log");
+	
+	/**
+	 * Split Links into differentFiles
+	 */
+	private boolean splitLinkExportFiles = false;
+	
+	/**
+	 * Timer which triggers each simulation step
+	 */
+	private Timer timer;
+	
+	/**
+	 * First Timestep of the simulation
+	 */
+	private long startTime = 0L;
+	/**
+	 * Last Timestep of the simulation
+	 */
+	private long endTime = 1000L;
+	/**
+	 * Current TimeStep in the simulation
+	 */
+	private long currentTime = 0L;
+	/**
+	 * Duration of the simulation
+	 */
+	private long duration = 100L;
 	
 	/**
 	 * Creates a new Simulationmanager
@@ -38,8 +73,25 @@ public class SimulationManager {
 	 */
 	public SimulationManager(Model model) {
 		this.model = model;
+		timer = new Timer(0, t -> simulateTimeStep());
 	}
-
+	
+	/**
+	 * Simulate the nexte Timestep
+	 */
+	private void simulateTimeStep(){
+		//Just simulate if timer is running
+		if(endTime <= currentTime)
+			stopSimulation();
+		if(currentTime + duration <= endTime){
+			simulateTimeIntervall(currentTime, duration);
+			currentTime += duration;
+		}else{
+			simulateTimeIntervall(currentTime,endTime-currentTime);
+			currentTime = endTime;
+		}
+	}
+	
 	/**
 	 * Simulates one time step at a given time fur a given duration
 	 * 
@@ -71,6 +123,14 @@ public class SimulationManager {
 			model.setChanged();
 			model.notifyObservers();
 		}
+		exportPacketsOfLastTimeStep();
+	}
+
+	/**
+	 * Exports the packets which were sent during the last time step according to the settings 
+	 * (whether packages should be printed, specified export File, splitLinks setting etc.)
+	 */
+	public void exportPacketsOfLastTimeStep() {
 		if(printPackets){
 			try {
 				File f = new File("testPackets.log");
@@ -97,10 +157,15 @@ public class SimulationManager {
 					} catch (IOException e) {}				
 			}
 		}
-		
-		
-		
-		
+	}
+	
+	/**
+	 * Returns true if the simulations will print the packets
+	 * 
+	 * @return if the packets are printed
+	 */
+	public boolean getPrintPackets() {
+		return printPackets;
 	}
 
 	/**
@@ -109,14 +174,163 @@ public class SimulationManager {
 	 */
 	public void setPrintPackets(boolean printPackets) {
 		this.printPackets = printPackets;
+		notifyPanels();
 	}
 
 	/**
-	 * Returns true if the simulations will print the packets
+	 * Get BaseFile of packet exports
 	 * 
-	 * @return if the packets are printed
+	 * @return ExportFile File, where the packets are written to
 	 */
-	public boolean getPrintPackets() {
-		return printPackets;
+	public File getExportFile() {
+		return exportFile;
+	}
+	
+	/**
+	 * Set BaseFile for the packet export
+	 * 
+	 * @param exportFile File, where the packets are written to
+	 */
+	public void setExportFile(File exportFile) {
+		this.exportFile = exportFile;
+		notifyPanels();
+	}
+
+	/**
+	 * True if each links uses a separated File: e.g. exportFile_link.log
+	 * @return true, if each links uses a single file for export
+	 */
+	public boolean isSplitLinkExportFiles() {
+		return splitLinkExportFiles;
+	}
+
+	/**
+	 * Set whether packets should be split into different files for each link
+	 * @param splitLinkExportFiles true if each link should export to a single file
+	 */
+	public void setSplitLinkExportFiles(boolean splitLinkExportFiles) {
+		this.splitLinkExportFiles = splitLinkExportFiles;
+		notifyPanels();
+	}
+	
+	/**
+	 * Start the simulation
+	 */
+	public void startSimulation(){
+		timer.start();
+		notifyPanels();
+	}
+	
+	/**
+	 * Stop the simulation
+	 */
+	public void stopSimulation(){
+		timer.stop();
+		notifyPanels();
+	}
+	
+	/**
+	 * Resets the Simulation to the start time
+	 */
+	public void resetSimulation(){
+		timer.stop();
+		timer = new Timer(0, a -> simulateTimeStep());
+		currentTime = startTime;
+		resetSimulation(currentTime);
+		notifyPanels();
+	}
+	
+	/**
+	 * Reset Simulation 
+	 * 
+	 * @param timestep
+	 */
+	public void resetSimulation(long timestep){
+		for(SmartDevice d: model.getDevices())
+			for(Port p:d.getPorts())
+				if(p.getLastTrigger()>timestep)
+					p.setLastTrigger(timestep);
+	}
+	
+	/**
+	 * Returns true if the simulation is running, false if not
+	 * @return
+	 */
+	public boolean isRunning(){
+		return timer.isRunning();
+	}
+	
+	/**
+	 * Returns the StartTime of the simulation
+	 * @return startTime
+	 */
+	public long getStartTime(){
+		return startTime;
+	}
+	
+	/**
+	 * Sets the new startTime
+	 * @param startTime time the simulations starts
+	 */
+	public void setStartTime(long startTime){
+		this.startTime = startTime;
+		notifyPanels();
+	}
+	
+	/**
+	 * Returns the end time of the simulation
+	 * @return End time of the simulation
+	 */
+	public long getEndTime(){
+		return endTime;
+	}
+	
+	/**
+	 * Sets the new startTime
+	 * @return true on success
+	 */
+	public void setEndTime(long endTime){
+		this.endTime = endTime;
+		notifyPanels();
+	}
+	
+	/**
+	 * @return the currentTime
+	 */
+	public long getCurrentTime() {
+		return currentTime;
+	}
+
+	/**
+	 * @param currentTime the currentTime to set
+	 */
+	public void setCurrentTime(long currentTime) {
+		this.currentTime = currentTime;
+		notifyPanels();
+	}
+
+	/**
+	 * Returns the simulation step duration in milliseconds
+	 * @return duration of each simulation step in milliseconds
+	 */
+	public long getStepDuration(){
+		return duration;
+	}
+	
+	/**
+	 * Sets the duration of simulation steps
+	 * @param duration duration in milliseconds of a step
+	 */
+	public void setStepDuration(long duration){
+		this.duration = duration;
+		notifyPanels();
+	}
+	
+	/**
+	 * Notify the panels, which could update their GUI
+	 */
+	private void notifyPanels(){
+		this.setChanged();
+		this.notifyObservers();
 	}
 }

+ 3 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualisationPanel.java

@@ -126,6 +126,9 @@ public class VisualisationPanel extends JPanel implements Observer {
 			 * Graphics2D options, if enabled on the machine
 			 */
 			Graphics2D graphics = (Graphics2D) g;
+			/**
+			 * Rendering Options for the visualization
+			 */
 			RenderingHints renders = new RenderingHints(new HashMap<>());
 			/**
 			 * Add AntiAliasing

+ 205 - 114
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/popups/SimulationConfigurator.java

@@ -1,21 +1,25 @@
 package de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups;
 
-import javax.swing.JFrame;
-import javax.swing.JProgressBar;
-import javax.swing.JSeparator;
-
+import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Rectangle;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.Observable;
+import java.util.Observer;
 
 import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JProgressBar;
+import javax.swing.JSeparator;
 import javax.swing.JLabel;
-import javax.swing.JOptionPane;
 import javax.swing.JTextField;
-import javax.swing.Timer;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
 
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SimulationController;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SimulationManager;
 
 import javax.swing.JCheckBox;
 
@@ -25,7 +29,7 @@ import javax.swing.JCheckBox;
  * @author Andreas T. Meyer-Berg
  */
 @SuppressWarnings("serial")
-public class SimulationConfigurator extends JFrame {
+public class SimulationConfigurator extends JFrame implements Observer{
 	/**
 	 * Textfield for editing the start time
 	 */
@@ -38,6 +42,10 @@ public class SimulationConfigurator extends JFrame {
 	 * Textfield for editing the step duration
 	 */
 	private JTextField tfStepDuration;
+	/**
+	 * Checkbox if packets should be printed
+	 */
+	private JCheckBox chckbxPrintpackets;
 	/**
 	 * Label which shows the name of the export File
 	 */
@@ -45,7 +53,7 @@ public class SimulationConfigurator extends JFrame {
 	/**
 	 * Label which shows the current Time of the simulation
 	 */
-	private JLabel lbCurrentTimeShow;
+	private JLabel lblCurrentTimeShow;
 	/**
 	 * Button for starting/stopping the simulation
 	 */
@@ -57,33 +65,21 @@ public class SimulationConfigurator extends JFrame {
 	 */
 	private JProgressBar progressBar;
 	/**
-	 * Timer which triggers each simulation step
-	 */
-	private Timer timer;
-	/**
-	 * SimulationManager, which simulates the network
-	 */
-	private SimulationManager sim;
-	/**
-	 * Current Time in the simulation
-	 */
-	private long currentTime = 0;
-	/**
-	 * Start Time of the Simulation, as presented in long
+	 * Controller of the Application
 	 */
-	private long startTime = 0;
+	private Controller controller;
 	/**
-	 * Duration of each simulation step
+	 * Simulation controller
 	 */
-	private long duration = 100;
+	private SimulationController sim;
 	/**
-	 * End Time of the simulation
+	 * Reference to this instance for inner classes
 	 */
-	private long endTime = 1000;
+	private SimulationConfigurator that = this;
 	/**
-	 * Controller of the Application
+	 * Mutex to disable
 	 */
-	Controller controller;
+	private boolean mutex = false;
 
 	/**
 	 * Create a new SimulationConfigurator Panel, which controls the given
@@ -93,11 +89,18 @@ public class SimulationConfigurator extends JFrame {
 	 */
 	public SimulationConfigurator(Controller control) {
 		this.controller = control;
-		this.sim = controller.getSimulationController().getSimulationManager();
-		
+		this.sim = controller.getSimulationController();
+		sim.addObserver(this);
+		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
+		this.addWindowListener(new WindowAdapter() {
+			@Override
+			public void windowClosing(WindowEvent e) {
+				sim.removeObserver(that);
+			}
+		});
+
 		this.getContentPane().setMinimumSize(new Dimension(640, 310));
 		this.setBounds(new Rectangle(0, 0, 640, 310));
-		//setBounds(new Rectangle(0, 0, 640, 290));
 		setResizable(false);
 		getContentPane().setLayout(null);
 		this.setTitle("Simulation Configuration");
@@ -126,17 +129,17 @@ public class SimulationConfigurator extends JFrame {
 		getContentPane().add(lblStarttimeLong);
 
 		tfStartTimeLong = new JTextField();
-		tfStartTimeLong.setText("" + startTime);
 		tfStartTimeLong.setBounds(160, 40, 130, 20);
 		getContentPane().add(tfStartTimeLong);
 		tfStartTimeLong.setColumns(10);
+		tfStartTimeLong.setText(sim.getStartTime()+"");
+		
 
 		JLabel lblEndtimeLong = new JLabel("End Time (in ms):");
 		lblEndtimeLong.setBounds(300, 40, 160, 20);
 		getContentPane().add(lblEndtimeLong);
 		
 		tfEndTimeLong = new JTextField();
-		tfEndTimeLong.setText("" + endTime);
 		tfEndTimeLong.setBounds(450, 40, 130, 20);
 		getContentPane().add(tfEndTimeLong);
 		tfEndTimeLong.setColumns(10);
@@ -146,7 +149,6 @@ public class SimulationConfigurator extends JFrame {
 		getContentPane().add(lblStepDuration);
 		
 		tfStepDuration = new JTextField();
-		tfStepDuration.setText("" + duration);
 		tfStepDuration.setBounds(160, 70, 130, 20);
 		getContentPane().add(tfStepDuration);
 		tfStepDuration.setColumns(10);
@@ -163,11 +165,9 @@ public class SimulationConfigurator extends JFrame {
 		getContentPane().add(lblConfigureExports);
 		
 
-		JCheckBox chckbxPrintpackets = new JCheckBox("print Packets");
+		chckbxPrintpackets = new JCheckBox("print Packets");
 		chckbxPrintpackets.setBounds(10, 130, 120, 20);
-		chckbxPrintpackets.setSelected(sim.getPrintPackets());
 		getContentPane().add(chckbxPrintpackets);
-		chckbxPrintpackets.addActionListener(l -> sim.setPrintPackets(chckbxPrintpackets.isSelected()));
 		chckbxPrintpackets
 		.setToolTipText("Print Packets as human readable String to testPackets.log in the projekt folder.");
 		
@@ -175,7 +175,7 @@ public class SimulationConfigurator extends JFrame {
 		btnExportFile.setBounds(140, 130, 180, 20);
 		getContentPane().add(btnExportFile);
 		
-		lblExportFileName = new JLabel("ExportFileName");
+		lblExportFileName = new JLabel();
 		lblExportFileName.setBounds(330, 130, 300, 20);
 		getContentPane().add(lblExportFileName);
 		
@@ -194,96 +194,29 @@ public class SimulationConfigurator extends JFrame {
 		lblCurrentTime.setBounds(10, 190, 100, 20);
 		getContentPane().add(lblCurrentTime);
 
-		lbCurrentTimeShow = new JLabel("0 ms");
-		lbCurrentTimeShow.setBounds(120, 190, 120, 20);
-		lbCurrentTimeShow.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
-		getContentPane().add(lbCurrentTimeShow);
+		lblCurrentTimeShow = new JLabel();
+		lblCurrentTimeShow.setBounds(120, 190, 120, 20);
+		lblCurrentTimeShow.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
+		getContentPane().add(lblCurrentTimeShow);
 
 		btnStartStop = new JButton("Start Simulation");
 		btnStartStop.setBounds(10, 220, 150, 40);
 		getContentPane().add(btnStartStop);
-		btnStartStop.addActionListener(a -> startStopButtonAction());
+		
 		
 		JButton btnReset = new JButton("Reset");
 		btnReset.setBounds(170, 220, 150, 40);
+		btnReset.addActionListener(a -> sim.resetSimulation());
 		getContentPane().add(btnReset);
-		btnReset.addActionListener(a -> resetAction());
 
 		progressBar = new JProgressBar();
 		progressBar.setBounds(0, 270, this.getWidth(), 20);
 		getContentPane().add(progressBar);
-		progressBar.setValue(0);
 		progressBar.setMinimum(0);
 		progressBar.setMaximum(10000);
-	}
-
-	/**
-	 * Action which should happen if the StartStop Button is pressed
-	 */
-	private void startStopButtonAction() {
-		if (timer == null) {
-			try {
-				timer = new Timer(0, a -> simulateTimeStep());
-				currentTime = Long.parseLong(tfStartTimeLong.getText());
-				endTime = Long.parseLong(tfEndTimeLong.getText());
-				startTime = Long.parseLong(tfStartTimeLong.getText());
-				duration = Long.parseLong(tfStepDuration.getText());
-				progressBar.setValue(0);
-				lbCurrentTimeShow.setText(currentTime + " ms");
-			} catch (Exception e) {
-				JOptionPane.showMessageDialog(this, "Following Error occured: " + e.toString(),
-						"Error while configuring simulation ", JOptionPane.ERROR_MESSAGE);
-				// Don't start the timer
-				timer.stop();
-				timer = null;
-				return;
-			}
-		}
-		if (timer.isRunning()) {
-			timer.stop();
-			btnStartStop.setText("Start Simulation");
-		} else {
-			timer.start();
-			btnStartStop.setText("Stop Simulation");
-		}
-	}
-
-	/**
-	 * Action for the reset Button
-	 */
-	private void resetAction() {
-		try {
-			currentTime = Long.parseLong(tfStartTimeLong.getText());
-			endTime = Long.parseLong(tfEndTimeLong.getText());
-			startTime = Long.parseLong(tfStartTimeLong.getText());
-			duration = Long.parseLong(tfStepDuration.getText());
-			progressBar.setValue(0);
-			lbCurrentTimeShow.setText(currentTime + " ms");
-			controller.getSimulationController().resetSimulation(currentTime);
-		} catch (Exception e) {
-			JOptionPane.showMessageDialog(this, "Following Error occured:\n" + e.toString(),
-					"Error while configuring simulation ", JOptionPane.ERROR_MESSAGE);
-		}
-		if (timer == null)
-			return;
-		timer.stop();
-	}
-
-	/**
-	 * Simulates the next TimeStep
-	 */
-	private void simulateTimeStep() {
-		if (currentTime >= endTime) {
-			timer.stop();
-			btnStartStop.setText("Start Simulation");
-			return;
+		this.update(null,null);
+		initializeListener();
 		}
-		duration = currentTime + duration > endTime ? endTime - currentTime : duration;
-		sim.simulateTimeIntervall(currentTime, duration);
-		currentTime += duration;
-		progressBar.setValue((int) ((currentTime - startTime) * 10000 / (endTime - startTime)));
-		lbCurrentTimeShow.setText(currentTime + " ms");
-	}
 
 	/**
 	 * Test the GUI
@@ -297,4 +230,162 @@ public class SimulationConfigurator extends JFrame {
 		simConfig.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
 	}
+
+	@Override
+	public void update(Observable o, Object arg) {
+		long currentTime = sim.getCurrentTime();
+		long startTime = sim.getStartTime();
+		long endTime = sim.getEndTime();
+		long duration = sim.getStepDuration();
+		if(!mutex){
+			tfStartTimeLong.setText("" + startTime);
+			tfStartTimeLong.setBackground(Color.WHITE);
+			tfEndTimeLong.setText("" + endTime);
+			tfEndTimeLong.setBackground(Color.WHITE);
+			tfStepDuration.setText("" + duration);
+			tfStepDuration.setBackground(Color.WHITE);
+		}
+		chckbxPrintpackets.setSelected(sim.getPrintPackets());
+		lblExportFileName.setText(sim.getExportFile().getPath());
+		lblCurrentTimeShow.setText(currentTime+" ms");
+		if(endTime!=startTime)
+			progressBar.setValue((int) ((currentTime - startTime) * 10000 / (endTime - startTime)));
+		else
+			progressBar.setValue(10000);
+		
+		//Prevent manipulation of parameters during simulation
+		tfStartTimeLong.setEditable(!sim.isRunning());
+		tfEndTimeLong.setEditable(!sim.isRunning());
+		tfStepDuration.setEditable(!sim.isRunning());
+		
+		//Change Button Text
+		if (sim.isRunning()) {
+			btnStartStop.setText("Stop Simulation");
+		} else {
+			btnStartStop.setText("Start Simulation");
+		}
+		mutex = false;
+		
+	}
+	
+	/**
+	 * Add listeners to the different Textfields, Buttons etc.
+	 */
+	private void initializeListener(){
+		/**
+		 * Start Time listener
+		 */
+		tfStartTimeLong.getDocument().addDocumentListener(new DocumentListener() {
+			@Override
+			public void removeUpdate(DocumentEvent e) {update(e);}
+			@Override
+			public void insertUpdate(DocumentEvent e) {update(e);}
+			@Override
+			public void changedUpdate(DocumentEvent e) {update(e);}
+			
+			private void update(DocumentEvent e){
+				if(mutex)return;//Skip if document change in progress
+				try{
+					/**
+					 * Parsed Long
+					 */
+					long l = Long.parseLong(tfStartTimeLong.getText());
+					if(!sim.isRunning()){
+						/**
+						 * Set Mutex, to disable document change
+						 */
+						mutex = true;
+						try{
+							/**
+							 * Catch InvalidStateException, change startTime
+							 */
+							sim.setStartTime(l);
+						}catch(Exception e1){}
+						mutex = false;
+						tfStartTimeLong.setBackground(Color.WHITE);
+						return;
+					}
+					tfStartTimeLong.setBackground(Color.WHITE);
+				}catch(Exception e1){
+					/**
+					 * Invalid Long -> Red Background
+					 */
+					tfStartTimeLong.setBackground(Color.RED);					
+				}
+			}
+		});
+		/**
+		 * End time listener
+		 */
+		tfEndTimeLong.getDocument().addDocumentListener(new DocumentListener() {
+			@Override
+			public void removeUpdate(DocumentEvent e) {update(e);}
+			@Override
+			public void insertUpdate(DocumentEvent e) {update(e);}
+			@Override
+			public void changedUpdate(DocumentEvent e) {update(e);}
+			
+			private void update(DocumentEvent e){
+				if(mutex)return;
+				try{
+					long l = Long.parseLong(tfEndTimeLong.getText());
+					if(!sim.isRunning()){
+						mutex = true;
+						try{
+							sim.setEndTime(l);
+						}catch(Exception e1){}
+						mutex = false;
+						tfEndTimeLong.setBackground(Color.WHITE);
+						return;
+					}
+					tfEndTimeLong.setBackground(Color.WHITE);
+				}catch(Exception e1){
+					tfEndTimeLong.setBackground(Color.RED);					
+				}
+			}
+		});
+		/**
+		 * Step duration listener
+		 */
+		tfStepDuration.getDocument().addDocumentListener(new DocumentListener() {
+			@Override
+			public void removeUpdate(DocumentEvent e) {update(e);}
+			@Override
+			public void insertUpdate(DocumentEvent e) {update(e);}
+			@Override
+			public void changedUpdate(DocumentEvent e) {update(e);}
+			
+			private void update(DocumentEvent e){
+				if(mutex)return;
+				try{
+					long l = Long.parseLong(tfStepDuration.getText());
+					if(!sim.isRunning()){
+						mutex = true;
+						try{
+							sim.setStepDuration(l);
+						}catch(Exception e1){}
+						mutex = false;
+						tfStepDuration.setBackground(Color.WHITE);
+						return;
+					}
+					tfStepDuration.setBackground(Color.WHITE);
+				}catch(Exception e1){
+					tfStepDuration.setBackground(Color.RED);					
+				}
+			}
+		});
+		/**
+		 * Start Stop listener
+		 */
+		btnStartStop.addActionListener(a -> {
+			if(sim.isRunning()){
+				sim.stopSimulation();
+			}else{
+				sim.startSimulation();
+			}
+		});
+		
+		chckbxPrintpackets.addActionListener(l -> sim.setPrintPackets(chckbxPrintpackets.isSelected()));
+		
+	}
 }