浏览代码

Fixed bugs in SymbolLayer, added button to center map

- selected nodes and edges shown correctly again
- fixed deselect bug
- added button to center map in symbolLayer
dominik 8 年之前
父节点
当前提交
6057ec5bd1

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

@@ -4,14 +4,17 @@ import java.awt.Event;
 import java.io.IOException;
 import java.net.URLConnection;
 import java.util.ArrayList;
+import java.util.HashSet;
 
 import org.graphstream.graph.implementations.Graphs;
+import org.jxmapviewer.viewer.GeoPosition;
 import org.jxmapviewer.viewer.WaypointPainter;
 
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.CustomMapClickListener;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.CustomWaypoint;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.CustomWaypointRenderer;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.MapViewFunctions;
@@ -88,6 +91,19 @@ public final class ButtonManager {
 			Main.getInstance().getGraphManager().zoomOut();
 		}
 	}
+	
+	/**
+	 * Handler for center map Button
+	 * @param event
+	 */
+	public static void centerMapAction(ActionEvent event) {
+		if (GraphDisplayManager.getCurrentLayer().equals(Layer.SYMBOL)) {
+			HashSet<GeoPosition> positions = new HashSet<GeoPosition>(WorldView.waypoints.size());
+			WorldView.waypoints.forEach((w) -> positions.add(w.getPosition()));
+			
+			WorldView.internMapViewer.zoomToBestFit(positions, 0.7);;
+		}
+	}
 
 	/**
 	 * After switching from symbol-layer to other layer show toolbox and make
@@ -119,9 +135,15 @@ public final class ButtonManager {
 			controller.pane.setMouseTransparent(false);
 			controller.swingNode.setMouseTransparent(false);
 			
-			// deselect graph element
+			// dont show center map Button
+			controller.centerMap.setVisible(false);
+			
+			// dont show properties of selected node or edge
 			PropertiesManager.showNewDataSet(null);
 			
+			// deselect current selected node or edge
+			CustomMapClickListener.deselectAll();
+			
 			// reset loaded images
 			MapViewFunctions.resetImageMap();
 
@@ -248,6 +270,9 @@ public final class ButtonManager {
 
 		// show VBox for map options
 		controller.symbolToolVBox.setVisible(true);
+		
+		// show center map Button
+		controller.centerMap.setVisible(true);
 
 		WorldView.loadWorldView();
 

+ 6 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GUIController.java

@@ -65,6 +65,8 @@ public class GUIController implements Initializable {
 	public Button zoomIn;
 	@FXML
 	public Button zoomOut;
+	@FXML
+	public Button centerMap;
 
 	@FXML
 	public Button underlayButton;
@@ -224,6 +226,9 @@ public class GUIController implements Initializable {
 	private void initializeZoomButtons() {
 		zoomIn.setOnAction((event) -> ButtonManager.zoomInAction(event));
 		zoomOut.setOnAction((event) -> ButtonManager.zoomOutAction(event));
+		centerMap.setOnAction((event) -> ButtonManager.centerMapAction(event));
+		
+		centerMap.setVisible(false);
 	}
 
 	/**
@@ -392,6 +397,7 @@ public class GUIController implements Initializable {
 
 		assert zoomIn != null : "fx:id=\"zoomIn\" was not injected: check your FXML file 'MainWindow.fxml'.";
 		assert zoomOut != null : "fx:id=\"zoomOut\" was not injected: check your FXML file 'MainWindow.fxml'.";
+		assert centerMap != null : "fx:id=\"centerMap\" was not injected: check your FXML file 'MainWindow.fxml'.";
 
 		assert underlayButton != null : "fx:id=\"underlayButton\" was not injected: check your FXML file 'MainWindow.fxml'.";
 		assert operatorButton != null : "fx:id=\"operatorButton\" was not injected: check your FXML file 'MainWindow.fxml'.";

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

@@ -9,6 +9,7 @@ import org.jxmapviewer.JXMapViewer;
 import org.jxmapviewer.input.MapClickListener;
 import org.jxmapviewer.viewer.GeoPosition;
 
+import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.GraphDisplayManager;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.PropertiesManager;
@@ -18,12 +19,17 @@ public class CustomMapClickListener extends MapClickListener {
 	/*
 	 * World view viewer
 	 */
