Browse Source

Adds visualisation of Connection status and terminated connections

Green: Active
Orange: Halted
Red: Terminated

Missing SmartDevices of terminated Connections will be visualised as red
Dots. The terminated connections will print their last packets and be
removed on the next press of rightclick->printDebug.
Andreas T. Meyer-Berg 5 years ago
parent
commit
1e9bbc98e1

+ 393 - 336
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualisationInteractor.java

@@ -1,336 +1,393 @@
-package de.tu_darmstadt.tk.SmartHomeNetworkSim.view;
-
-import java.awt.Point;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseMotionListener;
-
-import javax.swing.JMenuItem;
-import javax.swing.JPopupMenu;
-import javax.swing.event.MouseInputListener;
-
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
-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.Packet;
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleConnection;
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleLink;
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleProtocol;
-
-/**
- * Listener which detects User Interaction with the {@link VisualisationPanel},
- * stores interaction information, triggers the controller and helps
- * visualization of the interaction
- * 
- * @author Andreas T. Meyer-Berg
- */
-public class VisualisationInteractor implements MouseInputListener, MouseMotionListener, ActionListener {
-
-	/**
-	 * Smart Home model which should be interacted with
-	 */
-	private Model model;
-
-	/**
-	 * Controller to notify when the model changes
-	 */
-	private Controller control;
-
-	/**
-	 * Panel which is observed
-	 */
-	private VisualisationPanel panel;
-	
-	/**
-	 * Menu which is shown on right clicks
-	 */
-	private JPopupMenu rightClickMenu;
-	
-	/**
-	 * RightClick MenuItem for SmartDevice creation
-	 */
-	private JMenuItem itemCreate;
-	
-	/**
-	 * RightClick MenuItem for SmartDevice deletion
-	 */
-	private JMenuItem itemDelete;
-	
-	/**
-	 * RightClick MenuItem for debug purposes
-	 */
-	private JMenuItem itemDebug;
-	
-	/**
-	 * SmartDevice that is dragged on Screen
-	 */
-	public SmartDevice dragged = null;
-
-	/**
-	 * Current x Position of the dragged device
-	 */
-	public int dragged_x;
-
-	/**
-	 * Current y Position of the dragged device
-	 */
-	public int dragged_y;
-	
-	/**
-	 * SmartDevice that was clicked
-	 */
-	private SmartDevice clicked = null;
-
-	public SmartDevice connectionFrom = null;
-	
-	/**
-	 * Creates a new VisualisationInteractor
-	 *
-	 * @param model Model which is visualized
-	 * @param controller controller that is accessed
-	 * @param panel which should visualize the interactions
-	 */
-	public VisualisationInteractor(Model model, Controller controller, VisualisationPanel panel) {
-		//Initialize the values
-		this.model = model;
-		this.control = controller;
-		this.panel = panel;
-		
-		this.rightClickMenu = new JPopupMenu();
-		
-		//Create device option
-		itemCreate = new JMenuItem("Create SmartDevice");
-		
-		itemCreate.addActionListener(e -> {
-			SmartDeviceCreationPopUp popUp = new SmartDeviceCreationPopUp(dragged_x, dragged_y, model.getWidth(), model.getHeight(), panel.getVisualisationRadius(), control, panel);
-			popUp.setLocationRelativeTo(panel);
-			popUp.setEnabled(true);
-			popUp.setVisible(true);
-			
-		});
-		
-		rightClickMenu.add(itemCreate);
-		
-		//Delete device option
-		itemDelete = new JMenuItem("Delete");
-		
-		itemDelete.addActionListener(e -> {
-			//Delete the clicked object
-			controller.deleteSmartDevice(clicked);
-			clicked = null;
-			panel.repaint();
-			});
-
-		rightClickMenu.add(itemDelete);
-		
-		/*
-		 * Add PrintDebug option
-		 */
-		itemDebug = new JMenuItem("Print NetworkState");
-		itemDebug.addActionListener(e->{
-			//Print Links, Devices and Connections
-			for(Link l:model.getConnectionNetworks())
-				System.out.println("Link: "+l.getName());
-			for(SmartDevice d: model.getDevices()){
-				System.out.println("Device: "+d.getName());
-				for(Connection c: d.getConnections()){
-					if(c.getSource()==null)
-						System.out.println("Connection: terminated");
-					else
-						System.out.println("Connection: "+c.getSource().getName());
-				}
-			}
-			//Print Terminating Packages
-			for(Connection c: model.getTerminatingConnections()){
-				for(Packet p:c.getTerminationPackages(1000))
-					System.out.println(p.toString());
-			}
-		});
-		rightClickMenu.add(itemDebug);
-		
-		this.panel.add(rightClickMenu);
-	}
-
-	@Override
-	public void mouseClicked(MouseEvent e) {
-		//Finish operations
-		if(dragged!=null){
-			finishDrag();
-		}
-		connectionFrom =null;
-		
-		/*
-		 * FindSmartDevice that was clicked
-		 */
-		clicked = null;
-		// Find the clicked SmartDevice
-		for (SmartDevice d : model.getDevices()) {
-			if (Math.abs(d.getX() - e.getX()) < panel.getVisualisationRadius()
-					&& Math.abs(d.getY() - e.getY()) < panel.getVisualisationRadius()) {
-				clicked = d;
-			}
-		}
-		//If Rightclick
-		if(e.getButton()==MouseEvent.BUTTON3) {
-			//Show the RightClickMenu
-			showRightClickMenu(clicked);	
-		}
-			
-	}
-
-	/**
-	 * Shows the RightClick Menu on the Visualization Panel, with Options for the given SmartDevice clickedOn, 
-	 * if clickedOn is null, the RightClick Menu contains Options for creation of new SmartDevices.
-	 * The Menu will be shown at the Mouse position on the VisualisationPanel. 
-	 * @param clickedOn Device which was clicked, null if no
-	 */
-	protected void showRightClickMenu(SmartDevice clickedOn) {
-		/**
-		 * Mouse Position on the VisualisationPanel
-		 */
-		Point mousePos = panel.getMousePosition();
-		//Just execute if Mouse Position is on the Panel
-		if(mousePos != null){
-			if(clickedOn == null){		
-				itemCreate.setEnabled(true);
-				itemDelete.setEnabled(false);
-			}
-			else{
-				itemCreate.setEnabled(false);
-				itemDelete.setEnabled(true);
-			}
-			//Show the RightClickMenu
-			rightClickMenu.show(panel, mousePos.x, mousePos.y);
-			rightClickMenu.setEnabled(true);
-			rightClickMenu.setVisible(true);
-		}
-	}
-
-	@Override
-	public void mousePressed(MouseEvent e) {
-		//Save mouse position for right Click options
-		dragged_x = e.getX();
-		dragged_y = e.getY();
-		// Check if SmartDevice was clicked
-		SmartDevice pressedOn = getSmartDeviceAtPosition(e.getX(), e.getY());
-		if(pressedOn == null)return;
-		
-		// Recognize possible drag operation
-		if (e.getButton() == MouseEvent.BUTTON1 && connectionFrom == null) {
-			dragged = pressedOn;
-			dragged_x = pressedOn.getX();
-			dragged_y = pressedOn.getY();
-		} else if(e.getButton() == MouseEvent.BUTTON3 && dragged == null){
-			connectionFrom = pressedOn;
-		}
-	}
-
-	@Override
-	public void mouseReleased(MouseEvent e) {
-		// Finish drag operation
-		//if (e.getButton() == MouseEvent.BUTTON1)
-			finishDrag();
-		//else if(e.getButton() == MouseEvent.BUTTON3){
-			finishConnectionCreation();
-		//}
-	}
-
-	@Override
-	public void mouseEntered(MouseEvent e) {
-
-	}
-
-	@Override
-	public void mouseExited(MouseEvent e) {
-
-	}
-
-	@Override
-	public void actionPerformed(ActionEvent e) {
-
-	}
-
-	@Override
-	public void mouseDragged(MouseEvent e) {
-		// move dragged object on screen along y Axis
-		if (e.getX() <= panel.getVisualisationRadius())
-			dragged_x = panel.getVisualisationRadius();
-		else if (e.getX() >= model.getWidth() - panel.getVisualisationRadius())
-			dragged_x = model.getWidth() - panel.getVisualisationRadius();
-		else
-			dragged_x = e.getX();
-		// move dragged object on screen along y Axis
-		if (e.getY() <= panel.getVisualisationRadius())
-			dragged_y = panel.getVisualisationRadius();
-		else if (e.getY() >= model.getHeight() - panel.getVisualisationRadius())
-			dragged_y = model.getHeight() - panel.getVisualisationRadius();
-		else
-			dragged_y = e.getY();
-		// repaint the dragged smartDevice or new connection
-		if (dragged != null || connectionFrom != null)
-			panel.repaint();
-	}
-
-	@Override
-	public void mouseMoved(MouseEvent e) {
-		
-	}
-	
-	/**
-	 * Finishes the drag operation, if a SmartDevice was dragged, repaint the panel and set dragged to null
-	 */
-	public void finishDrag(){
-		if (dragged != null && (dragged.getX() != dragged_x || dragged.getY() != dragged_y)) {
-			control.moveSmartDevice(dragged, dragged_x, dragged_y, dragged.getZ());
-			panel.repaint();
-			dragged = null;
-		}
-	}
-	
-	/**
-	 * Finishes the create connection operation and open a PopUp for Link/Connection creation
-	 */
-	private void finishConnectionCreation() {
-		/**
-		 * SmartDevice the connection was 
-		 */
-		SmartDevice connectionTo = getSmartDeviceAtPosition(dragged_x, dragged_y);
-		if(connectionFrom != null && connectionTo != null && connectionFrom != connectionTo){
-			//Create new Connection
-			Link l = new SimpleLink("Ethernet: "+connectionFrom.getName()+" to "+connectionTo.getName());
-			l.addDevice(connectionFrom);
-			l.addDevice(connectionTo);
-			Connection c = new SimpleConnection(connectionFrom, connectionTo, l, new SimpleProtocol(connectionFrom, connectionTo));
-			connectionTo.addLink(l);
-			connectionTo.addConnection(c);
-			connectionFrom.addLink(l);
-			connectionFrom.addConnection(c);
-			connectionFrom = null;
-		}else{
-			connectionFrom = null;
-		}
-		panel.repaint();
-	}
-	
-	/**
-	 * Returns SmartDevice which is at position (x,y) or within its visualization radius.
-	 * Returns null, if no SmartDevice is within the range.
-	 * 
-	 * @param x x-position which should be checked
-	 * @param y y-position which should be checked
-	 * @return {@link SmartDevice} at position (x,y) or null if there is no
-	 */
-	private SmartDevice getSmartDeviceAtPosition(int x, int y) {
-		//Check is device is inside visualization radius
-		for (SmartDevice d : model.getDevices()) {
-			if (Math.abs(d.getX() - x) < panel.getVisualisationRadius()
-					&& Math.abs(d.getY() - y) < panel.getVisualisationRadius()) {
-				return d;
-			}
-		}
-		return null;
-	}
-}
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.view;
+
+import java.awt.Point;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionListener;
+import java.util.LinkedList;
+
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+import javax.swing.event.MouseInputListener;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
+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.Packet;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleConnection;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleLink;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleProtocol;
+
+/**
+ * Listener which detects User Interaction with the {@link VisualisationPanel},
+ * stores interaction information, triggers the controller and helps
+ * visualization of the interaction
+ * 
+ * @author Andreas T. Meyer-Berg
+ */
+public class VisualisationInteractor implements MouseInputListener,
+		MouseMotionListener, ActionListener {
+
+	/**
+	 * Smart Home model which should be interacted with
+	 */
+	private Model model;
+
+	/**
+	 * Controller to notify when the model changes
+	 */
+	private Controller control;
+
+	/**
+	 * Panel which is observed
+	 */
+	private VisualisationPanel panel;
+
+	/**
+	 * Menu which is shown on right clicks
+	 */
+	private JPopupMenu rightClickMenu;
+
+	/**
+	 * RightClick MenuItem for SmartDevice creation
+	 */
+	private JMenuItem itemCreate;
+
+	/**
+	 * RightClick MenuItem for SmartDevice deletion
+	 */
+	private JMenuItem itemDelete;
+
+	/**
+	 * RightClick MenuItem for debug purposes
+	 */
+	private JMenuItem itemDebug;
+
+	/**
+	 * SmartDevice that is dragged on Screen
+	 */
+	public SmartDevice dragged = null;
+
+	/**
+	 * Current x Position of the dragged device
+	 */
+	public int dragged_x;
+
+	/**
+	 * Current y Position of the dragged device
+	 */
+	public int dragged_y;
+
+	/**
+	 * SmartDevice that was clicked
+	 */
+	private SmartDevice clicked = null;
+
+	public SmartDevice connectionFrom = null;
+
+	/**
+	 * Creates a new VisualisationInteractor
+	 *
+	 * @param model
+	 *            Model which is visualized
+	 * @param controller
+	 *            controller that is accessed
+	 * @param panel
+	 *            which should visualize the interactions
+	 */
+	public VisualisationInteractor(Model model, Controller controller,
+			VisualisationPanel panel) {
+		// Initialize the values
+		this.model = model;
+		this.control = controller;
+		this.panel = panel;
+
+		this.rightClickMenu = new JPopupMenu();
+
+		// Create device option
+		itemCreate = new JMenuItem("Create SmartDevice");
+
+		itemCreate.addActionListener(e -> {
+			SmartDeviceCreationPopUp popUp = new SmartDeviceCreationPopUp(
+					dragged_x, dragged_y, model.getWidth(), model.getHeight(),
+					panel.getVisualisationRadius(), control, panel);
+			popUp.setLocationRelativeTo(panel);
+			popUp.setEnabled(true);
+			popUp.setVisible(true);
+
+		});
+
+		rightClickMenu.add(itemCreate);
+
+		// Delete device option
+		itemDelete = new JMenuItem("Delete");
+
+		itemDelete.addActionListener(e -> {
+			// Delete the clicked object
+				controller.deleteSmartDevice(clicked);
+				clicked = null;
+				panel.repaint();
+			});
+
+		rightClickMenu.add(itemDelete);
+
+		/*
+		 * Add PrintDebug option
+		 */
+		itemDebug = new JMenuItem("Print NetworkState");
+		itemDebug.addActionListener(e -> {
+			// Print Links, Devices and Connections
+				for (Link l : model.getConnectionNetworks())
+					System.out.println("Link: " + l.getName());
+				for (SmartDevice d : model.getDevices()) {
+					System.out.println("Device: " + d.getName());
+					for (Port p : d.getPorts()) {
+						if(p==null){
+							System.out.println("Port: null");
+							continue;
+						}
+						if(p.getConnection()==null){
+							System.out.println("Connection: null");
+							continue;
+						}
+						switch (p.getConnection().getStatus()) {
+						case Connection.ACTIVE:
+							System.out.println("Connection: active");
+							break;
+						case Connection.FINISHED:
+						case Connection.TERMINATED:
+							System.out.println("Connection: terminated");
+
+							break;
+
+						case Connection.HALTED:
+						default:
+							break;
+						}
+					}
+				}
+				// Print Terminating Packages
+				LinkedList<Connection> terminated = new LinkedList<Connection>();
+				model.getConnections()
+						.stream()
+						.filter(c -> (c.getStatus() == Connection.FINISHED || c
+								.getStatus() == Connection.TERMINATED))
+						.forEach(c -> {
+							terminated.add(c);
+							for (Packet p : c.getTerminationPackages(1000))
+								System.out.println(p.toString());
+						});
+				model.getConnections().removeAll(terminated);
+				panel.repaint();
+			});
+		rightClickMenu.add(itemDebug);
+
+		this.panel.add(rightClickMenu);
+	}
+
+	@Override
+	public void mouseClicked(MouseEvent e) {
+		// Finish operations
+		if (dragged != null) {
+			finishDrag();
+		}
+		connectionFrom = null;
+
+		/*
+		 * FindSmartDevice that was clicked
+		 */
+		clicked = null;
+		// Find the clicked SmartDevice
+		for (SmartDevice d : model.getDevices()) {
+			if (Math.abs(d.getX() - e.getX()) < panel.getVisualisationRadius()
+					&& Math.abs(d.getY() - e.getY()) < panel
+							.getVisualisationRadius()) {
+				clicked = d;
+			}
+		}
+		// If Rightclick
+		if (e.getButton() == MouseEvent.BUTTON3) {
+			// Show the RightClickMenu
+			showRightClickMenu(clicked);
+		}
+
+	}
+
+	/**
+	 * Shows the RightClick Menu on the Visualization Panel, with Options for
+	 * the given SmartDevice clickedOn, if clickedOn is null, the RightClick
+	 * Menu contains Options for creation of new SmartDevices. The Menu will be
+	 * shown at the Mouse position on the VisualisationPanel.
+	 * 
+	 * @param clickedOn
+	 *            Device which was clicked, null if no
+	 */
+	protected void showRightClickMenu(SmartDevice clickedOn) {
+		/**
+		 * Mouse Position on the VisualisationPanel
+		 */
+		Point mousePos = panel.getMousePosition();
+		// Just execute if Mouse Position is on the Panel
+		if (mousePos != null) {
+			if (clickedOn == null) {
+				itemCreate.setEnabled(true);
+				itemDelete.setEnabled(false);
+			} else {
+				itemCreate.setEnabled(false);
+				itemDelete.setEnabled(true);
+			}
+			// Show the RightClickMenu
+			rightClickMenu.show(panel, mousePos.x, mousePos.y);
+			rightClickMenu.setEnabled(true);
+			rightClickMenu.setVisible(true);
+		}
+	}
+
+	@Override
+	public void mousePressed(MouseEvent e) {
+		// Save mouse position for right Click options
+		dragged_x = e.getX();
+		dragged_y = e.getY();
+		// Check if SmartDevice was clicked
+		SmartDevice pressedOn = getSmartDeviceAtPosition(e.getX(), e.getY());
+		if (pressedOn == null)
+			return;
+
+		// Recognize possible drag operation
+		if (e.getButton() == MouseEvent.BUTTON1 && connectionFrom == null) {
+			dragged = pressedOn;
+			dragged_x = pressedOn.getX();
+			dragged_y = pressedOn.getY();
+		} else if (e.getButton() == MouseEvent.BUTTON3 && dragged == null) {
+			connectionFrom = pressedOn;
+		}
+	}
+
+	@Override
+	public void mouseReleased(MouseEvent e) {
+		// Finish drag operation
+		// if (e.getButton() == MouseEvent.BUTTON1)
+		finishDrag();
+		// else if(e.getButton() == MouseEvent.BUTTON3){
+		finishConnectionCreation();
+		// }
+	}
+
+	@Override
+	public void mouseEntered(MouseEvent e) {
+
+	}
+
+	@Override
+	public void mouseExited(MouseEvent e) {
+
+	}
+
+	@Override
+	public void actionPerformed(ActionEvent e) {
+
+	}
+
+	@Override
+	public void mouseDragged(MouseEvent e) {
+		// move dragged object on screen along y Axis
+		if (e.getX() <= panel.getVisualisationRadius())
+			dragged_x = panel.getVisualisationRadius();
+		else if (e.getX() >= model.getWidth() - panel.getVisualisationRadius())
+			dragged_x = model.getWidth() - panel.getVisualisationRadius();
+		else
+			dragged_x = e.getX();
+		// move dragged object on screen along y Axis
+		if (e.getY() <= panel.getVisualisationRadius())
+			dragged_y = panel.getVisualisationRadius();
+		else if (e.getY() >= model.getHeight() - panel.getVisualisationRadius())
+			dragged_y = model.getHeight() - panel.getVisualisationRadius();
+		else
+			dragged_y = e.getY();
+		// repaint the dragged smartDevice or new connection
+		if (dragged != null || connectionFrom != null)
+			panel.repaint();
+	}
+
+	@Override
+	public void mouseMoved(MouseEvent e) {
+
+	}
+
+	/**
+	 * Finishes the drag operation, if a SmartDevice was dragged, repaint the
+	 * panel and set dragged to null
+	 */
+	public void finishDrag() {
+		if (dragged != null
+				&& (dragged.getX() != dragged_x || dragged.getY() != dragged_y)) {
+			control.moveSmartDevice(dragged, dragged_x, dragged_y,
+					dragged.getZ());
+			panel.repaint();
+			dragged = null;
+		}
+	}
+
+	/**
+	 * Finishes the create connection operation and open a PopUp for
+	 * Link/Connection creation
+	 */
+	private void finishConnectionCreation() {
+		/**
+		 * SmartDevice the connection was
+		 */
+		SmartDevice connectionTo = getSmartDeviceAtPosition(dragged_x,
+				dragged_y);
+		if (connectionFrom != null && connectionTo != null
+				&& connectionFrom != connectionTo) {
+			// Create new Connection
+			Link l = new SimpleLink("Ethernet: " + connectionFrom.getName()
+					+ " to " + connectionTo.getName());
+			l.addDevice(connectionFrom);
+			l.addDevice(connectionTo);
+			Port p1 = new Port(connectionFrom, (short) 1);
+			Port p2 = new Port(connectionTo, (short) 2);
+			
+			Connection c = new SimpleConnection(p1, p2,
+					l, new SimpleProtocol(p1, p2));
+			p1.setConnection(c);
+			p2.setConnection(c);
+			connectionTo.addLink(l);
+			connectionTo.addPort(p2);
+			connectionFrom.addLink(l);
+			connectionFrom.addPort(p1);
+			l.addConnection(c);
+			model.addConnection(c);
+			connectionFrom = null;
+		} else {
+			connectionFrom = null;
+		}
+		panel.repaint();
+	}
+
+	/**
+	 * Returns SmartDevice which is at position (x,y) or within its
+	 * visualization radius. Returns null, if no SmartDevice is within the
+	 * range.
+	 * 
+	 * @param x
+	 *            x-position which should be checked
+	 * @param y
+	 *            y-position which should be checked
+	 * @return {@link SmartDevice} at position (x,y) or null if there is no
+	 */
+	private SmartDevice getSmartDeviceAtPosition(int x, int y) {
+		// Check is device is inside visualization radius
+		for (SmartDevice d : model.getDevices()) {
+			if (Math.abs(d.getX() - x) < panel.getVisualisationRadius()
+					&& Math.abs(d.getY() - y) < panel.getVisualisationRadius()) {
+				return d;
+			}
+		}
+		return null;
+	}
+}

