Browse Source

Refactors SimulationConfiguration PopUp

Andreas T. Meyer-Berg 6 years ago
parent
commit
47e4d5804a

+ 105 - 50
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/popups/SimulationConfigurator.java

@@ -2,6 +2,11 @@ package de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups;
 
 import javax.swing.JFrame;
 import javax.swing.JProgressBar;
+import javax.swing.JSeparator;
+
+import java.awt.Dimension;
+import java.awt.Rectangle;
+
 import javax.swing.JButton;
 import javax.swing.JLabel;
 import javax.swing.JOptionPane;
@@ -12,8 +17,6 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SimulationManager;
 
-import java.awt.Rectangle;
-
 import javax.swing.JCheckBox;
 
 /**
@@ -27,22 +30,26 @@ public class SimulationConfigurator extends JFrame {
 	 * Textfield for editing the start time
 	 */
 	private JTextField tfStartTimeLong;
-	/**
-	 * Textfield for editing the step duration
-	 */
-	private JTextField tfStepDuration;
 	/**
 	 * Textfield for editing the end time
 	 */
 	private JTextField tfEndTimeLong;
 	/**
-	 * Button for starting/stopping the simulation
+	 * Textfield for editing the step duration
 	 */
-	private JButton btnStartStop;
+	private JTextField tfStepDuration;
+	/**
+	 * Label which shows the name of the export File
+	 */
+	private JLabel lblExportFileName;
 	/**
 	 * Label which shows the current Time of the simulation
 	 */
 	private JLabel lbCurrentTimeShow;
+	/**
+	 * Button for starting/stopping the simulation
+	 */
+	private JButton btnStartStop;
 	/**
 	 * ProgressionBar which shows the progression. Values are between 0 and
 	 * 10000 where 0 represents the start time, and 10000 represents the end
@@ -88,20 +95,15 @@ public class SimulationConfigurator extends JFrame {
 		this.controller = control;
 		this.sim = controller.getSimulationController().getSimulationManager();
 		
-		setBounds(new Rectangle(0, 0, 460, 300));
+		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");
 
-		btnStartStop = new JButton("Start Simulation");
-		btnStartStop.setBounds(12, 189, 149, 37);
-		getContentPane().add(btnStartStop);
-		btnStartStop.addActionListener(a -> startStopButtonAction());
-
-		JButton btnReset = new JButton("Reset");
-		btnReset.setBounds(173, 189, 123, 37);
-		getContentPane().add(btnReset);
-		btnReset.addActionListener(a -> resetAction());
-
+		/*Buttons for setting Start/End Dates
+		 * Currently not in use
 		JButton btnChooseStartDate = new JButton("Choose Start Date");
 		btnChooseStartDate.setBounds(12, 13, 161, 25);
 		getContentPane().add(btnChooseStartDate);
@@ -109,59 +111,110 @@ public class SimulationConfigurator extends JFrame {
 		JButton btnStartTime = new JButton("Choose End Date");
 		btnStartTime.setBounds(271, 13, 161, 25);
 		getContentPane().add(btnStartTime);
-
-		JLabel lblStarttimeLong = new JLabel("StartTime (long):");
-		lblStarttimeLong.setBounds(12, 70, 128, 16);
+		 */
+		
+		/*******************************************************************************
+		 * Buttons and labels for simulation Configuration (start, end, duration, steps) 
+		 ******************************************************************************/
+		
+		JLabel lblConfigureParameters = new JLabel("Change Simulation parameters:");
+		lblConfigureParameters.setBounds(10, 10, 300, 20);
+		getContentPane().add(lblConfigureParameters);
+		
+		JLabel lblStarttimeLong = new JLabel("Start Time (in ms):");
+		lblStarttimeLong.setBounds(10, 40, 160, 20);
 		getContentPane().add(lblStarttimeLong);
 
-		JLabel lblStepDuration = new JLabel("Step duration:");
-		lblStepDuration.setBounds(12, 99, 97, 16);
-		getContentPane().add(lblStepDuration);
-
 		tfStartTimeLong = new JTextField();
 		tfStartTimeLong.setText("" + startTime);
-		tfStartTimeLong.setBounds(116, 67, 116, 22);
+		tfStartTimeLong.setBounds(160, 40, 130, 20);
 		getContentPane().add(tfStartTimeLong);
 		tfStartTimeLong.setColumns(10);
 