-	private final JXMapViewer viewer;
+	private static JXMapViewer viewer;
 
 	/*
 	 * selected waypoint
 	 */
-	public static CustomWaypoint selected;
+	public static CustomWaypoint selectedNode;
+	
+	/*
+	 * selected edge
+	 */
+	public static Edge selectedEdge;
 
 	/*
 	 * all edges of the graph
@@ -43,14 +49,14 @@ public class CustomMapClickListener extends MapClickListener {
 	public CustomMapClickListener(JXMapViewer viewer) {
 		super(viewer);
 
-		this.viewer = viewer;
+		CustomMapClickListener.viewer = viewer;
 
 	}
 
 	@Override
 	public void mapClicked(GeoPosition arg0) {
 
-		Point2D clickedPoint = this.viewer.getTileFactory().geoToPixel(arg0, this.viewer.getZoom());
+		Point2D clickedPoint = CustomMapClickListener.viewer.getTileFactory().geoToPixel(arg0, CustomMapClickListener.viewer.getZoom());
 		Point2D nodePoint;
 
 		// a waypoint was clicked
@@ -58,7 +64,7 @@ public class CustomMapClickListener extends MapClickListener {
 
 		for (CustomWaypoint nodeWaypoint : CustomMapClickListener.waypoints) {
 			// transform GeoPosition to point on screen
-			nodePoint = this.viewer.getTileFactory().geoToPixel(nodeWaypoint.getPosition(), this.viewer.getZoom());
+			nodePoint = CustomMapClickListener.viewer.getTileFactory().geoToPixel(nodeWaypoint.getPosition(), CustomMapClickListener.viewer.getZoom());
 
 			boolean yChecked = false;
 
@@ -81,7 +87,7 @@ public class CustomMapClickListener extends MapClickListener {
 				// deselect old waypoint and select new clicked waypoint
 				deselectAll();
 				nodeWaypoint.select();
-				selected = nodeWaypoint;
+				selectedNode = nodeWaypoint;
 				viewer.repaint();
 				break;
 			}
@@ -105,18 +111,24 @@ public class CustomMapClickListener extends MapClickListener {
 
 				// Clicked point in 10 pixel range of line
 				if (line.ptLineDist(clickedPoint) < 10) {
+					
+					PropertiesManager.showNewDataSet(edge);
+					
 					deselectAll();
+					
 					if (!edge.hasAttribute("ui.map.selected"))
 						edge.addAttribute("ui.map.selected", true);
 					else
 						edge.changeAttribute("ui.map.selected", true);
-
-					PropertiesManager.showNewDataSet(edge);
+					
+					selectedEdge = edge;
 
 					viewer.repaint();
 					break;
 				} else {
-					edge.changeAttribute("ui.map.selected", false);
+					if(edge.hasAttribute("ui.map.selected")){
+						edge.changeAttribute("ui.map.selected", false);
+					}
 				}
 			}
 		}
@@ -127,13 +139,18 @@ public class CustomMapClickListener extends MapClickListener {
 	 * deselect all edges and the selected node
 	 */
 	public static void deselectAll() {
-		if (selected != null) {
-			selected.deselect();
-			selected = null;
+		if (selectedNode != null) {
+			
+			selectedNode.deselect();
+			selectedNode = null;
 		}
-		for (Edge edge : edges) {
-			edge.changeAttribute("ui.map.selected", false);
+		if(selectedEdge != null){
+			
+			selectedEdge.changeAttribute("ui.map.selected", false);
+			selectedEdge = null;
 		}
+		
+		viewer.repaint();
 	}
 
 }

+ 4 - 2
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/CustomWaypointRenderer.java

@@ -11,6 +11,8 @@ import java.awt.image.BufferedImage;
 import org.jxmapviewer.JXMapViewer;
 import org.jxmapviewer.viewer.WaypointRenderer;
 
+import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
+
 public class CustomWaypointRenderer implements WaypointRenderer<CustomWaypoint> {
 
 	/**
@@ -41,12 +43,12 @@ public class CustomWaypointRenderer implements WaypointRenderer<CustomWaypoint>
 	/**
 	 * the standard width of the shown images, after scaling it
 	 */
-	public static final int SCALEWIDTH = 60;
+	public static final int SCALEWIDTH = 50;
 
 	/**
 	 * the standard height of the shwon images, after scaling it
 	 */
-	public static final int SCALEHEIGHT = 60;
+	public static final int SCALEHEIGHT = 50;
 
 	@Override
 	public void paintWaypoint(Graphics2D g, JXMapViewer viewer, CustomWaypoint w) {

+ 0 - 6
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/EdgePainter.java

@@ -74,12 +74,6 @@ public class EdgePainter implements Painter<JXMapViewer> {
 			if (antiAlias)
 				g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 
-			// do the drawing
-			g.setColor(STANDARD);
-			g.setStroke(new BasicStroke(4));
-
-			drawRoute(g, mapViewer);
-
 			// do the drawing again
 			g.setColor(STANDARD);
 			g.setStroke(new BasicStroke(2));

+ 17 - 4
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/WorldView.java

@@ -35,6 +35,11 @@ public class WorldView {
 	 * waypointPointer of overlayPainter
 	 */
 	public static WaypointPainter<CustomWaypoint> waypointPainter;
+	
+	/*
+	 * mapClickListener, used to only initialize the Listener once
+	 */
+	public static CustomMapClickListener mapClickListener;
 
 	/*
 	 * GUIController with UI elements
@@ -116,7 +121,9 @@ public class WorldView {
 		}
 
 		CustomTileFactory tileFactory = new CustomTileFactory(info);
-		internMapViewer.setTileFactory(tileFactory);
+		if(!internMapViewer.getTileFactory().equals(tileFactory)){
+			internMapViewer.setTileFactory(tileFactory);
+		}
 
 		// Use 8 threads in parallel to load the tiles
 		tileFactory.setThreadPoolSize(8);
@@ -124,10 +131,16 @@ public class WorldView {
 		// set Zoom and Center to show all node positions
 		internMapViewer.zoomToBestFit(nodePositions, 0.7);
 
-		internMapViewer.setOverlayPainter(painter);
+		if(internMapViewer.getOverlayPainter() == null){
+			internMapViewer.setOverlayPainter(painter);
+		}
+		
+		if(mapClickListener == null){
+			mapClickListener = new CustomMapClickListener(internMapViewer);
 
-		// "click on waypoints" listener
-		internMapViewer.addMouseListener(new CustomMapClickListener(internMapViewer));
+			// "click on waypoints" listener
+			internMapViewer.addMouseListener(mapClickListener);
+		}
 
 		internMapViewer.repaint();
 	}

+ 2 - 1
scopviz/src/main/resources/MainWindow.fxml

@@ -17,7 +17,7 @@
 <?import javafx.scene.layout.StackPane?>
 <?import javafx.scene.layout.VBox?>
 
-<VBox minHeight="768.0" minWidth="1024.0" prefHeight="768.0" prefWidth="1024.0" stylesheets="@GUITheme.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.tu_darmstadt.informatik.tk.scopviz.ui.GUIController">
+<VBox minHeight="768.0" minWidth="1024.0" prefHeight="768.0" prefWidth="1024.0" stylesheets="@GUITheme.css" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.tu_darmstadt.informatik.tk.scopviz.ui.GUIController">
   <children>
     <MenuBar VBox.vgrow="NEVER">
       <menus>
@@ -126,6 +126,7 @@
                                     </Pane>
                                     <Button fx:id="zoomIn" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="30.0" prefWidth="30.0" text="+" textAlignment="JUSTIFY" AnchorPane.bottomAnchor="45.0" AnchorPane.rightAnchor="10.0" />
                                     <Button fx:id="zoomOut" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="30.0" prefWidth="30.0" text="-" textAlignment="JUSTIFY" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="10.0" />
+                                    <Button fx:id="centerMap" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="30.0" prefWidth="30.0" text="O" textAlignment="JUSTIFY" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="45.0" />
                                  </children>
                               </AnchorPane>
                             <AnchorPane SplitPane.resizableWithParent="false">