Jelajahi Sumber

Adds option to hide the link toolTips

Andreas T. Meyer-Berg 6 tahun lalu
induk
melakukan
a6f699c1f4

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

@@ -126,5 +126,35 @@ public class ConfigurationController {
 		model.getConfigurator().getVisualizationConfiguration().setDeviceVisualizationRadius(deviceVisualizationRadius);
 		controller.notifyObservers();
 	}
+
+	/**
+	 * @return the linkRadius
+	 */
+	public int getLinkRadius() {
+		return model.getConfigurator().getVisualizationConfiguration().getLinkRadius();
+	}
+
+	/**
+	 * @param linkRadius the linkRadius to set
+	 */
+	public void setLinkRadius(int linkRadius) {
+		model.getConfigurator().getVisualizationConfiguration().setLinkRadius(linkRadius);
+		controller.notifyObservers();
+	}
 	
+
+	/**
+	 * @return the showLinkToolTips
+	 */
+	public boolean isShowLinkToolTips() {
+		return model.getConfigurator().getVisualizationConfiguration().isShowLinkToolTips();
+	}
+
+	/**
+	 * @param showLinkToolTips the showLinkToolTips to set
+	 */
+	public void setShowLinkToolTips(boolean showLinkToolTips) {
+		model.getConfigurator().getVisualizationConfiguration().setShowLinkToolTips(showLinkToolTips);
+		controller.notifyObservers();
+	}
 }

+ 39 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/VisualizationConfiguration.java

@@ -16,6 +16,10 @@ public class VisualizationConfiguration {
 	 * Whether links should be shown
 	 */
 	private boolean showLinks;
+	/**
+	 * Whether link toolTips should be shown
+	 */
+	private boolean showLinkToolTips;
 	
 	/**
 	 * Whether SmartDevices should be shown
@@ -36,6 +40,11 @@ public class VisualizationConfiguration {
 	 * Radius (including the middlePoinnt) of a smartDevice
 	 */
 	private int deviceVisualizationRadius;
+	
+	/**
+	 * Radius of the link. (deviceRadius+linkRadius)
+	 */
+	private int linkRadius;
 
 	/**
 	 * Initialize the configuration
@@ -47,6 +56,8 @@ public class VisualizationConfiguration {
 		setShowSmartDeviceNames(true);
 		setShowTerminatedConnections(true);
 		setDeviceVisualizationRadius(17);
+		setShowLinkToolTips(true);
+		setLinkRadius(6);
 	}
 
 	/**
@@ -132,5 +143,33 @@ public class VisualizationConfiguration {
 	public void setDeviceVisualizationRadius(int deviceVisualizationRadius) {
 		this.deviceVisualizationRadius = deviceVisualizationRadius;
 	}
+
+	/**
+	 * @return the linkRadius
+	 */
+	public int getLinkRadius() {
+		return linkRadius;
+	}
+
+	/**
+	 * @param linkRadius the linkRadius to set
+	 */
+	public void setLinkRadius(int linkRadius) {
+		this.linkRadius = linkRadius;
+	}
+
+	/**
+	 * @return the showLinkToolTips
+	 */
+	public boolean isShowLinkToolTips() {
+		return showLinkToolTips;
+	}
+
+	/**
+	 * @param showLinkToolTips the showLinkToolTips to set
+	 */
+	public void setShowLinkToolTips(boolean showLinkToolTips) {
+		this.showLinkToolTips = showLinkToolTips;
+	}
 	
 }

+ 21 - 5
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualisationInteractor.java

@@ -7,6 +7,7 @@ import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseMotionListener;
+
 import java.util.LinkedList;
 
 import javax.swing.JMenu;
@@ -598,10 +599,15 @@ public class VisualisationInteractor implements MouseInputListener,
 	
 	@Override
 	public void mouseMoved(MouseEvent e) {
+		/**
+		 * Link which might get a toolTip
+		 */
+		Link l = null; 
 		/**
 		 * Check Hover on Link
 		 */
-		Link l = checkHoverOnLink(e.getX(),e.getY());
+		if(config.isShowLinkToolTips())
+			l = checkHoverOnLink(e.getX(),e.getY());
 		if(l != null){
 			if(l != toolTip.getLink() || !toolTip.isEnabled()){
 				toolTip.setText("Link "+l.getName());
@@ -622,15 +628,25 @@ public class VisualisationInteractor implements MouseInputListener,
 
 	private Link checkHoverOnLink(int x, int y) {
 		// Check is device is inside visualization radius
+		/**
+		 * Radius of the device
+		 */
 		int smallRadius = config.getDeviceVisualizationRadius();
+		/**
+		 * Radius of the device + link
+		 */
 		int radius =  smallRadius + config.getLinkRadius();
 		for (SmartDevice d : model.getDevices()) {
 			//In DeviceRadius + Link Radius ?
-			if (Math.abs(d.getX() - x) < radius && Math.abs(d.getY() - y) < radius) {
+			if (Math.abs(d.getX() - x) <= radius && Math.abs(d.getY() - y) <= radius) {
+				//More detailed check
+				// On Ring ?
+				// On which part of Ring ?
 				//Outside of device ?
-				if(!d.getLinks().isEmpty())
-					return d.getLinks().get(0);
-				if (Math.abs(d.getX() - x) >= smallRadius && Math.abs(d.getY() - y) >= smallRadius) {
+				int realDistance = (int)Math.round(Math.sqrt((d.getX() - x)*(d.getX() - x)+(d.getY() - y)*(d.getY() - y)));
+				if (realDistance > smallRadius && realDistance <= radius) {
+					if(!d.getLinks().isEmpty())
+						return d.getLinks().get(0);
 					//TODO: +Link Detection & Radius
 					
 				}

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

@@ -4,6 +4,7 @@ import java.awt.Color;
 import java.awt.Graphics;
 import java.awt.event.ComponentEvent;
 import java.awt.event.ComponentListener;
+
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Observable;
@@ -413,7 +414,7 @@ public class VisualisationPanel extends JPanel implements Observer {
 		 */
 		LinkToolTip toolTip = interactor.getToolTip();
 
-		if (toolTip.isEnabled()) {
+		if (toolTip.isEnabled() && config.isShowLinkToolTips()) {
 			/**
 			 * free space around the ToolTipText
 			 */

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

@@ -71,12 +71,6 @@ public class SettingsPopUp extends JFrame {
 		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());
@@ -89,12 +83,24 @@ public class SettingsPopUp extends JFrame {
 		chckbxLinks.addActionListener(a->config.setShowLinks(chckbxLinks.isSelected()));
 		pVisualisation.add(chckbxLinks);
 		
+		JCheckBox chckbxLinkToolTips = new JCheckBox("Show link ToolTips");
+		chckbxLinkToolTips.setBounds(237, 127, 178, 25);
+		chckbxLinkToolTips.setSelected(config.isShowLinkToolTips());
+		chckbxLinkToolTips.addActionListener(a->config.setShowLinkToolTips(chckbxLinkToolTips.isSelected()));
+		pVisualisation.add(chckbxLinkToolTips);
+		
 		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);
 		
+		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);
+
 		JPanel pImports = new JPanel();
 		tabbedPane.addTab("Imports", null, pImports, null);