|
@@ -8,17 +8,23 @@ import javax.swing.JOptionPane;
|
|
|
import javax.swing.JScrollPane;
|
|
|
import javax.swing.ListSelectionModel;
|
|
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.ClassImportException;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SimulationController;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.NetworkManipulationAlgorithm;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PacketCollector;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PacketSniffer;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.view.util.Utility;
|
|
|
|
|
|
import java.awt.Container;
|
|
|
+import java.awt.Toolkit;
|
|
|
|
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JLabel;
|
|
|
|
|
|
+import java.awt.event.ActionListener;
|
|
|
+import java.awt.event.ActionEvent;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* PopUp for creation or editing of packet sniffers
|
|
@@ -45,7 +51,14 @@ public class EditPacketSniffer extends JDialog {
|
|
|
* PacketCollector which is being edited
|
|
|
*/
|
|
|
private PacketCollector collector;
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Label to show the algorithm name
|
|
|
+ */
|
|
|
+ private JLabel lblAlgorithm;
|
|
|
+ /**
|
|
|
+ * Reference to this for inner classes
|
|
|
+ */
|
|
|
+ private EditPacketSniffer that = this;
|
|
|
/**
|
|
|
* Creates and shows a new EditAlgorithmPopUp
|
|
|
* @param controller controller
|
|
@@ -60,12 +73,71 @@ public class EditPacketSniffer extends JDialog {
|
|
|
setTitle("Create PacketCollector");
|
|
|
this.setIconImage(Utility.loadFile("images/smartHome_icon.png"));
|
|
|
getContentPane().setLayout(null);
|
|
|
+
|
|
|
+ JButton btnImportPacketcapturealgorithm = new JButton("Import PacketAlgorithm");
|
|
|
+ btnImportPacketcapturealgorithm.addActionListener(new ActionListener() {
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ ImportPopUp<PacketSniffer> importPopUp = new ImportPopUp<PacketSniffer>(that, PacketSniffer.class);
|
|
|
+ Class<? extends PacketSniffer> imported = null;
|
|
|
+ try {
|
|
|
+ imported = importPopUp.showPopUp();
|
|
|
+ } catch (ClassImportException e1) {
|
|
|
+ JOptionPane.showMessageDialog(that, "Import failed: " + e1.getMessage());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(imported!=null){
|
|
|
+ try {
|
|
|
+ PacketSniffer p = imported.newInstance();
|
|
|
+ that.collector.setPacketAlgorithm(p);
|
|
|
+ } catch (InstantiationException | IllegalAccessException e1) {
|
|
|
+ JOptionPane.showMessageDialog(that, "Instance creation failed: " + e1.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ btnImportPacketcapturealgorithm.setBounds(189, 13, 181, 25);
|
|
|
+ getContentPane().add(btnImportPacketcapturealgorithm);
|
|
|
+
|
|
|
+ lblAlgorithm = new JLabel();
|
|
|
+ lblAlgorithm.setBounds(12, 17, 165, 16);
|
|
|
+ getContentPane().add(lblAlgorithm);
|
|
|
+
|
|
|
+ JScrollPane scrollPane = new JScrollPane();
|
|
|
+ scrollPane.setBounds(12, 46, 165, 132);
|
|
|
+ getContentPane().add(scrollPane);
|
|
|
+
|
|
|
+ JList list_1 = new JList();
|
|
|
+ scrollPane.setViewportView(list_1);
|
|
|
+
|
|
|
+ JScrollPane scrollPane_1 = new JScrollPane();
|
|
|
+ scrollPane_1.setBounds(12, 208, 165, 132);
|
|
|
+ getContentPane().add(scrollPane_1);
|
|
|
+
|
|
|
+ JList list = new JList();
|
|
|
+ scrollPane_1.setViewportView(list);
|
|
|
+
|
|
|
+ JButton btnStopCapturingLink = new JButton("Stop Capturing Link");
|
|
|
+ btnStopCapturingLink.setBounds(189, 153, 181, 25);
|
|
|
+ getContentPane().add(btnStopCapturingLink);
|
|
|
+
|
|
|
+ JButton btnStopCapturingDevice = new JButton("Stop Capturing Device");
|
|
|
+ btnStopCapturingDevice.setBounds(189, 206, 181, 25);
|
|
|
+ getContentPane().add(btnStopCapturingDevice);
|
|
|
+
|
|
|
+ JButton btnCreatePacketCollector = new JButton("Create Packet Collector");
|
|
|
+ btnCreatePacketCollector.addActionListener(new ActionListener() {
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ btnCreatePacketCollector.setBounds(189, 315, 181, 25);
|
|
|
+ getContentPane().add(btnCreatePacketCollector);
|
|
|
/**
|
|
|
* Either Modal - or refresh other instances of this PopUp on refresh
|
|
|
*/
|
|
|
this.setModal(true);
|
|
|
+ updateThis(null);
|
|
|
+ this.setLocationRelativeTo(parent);
|
|
|
|
|
|
- System.out.println("Collector: "+collector.toString());
|
|
|
|
|
|
}
|
|
|
|
|
@@ -74,6 +146,9 @@ public class EditPacketSniffer extends JDialog {
|
|
|
* @param o object (unused)
|
|
|
*/
|
|
|
public void updateThis(Object o){
|
|
|
-
|
|
|
+ if(collector.getPacketAlgorithm()==null)
|
|
|
+ lblAlgorithm.setText("Algorithm: null");
|
|
|
+ else
|
|
|
+ lblAlgorithm.setText("Algorithm: "+collector.getPacketAlgorithm().getClass().getSimpleName());
|
|
|
}
|
|
|
}
|