Explorar el Código

Adds NetworkController, splits controller into different controllers

* NetworkController
* SettingsController
Andreas T. Meyer-Berg hace 5 años
padre
commit
135deae56d

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

@@ -1,8 +1,6 @@
 package de.tu_darmstadt.tk.SmartHomeNetworkSim.control;
 
 import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.Observer;
 
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
@@ -22,7 +20,7 @@ public class Controller {
 	/**
 	 * {@link Model} which stores the smart home model
 	 */
-	private Model model;
+	Model model;
 	
 	/**
 	 * Controller for Import of user defined java classes
@@ -89,12 +87,10 @@ public class Controller {
 	 *            new y position
 	 * @param z
 	 *            new z position
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#moveSmartDevice(SmartDevice,int,int,int)} instead
 	 */
 	public void moveSmartDevice(SmartDevice device, int x, int y, int z) {
-		device.setX(x);
-		device.setY(y);
-		device.setZ(z);
-
+		networkController.moveSmartDevice(device, x, y, z);
 	}
 
 	/**
@@ -107,9 +103,10 @@ public class Controller {
 	 *            the new height to set
 	 * @param depth
 	 *            the new depth to set
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#setDimension(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,int,int,int)} instead
 	 */
 	public void setDimension(int width, int height, int depth) {
-		setDimension(width, height, depth, false);
+		settingsController.setDimension(width, height, depth);
 	}
 
 	/**
@@ -124,57 +121,18 @@ public class Controller {
 	 *            the new depth to set
 	 * @param stretchModel
 	 *            true, if smartDevice positions should be stretched
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#setDimension(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,int,int,int,boolean)} instead
 	 */
 	public void setDimension(int width, int height, int depth, boolean stretchModel) {
-		// Don't allow to small Models
-		if (width < 400)
-			width = 400;
-		if (height < 400)
-			height = 400;
-		if (depth < 400)
-			depth = 400;
-
-		if (stretchModel) {
-			/**
-			 * Factor that changes the x position. Example: 1 -> positions stay
-			 * the same 0.5 -> x position is halved 2 -> x position is doubled
-			 */
-			double width_factor = ((double) width) / ((double) model.getWidth());
-			/**
-			 * Factor that changes the y position. Example: 1 -> positions stay
-			 * the same 0.5 -> y position is halved 2 -> y position is doubled
-			 */
-			double height_factor = ((double) height) / ((double) model.getHeight());
-			/**
-			 * Factor that changes the z position. Example: 1 -> positions stay
-			 * the same 0.5 -> z position is halved 2 -> z position is doubled
-			 */
-			double depth_factor = ((double) depth) / ((double) model.getDepth());
-			// Update all device positions
-			for (SmartDevice d : model.getDevices()) {
-				if (width_factor != 1.0)
-					d.setX(scalePos(d.getX(), width_factor, width));
-				if (height_factor != 1.0)
-					d.setY(scalePos(d.getY(), height_factor, height));
-				if (depth_factor != 1.0)
-					d.setZ(scalePos(d.getZ(), depth_factor, depth));
-			}
-		}
-		model.setWidth(width);
-		model.setHeight(height);
-		model.setDepth(depth);
+		settingsController.setDimension(width, height, depth, stretchModel);
 	}
 	
 	/**
 	 * Validate all device positions, move all devices into the bounds, if they are outside the visualization
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#validateDevicePosition(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
 	 */
 	public void validateDevicePosition() {
-		// Update all device positions
-		for (SmartDevice d : model.getDevices()) {
-			d.setX(scalePos(d.getX(), 1.0, getWidth()));
-			d.setY(scalePos(d.getY(), 1.0, getHeight()));
-			d.setZ(scalePos(d.getZ(), 1.0, getDepth()));
-		}
+		networkController.validateDevicePosition();
 	}
 	/**
 	 * Calculates the new scaled position, which should be in Bounds:
@@ -188,19 +146,10 @@ public class Controller {
 	 * @param upperBound
 	 *            upper bound of the frame, which should not be exceeded
 	 * @return new position that was calculated
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#scalePos(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,int,double,int)} instead
 	 */
-	private int scalePos(int oldPosition, double factor, int upperBound) {
-		/**
-		 * New Position that should be validated and returned
-		 */
-		int newPosition = (int) Math.round(factor * oldPosition);
-		// Update if it moves out of the frame
-		if (newPosition < getDevice_visualization_radius())
-			newPosition = getDevice_visualization_radius();
-		if (newPosition >= upperBound - getDevice_visualization_radius())
-			newPosition = upperBound - getDevice_visualization_radius();
-
-		return newPosition;
+	int scalePos(int oldPosition, double factor, int upperBound) {
+		return settingsController.scalePos(oldPosition, factor, upperBound);
 	}
 
 	/**
@@ -209,15 +158,10 @@ public class Controller {
 	 * 
 	 * @param sd
 	 *            SmartDevice which should be added to the model
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#addSmartDevice(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,SmartDevice)} instead
 	 */
 	public void addSmartDevice(SmartDevice sd) {
-		if (model.getDevices().contains(sd))
-			return;
-		model.addDevices(sd);
-		// validate Position
-		sd.setX(scalePos(sd.getX(), 1.0, model.getWidth()));
-		sd.setY(scalePos(sd.getY(), 1.0, model.getHeight()));
-		sd.setZ(scalePos(sd.getZ(), 1.0, model.getDepth()));
+		networkController.addSmartDevice(sd);
 	}
 
 	/**
@@ -232,13 +176,10 @@ public class Controller {
 	 *            position on the y-Axis
 	 * @param z_pos
 	 *            position on the z-Axis
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#createSmartDevice(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,String,int,int,int)} instead
 	 */
 	public void createSmartDevice(String name, int x_pos, int y_pos, int z_pos) {
-		SmartDevice sd = new SmartDevice(name);
-		sd.setX(scalePos(x_pos, 1.0, model.getWidth()));
-		sd.setY(scalePos(y_pos, 1.0, model.getHeight()));
-		sd.setZ(scalePos(z_pos, 1.0, model.getDepth()));
-		model.addDevices(sd);
+		networkController.createSmartDevice(name, x_pos, y_pos, z_pos);
 	}
 
 	/**
@@ -247,48 +188,10 @@ public class Controller {
 	 * 
 	 * @param toDelete
 	 *            the SmartDevice to delete
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#deleteSmartDevice(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,SmartDevice)} instead
 	 */
 	public void deleteSmartDevice(SmartDevice toDelete) {
-		if (toDelete == null)
-			return;
-
-		// Delete Connections
-		for (Port p : toDelete.getPorts()) {
-			//Skip ports that are not connected
-			if(p.getConnection()==null)continue;
-			this.removeDeviceFromConnection(p, p.getConnection());
-			
-			/**
-			 * Connection of the current port
-			 *
-			Connection c = p.getConnection();
-			
-			//remove from protocol
-			if(c.getProtocol()!=null)
-				c.getProtocol().removeDevice(p);
-			
-			//remove from connection
-			c.removeSmartDevice(p);
-			if (c.getStatus()==Connection.FINISHED||c.getStatus()==Connection.TERMINATED) {
-				//if connection terminated - remove rest of ports
-				for (Port sd : c.getParticipants()) {
-					if (sd != null && sd != p)
-						sd.getOwner().removePort(sd);
-				}
-			}*/
-		}
-		
-		// Remove from Links
-		LinkedList<Link> links = new LinkedList<Link>(toDelete.getLinks());
-		for (Link link : links)
-			removeSmartDeviceFromLink(toDelete, link);
-		links.clear();
-		// Remove Links from Device
-		toDelete.getLinks().clear();
-				
-		//Remove all ports from the device
-		toDelete.getPorts().clear();
-		model.getDevices().remove(toDelete);
+		networkController.deleteSmartDevice(toDelete);
 	}
 
 	/**
@@ -296,15 +199,10 @@ public class Controller {
 	 * 
 	 * @param toRemove the Device that should be removed from the link
 	 * @param link the Link, which contains the SmartDevice
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#removeSmartDeviceFromLink(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,SmartDevice,Link)} instead
 	 */
 	public void removeSmartDeviceFromLink(SmartDevice toRemove, Link link) {
-		if(link != null){
-			link.removeDevice(toRemove);
-			if(link.getDevices().size()==0)
-				deleteLink(link);
-		}
-		if(toRemove!=null)
-			toRemove.removeLink(link);
+		networkController.removeSmartDeviceFromLink(toRemove, link);
 	}
 	
 	/**
@@ -335,101 +233,118 @@ public class Controller {
 	
 	/**
 	 * @return the width
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#getWidth(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
 	 */
 	public int getWidth() {
-		return model.getWidth();
+		return settingsController.getWidth();
 	}
 
 	/**
 	 * @param width the width to set
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#setWidth(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,int)} instead
 	 */
 	public void setWidth(int width) {
-		model.setWidth(width);
+		settingsController.setWidth(width);
 	}
 
 	/**
 	 * @return the height
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#getHeight(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
 	 */
 	public int getHeight() {
-		return model.getHeight();
+		return settingsController.getHeight();
 	}
 
 	/**
 	 * @param height the height to set
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#setHeight(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,int)} instead
 	 */
 	public void setHeight(int height) {
-		model.setHeight(height);
+		settingsController.setHeight(height);
 	}
 
 	/**
 	 * @return the depth
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.ImportController#getDepth(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
 	 */
 	public int getDepth() {
-		return model.getDepth();
+		return settingsController.getDepth();
 	}
 
 	/**
 	 * @param depth the depth to set
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#setDepth(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,int)} instead
 	 */
 	public void setDepth(int depth) {
-		model.setDepth(depth);
+		settingsController.setDepth(depth);
 	}
 	
 	/**
 	 * @return the device_visualization_radius
+	 * @deprecated 
 	 */
-	private int getDevice_visualization_radius() {
+	int getDevice_visualization_radius() {
 		return settingsController.getDeviceVisualizationRadius();
 	}
 	
 	/**
 	 * Adds Link to the model
 	 * @param link link to add
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#addLink(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Link)} instead
 	 */
 	public void addLink(Link link){
-		model.addConnectionNetwork(link);
+		networkController.addLink(link);
 	}
 	
 	/**
 	 * Removes Link from the Model
 	 * @param link link to remove
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#removeLink(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Link)} instead
 	 */
 	public void removeLink(Link link){
-		model.getConnectionNetworks().remove(link);
+		networkController.removeLink(link);
 	}
 	
+	/**
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#getLinks(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
+	 */
 	public Collection<Link> getLinks(){
-		return model.getConnectionNetworks();
+		return networkController.getLinks();
 	}
 	
+	/**
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#addConnection(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Connection)} instead
+	 */
 	public void addConnection(Connection connection){
-		model.addConnection(connection);
+		networkController.addConnection(connection);
 	}
 	
+	/**
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#removeConnection(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Connection)} instead
+	 */
 	public void removeConnection(Connection connection){
-		model.getConnections().remove(connection);
+		networkController.removeConnection(connection);
 	}
 	
+	/**
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#getConnections(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
+	 */
 	public Collection<Connection> getConnections(){
-		return model.getConnections();
+		return networkController.getConnections();
 	}
 
+	/**
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#addLinkToDevice(Link,SmartDevice)} instead
+	 */
 	public void addLinkToDevice(Link newLink, SmartDevice smartDevice) {
-		if(!newLink.getDevices().contains(smartDevice)){
-			newLink.addDevice(smartDevice);
-			smartDevice.addLink(newLink);
-		}
-		
+		networkController.addLinkToDevice(newLink, smartDevice);
 	}
 
+	/**
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#removeLinkFromDevice(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Link,SmartDevice)} instead
+	 */
 	public void removeLinkFromDevice(Link link, SmartDevice smartDevice) {
-		if(smartDevice!=null)
-			smartDevice.removeLink(link);
-		if(link!=null){
-			link.removeDevice(smartDevice);
-			if(link.getDevices().size()==0)
-				deleteLink(link);
-		}
+		networkController.removeLinkFromDevice(link, smartDevice);
 	}
 	
 	/**
@@ -440,55 +355,20 @@ public class Controller {
 	 * @param device device which should be added
 	 * @param newRole new role of the device
 	 * @return true if new role was set, false if not
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#changeRoleOfDevice(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Protocol,Connection,Port,int)} instead
 	 */
 	public boolean changeRoleOfDevice(Protocol protocol, Connection con, Port device, int newRole){
-		if(newRole < 0 || newRole >= protocol.getNumberOfRoles()){
-			protocol.removeDevice(device);
-			removeDeviceFromConnection(device, con);
-			return false;
-		} else if(protocol.getDevicesWithRole(newRole).contains(device)){
-			if(!con.getParticipants().contains(device))
-				con.addSmartDevice(device);
-			if(device.getConnection()!=con)
-				device.setConnection(con);
-			return true;
-		}
-		else{
-			protocol.removeDevice(device);
-			boolean added = protocol.addDeviceOfRole(device, newRole);
-			if(added){
-				if(!con.getParticipants().contains(device))
-					con.addSmartDevice(device);
-				if(device.getConnection()!=con)
-					device.setConnection(con);
-				return true;
-			}else{
-				if(con.getParticipants().contains(device))
-					con.removeSmartDevice(device);
-				if(device.getConnection()!=null)
-					device.setConnection(null);
-				return false;
-			}
-		}
+		return networkController.changeRoleOfDevice(protocol, con, device, newRole);
 	}
 	
 	/**
 	 * Removes Device p from the Connection
 	 * @param p Port/Device to remove
 	 * @param connection connection, which should remove the device
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#removeDeviceFromConnection(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Port,Connection)} instead
 	 */
 	public void removeDeviceFromConnection(Port p, Connection connection){
-		if(connection != null){
-			connection.removeSmartDevice(p);
-			connection.getProtocol().removeDevice(p);
-			//TODO: Protocol ?
-			if(connection.getProtocol()!=null)
-				connection.getProtocol().removeDevice(p);
-			if(connection.getParticipants().size() == 0)
-				deleteConnection(connection);
-		}
-		if(p!=null)
-			p.setConnection(null);
+		networkController.removeDeviceFromConnection(p, connection);
 	}
 	
 	/**
@@ -497,25 +377,10 @@ public class Controller {
 	 * @param connection Connection
 	 * @param role new role of the device (See {@link Protocol} Roles)
 	 * @return true, if the device was added
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#addDeviceToConnection(Port,Connection,int)} instead
 	 */
 	public boolean addDeviceToConnection(Port p, Connection connection, int role){
-		if(connection.getProtocol().getDevicesWithRole(role).contains(p) || connection.getProtocol().addDeviceOfRole(p, role)){
-			//If port already has the role, or it could be assigned - just check the fields
-			if(!connection.getParticipants().contains(p))
-				connection.addSmartDevice(p);
-			if(p.getConnection()!=connection)
-				p.setConnection(connection);
-			return true;
-		}else {
-			//Device could not be added -> Remove
-			if(p.getConnection()==connection)
-				p.setConnection(null);
-			if(connection.getParticipants().contains(p))
-				connection.removeSmartDevice(p);
-			if(connection.getProtocol().getDevices().contains(p))
-				connection.getProtocol().removeDevice(p);
-			return false;
-		}
+		return networkController.addDeviceToConnection(p, connection, role);
 	}
 
 	/**
@@ -523,22 +388,10 @@ public class Controller {
 	 * @param connection
 	 * @param newLink
 	 * @return true on successful change, false on failure & restore
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#changeLinkOfConnection(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Connection,Link)} instead
 	 */
 	public boolean changeLinkOfConnection(Connection connection, Link newLink) {
-		if(newLink != null){
-			connection.getLink().removeConnection(connection);
-			connection.setLink(newLink);
-			for(Port p:connection.getParticipants()){
-				if(p.getOwner()!=null&& !newLink.getDevices().contains(p.getOwner())){
-					this.addLinkToDevice(newLink, p.getOwner());
-				}
-			}
-			connection.setLink(newLink);
-			newLink.addConnection(connection);
-			return true;
-		}else{
-			return false;
-		}
+		return networkController.changeLinkOfConnection(connection, newLink);
 	}
 	
 	/**
@@ -546,144 +399,60 @@ public class Controller {
 	 * @param connection connection to be updated
 	 * @param newConnectionClass class of new type
 	 * @return newly created connection
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#changeConnectionType(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Connection,Class<? extends Connection>)} instead
 	 */
 	public Connection changeConnectionType(Connection connection, Class<? extends Connection> newConnectionClass) {
-		
-		Connection newCon = null;
-		try{
-			newCon = newConnectionClass.newInstance();
-			newCon.setProtocol(connection.getProtocol());
-			newCon.setLink(connection.getLink());
-			connection.getLink().addConnection(newCon);
-			newCon.setStatus(connection.getStatus());
-			newCon.setPacketLossProbability(connection.getPacketLossProbability());
-			newCon.setName(connection.getName());
-			for (Iterator<Port> p = connection.getParticipants().iterator(); p.hasNext();) {
-				Port type = (Port) p.next();
-				newCon.addSmartDevice(type);
-				type.setConnection(newCon);
-				
-			}
-		}catch(Exception e){
-			System.out.println("Error while changing protocol: "+e.toString());
-			/**
-			 * Restore old connection on Failure
-			 */
-			if(newCon != null){
-				newCon.setProtocol(null);
-				if(newCon.getLink()!=null)
-					newCon.getLink().removeConnection(newCon);
-				newCon.setLink(null);
-				for (Iterator<Port> p = connection.getParticipants().iterator(); p.hasNext();) {
-					Port type = (Port) p.next();
-					if(type.getConnection()!=connection)
-						type.setConnection(connection);
-					newCon.removeSmartDevice(type);
-					
-				}
-				
-				
-			}
-			return null;
-		}
-		if(this.getConnections().contains(connection)){
-			this.removeConnection(connection);
-		}
-		this.addConnection(newCon);	
-		getControllerConfiguration().getConfigurationManager().getSelectionModel().clickedConnection.clear();
-			
-			
-		connection.setLink(null);
-		connection.setProtocol(null);
-		connection.setStatus(Connection.TERMINATED);
-		connection.setName("deleted");
-		for(Port p: newCon.getParticipants()){
-			connection.removeSmartDevice(p);			
-		}
-		
-		notifyObservers();
-		
-		return newCon;
+		return networkController.changeConnectionType(connection, newConnectionClass);
 	}
 	
 	/**
 	 * Deletes the network model, removes all Devices, Connections and Links
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#deleteNetworkModel(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
 	 */
 	public void deleteNetworkModel(){
-		/**
-		 * Devices which should be deleted
-		 */
-		LinkedList<SmartDevice> devicesToDelete = new LinkedList<SmartDevice>(model.getDevices());
-		for(SmartDevice d: devicesToDelete)
-			deleteSmartDevice(d);
-		devicesToDelete.clear();
-		/**
-		 * Connections which should be deleted
-		 */
-		LinkedList<Connection> connectionsToDelete = new LinkedList<Connection>(model.getConnections());
-		for(Connection c: connectionsToDelete)
-			deleteConnection(c);
-		connectionsToDelete.clear();
-		/**
-		 * Links which should be delted
-		 */
-		LinkedList<Link> linksToDelete = new LinkedList<Link>(model.getConnectionNetworks());
-		for(Link l: model.getConnectionNetworks())
-			deleteLink(l);
-		linksToDelete.clear();
-		/**
-		 * Update the GUI
-		 */
-		notifyObservers();
+		networkController.deleteNetworkModel();
 	}
 
 	/**
 	 * Deletes the Connection c and all references
 	 * @param c Connection to be deleted
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#deleteConnection(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Connection)} instead
 	 */
 	public void deleteConnection(Connection c) {
-		if(c == null)return;
-		LinkedList<Port> ports = new LinkedList<Port>(c.getParticipants());
-		for(Port p:ports)
-			removeDeviceFromConnection(p, c);
-		ports.clear();
-		removeConnectionFromLink(c, c.getLink());
-		c.setStatus(Connection.TERMINATED);
-		removeConnection(c);
+		networkController.deleteConnection(c);
 	}
 
 	/**
 	 * Deletes Link l and all references
 	 * @param l Link to be deleted
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#deleteLink(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Link)} instead
 	 */
 	public void deleteLink(Link l) {
-		if(l==null)return;
-		LinkedList<SmartDevice> devices = new LinkedList<SmartDevice>(l.getDevices());
-		for(SmartDevice d : devices)
-			removeLinkFromDevice(l, d);
-		devices.clear();
-		LinkedList<Connection> connections = new LinkedList<Connection>(l.getConnections());
-		for(Connection c:connections)
-			removeConnectionFromLink(c,l);
-		connections.clear();
-		l.getPackets().clear();
-		removeLink(l);
+		networkController.deleteLink(l);
 	}
 	
 	/**
 	 * Removes Connection from Link
 	 * @param c Connection to be removed
 	 * @param l Link to be removed
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#removeConnectionFromLink(Connection,Link)} instead
 	 */
 	public void removeConnectionFromLink(Connection c, Link l) {
-		if(c!=null && c.getLink()==l){
-			c.setLink(null);
-		}
-		if(l!=null){
-			l.removeConnection(c);		
-		}
+		networkController.removeConnectionFromLink(c, l);
+	}
+
+	/**
+	 * Changes the type of the link to new type, specified by the given Link-class
+	 * @param oldLink oldLink, whose attributes will b copied to the new Link 
+	 * @param newType Type/Class of the new Link
+	 * @return newly created Link, null on failure/error
+	 * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#changeLinkType(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Link,Class<? extends Link>)} instead
+	 */
+	public Link changeLinkType(Link oldLink, Class<? extends Link> newType) {
+		return networkController.changeLinkType(oldLink, newType);
 	}
 	
+	// TODO: Maybe Settings controller ? 
 	/**
 	 * Reset Simulation 
 	 * 
@@ -695,7 +464,7 @@ public class Controller {
 				if(p.getLastTrigger()>timestep)
 					p.setLastTrigger(timestep);
 	}
-
+	
 	/**
 	 * Returns the Simulation Manager of the Program
 	 * @return Simulation Manager
@@ -703,42 +472,4 @@ public class Controller {
 	public SimulationManager getSimulationManager() {
 		return model.getSim();
 	}
-
-	/**
-	 * Changes the type of the link to new type, specified by the given Link-class
-	 * @param oldLink oldLink, whose attributes will b copied to the new Link 
-	 * @param newType Type/Class of the new Link
-	 * @return newly created Link, null on failure/error
-	 */
-	public Link changeLinkType(Link oldLink, Class<? extends Link> newType) {
-		if(newType == null)
-			return null;
-		/**
-		 * New Link which was created
-		 */
-		Link newLink = null;
-		try{
-			newLink = newType.newInstance();
-		}catch(Exception e){
-			return null;
-		}
-		if (newLink == null) {
-			return null;
-		}else {
-			// Set old Name
-			newLink.setName(oldLink.getName());
-			// Add to Mode
-			if(getLinks().contains(oldLink)){
-				removeLink(oldLink);
-				addLink(newLink);
-			}
-			// Add devices to the new Link
-			LinkedList<SmartDevice> devices= new LinkedList<>(oldLink.getDevices());
-			for(SmartDevice device:devices){
-				removeLinkFromDevice(oldLink, device);
-				addLinkToDevice(newLink, device);
-			}
-		return newLink;
-		}
-	}
 }

+ 0 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/ImportController.java

@@ -293,7 +293,6 @@ public class ImportController {
 		return true;
 	}
 	
-	
 	/**
 	 * Imports the given .java File, compiles it and returns the 
 	 * 

+ 518 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/NetworkController.java

@@ -0,0 +1,518 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.control;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
+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.Protocol;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
+
+/**
+ * Controller for manipulation of the network model with methods like  
+ * 
+ *
+ * @author Andreas T. Meyer-Berg
+ */
+public class NetworkController {
+
+	/**
+	 * Model which will be manipulated
+	 */
+	private Model model;
+	/**
+	 * Controller which can be use
+	 */
+	private Controller controller;
+	
+	/**
+	 * Creates a new NetworkController, which may manipulate the given model and use the controller
+	 * @param model
+	 * @param controller
+	 */
+	public NetworkController(Model model, Controller controller) {
+		this.model = model;
+		this.controller = controller;
+	}
+
+	/**
+	 * Validate all device positions, move all devices into the bounds, if they are outside the visualization
+	 */
+	public void validateDevicePosition() {
+		// Update all device positions
+		for (SmartDevice d : controller.model.getDevices()) {
+			d.setX(controller.getControllerConfiguration().scalePos(d.getX(), 1.0, controller.getControllerConfiguration().getWidth()));
+			d.setY(controller.getControllerConfiguration().scalePos(d.getY(), 1.0, controller.getControllerConfiguration().getHeight()));
+			d.setZ(controller.getControllerConfiguration().scalePos(d.getZ(), 1.0, controller.getControllerConfiguration().getDepth()));
+		}
+	}
+
+	/**
+	 * Adds SmartDevice to the Model and verifies that it is inside the model
+	 * bounds
+	 * 
+	 * @param sd
+	 *            SmartDevice which should be added to the model
+	 */
+	public void addSmartDevice(SmartDevice sd) {
+		if (controller.model.getDevices().contains(sd))
+			return;
+		controller.model.addDevices(sd);
+		// validate Position
+		sd.setX(controller.scalePos(sd.getX(), 1.0, controller.model.getWidth()));
+		sd.setY(controller.scalePos(sd.getY(), 1.0, controller.model.getHeight()));
+		sd.setZ(controller.scalePos(sd.getZ(), 1.0, controller.model.getDepth()));
+	}
+
+	/**
+	 * Creates a new SmartDevice at the given Position. The Device is moved
+	 * into the model bounds, if the position is outside the bounds
+	 * 
+	 * @param name
+	 *            name of the smartDevice
+	 * @param x_pos
+	 *            position on the x-Axis
+	 * @param y_pos
+	 *            position on the y-Axis
+	 * @param z_pos
+	 *            position on the z-Axis
+	 */
+	public void createSmartDevice(String name, int x_pos, int y_pos, int z_pos) {
+		SmartDevice sd = new SmartDevice(name);
+		sd.setX(controller.scalePos(x_pos, 1.0, controller.model.getWidth()));
+		sd.setY(controller.scalePos(y_pos, 1.0, controller.model.getHeight()));
+		sd.setZ(controller.scalePos(z_pos, 1.0, controller.model.getDepth()));
+		controller.model.addDevices(sd);
+	}
+
+	/**
+	 * Deletes the given SmartDevice toDelete, removes it from its links and
+	 * connections.
+	 * 
+	 * @param toDelete
+	 *            the SmartDevice to delete
+	 */
+	public void deleteSmartDevice(SmartDevice toDelete) {
+		if (toDelete == null)
+			return;
+	
+		// Delete Connections
+		for (Port p : toDelete.getPorts()) {
+			//Skip ports that are not connected
+			if(p.getConnection()==null)continue;
+			controller.removeDeviceFromConnection(p, p.getConnection());
+			
+			/**
+			 * Connection of the current port
+			 *
+			Connection c = p.getConnection();
+			
+			//remove from protocol
+			if(c.getProtocol()!=null)
+				c.getProtocol().removeDevice(p);
+			
+			//remove from connection
+			c.removeSmartDevice(p);
+			if (c.getStatus()==Connection.FINISHED||c.getStatus()==Connection.TERMINATED) {
+				//if connection terminated - remove rest of ports
+				for (Port sd : c.getParticipants()) {
+					if (sd != null && sd != p)
+						sd.getOwner().removePort(sd);
+				}
+			}*/
+		}
+		
+		// Remove from Links
+		LinkedList<Link> links = new LinkedList<Link>(toDelete.getLinks());
+		for (Link link : links)
+			controller.removeSmartDeviceFromLink(toDelete, link);
+		links.clear();
+		// Remove Links from Device
+		toDelete.getLinks().clear();
+				
+		//Remove all ports from the device
+		toDelete.getPorts().clear();
+		controller.model.getDevices().remove(toDelete);
+	}
+
+	/**
+	 * Removes the SmartDevice from the given Link
+	 * 
+	 * @param toRemove the Device that should be removed from the link
+	 * @param link the Link, which contains the SmartDevice
+	 */
+	public void removeSmartDeviceFromLink(SmartDevice toRemove, Link link) {
+		if(link != null){
+			link.removeDevice(toRemove);
+			if(link.getDevices().size()==0)
+				controller.deleteLink(link);
+		}
+		if(toRemove!=null)
+			toRemove.removeLink(link);
+	}
+
+	/**
+	 * Moves the SmartDevice device to the specified location, if it exists
+	 * 
+	 * @param device
+	 *            the device to move
+	 * @param x
+	 *            new x position
+	 * @param y
+	 *            new y position
+	 * @param z
+	 *            new z position
+	 */
+	public void moveSmartDevice(SmartDevice device, int x, int y, int z) {
+		device.setX(x);
+		device.setY(y);
+		device.setZ(z);
+	
+	}
+
+	/**
+	 * Adds Link to the model
+	 * @param link link to add
+	 */
+	public void addLink(Link link){
+		controller.model.addConnectionNetwork(link);
+	}
+
+	/**
+	 * Removes Link from the Model
+	 * @param link link to remove
+	 */
+	public void removeLink(Link link){
+		controller.model.getConnectionNetworks().remove(link);
+	}
+
+	public Collection<Link> getLinks(){
+		return controller.model.getConnectionNetworks();
+	}
+
+	public void addConnection(Connection connection){
+		controller.model.addConnection(connection);
+	}
+
+	public void removeConnection(Connection connection){
+		controller.model.getConnections().remove(connection);
+	}
+
+	public Collection<Connection> getConnections(){
+		return controller.model.getConnections();
+	}
+
+	public void addLinkToDevice(Link newLink, SmartDevice smartDevice) {
+		if(!newLink.getDevices().contains(smartDevice)){
+			newLink.addDevice(smartDevice);
+			smartDevice.addLink(newLink);
+		}
+		
+	}
+
+	public void removeLinkFromDevice(Link link, SmartDevice smartDevice) {
+		if(smartDevice!=null)
+			smartDevice.removeLink(link);
+		if(link!=null){
+			link.removeDevice(smartDevice);
+			if(link.getDevices().size()==0)
+				controller.deleteLink(link);
+		}
+	}
+
+	/**
+	 * Changes Roles of the device to the newRole, returns true, if the role was successfully changed, false if not.
+	 * If false is returned, the device will no longer be part of this connection.
+	 * 
+	 * @param protocol protocol which should be edited
+	 * @param con TODO
+	 * @param device device which should be added
+	 * @param newRole new role of the device
+	 * @return true if new role was set, false if not
+	 */
+	public boolean changeRoleOfDevice(Protocol protocol, Connection con, Port device, int newRole){
+		if(newRole < 0 || newRole >= protocol.getNumberOfRoles()){
+			protocol.removeDevice(device);
+			controller.removeDeviceFromConnection(device, con);
+			return false;
+		} else if(protocol.getDevicesWithRole(newRole).contains(device)){
+			if(!con.getParticipants().contains(device))
+				con.addSmartDevice(device);
+			if(device.getConnection()!=con)
+				device.setConnection(con);
+			return true;
+		}
+		else{
+			protocol.removeDevice(device);
+			boolean added = protocol.addDeviceOfRole(device, newRole);
+			if(added){
+				if(!con.getParticipants().contains(device))
+					con.addSmartDevice(device);
+				if(device.getConnection()!=con)
+					device.setConnection(con);
+				return true;
+			}else{
+				if(con.getParticipants().contains(device))
+					con.removeSmartDevice(device);
+				if(device.getConnection()!=null)
+					device.setConnection(null);
+				return false;
+			}
+		}
+	}
+
+	/**
+	 * Removes Device p from the Connection
+	 * @param p Port/Device to remove
+	 * @param connection connection, which should remove the device
+	 */
+	public void removeDeviceFromConnection(Port p, Connection connection){
+		if(connection != null){
+			connection.removeSmartDevice(p);
+			connection.getProtocol().removeDevice(p);
+			//TODO: Protocol ?
+			if(connection.getProtocol()!=null)
+				connection.getProtocol().removeDevice(p);
+			if(connection.getParticipants().size() == 0)
+				controller.deleteConnection(connection);
+		}
+		if(p!=null)
+			p.setConnection(null);
+	}
+
+	/**
+	 * Adds Device p to the connection with the specified role
+	 * @param p Port/Device to be added
+	 * @param connection Connection
+	 * @param role new role of the device (See {@link Protocol} Roles)
+	 * @return true, if the device was added
+	 */
+	public boolean addDeviceToConnection(Port p, Connection connection, int role){
+		if(connection.getProtocol().getDevicesWithRole(role).contains(p) || connection.getProtocol().addDeviceOfRole(p, role)){
+			//If port already has the role, or it could be assigned - just check the fields
+			if(!connection.getParticipants().contains(p))
+				connection.addSmartDevice(p);
+			if(p.getConnection()!=connection)
+				p.setConnection(connection);
+			return true;
+		}else {
+			//Device could not be added -> Remove
+			if(p.getConnection()==connection)
+				p.setConnection(null);
+			if(connection.getParticipants().contains(p))
+				connection.removeSmartDevice(p);
+			if(connection.getProtocol().getDevices().contains(p))
+				connection.getProtocol().removeDevice(p);
+			return false;
+		}
+	}
+
+	/**
+	 * Changes the link of the given connection to the new link. Returns true if it was successfully changed, false if it could not be changed.
+	 * @param connection
+	 * @param newLink
+	 * @return true on successful change, false on failure & restore
+	 */
+	public boolean changeLinkOfConnection(Connection connection, Link newLink) {
+		if(newLink != null){
+			connection.getLink().removeConnection(connection);
+			connection.setLink(newLink);
+			for(Port p:connection.getParticipants()){
+				if(p.getOwner()!=null&& !newLink.getDevices().contains(p.getOwner())){
+					controller.addLinkToDevice(newLink, p.getOwner());
+				}
+			}
+			connection.setLink(newLink);
+			newLink.addConnection(connection);
+			return true;
+		}else{
+			return false;
+		}
+	}
+
+	/**
+	 * Changes the type of the connection to the new Type and updates all references
+	 * @param connection connection to be updated
+	 * @param newConnectionClass class of new type
+	 * @return newly created connection
+	 */
+	public Connection changeConnectionType(Connection connection, Class<? extends Connection> newConnectionClass) {
+		
+		Connection newCon = null;
+		try{
+			newCon = newConnectionClass.newInstance();
+			newCon.setProtocol(connection.getProtocol());
+			newCon.setLink(connection.getLink());
+			connection.getLink().addConnection(newCon);
+			newCon.setStatus(connection.getStatus());
+			newCon.setPacketLossProbability(connection.getPacketLossProbability());
+			newCon.setName(connection.getName());
+			for (Iterator<Port> p = connection.getParticipants().iterator(); p.hasNext();) {
+				Port type = (Port) p.next();
+				newCon.addSmartDevice(type);
+				type.setConnection(newCon);
+				
+			}
+		}catch(Exception e){
+			System.out.println("Error while changing protocol: "+e.toString());
+			/**
+			 * Restore old connection on Failure
+			 */
+			if(newCon != null){
+				newCon.setProtocol(null);
+				if(newCon.getLink()!=null)
+					newCon.getLink().removeConnection(newCon);
+				newCon.setLink(null);
+				for (Iterator<Port> p = connection.getParticipants().iterator(); p.hasNext();) {
+					Port type = (Port) p.next();
+					if(type.getConnection()!=connection)
+						type.setConnection(connection);
+					newCon.removeSmartDevice(type);
+					
+				}
+				
+				
+			}
+			return null;
+		}
+		if(controller.getConnections().contains(connection)){
+			controller.removeConnection(connection);
+		}
+		controller.addConnection(newCon);	
+		controller.getControllerConfiguration().getConfigurationManager().getSelectionModel().clickedConnection.clear();
+			
+			
+		connection.setLink(null);
+		connection.setProtocol(null);
+		connection.setStatus(Connection.TERMINATED);
+		connection.setName("deleted");
+		for(Port p: newCon.getParticipants()){
+			connection.removeSmartDevice(p);			
+		}
+		
+		controller.notifyObservers();
+		
+		return newCon;
+	}
+
+	/**
+	 * Deletes the network model, removes all Devices, Connections and Links
+	 */
+	public void deleteNetworkModel(){
+		/**
+		 * Devices which should be deleted
+		 */
+		LinkedList<SmartDevice> devicesToDelete = new LinkedList<SmartDevice>(controller.model.getDevices());
+		for(SmartDevice d: devicesToDelete)
+			controller.deleteSmartDevice(d);
+		devicesToDelete.clear();
+		/**
+		 * Connections which should be deleted
+		 */
+		LinkedList<Connection> connectionsToDelete = new LinkedList<Connection>(controller.model.getConnections());
+		for(Connection c: connectionsToDelete)
+			controller.deleteConnection(c);
+		connectionsToDelete.clear();
+		/**
+		 * Links which should be delted
+		 */
+		LinkedList<Link> linksToDelete = new LinkedList<Link>(controller.model.getConnectionNetworks());
+		for(Link l: controller.model.getConnectionNetworks())
+			controller.deleteLink(l);
+		linksToDelete.clear();
+		/**
+		 * Update the GUI
+		 */
+		controller.notifyObservers();
+	}
+
+	/**
+	 * Deletes the Connection c and all references
+	 * @param c Connection to be deleted
+	 */
+	public void deleteConnection(Connection c) {
+		if(c == null)return;
+		LinkedList<Port> ports = new LinkedList<Port>(c.getParticipants());
+		for(Port p:ports)
+			controller.removeDeviceFromConnection(p, c);
+		ports.clear();
+		controller.removeConnectionFromLink(c, c.getLink());
+		c.setStatus(Connection.TERMINATED);
+		controller.removeConnection(c);
+	}
+
+	/**
+	 * Deletes Link l and all references
+	 * @param controller TODO
+	 * @param l Link to be deleted
+	 */
+	public void deleteLink(Link l) {
+		if(l==null)return;
+		LinkedList<SmartDevice> devices = new LinkedList<SmartDevice>(l.getDevices());
+		for(SmartDevice d : devices)
+			controller.removeLinkFromDevice(l, d);
+		devices.clear();
+		LinkedList<Connection> connections = new LinkedList<Connection>(l.getConnections());
+		for(Connection c:connections)
+			controller.removeConnectionFromLink(c,l);
+		connections.clear();
+		l.getPackets().clear();
+		controller.removeLink(l);
+	}
+
+	/**
+	 * Removes Connection from Link
+	 * @param c Connection to be removed
+	 * @param l Link to be removed
+	 */
+	public void removeConnectionFromLink(Connection c, Link l) {
+		if(c!=null && c.getLink()==l){
+			c.setLink(null);
+		}
+		if(l!=null){
+			l.removeConnection(c);		
+		}
+	}
+
+	/**
+	 * Changes the type of the link to new type, specified by the given Link-class
+	 * @param oldLink oldLink, whose attributes will b copied to the new Link 
+	 * @param newType Type/Class of the new Link
+	 * @return newly created Link, null on failure/error
+	 */
+	public Link changeLinkType(Link oldLink, Class<? extends Link> newType) {
+		if(newType == null)
+			return null;
+		/**
+		 * New Link which was created
+		 */
+		Link newLink = null;
+		try{
+			newLink = newType.newInstance();
+		}catch(Exception e){
+			return null;
+		}
+		if (newLink == null) {
+			return null;
+		}else {
+			// Set old Name
+			newLink.setName(oldLink.getName());
+			// Add to Mode
+			if(controller.getLinks().contains(oldLink)){
+				controller.removeLink(oldLink);
+				controller.addLink(newLink);
+			}
+			// Add devices to the new Link
+			LinkedList<SmartDevice> devices= new LinkedList<>(oldLink.getDevices());
+			for(SmartDevice device:devices){
+				controller.removeLinkFromDevice(oldLink, device);
+				controller.addLinkToDevice(newLink, device);
+			}
+		return newLink;
+		}
+	}
+
+}

+ 139 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/SettingsController.java

@@ -2,6 +2,7 @@ package de.tu_darmstadt.tk.SmartHomeNetworkSim.control;
 
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.ConfigurationManager;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
 
 /**
  * Controller which allows access to the configuration
@@ -124,7 +125,7 @@ public class SettingsController {
 	 */
 	public void setDeviceVisualizationRadius(int deviceVisualizationRadius) {
 		model.getConfigurator().getVisualizationConfiguration().setDeviceVisualizationRadius(deviceVisualizationRadius);
-		controller.validateDevicePosition();
+		controller.getNetworkController().validateDevicePosition();
 		controller.notifyObservers();
 	}
 
@@ -158,4 +159,141 @@ public class SettingsController {
 		model.getConfigurator().getVisualizationConfiguration().setShowLinkToolTips(showLinkToolTips);
 		controller.notifyObservers();
 	}
+
+	/**
+	 * Changes the dimension of the model, without scaling the SmartDevice
+	 * positions
+	 * 
+	 * @param width
+	 *            the new width to set
+	 * @param height
+	 *            the new height to set
+	 * @param depth
+	 *            the new depth to set
+	 */
+	public void setDimension(int width, int height, int depth) {
+		setDimension(width, height, depth, false);
+	}
+
+	/**
+	 * Changes the dimension of the model and moves SmartDevices to new relative
+	 * positions if {@code stretchModel} is true
+	 * 
+	 * @param width
+	 *            the new width to set
+	 * @param height
+	 *            the new height to set
+	 * @param depth
+	 *            the new depth to set
+	 * @param stretchModel
+	 *            true, if smartDevice positions should be stretched
+	 */
+	public void setDimension(int width, int height, int depth, boolean stretchModel) {
+		// Don't allow to small Models
+		if (width < 400)
+			width = 400;
+		if (height < 400)
+			height = 400;
+		if (depth < 400)
+			depth = 400;
+	
+		if (stretchModel) {
+			/**
+			 * Factor that changes the x position. Example: 1 -> positions stay
+			 * the same 0.5 -> x position is halved 2 -> x position is doubled
+			 */
+			double width_factor = ((double) width) / ((double) controller.model.getWidth());
+			/**
+			 * Factor that changes the y position. Example: 1 -> positions stay
+			 * the same 0.5 -> y position is halved 2 -> y position is doubled
+			 */
+			double height_factor = ((double) height) / ((double) controller.model.getHeight());
+			/**
+			 * Factor that changes the z position. Example: 1 -> positions stay
+			 * the same 0.5 -> z position is halved 2 -> z position is doubled
+			 */
+			double depth_factor = ((double) depth) / ((double) controller.model.getDepth());
+			// Update all device positions
+			for (SmartDevice d : controller.model.getDevices()) {
+				if (width_factor != 1.0)
+					d.setX(scalePos(d.getX(), width_factor, width));
+				if (height_factor != 1.0)
+					d.setY(scalePos(d.getY(), height_factor, height));
+				if (depth_factor != 1.0)
+					d.setZ(scalePos(d.getZ(), depth_factor, depth));
+			}
+		}
+		controller.model.setWidth(width);
+		controller.model.setHeight(height);
+		controller.model.setDepth(depth);
+	}
+
+	/**
+	 * Calculates the new scaled position, which should be in Bounds:
+	 * {@code radius < newPosition <
+	 * (upperBound - radius)}
+	 * 
+	 * @param oldPosition
+	 *            previous position that should be scaled
+	 * @param factor
+	 *            how much it is stretched/shrunk
+	 * @param upperBound
+	 *            upper bound of the frame, which should not be exceeded
+	 * @return new position that was calculated
+	 */
+	int scalePos(int oldPosition, double factor, int upperBound) {
+		/**
+		 * New Position that should be validated and returned
+		 */
+		int newPosition = (int) Math.round(factor * oldPosition);
+		// Update if it moves out of the frame
+		if (newPosition < getDeviceVisualizationRadius())
+			newPosition = getDeviceVisualizationRadius();
+		if (newPosition >= upperBound - getDeviceVisualizationRadius())
+			newPosition = upperBound - getDeviceVisualizationRadius();
+	
+		return newPosition;
+	}
+
+	/**
+	 * @return the width
+	 */
+	public int getWidth() {
+		return controller.model.getWidth();
+	}
+
+	/**
+	 * @param width the width to set
+	 */
+	public void setWidth(int width) {
+		controller.model.setWidth(width);
+	}
+
+	/**
+	 * @return the height
+	 */
+	public int getHeight() {
+		return controller.model.getHeight();
+	}
+
+	/**
+	 * @param height the height to set
+	 */
+	public void setHeight(int height) {
+		controller.model.setHeight(height);
+	}
+	
+	/**
+	 * @return the depth
+	 */
+	public int getDepth() {
+		return controller.model.getDepth();
+	}
+
+	/**
+	 * @param depth the depth to set
+	 */
+	public void setDepth(int depth) {
+		controller.model.setDepth(depth);
+	}
 }