浏览代码

Adds List of Connections and Ports to the EditDevice PopUp

Andreas T. Meyer-Berg 5 年之前
父节点
当前提交
83f2da0da6

+ 19 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Port.java

@@ -185,4 +185,23 @@ public class Port {
 		this.connection = connection;
 	}
 
+	/**
+	 * Returns a String representation for the status byte
+	 * Returns 0:closed, 1:open, 2:sending
+	 * 
+	 * @param s as specified by {@link Port}
+	 * @return textual representation of the status
+	 */
+	public static String statusToString(short s){
+		switch (s) {
+		case CLOSED:
+			return "closed";
+		case OPEN:
+			return "open";
+		case SENDING:
+			return "sending";
+		default:
+			return "unknown";
+		}
+	}
 }

+ 6 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Protocol.java

@@ -72,4 +72,10 @@ public interface Protocol {
 	 */
 	public void removeDevice(Port device);
 
+	/**
+	 * Returns name of the protocol
+	 * 
+	 * @return name of the protocol 
+	 */
+	public String getName();
 }

+ 5 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/protocols/MQTT_protocol.java

@@ -259,4 +259,9 @@ public class MQTT_protocol implements Protocol {
 		topics.add(topic);
 	}
 
+	@Override
+	public String getName() {
+		return "MQTT";
+	}
+
 }

+ 4 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/simpleImplementation/SimpleProtocol.java

@@ -93,5 +93,9 @@ public class SimpleProtocol implements Protocol {
 			destination = null;
 		
 	}
+	@Override
+	public String getName() {
+		return "SimpleProtocol";
+	}
 
 }

+ 11 - 23
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/SmartDeviceCreationPopUp.java

@@ -14,6 +14,8 @@ import javax.swing.JLabel;
 import javax.swing.JButton;
 
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
 import java.awt.GridBagLayout;
 import java.awt.GridBagConstraints;
@@ -64,27 +66,6 @@ public class SmartDeviceCreationPopUp extends JDialog {
 	 * device should not be added to the controller.
 	 */
 	private boolean edit;
-	/**
-	 * Creates a new SmartDeviceCreationPopUp
-	 * 
-	 * @param currentX
-	 *            default xPosition of the new SmartDevice
-	 * @param currentY
-	 *            default yPosition of the new SmartDevice
-	 * @param maxX
-	 *            width of the model
-	 * @param maxY
-	 *            hieght of the model
-	 * @param visualisationRadius
-	 *            distance from the borders which should be kept
-	 * @param c
-	 *            controler which allows manipulation of the model
-	 * @param panel
-	 *            Visualisation panel, which represents the SmartDevice
-	 *
-	 *            public SmartDeviceCreationPopUp(int currentX, int currentY,
-	 *            int maxX, int maxY, int visualisationRadius, Controller c) {
-	 */
 
 	/**
 	 * Allows editing/creation of a smartDevice
@@ -185,10 +166,17 @@ public class SmartDeviceCreationPopUp extends JDialog {
 
 		JPanel panelLinks = new JPanel();
 		tabbedPane.addTab("Links", null, panelLinks, "Edit Links of the SmartDevice");
+		for(Link l:newDevice.getLinks()){
+			panelLinks.add(new JLabel(l.getName()));
+		}
 
 		JPanel panelConnections = new JPanel();
-		tabbedPane.addTab("Connections", null, panelConnections, null);
-
+		tabbedPane.addTab("Connections", null, panelConnections, "Edit Connections/Ports/Timings of the SmartDevice");
+		for(Port p:newDevice.getPorts()){
+			panelConnections.add(new JLabel("Port "+p.getPortNumber()+": "+p.getConnection().getProtocol().getName()+" state:"+Port.statusToString(p.getStatus())+" triggerIntervall:"+p.getTriggerInterval()));
+		}
+		
+		
 		JButton btnCreateDevice = new JButton("Verify & Create SmartDevice");
 		btnCreateDevice.addActionListener(a -> validateAndAddDevice());
 		getContentPane().add(btnCreateDevice, BorderLayout.SOUTH);