Browse Source

Adds configuration classes to seperate model and configuration

Andreas T. Meyer-Berg 6 years ago
parent
commit
9adf7f60ec

+ 16 - 16
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/Main.java

@@ -63,14 +63,14 @@ public class Main {
 		SmartDevice A = null, B = null, C = null;
 		for(int i = 0; i<5; i++){
 			A = new SmartDevice("SmartTV"+i);		
-			A.setX((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
-			A.setY((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
+			A.setX((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
+			A.setY((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
 			B = new SmartDevice("SmartDoor"+i);
-			B.setX((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
-			B.setY((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
+			B.setX((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
+			B.setY((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
 			C = new SmartDevice("SmartLight"+i);
-			C.setX((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
-			C.setY((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
+			C.setX((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
+			C.setY((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
 		
 			c.addSmartDevice(A);
 			c.addSmartDevice(B);
@@ -113,8 +113,8 @@ public class Main {
 		Link link = new SimpleLink("LossLess TCP-Network");
 		
 		SmartDevice broker = new SmartDevice("MQTT-Broker");
-		broker.setX((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
-		broker.setY((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
+		broker.setX((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
+		broker.setY((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
 		c.addSmartDevice(broker);
 		
 		Port brokerPort = new Port(broker, (short) 0);
@@ -133,16 +133,16 @@ public class Main {
 		con.addSmartDevice(brokerPort);
 		brokerPort.setConnection(con);
 		con.setStatus(Connection.ACTIVE);
-		m.addConnectionNetwork(link);
+		c.addLink(link);
 		link.addConnection(con);
-		m.addConnection(con);
+		c.addConnection(con);
 		
 		SmartDevice A = null, B = null, C = null;
 		Port aP,bP,cP;
 		for(int i = 0; i<3; i++){
 			A = new SmartDevice("SmartTV"+i+"(Sub)");		
-			A.setX((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
-			A.setY((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
+			A.setX((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
+			A.setY((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
 			link.addDevice(A);
 			A.addLink(link);
 			
@@ -161,8 +161,8 @@ public class Main {
 			
 			
 			B = new SmartDevice("SmartDoor"+i+"(Pub)");
-			B.setX((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
-			B.setY((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
+			B.setX((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
+			B.setY((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
 			link.addDevice(B);
 			B.addLink(link);
 			
@@ -179,8 +179,8 @@ public class Main {
 			c.addSmartDevice(B);
 			
 			C = new SmartDevice("SmartLight"+i+"(Pub,Sub)");
-			C.setX((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
-			C.setY((int)(Math.random()*m.getWidth()-2*m.getDevice_visualization_radius())+m.getDevice_visualization_radius());
+			C.setX((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
+			C.setY((int)(Math.random()*c.getWidth()-2*c.getDevice_visualization_radius())+c.getDevice_visualization_radius());
 			link.addDevice(C);
 			C.addLink(link);
 			

+ 6 - 6
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/Controller.java

@@ -153,10 +153,10 @@ public class Controller {
 		 */
 		int newPosition = (int) Math.round(factor * oldPosition);
 		// Update if it moves out of the frame
-		if (newPosition < model.getDevice_visualization_radius())
-			newPosition = model.getDevice_visualization_radius();
-		if (newPosition >= upperBound - model.getDevice_visualization_radius())
-			newPosition = upperBound - model.getDevice_visualization_radius();
+		if (newPosition < getDevice_visualization_radius())
+			newPosition = getDevice_visualization_radius();
+		if (newPosition >= upperBound - getDevice_visualization_radius())
+			newPosition = upperBound - getDevice_visualization_radius();
 
 		return newPosition;
 	}
@@ -325,14 +325,14 @@ public class Controller {
 	 * @return the device_visualization_radius
 	 */
 	public int getDevice_visualization_radius() {
-		return model.getDevice_visualization_radius();
+		return model.getConfigurator().getVisualizationConfiguration().getDeviceVisualizationRadius();
 	}
 
 	/**
 	 * @param device_visualization_radius the device_visualization_radius to set
 	 */
 	public void setDevice_visualization_radius(int device_visualization_radius) {
-		model.setDevice_visualization_radius(device_visualization_radius);
+		model.getConfigurator().getVisualizationConfiguration().setDeviceVisualizationRadius(device_visualization_radius);
 	}
 	
 	/**

+ 30 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/ConfigurationManager.java

@@ -0,0 +1,30 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
+
+/**
+ * Class which stores and returns the different configuration classes
+ *
+ * @author Andreas T. Meyer-Berg
+ */
+public class ConfigurationManager {
+
+	/**
+	 * Visual Configuration
+	 */
+	private VisualizationConfiguration visual;
+	
+	/**
+	 * Initialize the Configuration Manager
+	 */
+	public ConfigurationManager() {
+		visual = new VisualizationConfiguration();
+	}
+
+	/**
+	 * Returns the visualization configuration
+	 * 
+	 * @return the visualization configuration
+	 */
+	public VisualizationConfiguration getVisualizationConfiguration() {
+		return visual;
+	}
+}

+ 13 - 19
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Model.java

@@ -50,15 +50,14 @@ public class Model extends Observable{
 	private int depth;
 	
 	/**
-	 * Radius (including the middlePoinnt) of a smartDevice
-	 * 
+	 * Simulation Manager which allows simulation of this model
 	 */
-	private int device_visualization_radius = 17;
+	private SimulationManager sim;
 	
 	/**
-	 * Simulation Manager which allows simulation of this model
+	 * Configurations of the Program
 	 */
-	private SimulationManager sim;
+	private ConfigurationManager config;
 	
 	/**
 	 * Initializes the Model, with 3 default devices for testing purposes
@@ -69,6 +68,8 @@ public class Model extends Observable{
 		setHeight(480);
 		setDepth(480);
 		
+		config = new ConfigurationManager();
+		
 		devices = new LinkedList<SmartDevice>();
 		connectionNetworks = new LinkedList<Link>();
 		connections = new LinkedList<Connection>();
@@ -154,20 +155,6 @@ public class Model extends Observable{
 	public void setDepth(int depth) {
 		this.depth = depth;
 	}
-
-	/**
-	 * @return the device_visualization_radius
-	 */
-	public int getDevice_visualization_radius() {
-		return device_visualization_radius;
-	}
-
-	/**
-	 * @param device_visualization_radius the device_visualization_radius to set
-	 */
-	public void setDevice_visualization_radius(int device_visualization_radius) {
-		this.device_visualization_radius = device_visualization_radius;
-	}
 	
 	/**
 	 * @return the connections
@@ -308,4 +295,11 @@ public class Model extends Observable{
 	public void removeSmartDeviceClass(Class<? extends SmartDevice> remove){
 		importedSmartDevices.remove(remove);
 	}
+
+	/**
+	 * @return the configurations
+	 */
+	public ConfigurationManager getConfigurator() {
+		return config;
+	}
 }

+ 136 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/VisualizationConfiguration.java

@@ -0,0 +1,136 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
+
+/**
+ * Stores the configuration details of the visualization
+ *
+ * @author Andreas T. Meyer-Berg
+ */
+public class VisualizationConfiguration {
+	
+	/**
+	 * Whether connections should be shown
+	 */
+	private boolean showConnections;
+	
+	/**
+	 * Whether links should be shown
+	 */
+	private boolean showLinks;
+	
+	/**
+	 * Whether SmartDevices should be shown
+	 */
+	private boolean showSmartDevices;
+	
+	/**
+	 * Whether SmartDevice names should be shown
+	 */
+	private boolean showSmartDeviceNames;
+	
+	/**
+	 * Whether terminated connections should be shown
+	 */
+	private boolean showTerminatedConnections;
+	
+	/**
+	 * Radius (including the middlePoinnt) of a smartDevice
+	 */
+	private int deviceVisualizationRadius;
+
+	/**
+	 * Initialize the configuration
+	 */
+	public VisualizationConfiguration() {
+		setShowConnections(true);
+		setShowLinks(true);
+		setShowSmartDevices(true);
+		setShowSmartDeviceNames(true);
+		setShowTerminatedConnections(true);
+		setDeviceVisualizationRadius(17);
+	}
+
+	/**
+	 * @return the showConnections
+	 */
+	public boolean isShowConnections() {
+		return showConnections;
+	}
+
+	/**
+	 * @param showConnections the showConnections to set
+	 */
+	public void setShowConnections(boolean showConnections) {
+		this.showConnections = showConnections;
+	}
+
+	/**
+	 * @return the showLinks
+	 */
+	public boolean isShowLinks() {
+		return showLinks;
+	}
+
+	/**
+	 * @param showLinks the showLinks to set
+	 */
+	public void setShowLinks(boolean showLinks) {
+		this.showLinks = showLinks;
+	}
+
+	/**
+	 * @return the showSmartDevices
+	 */
+	public boolean isShowSmartDevices() {
+		return showSmartDevices;
+	}
+
+	/**
+	 * @param showSmartDevices the showSmartDevices to set
+	 */
+	public void setShowSmartDevices(boolean showSmartDevices) {
+		this.showSmartDevices = showSmartDevices;
+	}
+
+	/**
+	 * @return the showSmartDeviceNames
+	 */
+	public boolean isShowSmartDeviceNames() {
+		return showSmartDeviceNames;
+	}
+
+	/**
+	 * @param showSmartDeviceNames the showSmartDeviceNames to set
+	 */
+	public void setShowSmartDeviceNames(boolean showSmartDeviceNames) {
+		this.showSmartDeviceNames = showSmartDeviceNames;
+	}
+
+	/**
+	 * @return the showTerminatedConnections
+	 */
+	public boolean isShowTerminatedConnections() {
+		return showTerminatedConnections;
+	}
+
+	/**
+	 * @param showTerminatedConnections the showTerminatedConnections to set
+	 */
+	public void setShowTerminatedConnections(boolean showTerminatedConnections) {
+		this.showTerminatedConnections = showTerminatedConnections;
+	}
+
+	/**
+	 * @return the deviceVisualizationRadius
+	 */
+	public int getDeviceVisualizationRadius() {
+		return deviceVisualizationRadius;
+	}
+
+	/**
+	 * @param deviceVisualizationRadius the deviceVisualizationRadius to set
+	 */
+	public void setDeviceVisualizationRadius(int deviceVisualizationRadius) {
+		this.deviceVisualizationRadius = deviceVisualizationRadius;
+	}
+	
+}