|
@@ -1,21 +1,25 @@
|
|
package de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups;
|
|
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.Dimension;
|
|
import java.awt.Rectangle;
|
|
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.JButton;
|
|
|
|
+import javax.swing.JFrame;
|
|
|
|
+import javax.swing.JProgressBar;
|
|
|
|
+import javax.swing.JSeparator;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JLabel;
|
|
-import javax.swing.JOptionPane;
|
|
|
|
import javax.swing.JTextField;
|
|
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.Controller;
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SimulationController;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
|
|
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SimulationManager;
|
|
|
|
|
|
|
|
import javax.swing.JCheckBox;
|
|
import javax.swing.JCheckBox;
|
|
|
|
|
|
@@ -25,7 +29,7 @@ import javax.swing.JCheckBox;
|
|
* @author Andreas T. Meyer-Berg
|
|
* @author Andreas T. Meyer-Berg
|
|
*/
|
|
*/
|
|
@SuppressWarnings("serial")
|
|
@SuppressWarnings("serial")
|
|
-public class SimulationConfigurator extends JFrame {
|
|
|
|
|
|
+public class SimulationConfigurator extends JFrame implements Observer{
|
|
/**
|
|
/**
|
|
* Textfield for editing the start time
|
|
* Textfield for editing the start time
|
|
*/
|
|
*/
|
|
@@ -38,6 +42,10 @@ public class SimulationConfigurator extends JFrame {
|
|
* Textfield for editing the step duration
|
|
* Textfield for editing the step duration
|
|
*/
|
|
*/
|
|
private JTextField tfStepDuration;
|
|
private JTextField tfStepDuration;
|
|
|
|
+ /**
|
|
|
|
+ * Checkbox if packets should be printed
|
|
|
|
+ */
|
|
|
|
+ private JCheckBox chckbxPrintpackets;
|
|
/**
|
|
/**
|
|
* Label which shows the name of the export File
|
|
* 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
|
|
* Label which shows the current Time of the simulation
|
|
*/
|
|
*/
|
|
- private JLabel lbCurrentTimeShow;
|
|
|
|
|
|
+ private JLabel lblCurrentTimeShow;
|
|
/**
|
|
/**
|
|
* Button for starting/stopping the simulation
|
|
* Button for starting/stopping the simulation
|
|
*/
|
|
*/
|
|
@@ -57,33 +65,21 @@ public class SimulationConfigurator extends JFrame {
|
|
*/
|
|
*/
|
|
private JProgressBar progressBar;
|
|
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
|
|
* Create a new SimulationConfigurator Panel, which controls the given
|
|
@@ -93,11 +89,18 @@ public class SimulationConfigurator extends JFrame {
|
|
*/
|
|
*/
|
|
public SimulationConfigurator(Controller control) {
|
|
public SimulationConfigurator(Controller control) {
|
|
this.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.getContentPane().setMinimumSize(new Dimension(640, 310));
|
|
this.setBounds(new Rectangle(0, 0, 640, 310));
|
|
this.setBounds(new Rectangle(0, 0, 640, 310));
|
|
- //setBounds(new Rectangle(0, 0, 640, 290));
|
|
|
|
setResizable(false);
|
|
setResizable(false);
|
|
getContentPane().setLayout(null);
|
|
getContentPane().setLayout(null);
|
|
this.setTitle("Simulation Configuration");
|
|
this.setTitle("Simulation Configuration");
|
|
@@ -126,17 +129,17 @@ public class SimulationConfigurator extends JFrame {
|
|
getContentPane().add(lblStarttimeLong);
|
|
getContentPane().add(lblStarttimeLong);
|
|
|
|
|
|
tfStartTimeLong = new JTextField();
|
|
tfStartTimeLong = new JTextField();
|
|
- tfStartTimeLong.setText("" + startTime);
|
|
|
|
tfStartTimeLong.setBounds(160, 40, 130, 20);
|
|
tfStartTimeLong.setBounds(160, 40, 130, 20);
|
|
getContentPane().add(tfStartTimeLong);
|
|
getContentPane().add(tfStartTimeLong);
|
|
tfStartTimeLong.setColumns(10);
|
|
tfStartTimeLong.setColumns(10);
|
|
|
|
+ tfStartTimeLong.setText(sim.getStartTime()+"");
|
|
|
|
+
|
|
|
|
|
|
JLabel lblEndtimeLong = new JLabel("End Time (in ms):");
|
|
JLabel lblEndtimeLong = new JLabel("End Time (in ms):");
|
|
lblEndtimeLong.setBounds(300, 40, 160, 20);
|
|
lblEndtimeLong.setBounds(300, 40, 160, 20);
|
|
getContentPane().add(lblEndtimeLong);
|
|
getContentPane().add(lblEndtimeLong);
|
|
|
|
|
|
tfEndTimeLong = new JTextField();
|
|
tfEndTimeLong = new JTextField();
|
|
- tfEndTimeLong.setText("" + endTime);
|
|
|
|
tfEndTimeLong.setBounds(450, 40, 130, 20);
|
|
tfEndTimeLong.setBounds(450, 40, 130, 20);
|
|
getContentPane().add(tfEndTimeLong);
|
|
getContentPane().add(tfEndTimeLong);
|
|
tfEndTimeLong.setColumns(10);
|
|
tfEndTimeLong.setColumns(10);
|
|
@@ -146,7 +149,6 @@ public class SimulationConfigurator extends JFrame {
|
|
getContentPane().add(lblStepDuration);
|
|
getContentPane().add(lblStepDuration);
|
|
|
|
|
|
tfStepDuration = new JTextField();
|
|
tfStepDuration = new JTextField();
|
|
- tfStepDuration.setText("" + duration);
|
|
|
|
tfStepDuration.setBounds(160, 70, 130, 20);
|
|
tfStepDuration.setBounds(160, 70, 130, 20);
|
|
getContentPane().add(tfStepDuration);
|
|
getContentPane().add(tfStepDuration);
|
|
tfStepDuration.setColumns(10);
|
|
tfStepDuration.setColumns(10);
|
|
@@ -163,11 +165,9 @@ public class SimulationConfigurator extends JFrame {
|
|
getContentPane().add(lblConfigureExports);
|
|
getContentPane().add(lblConfigureExports);
|
|
|
|
|
|
|
|
|
|
- JCheckBox chckbxPrintpackets = new JCheckBox("print Packets");
|
|
|
|
|
|
+ chckbxPrintpackets = new JCheckBox("print Packets");
|
|
chckbxPrintpackets.setBounds(10, 130, 120, 20);
|
|
chckbxPrintpackets.setBounds(10, 130, 120, 20);
|
|
- chckbxPrintpackets.setSelected(sim.getPrintPackets());
|
|
|
|
getContentPane().add(chckbxPrintpackets);
|
|
getContentPane().add(chckbxPrintpackets);
|
|
- chckbxPrintpackets.addActionListener(l -> sim.setPrintPackets(chckbxPrintpackets.isSelected()));
|
|
|
|
chckbxPrintpackets
|
|
chckbxPrintpackets
|
|
.setToolTipText("Print Packets as human readable String to testPackets.log in the projekt folder.");
|
|
.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);
|
|
btnExportFile.setBounds(140, 130, 180, 20);
|
|
getContentPane().add(btnExportFile);
|
|
getContentPane().add(btnExportFile);
|
|
|
|
|
|
- lblExportFileName = new JLabel("ExportFileName");
|
|
|
|
|
|
+ lblExportFileName = new JLabel();
|
|
lblExportFileName.setBounds(330, 130, 300, 20);
|
|
lblExportFileName.setBounds(330, 130, 300, 20);
|
|
getContentPane().add(lblExportFileName);
|
|
getContentPane().add(lblExportFileName);
|
|
|
|
|
|
@@ -194,96 +194,29 @@ public class SimulationConfigurator extends JFrame {
|
|
lblCurrentTime.setBounds(10, 190, 100, 20);
|
|
lblCurrentTime.setBounds(10, 190, 100, 20);
|
|
getContentPane().add(lblCurrentTime);
|
|
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 = new JButton("Start Simulation");
|
|
btnStartStop.setBounds(10, 220, 150, 40);
|
|
btnStartStop.setBounds(10, 220, 150, 40);
|
|
getContentPane().add(btnStartStop);
|
|
getContentPane().add(btnStartStop);
|
|
- btnStartStop.addActionListener(a -> startStopButtonAction());
|
|
|
|
|
|
+
|
|
|
|
|
|
JButton btnReset = new JButton("Reset");
|
|
JButton btnReset = new JButton("Reset");
|
|
btnReset.setBounds(170, 220, 150, 40);
|
|
btnReset.setBounds(170, 220, 150, 40);
|
|
|
|
+ btnReset.addActionListener(a -> sim.resetSimulation());
|
|
getContentPane().add(btnReset);
|
|
getContentPane().add(btnReset);
|
|
- btnReset.addActionListener(a -> resetAction());
|
|
|
|
|
|
|
|
progressBar = new JProgressBar();
|
|
progressBar = new JProgressBar();
|
|
progressBar.setBounds(0, 270, this.getWidth(), 20);
|
|
progressBar.setBounds(0, 270, this.getWidth(), 20);
|
|
getContentPane().add(progressBar);
|
|
getContentPane().add(progressBar);
|
|
- progressBar.setValue(0);
|
|
|
|
progressBar.setMinimum(0);
|
|
progressBar.setMinimum(0);
|
|
progressBar.setMaximum(10000);
|
|
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
|
|
* Test the GUI
|
|
@@ -297,4 +230,162 @@ public class SimulationConfigurator extends JFrame {
|
|
simConfig.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
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()));
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|