|
@@ -11,8 +11,16 @@ import java.awt.event.MouseListener;
|
|
|
import javax.swing.*;
|
|
|
import javax.swing.event.*;
|
|
|
|
|
|
+import junit.framework.TestListener;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.ConnectionImplementation;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.MQTT_protocol;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleLink;
|
|
|
|
|
|
/**
|
|
|
* Panel for editing of Ports of a SmartDevice
|
|
@@ -73,8 +81,9 @@ public class PortEditorPanel extends JPanel
|
|
|
/**
|
|
|
* Creates a new PortEditorPanel, which allows editing of the Ports of toEdit
|
|
|
* @param toEdit SmartDevice, which ports will be edited
|
|
|
+ * @param controller Controller to modify the Model
|
|
|
*/
|
|
|
- public PortEditorPanel(SmartDevice toEdit) {
|
|
|
+ public PortEditorPanel(SmartDevice toEdit, Controller controller) {
|
|
|
|
|
|
this.toEdit = toEdit;
|
|
|
//Create the list of ports
|
|
@@ -98,7 +107,7 @@ public class PortEditorPanel extends JPanel
|
|
|
lblPortnumber.setBounds(10, 10, 110, 20);
|
|
|
editPanel.add(lblPortnumber);
|
|
|
|
|
|
- JScrollPane pictureScrollPane = new JScrollPane(editPanel);
|
|
|
+ JScrollPane portsScrollPane = new JScrollPane(editPanel);
|
|
|
|
|
|
tfPortNumber = new JTextField();
|
|
|
tfPortNumber.setBounds(130, 10, 130, 20);
|
|
@@ -120,6 +129,7 @@ public class PortEditorPanel extends JPanel
|
|
|
JButton btnEditConnection = new JButton("Edit");
|
|
|
btnEditConnection.setBounds(200, 40, 60, 20);
|
|
|
editPanel.add(btnEditConnection);
|
|
|
+ btnEditConnection.addActionListener(a->new ConnectionCreationDialog(list.getSelectedValue().getConnection(), controller, this));
|
|
|
|
|
|
JLabel lblStatus = new JLabel("Status:");
|
|
|
lblStatus.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
@@ -192,7 +202,7 @@ public class PortEditorPanel extends JPanel
|
|
|
tfJitter.addMouseListener(this);
|
|
|
|
|
|
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
|
|
|
- listScrollPane, pictureScrollPane);
|
|
|
+ listScrollPane, portsScrollPane);
|
|
|
splitPane.setDividerLocation(90);
|
|
|
|
|
|
/**
|
|
@@ -201,7 +211,7 @@ public class PortEditorPanel extends JPanel
|
|
|
Dimension minimumSize = new Dimension(60, 50);
|
|
|
listScrollPane.setMinimumSize(minimumSize);
|
|
|
listScrollPane.setMaximumSize(minimumSize);
|
|
|
- pictureScrollPane.setMinimumSize(minimumSize);
|
|
|
+ portsScrollPane.setMinimumSize(minimumSize);
|
|
|
|
|
|
// Set the preferred size
|
|
|
splitPane.setPreferredSize(new Dimension(380, 220));
|
|
@@ -255,9 +265,21 @@ public class PortEditorPanel extends JPanel
|
|
|
JFrame frame = new JFrame("Port Editor");
|
|
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
SmartDevice test = new SmartDevice("TestDevice");
|
|
|
- test.addPort(new Port(test, (short) 1));
|
|
|
- test.addPort(new Port(test, (short) 2));
|
|
|
- PortEditorPanel portEditorPanel = new PortEditorPanel(test);
|
|
|
+ Port p1 = new Port(test, (short) 1);
|
|
|
+ Port p2 = new Port(test, (short) 2);
|
|
|
+ test.addPort(p1);
|
|
|
+ test.addPort(p2);
|
|
|
+ MQTT_protocol testProtocol = new MQTT_protocol();
|
|
|
+ testProtocol.addDeviceOfRole(p1, 0);
|
|
|
+ testProtocol.addDeviceOfRole(p2, 1);
|
|
|
+ Link test_link = new SimpleLink("Test");
|
|
|
+ test_link.addDevice(test);
|
|
|
+ Connection con = new ConnectionImplementation(test_link, testProtocol);
|
|
|
+ p1.setConnection(con);
|
|
|
+ p2.setConnection(con);
|
|
|
+ con.addSmartDevice(p1);
|
|
|
+ con.addSmartDevice(p2);
|
|
|
+ PortEditorPanel portEditorPanel = new PortEditorPanel(test, new Controller(new Model()));
|
|
|
frame.getContentPane().add(portEditorPanel.getSplitPane());
|
|
|
|
|
|
frame.pack();
|