Browse Source

Adds visualization settings functionalities

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

+ 6 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/ConfigurationController.java

@@ -48,6 +48,7 @@ public class ConfigurationController {
 	 */
 	public void setShowConnections(boolean showConnections) {
 		model.getConfigurator().getVisualizationConfiguration().setShowConnections(showConnections);
+		controller.notifyObservers();
 	}
 
 	/**
@@ -62,6 +63,7 @@ public class ConfigurationController {
 	 */
 	public void setShowLinks(boolean showLinks) {
 		model.getConfigurator().getVisualizationConfiguration().setShowLinks(showLinks);
+		controller.notifyObservers();
 	}
 
 	/**
@@ -76,6 +78,7 @@ public class ConfigurationController {
 	 */
 	public void setShowSmartDevices(boolean showSmartDevices) {
 		model.getConfigurator().getVisualizationConfiguration().setShowSmartDevices(showSmartDevices);
+		controller.notifyObservers();
 	}
 
 	/**
@@ -90,6 +93,7 @@ public class ConfigurationController {
 	 */
 	public void setShowSmartDeviceNames(boolean showSmartDeviceNames) {
 		model.getConfigurator().getVisualizationConfiguration().setShowSmartDeviceNames(showSmartDeviceNames);
+		controller.notifyObservers();
 	}
 
 	/**
@@ -104,6 +108,7 @@ public class ConfigurationController {
 	 */
 	public void setShowTerminatedConnections(boolean showTerminatedConnections) {
 		model.getConfigurator().getVisualizationConfiguration().setShowTerminatedConnections(showTerminatedConnections);
+		controller.notifyObservers();
 	}
 
 	/**
@@ -118,6 +123,7 @@ public class ConfigurationController {
 	 */
 	public void setDeviceVisualizationRadius(int deviceVisualizationRadius) {
 		model.getConfigurator().getVisualizationConfiguration().setDeviceVisualizationRadius(deviceVisualizationRadius);
+		controller.notifyObservers();
 	}
 	
 }

+ 15 - 7
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualisationPanel.java

@@ -106,9 +106,10 @@ public class VisualisationPanel extends JPanel implements Observer {
 		g.setColor(Color.white);
 		g.fillRect(0, 0, this.getWidth(), this.getHeight());
 
-		paintConnections(g);
-
-		paintDevices(g);
+		if(config.isShowConnections())
+			paintConnections(g);
+		if(config.isShowSmartDevices())
+			paintDevices(g);
 		
 		paintDrag(g);
 		
@@ -134,7 +135,7 @@ public class VisualisationPanel extends JPanel implements Observer {
 			modus="Selected";
 			break;
 		default:
-			modus="Uknown";
+			modus="Unknown";
 			break;
 		}
 		g.drawString("Debug(Modus:"+modus+")", 0, 10);
@@ -181,7 +182,8 @@ public class VisualisationPanel extends JPanel implements Observer {
 					y - config.getDeviceVisualizationRadius() + 2, 2 * config.getDeviceVisualizationRadius() - 5,
 					2 * config.getDeviceVisualizationRadius() - 5);
 			g.setColor(Color.BLACK);
-			g.drawString(s.getName(),
+			if(config.isShowSmartDeviceNames())
+				g.drawString(s.getName(),
 					x - g.getFontMetrics().stringWidth(s.getName()) / 2, y
 							+ config.getDeviceVisualizationRadius() + 11);
 		}
@@ -262,8 +264,14 @@ public class VisualisationPanel extends JPanel implements Observer {
 			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);
+				else{
+					//Just paint terminated connection, if config says so
+					if(config.isShowTerminatedConnections())
+						g.setColor(Color.RED);
+					else
+						continue;
+				
+				}
 				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();

+ 15 - 2
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/popups/SettingsPopUp.java

@@ -12,6 +12,7 @@ import javax.swing.JSlider;
 import javax.swing.JTabbedPane;
 import javax.swing.SwingConstants;
 
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.ConfigurationController;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
 
@@ -23,11 +24,13 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
 public class SettingsPopUp extends JFrame {
 	Model model;
 	Controller controller;
+	ConfigurationController config;
 	
 	public SettingsPopUp(Model model, Controller controller) {
 		setBounds(new Rectangle(0, 0, 450, 300));
 		this.model = model;
 		this.controller = controller;
+		this.config = controller.getControllerConfiguration();
 		
 		setTitle("Settings");
 		setIconImage(Toolkit.getDefaultToolkit().getImage(SettingsPopUp.class.getResource("/images/settings.png")));
@@ -54,32 +57,42 @@ public class SettingsPopUp extends JFrame {
 		sliderRadius.setMajorTickSpacing(18);
 		sliderRadius.setMaximum(110);
 		sliderRadius.setMinimum(2);
-		sliderRadius.setValue(controller.getDevice_visualization_radius());
+		sliderRadius.setValue(config.getDeviceVisualizationRadius());
 		sliderRadius.setBounds(135, 13, 280, 45);
 		pVisualisation.add(sliderRadius);
 		sliderRadius.addChangeListener(a -> {
-			controller.setDevice_visualization_radius(sliderRadius.getValue());
+			config.setDeviceVisualizationRadius(sliderRadius.getValue());
 			controller.notifyObservers();
 		});
 		
 		JCheckBox chckbxTerminatedConnections = new JCheckBox("Show terminated connections");
 		chckbxTerminatedConnections.setBounds(8, 67, 197, 25);
+		chckbxTerminatedConnections.setSelected(config.isShowTerminatedConnections());
+		chckbxTerminatedConnections.addActionListener(a->config.setShowTerminatedConnections(chckbxTerminatedConnections.isSelected()));
 		pVisualisation.add(chckbxTerminatedConnections);
 		
 		JCheckBox chckbxDeviceNames = new JCheckBox("Show SmartDevice names");
 		chckbxDeviceNames.setBounds(8, 127, 197, 25);
+		chckbxDeviceNames.setSelected(config.isShowSmartDeviceNames());
+		chckbxDeviceNames.addActionListener(a->config.setShowSmartDeviceNames(chckbxDeviceNames.isSelected()));
 		pVisualisation.add(chckbxDeviceNames);
 		
 		JCheckBox chckbxConnections = new JCheckBox("Show connections");
 		chckbxConnections.setBounds(237, 67, 182, 25);
+		chckbxConnections.setSelected(config.isShowConnections());
+		chckbxConnections.addActionListener(a->config.setShowConnections(chckbxConnections.isSelected()));
 		pVisualisation.add(chckbxConnections);
 		
 		JCheckBox chckbxLinks = new JCheckBox("Show links");
 		chckbxLinks.setBounds(237, 97, 178, 25);
+		chckbxLinks.setSelected(config.isShowLinks());
+		chckbxLinks.addActionListener(a->config.setShowLinks(chckbxLinks.isSelected()));
 		pVisualisation.add(chckbxLinks);
 		
 		JCheckBox chckbxSmartdevices = new JCheckBox("Show SmartDevices");
 		chckbxSmartdevices.setBounds(8, 97, 197, 25);
+		chckbxSmartdevices.setSelected(config.isShowSmartDevices());
+		chckbxSmartdevices.addActionListener(a->config.setShowSmartDevices(chckbxSmartdevices.isSelected()));
 		pVisualisation.add(chckbxSmartdevices);
 		
 		JPanel pImports = new JPanel();