Преглед изворни кода

Adds Link name list to Panel

Andreas T. Meyer-Berg пре 5 година
родитељ
комит
e791087fa8

+ 15 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/SettingsController.java

@@ -187,7 +187,22 @@ public class SettingsController {
 		model.getConfigurator().getVisualizationConfiguration().setShowLinkToolTips(showLinkToolTips);
 		controller.notifyObservers();
 	}
+	
+	/**
+	 * @return the showLinkNameList
+	 */
+	public boolean isShowLinkNameList() {
+		return model.getConfigurator().getVisualizationConfiguration().isShowLinkNameList();
+	}
 
+	/**
+	 * @param showLinkNameList the showLinkNameList to set
+	 */
+	public void setShowLinkNameList(boolean showLinkNameList) {
+		model.getConfigurator().getVisualizationConfiguration().setShowLinkNameList(showLinkNameList);
+		controller.notifyObservers();
+	}
+	
 	/**
 	 * Changes the dimension of the model, without scaling the SmartDevice
 	 * positions

+ 45 - 16
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/configuration/VisualizationConfiguration.java

@@ -6,12 +6,12 @@ package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.configuration;
  * @author Andreas T. Meyer-Berg
  */
 public class VisualizationConfiguration {
-	
+
 	/**
 	 * Whether connections should be shown
 	 */
 	private boolean showConnections;
-	
+
 	/**
 	 * Whether links should be shown
 	 */
@@ -20,27 +20,33 @@ public class VisualizationConfiguration {
 	 * Whether link toolTips should be shown
 	 */
 	private boolean showLinkToolTips;
-	
+
+	/**
+	 * Whether the link names should be presented on the left hand side of the
+	 * visualization panel
+	 */
+	private boolean showLinkNameList;
+
 	/**
 	 * Whether SmartDevices should be shown
 	 */
 	private boolean showSmartDevices;
-	
+
 	/**
 	 * Whether SmartDevice names should be shown
 	 */
 	private boolean showSmartDeviceNames;
-	
+
 	/**
 	 * Whether terminated connections should be shown
 	 */
 	private boolean showTerminatedConnections;
-	
+
 	/**
 	 * Radius (including the middlePoinnt) of a smartDevice
 	 */
 	private int deviceVisualizationRadius;
-	
+
 	/**
 	 * Radius of the link. (deviceRadius+linkRadius)
 	 */
@@ -57,6 +63,7 @@ public class VisualizationConfiguration {
 		setShowTerminatedConnections(false);
 		setDeviceVisualizationRadius(17);
 		setShowLinkToolTips(true);
+		setShowLinkNameList(true);
 		setLinkRadius(6);
 	}
 
@@ -68,7 +75,8 @@ public class VisualizationConfiguration {
 	}
 
 	/**
-	 * @param showConnections the showConnections to set
+	 * @param showConnections
+	 *            the showConnections to set
 	 */
 	public void setShowConnections(boolean showConnections) {
 		this.showConnections = showConnections;
@@ -82,7 +90,8 @@ public class VisualizationConfiguration {
 	}
 
 	/**
-	 * @param showLinks the showLinks to set
+	 * @param showLinks
+	 *            the showLinks to set
 	 */
 	public void setShowLinks(boolean showLinks) {
 		this.showLinks = showLinks;
@@ -96,7 +105,8 @@ public class VisualizationConfiguration {
 	}
 
 	/**
-	 * @param showSmartDevices the showSmartDevices to set
+	 * @param showSmartDevices
+	 *            the showSmartDevices to set
 	 */
 	public void setShowSmartDevices(boolean showSmartDevices) {
 		this.showSmartDevices = showSmartDevices;
@@ -110,7 +120,8 @@ public class VisualizationConfiguration {
 	}
 
 	/**
-	 * @param showSmartDeviceNames the showSmartDeviceNames to set
+	 * @param showSmartDeviceNames
+	 *            the showSmartDeviceNames to set
 	 */
 	public void setShowSmartDeviceNames(boolean showSmartDeviceNames) {
 		this.showSmartDeviceNames = showSmartDeviceNames;
@@ -124,7 +135,8 @@ public class VisualizationConfiguration {
 	}
 
 	/**
-	 * @param showTerminatedConnections the showTerminatedConnections to set
+	 * @param showTerminatedConnections
+	 *            the showTerminatedConnections to set
 	 */
 	public void setShowTerminatedConnections(boolean showTerminatedConnections) {
 		this.showTerminatedConnections = showTerminatedConnections;
@@ -138,7 +150,8 @@ public class VisualizationConfiguration {
 	}
 
 	/**
-	 * @param deviceVisualizationRadius the deviceVisualizationRadius to set
+	 * @param deviceVisualizationRadius
+	 *            the deviceVisualizationRadius to set
 	 */
 	public void setDeviceVisualizationRadius(int deviceVisualizationRadius) {
 		this.deviceVisualizationRadius = deviceVisualizationRadius;
@@ -152,7 +165,8 @@ public class VisualizationConfiguration {
 	}
 
 	/**
-	 * @param linkRadius the linkRadius to set
+	 * @param linkRadius
+	 *            the linkRadius to set
 	 */
 	public void setLinkRadius(int linkRadius) {
 		this.linkRadius = linkRadius;
@@ -166,10 +180,25 @@ public class VisualizationConfiguration {
 	}
 
 	/**
-	 * @param showLinkToolTips the showLinkToolTips to set
+	 * @param showLinkToolTips
+	 *            the showLinkToolTips to set
 	 */
 	public void setShowLinkToolTips(boolean showLinkToolTips) {
 		this.showLinkToolTips = showLinkToolTips;
 	}
-	
+
+	/**
+	 * @return the showLinkNameList
+	 */
+	public boolean isShowLinkNameList() {
+		return showLinkNameList;
+	}
+
+	/**
+	 * @param showLinkNameList the showLinkNameList to set
+	 */
+	public void setShowLinkNameList(boolean showLinkNameList) {
+		this.showLinkNameList = showLinkNameList;
+	}
+
 }

+ 59 - 32
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualizationPanel.java

@@ -109,38 +109,7 @@ public class VisualizationPanel extends JPanel implements Observer {
 
 	@Override
 	public void paint(Graphics g) {
-		// More beautiful Graphics
-		if(g instanceof Graphics2D){
-			/**
-			 * Graphics2D options, if enabled on the machine
-			 */
-			Graphics2D graphics = (Graphics2D) g;
-			/**
-			 * Rendering Options for the visualization
-			 */
-			RenderingHints renders = new RenderingHints(new HashMap<>());
-			/**
-			 * Add AntiAliasing
-			 */
-			renders.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON));
-			/**
-			 * Add Text AntiAliasing
-			 */
-			renders.add(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
-			/**
-			 * Add Improved Color Rendering
-			 */
-			renders.add(new RenderingHints(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY));
-			/**
-			 * Add general quality Rendering
-			 */
-			renders.add(new RenderingHints(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY));
-			/**
-			 * Add improved interpolation for images
-			 */
-			renders.add(new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC));
-			graphics.setRenderingHints(renders);
-		}
+		setRenderOptions(g);
 		
 		// paint white background
 		g.setColor(Color.white);
@@ -183,6 +152,64 @@ public class VisualizationPanel extends JPanel implements Observer {
 		g.drawString("Debug(Modus:"+modus+")", 0, 10);
 		if(interactor.controlDown)
 			g.drawString("Control down", 0, 20);
+		
+		paintLinkLabels(g);
+	}
+	
+	/**
+	 * Paints a list of all Link names on the left hand side
+	 * @param g Graphics to be used
+	 */
+	private void paintLinkLabels(Graphics g) {
+		if(!config.isShowLinks()||network.getLinks().isEmpty()||!config.isShowLinkNameList())
+			return;
+		g.setColor(Color.BLACK);
+		g.drawString("Links:", 0, 35);
+		int i = 45;
+		for(Link l: network.getLinks()){
+			g.setColor(config.getLinkColors().getColorOfLink(l).getRight());
+			g.drawString(l.getName(), 0, i);
+			i+=10;
+		}
+	}
+
+	/**
+	 * Sets the different rending options if available
+	 * @param g Graphics to be improved
+	 */
+	private void setRenderOptions(Graphics g) {
+		// More beautiful Graphics
+		if(g instanceof Graphics2D){
+			/**
+			 * Graphics2D options, if enabled on the machine
+			 */
+			Graphics2D graphics = (Graphics2D) g;
+			/**
+			 * Rendering Options for the visualization
+			 */
+			RenderingHints renders = new RenderingHints(new HashMap<>());
+			/**
+			 * Add AntiAliasing
+			 */
+			renders.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON));
+			/**
+			 * Add Text AntiAliasing
+			 */
+			renders.add(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
+			/**
+			 * Add Improved Color Rendering
+			 */
+			renders.add(new RenderingHints(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY));
+			/**
+			 * Add general quality Rendering
+			 */
+			renders.add(new RenderingHints(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY));
+			/**
+			 * Add improved interpolation for images
+			 */
+			renders.add(new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC));
+			graphics.setRenderingHints(renders);
+		}
 	}
 
 	/**