Browse Source

Merge remote-tracking branch 'origin/dominik'

Jan Enders 7 years ago
parent
commit
fe02d9552f

+ 1 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/MainWindow.fxml

@@ -33,7 +33,7 @@
             <MenuItem fx:id="save" accelerator="Shortcut+S" mnemonicParsing="false" text="Save" />
             <MenuItem fx:id="saveAs" accelerator="Shortcut+Shift+S" mnemonicParsing="false" text="Save As…" />
             <SeparatorMenuItem mnemonicParsing="false" />
-            <MenuItem fx:id="preferences" accelerator="Shortcut+P" mnemonicParsing="false" text="Preferences" />
+            <MenuItem fx:id="preferences" accelerator="Alt+ENTER" mnemonicParsing="false" text="Preferences" />
             <SeparatorMenuItem mnemonicParsing="false" />
             <MenuItem fx:id="quit" mnemonicParsing="false" text="Quit" />
           </items>

+ 5 - 5
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);
 
@@ -315,9 +315,9 @@ public final class ButtonManager {
 	 */
 	public static void showConnectionErrorMsg() {
 		Alert alert = new Alert(AlertType.WARNING);
-		alert.setTitle("Connection Error");
-		alert.setHeaderText("Could not reach OpenStreetMap server");
-		alert.setContentText(null);
+		alert.setTitle("Warning");
+		alert.setHeaderText("Connection Error");
+		alert.setContentText("Could not reach OpenStreetMap server");
 
 		alert.showAndWait();
 	}

+ 3 - 3
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/OptionsManager.java

@@ -228,9 +228,9 @@ public final class OptionsManager {
 		
 		// Alert window -> when problems with input
 		Alert alert = new Alert(AlertType.WARNING);
-		alert.setTitle("Preferences-Type Alert");
-		alert.setHeaderText("Some Input doesnt fit the Convention (INT for Smybol Layer, Double for Default GeoPosition)");
-		alert.setContentText(null);
+		alert.setTitle("Warning");
+		alert.setHeaderText("Preferences-Type Alert");
+		alert.setContentText("Some Input doesnt fit the Convention (INT for Smybol Layer, Double for Default GeoPosition)");
 
 		// set dialog
 		addPropDialog.getDialogPane().setContent(grid);

+ 3 - 3
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/PropertiesManager.java

@@ -467,9 +467,9 @@ public final class PropertiesManager {
 
 		// Alert window -> when problems with input
 		Alert alert = new Alert(AlertType.WARNING);
-		alert.setTitle("Property-Type Alert");
-		alert.setHeaderText("The selected Type doesnt fit the Input");
-		alert.setContentText(null);
+		alert.setTitle("Warning");
+		alert.setHeaderText("Property-Type Alert");
+		alert.setContentText("The selected Type doesnt fit the Input");
 
 		ButtonType addButtonType = new ButtonType("Confirm", ButtonData.OK_DONE);
 		addPropDialog.getDialogPane().getButtonTypes().addAll(addButtonType, ButtonType.CANCEL);

+ 0 - 8
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/KeyboardShortcuts.java

@@ -36,10 +36,6 @@ public final class KeyboardShortcuts {
 	final static KeyCombination rAltShift = new KeyCodeCombination(KeyCode.R, KeyCombination.ALT_DOWN,
 			KeyCombination.SHIFT_DOWN);
 
-	/**
-	 * preferences shortcut
-	 */
-	final static KeyCombination pCtrl = new KeyCodeCombination(KeyCode.P, KeyCombination.CONTROL_DOWN);
 
 	/**
 	 * Private constructor to prevent Instantiation.
@@ -118,10 +114,6 @@ public final class KeyboardShortcuts {
 
 			}
 
-			else if (pCtrl.match(event)) {
-				MenuBarManager.preferencesAction(new ActionEvent());
-			}
-
 			else if (event.getCode().equals(KeyCode.RIGHT)) {
 				if (GraphDisplayManager.getCurrentLayer().equals(Layer.SYMBOL)) {
 					MapViewFunctions.switchToNextWaypoint();

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

@@ -2,8 +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.jxmapviewer.JXMapViewer;
 import org.jxmapviewer.input.MapClickListener;
 import org.jxmapviewer.viewer.GeoPosition;
@@ -31,16 +29,6 @@ public class CustomMapClickListener extends MapClickListener {
 	 */
 	public static MyEdge selectedEdge;
 
-	/*
-	 * all edges of the graph
-	 */
-	private final static HashSet<MyEdge> edges = WorldView.edges;
-
-	/*
-	 * all waypoints of the graph
-	 */
-	private final static HashSet<CustomWaypoint> waypoints = WorldView.waypoints;
-
 	/**
 	 * Constructor sets viewer
 	 * 
@@ -84,7 +72,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 +112,7 @@ public class CustomMapClickListener extends MapClickListener {
 
 		MyEdge result = null;
 
-		for (MyEdge edge : CustomMapClickListener.edges) {
+		for (MyEdge 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));
 			}
 		}
 

+ 89 - 4
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 {
 
@@ -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);
 
@@ -183,7 +202,61 @@ public class WorldView {
 
 		internMapViewer.setZoom(1);
 
-		internMapViewer.calculateZoomFrom(positions);
+		if (positions.size() == 1) {
+			internMapViewer.setCenterPosition(positions.iterator().next());
+			return;
+		}
+
+		Double defaultLat = null;
+		Double defaultLong = null;
+		Boolean onLineLat = true;
+		Boolean onLineLong = true;
+
+		// geoPositions are all on one line -> JXMapViewer2 method doesnt work
+		for (GeoPosition geoPos : positions) {
+			if (defaultLat == null && defaultLong == null) {
+				defaultLat = geoPos.getLatitude();
+				defaultLong = geoPos.getLongitude();
+			}
+
+			// there is a geoPosition with a different Latitude then the last
+			// one
+			if (!defaultLat.equals(geoPos.getLatitude())) {
+				onLineLat = false;
+			}
+			// there is a geoPosition with a different Longitude then the last
+			// one
+			if (!defaultLong.equals(geoPos.getLongitude())) {
+				onLineLong = false;
+			}
+		}
+
+		// geoPositions all have the same Latitude
+		if (onLineLat && !onLineLong) {
+			HashSet<GeoPosition> newPositions = new HashSet<GeoPosition>();
+			newPositions.addAll(positions);
+
+			GeoPosition newGeoPos = new GeoPosition(positions.iterator().next().getLatitude() + 0.00001,
+					positions.iterator().next().getLongitude());
+			newPositions.add(newGeoPos);
+
+			internMapViewer.calculateZoomFrom(newPositions);
+
+		} else if (onLineLong && !onLineLat) {
+			// geoPositions all have the same Longitude
+			HashSet<GeoPosition> newPositions = new HashSet<GeoPosition>();
+			newPositions.addAll(positions);
+
+			GeoPosition newGeoPos = new GeoPosition(positions.iterator().next().getLatitude(),
+					positions.iterator().next().getLongitude() + 0.00001);
+			newPositions.add(newGeoPos);
+
+			internMapViewer.calculateZoomFrom(newPositions);
+
+		} else {
+			// geoPositions have different Latitude and Longitude
+			internMapViewer.calculateZoomFrom(positions);
+		}
 
 		positions.forEach((geoPos) -> points.add(internMapViewer.convertGeoPositionToPoint(geoPos)));
 
@@ -291,5 +364,17 @@ public class WorldView {
 	public static HashSet<CustomWaypoint> getWaypoints() {
 		return waypoints;
 	}
+	
+	public static HashSet<GeoPosition> getNodePositions() {
+		return nodePositions;
+	}
+	
+	public static HashSet<MyEdge> getEdges() {
+		return edges;
+	}
+	
+	public static ArrayList<CustomWaypoint> getWaypointsAsArrayList() {
+		return waypointsAsList;
+	}
 
 }