Browse Source

Allows selecting of the Packet export File

Andreas T. Meyer-Berg 5 years ago
parent
commit
a45948c132

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

@@ -90,6 +90,7 @@ public class SimulationManager extends Observable{
 			simulateTimeIntervall(currentTime,endTime-currentTime);
 			currentTime = endTime;
 		}
+		notifyPanels();
 	}
 	
 	/**
@@ -133,9 +134,8 @@ public class SimulationManager extends Observable{
 	public void exportPacketsOfLastTimeStep() {
 		if(printPackets){
 			try {
-				File f = new File("testPackets.log");
-				f.createNewFile();
-				writer = new BufferedWriter(new FileWriter(f.getAbsolutePath(),true));
+				exportFile.createNewFile();
+				writer = new BufferedWriter(new FileWriter(exportFile.getAbsolutePath(),true));
 				model.getConnectionNetworks().forEach(d->d.getPackets()
 						.forEach(p-> 
 						{

+ 29 - 2
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/popups/SimulationConfigurator.java

@@ -5,6 +5,7 @@ import java.awt.Dimension;
 import java.awt.Rectangle;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
+import java.io.File;
 import java.util.Observable;
 import java.util.Observer;
 
@@ -22,6 +23,7 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SimulationController;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
 
 import javax.swing.JCheckBox;
+import javax.swing.JFileChooser;
 
 /**
  * Window for configuring, starting and stopping the Simulation
@@ -58,6 +60,10 @@ public class SimulationConfigurator extends JFrame implements Observer{
 	 * Button for starting/stopping the simulation
 	 */
 	private JButton btnStartStop;
+	/**
+	 * Button for specifying the export file
+	 */
+	private JButton btnExportFile;
 	/**
 	 * ProgressionBar which shows the progression. Values are between 0 and
 	 * 10000 where 0 represents the start time, and 10000 represents the end
@@ -171,7 +177,7 @@ public class SimulationConfigurator extends JFrame implements Observer{
 		chckbxPrintpackets
 		.setToolTipText("Print Packets as human readable String to testPackets.log in the projekt folder.");
 		
-		JButton btnExportFile = new JButton("Choose Export File");
+		btnExportFile = new JButton("Choose Export File");
 		btnExportFile.setBounds(140, 130, 180, 20);
 		getContentPane().add(btnExportFile);
 		
@@ -246,7 +252,8 @@ public class SimulationConfigurator extends JFrame implements Observer{
 			tfStepDuration.setBackground(Color.WHITE);
 		}
 		chckbxPrintpackets.setSelected(sim.getPrintPackets());
-		lblExportFileName.setText(sim.getExportFile().getPath());
+		lblExportFileName.setText(sim.getExportFile().getName());
+		lblExportFileName.setToolTipText("Path: "+sim.getExportFile().getPath());
 		lblCurrentTimeShow.setText(currentTime+" ms");
 		if(endTime!=startTime)
 			progressBar.setValue((int) ((currentTime - startTime) * 10000 / (endTime - startTime)));
@@ -387,5 +394,25 @@ public class SimulationConfigurator extends JFrame implements Observer{
 		
 		chckbxPrintpackets.addActionListener(l -> sim.setPrintPackets(chckbxPrintpackets.isSelected()));
 		
+		/**
+		 * Export location:
+		 */
+		btnExportFile.addActionListener(a->{
+			/**
+			 * Open FileChooser, starting from the last File
+			 */
+			JFileChooser fc = new JFileChooser(sim.getExportFile());
+			
+			/**
+			 * If File selected
+			 */
+	        if (fc.showSaveDialog(that.getParent()) == JFileChooser.APPROVE_OPTION) {
+	        	/**
+	        	 * and not null -> import
+	        	 */
+	            File file = fc.getSelectedFile();
+	            if(file!=null)sim.setExportFile(file);
+	       }
+		});
 	}
 }