+ 73 - 51
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualisationPanel.java

@@ -11,6 +11,7 @@ import javax.swing.JPanel;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
 
 @SuppressWarnings("serial")
@@ -69,7 +70,8 @@ public class VisualisationPanel extends JPanel {
 
 			@Override
 			public void componentResized(ComponentEvent e) {
-				control.setDimension(getWidth(), getHeight(), model.getDepth(), true);
+				control.setDimension(getWidth(), getHeight(), model.getDepth(),
+						true);
 				repaint();
 			}
 
@@ -90,14 +92,15 @@ public class VisualisationPanel extends JPanel {
 		g.fillRect(0, 0, this.getWidth(), this.getHeight());
 
 		paintConnections(g);
-		
+
 		paintDevices(g);
 	}
 
 	/**
 	 * Paints the smart devices of the Model
 	 * 
-	 * @param g the Graphics object to visualize on
+	 * @param g
+	 *            the Graphics object to visualize on
 	 */
 	public void paintDevices(Graphics g) {
 
@@ -110,70 +113,89 @@ public class VisualisationPanel extends JPanel {
 				y = interactor.dragged_y;
 			}
 			g.setColor(Color.WHITE);
-			g.fillOval(x - visualisationRadius, y - visualisationRadius, 2 * visualisationRadius - 1,
-					2 * visualisationRadius - 1);
+			g.fillOval(x - visualisationRadius, y - visualisationRadius,
+					2 * visualisationRadius - 1, 2 * visualisationRadius - 1);
 			g.setColor(Color.BLACK);
-			g.drawOval(x - visualisationRadius, y - visualisationRadius, 2 * visualisationRadius - 1,
-					2 * visualisationRadius - 1);
+			g.drawOval(x - visualisationRadius, y - visualisationRadius,
+					2 * visualisationRadius - 1, 2 * visualisationRadius - 1);
 			g.setColor(Color.BLUE);
-			g.drawOval(x - visualisationRadius + 2, y - visualisationRadius + 2, 2 * visualisationRadius - 5,
+			g.drawOval(x - visualisationRadius + 2,
+					y - visualisationRadius + 2, 2 * visualisationRadius - 5,
 					2 * visualisationRadius - 5);
 			g.setColor(Color.BLACK);
-			g.drawString(s.getName(), x - g.getFontMetrics().stringWidth(s.getName()) / 2,
-					y + visualisationRadius + 11);
+			g.drawString(s.getName(),
+					x - g.getFontMetrics().stringWidth(s.getName()) / 2, y
+							+ visualisationRadius + 11);
 		}
 	}
 
 	/**
 	 * Paints the Connections
 	 * 
-	 * @param g the Graphics object to visualize on
+	 * @param g
+	 *            the Graphics object to visualize on
 	 */
 	private void paintConnections(Graphics g) {
-		g.setColor(Color.RED);
 		// For all Connections
-		for (SmartDevice s : model.getDevices())
-			for (Connection c : s.getConnections()) {
-				// Draw just once, if the device is the source
-				if (c.getSource() == s) {
-					/**
-					 * All Devices that are part of the connection
-					 */
-					Collection<SmartDevice> d = c.getParticipants();
-					if (d.size() == 2) {
-
-						for (SmartDevice sd : d)
-							if (s != sd) {
-								// Check if dragged object
-								int s_x, s_y, sd_x, sd_y;
-								if (s == interactor.dragged) {
-									s_x = interactor.dragged_x;
-									s_y = interactor.dragged_y;
-								} else {
-									s_x = s.getX();
-									s_y = s.getY();
-								}
-								if (sd == interactor.dragged) {
-									sd_x = interactor.dragged_x;
-									sd_y = interactor.dragged_y;
-								} else {
-									sd_x = sd.getX();
-									sd_y = sd.getY();
-								}
-								g.drawLine(s_x, s_y, sd_x, sd_y);
-							}
-					} else if (d.size() == 1) {
-
-					} else if (d.size() <= 0) {
-						// Invalid Connection
-					} else {
-						// Draw MultiConnection
+		for (Connection c : model.getConnections()) {
+			switch (c.getStatus()) {
+			case Connection.ACTIVE:
+				g.setColor(Color.GREEN);
+				break;
+			case Connection.HALTED:
+				g.setColor(Color.ORANGE);
+				break;
+			default:
+				g.setColor(Color.RED);
+				break;
+			}
+			/**
+			 * All Devices that are part of the connection
+			 */
+			Collection<Port> d = c.getParticipants();
+			if (d.size() == 2) {
+				Port s = c.getSource();
+				for (Port sd : d) {
+					if(!model.getDevices().contains(sd.getOwner())){
+						SmartDevice removed = sd.getOwner();
+						g.fillOval(removed.getX()-visualisationRadius/4, removed.getY()-visualisationRadius/4, visualisationRadius/2, visualisationRadius/2);
+					}
+					if (s != sd) {
+						// Check if dragged object
+						int s_x, s_y, sd_x, sd_y;
+						if (s.getOwner() == interactor.dragged) {
+							s_x = interactor.dragged_x;
+							s_y = interactor.dragged_y;
+						} else {
+							s_x = s.getOwner().getX();
+							s_y = s.getOwner().getY();
+						}
+						if (sd.getOwner() == interactor.dragged) {
+							sd_x = interactor.dragged_x;
+							sd_y = interactor.dragged_y;
+						} else {
+							sd_x = sd.getOwner().getX();
+							sd_y = sd.getOwner().getY();
+						}
+						g.drawLine(s_x, s_y, sd_x, sd_y);
 					}
 				}
+			} else if (d.size() == 1) {
+
+			} else if (d.size() <= 0) {
+				// Invalid Connection
+			} else {
+				// Draw MultiConnection
 			}
-		//paint new in progress connection, if a connection or link is in creation
-		if(interactor.connectionFrom != null)
-			g.drawLine(interactor.connectionFrom.getX(), interactor.connectionFrom.getY(), interactor.dragged_x, interactor.dragged_y);
+
+		}
+		// paint new in progress connection, if a connection or link is in
+		// creation
+		g.setColor(Color.RED);
+		if (interactor.connectionFrom != null)
+			g.drawLine(interactor.connectionFrom.getX(),
+					interactor.connectionFrom.getY(), interactor.dragged_x,
+					interactor.dragged_y);
 	}
 
 	/**