-		tfStepDuration = new JTextField();
-		tfStepDuration.setText("" + duration);
-		tfStepDuration.setBounds(116, 99, 116, 22);
-		getContentPane().add(tfStepDuration);
-		tfStepDuration.setColumns(10);
-
-		JLabel lblEndtimeLong = new JLabel("EndTime (long):");
-		lblEndtimeLong.setBounds(244, 70, 93, 16);
+		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(347, 67, 85, 22);
+		tfEndTimeLong.setBounds(450, 40, 130, 20);
 		getContentPane().add(tfEndTimeLong);
 		tfEndTimeLong.setColumns(10);
+		
+		JLabel lblStepDuration = new JLabel("Step Duration(in ms):");
+		lblStepDuration.setBounds(10, 70, 160, 20);
+		getContentPane().add(lblStepDuration);
+		
+		tfStepDuration = new JTextField();
+		tfStepDuration.setText("" + duration);
+		tfStepDuration.setBounds(160, 70, 130, 20);
+		getContentPane().add(tfStepDuration);
+		tfStepDuration.setColumns(10);
+		
+		JSeparator topSeparator = new JSeparator(JSeparator.HORIZONTAL);
+		topSeparator.setBounds(0, 95, 660, 10);
+		getContentPane().add(topSeparator);
+		/*******************************************************************************
+		 * Buttons and labels for simulation Configuration (start, end, duration, steps) 
+		 ******************************************************************************/
+		
+		JLabel lblConfigureExports = new JLabel("Configure Packet export options:");
+		lblConfigureExports.setBounds(10, 100, 300, 20);
+		getContentPane().add(lblConfigureExports);
+		
+
+		JCheckBox 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.");
+		
+		JButton btnExportFile = new JButton("Choose Export File");
+		btnExportFile.setBounds(140, 130, 180, 20);
+		getContentPane().add(btnExportFile);
+		
+		lblExportFileName = new JLabel("ExportFileName");
+		lblExportFileName.setBounds(330, 130, 300, 20);
+		getContentPane().add(lblExportFileName);
+		
+		JSeparator botSeparator = new JSeparator(JSeparator.HORIZONTAL);
+		botSeparator.setBounds(0, 155, 660, 5);
+		getContentPane().add(botSeparator);
+		/*******************************************************************************
+		 * Buttons and labels for simulation Configuration (start, end, duration, steps) 
+		 ******************************************************************************/
+		
+		JLabel lblSimulationStatus = new JLabel("Running Simulation status:");
+		lblSimulationStatus.setBounds(10, 160, 300, 20);
+		getContentPane().add(lblSimulationStatus);
 
 		JLabel lblCurrentTime = new JLabel("Current Time:");
-		lblCurrentTime.setBounds(12, 160, 97, 16);
+		lblCurrentTime.setBounds(10, 190, 100, 20);
 		getContentPane().add(lblCurrentTime);
 
 		lbCurrentTimeShow = new JLabel("0 ms");
-		lbCurrentTimeShow.setBounds(121, 160, 111, 16);
+		lbCurrentTimeShow.setBounds(120, 190, 120, 20);
+		lbCurrentTimeShow.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
 		getContentPane().add(lbCurrentTimeShow);
 
+		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);
+		getContentPane().add(btnReset);
+		btnReset.addActionListener(a -> resetAction());
+
 		progressBar = new JProgressBar();
-		progressBar.setBounds(0, 251, 442, 14);
+		progressBar.setBounds(0, 270, this.getWidth(), 20);
 		getContentPane().add(progressBar);
 		progressBar.setValue(0);
 		progressBar.setMinimum(0);
 		progressBar.setMaximum(10000);
-
-		JCheckBox chckbxPrintpackets = new JCheckBox("printPackets");
-		chckbxPrintpackets.setBounds(116, 127, 113, 25);
-		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.");
 	}
 
 	/**
@@ -229,17 +282,19 @@ public class SimulationConfigurator extends JFrame {
 		sim.simulateTimeIntervall(currentTime, duration);
 		currentTime += duration;
 		progressBar.setValue((int) ((currentTime - startTime) * 10000 / (endTime - startTime)));
-		lbCurrentTimeShow.setText(currentTime + "");
+		lbCurrentTimeShow.setText(currentTime + " ms");
 	}
 
 	/**
-	 * Test the gui
+	 * Test the GUI
 	 * @param args none specified
 	 */
 	public static void main(String[] args) {
 		SimulationConfigurator simConfig = new SimulationConfigurator(new Controller(new Model()));
 		simConfig.setEnabled(true);
 		simConfig.setVisible(true);
+		//Prevent demon threads on close
+		simConfig.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
 	}
 }