Browse Source

Adds highlighting of selected edges

Andreas T. Meyer-Berg 6 years ago
parent
commit
6f8f61c56c

+ 9 - 14
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualisationInteractor.java

@@ -171,6 +171,10 @@ public class VisualisationInteractor implements MouseInputListener,
 		 * FindSmartDevice that was clicked
 		 */
 		clicked = getSmartDeviceAtPosition(e.getX(), e.getY());
+		clickedConnection.clear();
+		if(clicked == null)
+			clickedConnection = getConnectionsAtPosition(e.getX(), e.getY());
+		
 		
 		switch (mode) {
 		case DRAG_CONNECTION:
@@ -206,18 +210,8 @@ public class VisualisationInteractor implements MouseInputListener,
 					mode = NOTHING; 
 				else if(!selectedDevices.isEmpty())
 					mode = SELECTED;
-				
-				//TODO: Click on Edge functionalities
-				LinkedList<Pair<Connection, Pair<Port, Port>>> clickedCons = getConnectionsAtPosition(e.getX(), e.getY());
-				System.out.println("Click on Edge?: "+!clickedCons.isEmpty());
-				if(!(clickedCons.isEmpty()&&clickedConnection.isEmpty())){
-					clickedConnection.clear();
-					clickedConnection = clickedCons;
-					if(!clickedConnection.isEmpty())
-						mode = SELECTED;
-					panel.repaint();
-					
-				}
+
+				panel.repaint();	
 			}
 			break;
 		default:
@@ -298,7 +292,7 @@ public class VisualisationInteractor implements MouseInputListener,
 
 	@Override
 	public void mouseDragged(MouseEvent e) {
-		// move dragged object/objecte selection on screen
+		// move dragged object/object selection on screen
 		switch (mode) {
 		case DRAG_SELECT:
 		case DRAG_CONNECTION:
@@ -481,7 +475,7 @@ public class VisualisationInteractor implements MouseInputListener,
 			for(Pair<Port, Port> p: c.getProtocol().getTopology()){
 				if(pointOnConnection(x,y,p)){
 					edges.add(new Pair<Connection, Pair<Port,Port>>(c, p));
-					break;//Connection was clicked - check for further connections
+					//break;//Connection was clicked - check for further connections
 				}
 			}
 		}
@@ -651,6 +645,7 @@ public class VisualisationInteractor implements MouseInputListener,
 			else
 				mode = SELECTED;
 		});
+		rightClickMenu.add(itemCreateLink);
 		
 		// Create Connection
 		itemCreateConnection = new JMenuItem("Create Connection");

+ 8 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualisationPanel.java

@@ -231,6 +231,10 @@ public class VisualisationPanel extends JPanel implements Observer {
 			}
 			for(Pair<Port,Port> p: c.getProtocol().getTopology() ){
 				if(p.getLeft() != null && p.getLeft().getOwner() != null && p.getRight() != null && p.getRight().getOwner() != null){
+					if(interactor.clickedConnection.contains(new Pair<Connection, Pair<Port,Port>>(c, p)))
+						g.setColor(Color.BLUE);
+					else
+						g.setColor(connectionState);
 					SmartDevice from = p.getLeft().getOwner();
 					SmartDevice to = p.getRight().getOwner();
 					int xFrom = from.getX();
@@ -248,8 +252,11 @@ public class VisualisationPanel extends JPanel implements Observer {
 					g.drawLine(xFrom, yFrom, xTo, yTo);
 				}
 			}
-			g.setColor(Color.RED);
 			for(Pair<Port,Port> p: c.getProtocol().getDeletedTopology() ){
+				if(interactor.clickedConnection.contains(new Pair<Connection, Pair<Port,Port>>(c, p)))
+					g.setColor(Color.BLUE);
+				else
+					g.setColor(Color.RED);
 				if(p.getLeft() != null && p.getLeft().getOwner() != null && p.getRight() != null && p.getRight().getOwner() != null){
 					SmartDevice from = p.getLeft().getOwner();
 					SmartDevice to = p.getRight().getOwner();