Quellcode durchsuchen

Adds VisualizationPanel -> Hide Devices,Links,Cons which are hidden

* Adds Controller -> getVisibleDevices/Links/Connections
Andreas T. Meyer-Berg vor 6 Jahren
Ursprung
Commit
6e7de9e818

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

@@ -119,6 +119,15 @@ public class NetworkController {
 		toDelete.getPorts().clear();
 		model.getDevices().remove(toDelete);
 	}
+	/**
+	 * Returns smartDevices of the model
+	 * @return
+	 */
+	public Collection<SmartDevice> getVisibleSmartDevices(){
+		LinkedList<SmartDevice> devices = new LinkedList<SmartDevice>(model.getDevices());
+		devices.removeIf(c->!controller.getSettingsController().getNetworkTreeSettingsController().isVisible(c));
+		return devices;
+	}
 	/**
 	 * Returns smartDevices of the model
 	 * @return
@@ -178,6 +187,16 @@ public class NetworkController {
 		model.getConnectionNetworks().remove(link);
 	}
 
+	/**
+	 * Return visible links of the model
+	 * @return visible link
+	 */
+	public Collection<Link> getVisibleLinks(){
+		LinkedList<Link> links = new LinkedList<Link>(model.getConnectionNetworks());
+		links.removeIf(c->!controller.getSettingsController().getNetworkTreeSettingsController().isVisible(c));
+		return links;
+	}
+	
 	/**
 	 * Return links of the model
 	 * @return link
@@ -203,6 +222,16 @@ public class NetworkController {
 		model.getConnections().remove(connection);
 	}
 
+	/**
+	 * Returns visible connections of the model
+	 * @return visible connections
+	 */
+	public Collection<Connection> getVisibleConnections(){
+		LinkedList<Connection> links = new LinkedList<Connection>(model.getConnections());
+		links.removeIf(c->!controller.getSettingsController().getNetworkTreeSettingsController().isVisible(c));
+		return links;
+	}
+	
 	/**
 	 * Returns connections of the model
 	 * @return connections

+ 10 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/NetworkTreeSettingsController.java

@@ -168,9 +168,18 @@ public class NetworkTreeSettingsController {
 	 * @param o object to be shown/hidden
 	 * @param b
 	 */
-	private void setVisibilityNonRecursive(Object o, boolean b) {
+	public void setVisibilityNonRecursive(Object o, boolean b) {
 		getStatusOfObject(o).setVisible(b);
 		controller.notifyObservers();
 	}
+	
+	/**
+	 * Returns true if the given object is visible
+	 * @param o object which should be checked
+	 * @return true if visible
+	 */
+	public boolean isVisible(Object o){
+		return getStatusOfObject(o).isVisible();
+	}
 
 }

+ 12 - 6
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualisationInteractor.java

@@ -374,7 +374,7 @@ public class VisualisationInteractor implements MouseInputListener,
 			//Remove unselected
 			controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevicesDrag.removeIf(s->(s.getX()<min_x||s.getX()>max_x||s.getY()<min_y||s.getY()>max_y));
 			//Add selected devices
