|
@@ -0,0 +1,118 @@
|
|
|
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.control;
|
|
|
+
|
|
|
+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.SmartDevice;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.configuration.NetworkTreeSettings;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Controller which allows simple manipulation of the NetworkTreePanel, changing visibility of single or multiple Links/Connections & Devices
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author Andreas T. Meyer-Berg
|
|
|
+ */
|
|
|
+public class NetworkTreeSettingsController {
|
|
|
+ /**
|
|
|
+ * Model to be manipulated
|
|
|
+ */
|
|
|
+ private Model model;
|
|
|
+ /**
|
|
|
+ * Controller which can be used
|
|
|
+ */
|
|
|
+ private Controller controller;
|
|
|
+ /**
|
|
|
+ * NetworkTreeSettings of the model
|
|
|
+ */
|
|
|
+ private NetworkTreeSettings networkTreeSettings;
|
|
|
+ /**
|
|
|
+ * Create a new NetworkTreeSettingsController, which controls the networkTree
|
|
|
+ * @param model model of the application
|
|
|
+ * @param controller man controller for manipulation
|
|
|
+ */
|
|
|
+ public NetworkTreeSettingsController(Model model, Controller controller) {
|
|
|
+ this.model = model;
|
|
|
+ this.controller = controller;
|
|
|
+ networkTreeSettings = this.model.getConfigurator().getNetworkTreeSettings();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Toggles visibilty of the given object and all of its descendants
|
|
|
+ * @param o Object to be shown/hidden
|
|
|
+ */
|
|
|
+ public void toggleVisibilityOf(Object o){
|
|
|
+ /**
|
|
|
+ * o visible ?
|
|
|
+ */
|
|
|
+ boolean visible = networkTreeSettings.getStatusOfObject(o).isVisible();
|
|
|
+ setVisibilityOf(o, !visible);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Sets the visibility of Object {@code o} to {@code visible}, will also change visibility of all descendants
|
|
|
+ * @param o Object which should be set visible/hidden
|
|
|
+ * @param visible true -> object will be shown, false -> will not be shown
|
|
|
+ */
|
|
|
+ public void setVisibilityOf(Object o, boolean visible){
|
|
|
+ if(o instanceof String){
|
|
|
+ /**
|
|
|
+ * String node, is the top most -> Hide/Show the hole network
|
|
|
+ */
|
|
|
+ for(Link l:controller.getNetworkController().getLinks())
|
|
|
+ setVisibilityOfLink(l, visible);
|
|
|
+ }else if(o instanceof Link){
|
|
|
+ setVisibilityOfLink((Link)o, visible);
|
|
|
+ }else if(o instanceof Connection){
|
|
|
+ setVisibilityOfConnection((Connection)o, visible);
|
|
|
+ }else if(o instanceof SmartDevice){
|
|
|
+ setVisibilityOfSmartDevice((SmartDevice)o, visible);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Notify observer
|
|
|
+ */
|
|
|
+ controller.notifyObservers();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Change visibility of Device to the new value
|
|
|
+ * @param device device to hide/show
|
|
|
+ * @param isVisible new Visibility
|
|
|
+ */
|
|
|
+ private void setVisibilityOfSmartDevice(SmartDevice device, boolean isVisible) {
|
|
|
+ networkTreeSettings.getStatusOfObject(device).setVisible(isVisible);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Change visibility of Connection and all its Devices
|
|
|
+ * @param connection connection to hide/show
|
|
|
+ * @param isVisible new Visibility
|
|
|
+ */
|
|
|
+ private void setVisibilityOfConnection(Connection connection, boolean isVisible) {
|
|
|
+ networkTreeSettings.getStatusOfObject(connection).setVisible(isVisible);
|
|
|
+ /**
|
|
|
+ * Update alle devices
|
|
|
+ */
|
|
|
+ for(Port port: connection.getParticipants()){
|
|
|
+ if(port.getOwner()!=null)
|
|
|
+ networkTreeSettings.getStatusOfObject(port.getOwner()).setVisible(isVisible);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set visibility of Link, and all its connections & Devices
|
|
|
+ * @param link link, which should be shown/hidden
|
|
|
+ * @param visible whether it should be visible
|
|
|
+ */
|
|
|
+ public void setVisibilityOfLink(Link link, boolean visible){
|
|
|
+ networkTreeSettings.getStatusOfObject(link).setVisible(visible);
|
|
|
+ /**
|
|
|
+ * Update all connections of this link
|
|
|
+ */
|
|
|
+ for(Connection c: link.getConnections()){
|
|
|
+ setVisibilityOfConnection(c,visible);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|