Browse Source

Fixed selection bug in Symbol layer

dominik.renkel 7 years ago
parent
commit
fa2ba7f43f

+ 2 - 2
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ButtonManager.java

@@ -95,8 +95,8 @@ public final class ButtonManager {
 	 * @param event
 	 */
 	public static void centerMapAction(ActionEvent event) {
-		HashSet<GeoPosition> positions = new HashSet<GeoPosition>(WorldView.waypoints.size());
-		WorldView.waypoints.forEach((w) -> positions.add(w.getPosition()));
+		HashSet<GeoPosition> positions = new HashSet<GeoPosition>(WorldView.getWaypoints().size());
+		WorldView.getWaypoints().forEach((w) -> positions.add(w.getPosition()));
 
 		WorldView.showAllWaypoints(positions);
 

+ 2 - 12
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/CustomMapClickListener.java

@@ -2,7 +2,6 @@ package de.tu_darmstadt.informatik.tk.scopviz.ui.mapView;
 
 import java.awt.geom.Line2D;
 import java.awt.geom.Point2D;
-import java.util.HashSet;
 
 import org.graphstream.graph.Edge;
 import org.jxmapviewer.JXMapViewer;
@@ -31,15 +30,6 @@ public class CustomMapClickListener extends MapClickListener {
 	 */
 	public static Edge selectedEdge;
 
-	/*
-	 * all edges of the graph
-	 */
-	private final static HashSet<Edge> edges = WorldView.edges;
-
-	/*
-	 * all waypoints of the graph
-	 */
-	private final static HashSet<CustomWaypoint> waypoints = WorldView.waypoints;
 
 	/**
 	 * Constructor sets viewer
@@ -84,7 +74,7 @@ public class CustomMapClickListener extends MapClickListener {
 
 		int pictureSize = CustomWaypointRenderer.SCALEWIDTH;
 
-		for (CustomWaypoint nodeWaypoint : CustomMapClickListener.waypoints) {
+		for (CustomWaypoint nodeWaypoint : WorldView.getWaypoints()) {
 			// transform GeoPosition to point on screen
 			nodePoint = CustomMapClickListener.viewer.getTileFactory().geoToPixel(nodeWaypoint.getPosition(),
 					CustomMapClickListener.viewer.getZoom());
@@ -124,7 +114,7 @@ public class CustomMapClickListener extends MapClickListener {
 
 		Edge result = null;
 
-		for (Edge edge : CustomMapClickListener.edges) {
+		for (Edge edge : WorldView.getEdges()) {
 			// Get geo Positions of the two nodes that define the edge
 			GeoPosition startPos = new GeoPosition(edge.getNode0().getAttribute("lat"),
 					edge.getNode0().getAttribute("long"));

+ 13 - 13
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/MapViewFunctions.java

@@ -56,11 +56,11 @@ public final class MapViewFunctions {
 	 */
 	public static void initializeWaypointImages() {
 		
-		if (WorldView.waypoints == null) {
+		if (WorldView.getWaypoints() == null) {
 			return;
 		}
 
-		imageMap = new HashMap<String, BufferedImage>(WorldView.waypoints.size());
+		imageMap = new HashMap<String, BufferedImage>(WorldView.getWaypoints().size());
 
 		for (CustomWaypoint w : WorldView.getWaypoints()) {
 
@@ -295,17 +295,17 @@ public final class MapViewFunctions {
 
 		CustomWaypoint selectedWaypoint = CustomMapClickListener.selectedNode;
 
-		if (selectedWaypoint == null && WorldView.waypointsAsList.size() > 0) {
-			CustomMapClickListener.selectWaypoint(WorldView.waypointsAsList.get(0));
+		if (selectedWaypoint == null && WorldView.getWaypointsAsArrayList().size() > 0) {
+			CustomMapClickListener.selectWaypoint(WorldView.getWaypointsAsArrayList().get(0));
 
 		} else {
-			int index = WorldView.waypointsAsList.indexOf(selectedWaypoint);
+			int index = WorldView.getWaypointsAsArrayList().indexOf(selectedWaypoint);
 
 			if (index == 0) {
 				CustomMapClickListener
-						.selectWaypoint(WorldView.waypointsAsList.get(WorldView.waypointsAsList.size() - 1));
+						.selectWaypoint(WorldView.getWaypointsAsArrayList().get(WorldView.getWaypointsAsArrayList().size() - 1));
 			} else {
-				CustomMapClickListener.selectWaypoint(WorldView.waypointsAsList.get(index - 1));
+				CustomMapClickListener.selectWaypoint(WorldView.getWaypointsAsArrayList().get(index - 1));
 			}
 		}
 	}
@@ -317,16 +317,16 @@ public final class MapViewFunctions {
 
 		CustomWaypoint selectedWaypoint = CustomMapClickListener.selectedNode;
 
-		if (selectedWaypoint == null && WorldView.waypointsAsList.size() > 0) {
-			CustomMapClickListener.selectWaypoint(WorldView.waypointsAsList.get(0));
+		if (selectedWaypoint == null && WorldView.getWaypointsAsArrayList().size() > 0) {
+			CustomMapClickListener.selectWaypoint(WorldView.getWaypointsAsArrayList().get(0));
 
 		} else {
-			int index = WorldView.waypointsAsList.indexOf(selectedWaypoint);
+			int index = WorldView.getWaypointsAsArrayList().indexOf(selectedWaypoint);
 
-			if (index == WorldView.waypointsAsList.size() - 1) {
-				CustomMapClickListener.selectWaypoint(WorldView.waypointsAsList.get(0));
+			if (index == WorldView.getWaypointsAsArrayList().size() - 1) {
+				CustomMapClickListener.selectWaypoint(WorldView.getWaypointsAsArrayList().get(0));
 			} else {
-				CustomMapClickListener.selectWaypoint(WorldView.waypointsAsList.get(index + 1));
+				CustomMapClickListener.selectWaypoint(WorldView.getWaypointsAsArrayList().get(index + 1));
 			}
 		}
 

+ 39 - 15
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/WorldView.java

@@ -24,7 +24,10 @@ import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
 import de.tu_darmstadt.informatik.tk.scopviz.main.MainApp;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.GUIController;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.GraphDisplayManager;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.OptionsManager;
 import javafx.geometry.Rectangle2D;
+import javafx.scene.control.Alert;
+import javafx.scene.control.Alert.AlertType;
 
 public class WorldView {
 
@@ -56,19 +59,19 @@ public class WorldView {
 	/*
 	 * All waypoints in the WorldView
 	 */
-	public static HashSet<CustomWaypoint> waypoints;
+	private static HashSet<CustomWaypoint> waypoints;
 
 	/**
 	 * the waypoints represented as an ordered list
 	 */
-	public static ArrayList<CustomWaypoint> waypointsAsList;
+	private static ArrayList<CustomWaypoint> waypointsAsList;
 
 	/*
 	 * All edges in the WorldView
 	 */
-	public static HashSet<Edge> edges;
+	private static HashSet<Edge> edges;
 
-	public static HashSet<GeoPosition> nodePositions;
+	private static HashSet<GeoPosition> nodePositions;
 
 	/*
 	 * All painter in symbolLayer stored in a list
@@ -106,6 +109,22 @@ public class WorldView {
 
 		// Get GeoPositions of nodes and get all waypoints created
 		fetchGraphData();
+		
+		// underlay is empty
+		if (waypoints.size() == 0) {
+			Alert alert = new Alert(AlertType.WARNING);
+			alert.setTitle("Warning");
+			alert.setHeaderText("Underlay Empty");
+			alert.setContentText("The referenced Underlay-Graph has no nodes to visualize");
+			alert.showAndWait();
+			
+			GeoPosition defaultGeoPos = new GeoPosition(OptionsManager.getDefaultLat(), OptionsManager.getDefaultLong());
+			nodePositions.add(defaultGeoPos);
+			
+			CustomWaypoint defaultWaypoint = new CustomWaypoint("", "", getDeviceTypeURL(""), "", defaultGeoPos);
+			waypoints.add(defaultWaypoint);
+			waypointsAsList.add(defaultWaypoint);
+		}
 
 		MapViewFunctions.initializeWaypointImages();
 
@@ -127,13 +146,13 @@ public class WorldView {
 		// Create a TileFactoryInfo for OpenStreetMap
 		TileFactoryInfo info = new OSMTileFactoryInfo();
 
-		CustomTileFactory tileFactory = new CustomTileFactory(info);
-		if (!internMapViewer.getTileFactory().equals(tileFactory)) {
+		if (!internMapViewer.getTileFactory().equals(null)) {
+			CustomTileFactory tileFactory = new CustomTileFactory(info);
 			internMapViewer.setTileFactory(tileFactory);
 		}
 
 		// Use 8 threads in parallel to load the tiles
-		tileFactory.setThreadPoolSize(8);
+		((CustomTileFactory) internMapViewer.getTileFactory()).setThreadPoolSize(8);
 
 		showAllWaypoints(nodePositions);
 
@@ -146,14 +165,7 @@ public class WorldView {
 			// "click on waypoints" listener
 			internMapViewer.addMouseListener(mapClickListener);
 		}
-		// update listener
-		else {
-			internMapViewer.removeMouseListener(mapClickListener);
-
-			mapClickListener = new CustomMapClickListener(internMapViewer);
-
-			internMapViewer.addMouseListener(mapClickListener);
-		}
+		
 
 		internMapViewer.repaint();
 
@@ -345,5 +357,17 @@ public class WorldView {
 	public static HashSet<CustomWaypoint> getWaypoints() {
 		return waypoints;
 	}
+	
+	public static HashSet<GeoPosition> getNodePositions() {
+		return nodePositions;
+	}
+	
+	public static HashSet<Edge> getEdges() {
+		return edges;
+	}
+	
+	public static ArrayList<CustomWaypoint> getWaypointsAsArrayList() {
+		return waypointsAsList;
+	}
 
 }