-			for(SmartDevice sel:network.getSmartDevices()){
+			for(SmartDevice sel:network.getVisibleSmartDevices()){
 				if(sel.getX()>=min_x&&sel.getX()<=max_x&&sel.getY()>=min_y&&sel.getY()<=max_y&&!controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevicesDrag.contains(sel)){
 					controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevicesDrag.add(sel);
 				}
@@ -530,7 +530,7 @@ public class VisualisationInteractor implements MouseInputListener,
 	 */
 	private SmartDevice getSmartDeviceAtPosition(int x, int y) {
 		// Check is device is inside visualization radius
-		for (SmartDevice d : network.getSmartDevices()) {
+		for (SmartDevice d : network.getVisibleSmartDevices()) {
 			if (Math.abs(d.getX() - x) < config.getDeviceVisualizationRadius()
 					&& Math.abs(d.getY() - y) < config.getDeviceVisualizationRadius()) {
 				/**
@@ -553,7 +553,7 @@ public class VisualisationInteractor implements MouseInputListener,
 	private LinkedList<Pair<Connection, Pair<Port, Port>>> getConnectionsAtPosition(int x, int y) {
 		LinkedList<Pair<Connection,Pair<Port,Port>>> edges = new LinkedList<Pair<Connection,Pair<Port,Port>>>();
 		// Check is device is inside visualization radius
-		for(Connection c: network.getConnections()){
+		for(Connection c: network.getVisibleConnections()){
 			if(c.getProtocol()==null)
 				continue;
 			for(Pair<Port, Port> p: c.getProtocol().getTopology()){
@@ -664,6 +664,12 @@ public class VisualisationInteractor implements MouseInputListener,
 		}
 	}
 
+	/**
+	 * Return Link which is at position at the given position
+	 * @param x xPosition
+	 * @param y yPosition
+	 * @return Link at the position, else null
+	 */
 	private Link getLinkVisualizationAtPosition(int x, int y) {
 		if(!config.isShowLinks())
 			return null;
@@ -676,7 +682,7 @@ public class VisualisationInteractor implements MouseInputListener,
 		 * Radius of the device + link
 		 */
 		int radius =  smallRadius + config.getLinkRadius();
-		for (SmartDevice d : network.getSmartDevices()) {
+		for (SmartDevice d : network.getVisibleSmartDevices()) {
 			//In DeviceRadius + Link Radius ?
 			if (Math.abs(d.getX() - x) <= radius && Math.abs(d.getY() - y) <= radius) {
 				//More detailed check
@@ -692,7 +698,7 @@ public class VisualisationInteractor implements MouseInputListener,
 					/**
 					 * Number of Links in the Model
 					 */
-					int numberOfLinks = network.getLinks().size();
+					int numberOfLinks = network.getVisibleLinks().size();
 					/**
 					 * Angle per Link in "linkSlice degrees"
 					 */
@@ -709,7 +715,7 @@ public class VisualisationInteractor implements MouseInputListener,
 					/**
 					 * Link, which would be at this connection
 					 */
-					Link linkAtPosition = (Link) network.getLinks().toArray()[linkNumber];
+					Link linkAtPosition = (Link) network.getVisibleLinks().toArray()[linkNumber];
 					/**
 					 * Return link, if smartDevice contains it
 					 */

+ 5 - 4
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualisationPanel.java

@@ -202,7 +202,7 @@ public class VisualisationPanel extends JPanel implements Observer {
 		/**
 		 * Number of Links in the Model
 		 */
-		int numberOfLinks = network.getLinks().size();
+		int numberOfLinks = network.getVisibleLinks().size();
 		/**
 		 * Angle per Link in "linkSlice degrees"
 		 */
@@ -215,7 +215,7 @@ public class VisualisationPanel extends JPanel implements Observer {
 		if(config.isShowLinks()){
 			linkColors = new HashMap<Link, Pair<Integer,Color>>();
 			int i = 0;
-			for(Link l: network.getLinks()){
+			for(Link l: network.getVisibleLinks()){
 				/**
 				 * Distinct Color as String containing the hex values (128 static ones should be enough)
 				 */
@@ -264,7 +264,7 @@ public class VisualisationPanel extends JPanel implements Observer {
 			y_offset = interactor.dragged_y-interactor.dragged.getY();
 		}
 		//Paint Devices
-		for (SmartDevice s: network.getSmartDevices()) {
+		for (SmartDevice s: network.getVisibleSmartDevices()) {
 			/**
 			 * x Position of the device
 			 */
@@ -339,7 +339,7 @@ public class VisualisationPanel extends JPanel implements Observer {
 		}
 		
 		// For all Connections
-		for (Connection c : network.getConnections()) {
+		for (Connection c : network.getVisibleConnections()) {
 			Color connectionState;
 			switch (c.getStatus()) {
 			case Connection.ACTIVE:
@@ -380,6 +380,7 @@ public class VisualisationPanel extends JPanel implements Observer {
 						g.setColor(connectionState);
 					SmartDevice from = p.getLeft().getOwner();
 					SmartDevice to = p.getRight().getOwner();
+					if(!config.getNetworkTreeSettingsController().isVisible(from)||!config.getNetworkTreeSettingsController().isVisible(to))continue;
 					int xFrom = from.getX();
 					int yFrom = from.getY();
 					int xTo = to.getX();